[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | #include <string> |
| 5 | |
| 6 | #include "base/file_util.h" |
[email protected] | e078590 | 2011-05-19 23:34:17 | [diff] [blame] | 7 | #include "base/scoped_temp_dir.h" |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 8 | #include "chrome/common/pref_names.h" |
[email protected] | 6f87032 | 2011-06-27 23:07:09 | [diff] [blame] | 9 | #include "chrome/test/automation/automation_proxy.h" |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 10 | #include "chrome/test/automation/browser_proxy.h" |
| 11 | #include "chrome/test/automation/tab_proxy.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 12 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 13 | #include "chrome/test/ui/ui_test.h" |
[email protected] | 0ffaa48 | 2011-07-14 23:41:28 | [diff] [blame] | 14 | #include "content/browser/download/save_package.h" |
[email protected] | 8aee8ed3 | 2011-06-14 20:16:41 | [diff] [blame] | 15 | #include "content/browser/net/url_request_mock_http_job.h" |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 16 | |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 17 | static const FilePath::CharType* kTestDir = FILE_PATH_LITERAL("encoding_tests"); |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 18 | |
| 19 | class BrowserEncodingTest : public UITest { |
| 20 | protected: |
| 21 | BrowserEncodingTest() : UITest() {} |
| 22 | |
| 23 | // Make sure the content of the page are as expected |
| 24 | // after override or auto-detect |
| 25 | void CheckFile(const FilePath& generated_file, |
| 26 | const FilePath& expected_result_file, |
| 27 | bool check_equal) { |
[email protected] | 5a145436 | 2010-03-31 08:56:47 | [diff] [blame] | 28 | FilePath expected_result_filepath = ui_test_utils::GetTestFilePath( |
| 29 | FilePath(kTestDir), expected_result_file); |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 30 | |
| 31 | ASSERT_TRUE(file_util::PathExists(expected_result_filepath)); |
| 32 | WaitForGeneratedFileAndCheck(generated_file, |
| 33 | expected_result_filepath, |
| 34 | true, // We do care whether they are equal. |
| 35 | check_equal, |
| 36 | true); // Delete the generated file when done. |
| 37 | } |
| 38 | |
| 39 | virtual void SetUp() { |
| 40 | UITest::SetUp(); |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 41 | ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 42 | save_dir_ = temp_dir_.path(); |
| 43 | temp_sub_resource_dir_ = save_dir_.AppendASCII("sub_resource_files"); |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 44 | } |
| 45 | |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 46 | ScopedTempDir temp_dir_; |
| 47 | FilePath save_dir_; |
| 48 | FilePath temp_sub_resource_dir_; |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | // TODO(jnd): 1. Some encodings are missing here. It'll be added later. See |
| 52 | // http://crbug.com/13306. |
| 53 | // 2. Add more files with multiple encoding name variants for each canonical |
| 54 | // encoding name). Webkit layout tests cover some, but testing in the UI test is |
| 55 | // also necessary. |
[email protected] | 37a17688 | 2011-05-13 23:00:25 | [diff] [blame] | 56 | |
| 57 | #if defined(OS_MACOSX) |
| 58 | #define TestEncodingAliasMapping FLAKY_TestEncodingAliasMapping |
| 59 | #endif |
[email protected] | ee4461f | 2010-09-29 09:53:58 | [diff] [blame] | 60 | TEST_F(BrowserEncodingTest, TestEncodingAliasMapping) { |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 61 | struct EncodingTestData { |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 62 | const char* file_name; |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 63 | const char* encoding_name; |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | const EncodingTestData kEncodingTestDatas[] = { |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 67 | { "Big5.html", "Big5" }, |
| 68 | { "EUC-JP.html", "EUC-JP" }, |
| 69 | { "gb18030.html", "gb18030" }, |
| 70 | { "iso-8859-1.html", "ISO-8859-1" }, |
| 71 | { "ISO-8859-2.html", "ISO-8859-2" }, |
| 72 | { "ISO-8859-4.html", "ISO-8859-4" }, |
| 73 | { "ISO-8859-5.html", "ISO-8859-5" }, |
| 74 | { "ISO-8859-6.html", "ISO-8859-6" }, |
| 75 | { "ISO-8859-7.html", "ISO-8859-7" }, |
| 76 | { "ISO-8859-8.html", "ISO-8859-8" }, |
| 77 | { "ISO-8859-13.html", "ISO-8859-13" }, |
| 78 | { "ISO-8859-15.html", "ISO-8859-15" }, |
| 79 | { "KOI8-R.html", "KOI8-R" }, |
| 80 | { "KOI8-U.html", "KOI8-U" }, |
| 81 | { "macintosh.html", "macintosh" }, |
| 82 | { "Shift-JIS.html", "Shift_JIS" }, |
[email protected] | f73ebdf | 2009-09-22 02:31:04 | [diff] [blame] | 83 | { "US-ASCII.html", "ISO-8859-1" }, // http://crbug.com/15801 |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 84 | { "UTF-8.html", "UTF-8" }, |
| 85 | { "UTF-16LE.html", "UTF-16LE" }, |
| 86 | { "windows-874.html", "windows-874" }, |
[email protected] | 7ebafde | 2011-09-09 03:38:31 | [diff] [blame] | 87 | // http://crbug.com/95963 |
| 88 | // { "windows-949.html", "windows-949" }, |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 89 | { "windows-1250.html", "windows-1250" }, |
| 90 | { "windows-1251.html", "windows-1251" }, |
| 91 | { "windows-1252.html", "windows-1252" }, |
| 92 | { "windows-1253.html", "windows-1253" }, |
| 93 | { "windows-1254.html", "windows-1254" }, |
| 94 | { "windows-1255.html", "windows-1255" }, |
| 95 | { "windows-1256.html", "windows-1256" }, |
| 96 | { "windows-1257.html", "windows-1257" }, |
| 97 | { "windows-1258.html", "windows-1258" } |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 98 | }; |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 99 | const char* const kAliasTestDir = "alias_mapping"; |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 100 | |
[email protected] | 9d6dcdf | 2010-03-26 16:12:10 | [diff] [blame] | 101 | scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); |
| 102 | ASSERT_TRUE(tab_proxy.get()); |
| 103 | |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 104 | FilePath test_dir_path = FilePath(kTestDir).AppendASCII(kAliasTestDir); |
[email protected] | d5360f638 | 2009-08-22 09:37:36 | [diff] [blame] | 105 | for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kEncodingTestDatas); ++i) { |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 106 | FilePath test_file_path(test_dir_path); |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 107 | test_file_path = test_file_path.AppendASCII( |
| 108 | kEncodingTestDatas[i].file_name); |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 109 | |
[email protected] | 9d6dcdf | 2010-03-26 16:12:10 | [diff] [blame] | 110 | NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(test_file_path)); |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 111 | |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 112 | std::string encoding; |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 113 | EXPECT_TRUE(tab_proxy->GetPageCurrentEncoding(&encoding)); |
[email protected] | 7ebafde | 2011-09-09 03:38:31 | [diff] [blame] | 114 | EXPECT_EQ(kEncodingTestDatas[i].encoding_name, encoding); |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 115 | } |
| 116 | } |
| 117 | |
[email protected] | e45b40f | 2010-05-20 18:14:07 | [diff] [blame] | 118 | // Marked as flaky: see http://crbug.com/44668 |
| 119 | TEST_F(BrowserEncodingTest, FLAKY_TestOverrideEncoding) { |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 120 | const char* const kTestFileName = "gb18030_with_iso88591_meta.html"; |
| 121 | const char* const kExpectedFileName = |
| 122 | "expected_gb18030_saved_from_iso88591_meta.html"; |
| 123 | const char* const kOverrideTestDir = "user_override"; |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 124 | |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 125 | FilePath test_dir_path = FilePath(kTestDir).AppendASCII(kOverrideTestDir); |
| 126 | test_dir_path = test_dir_path.AppendASCII(kTestFileName); |
[email protected] | 158a089 | 2009-10-14 20:32:19 | [diff] [blame] | 127 | GURL url = URLRequestMockHTTPJob::GetMockUrl(test_dir_path); |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 128 | scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); |
| 129 | ASSERT_TRUE(tab_proxy.get()); |
| 130 | ASSERT_TRUE(tab_proxy->NavigateToURL(url)); |
| 131 | WaitUntilTabCount(1); |
| 132 | |
| 133 | // Get the encoding declared in the page. |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 134 | std::string encoding; |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 135 | EXPECT_TRUE(tab_proxy->GetPageCurrentEncoding(&encoding)); |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 136 | EXPECT_EQ(encoding, "ISO-8859-1"); |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 137 | |
| 138 | // Override the encoding to "gb18030". |
| 139 | int64 last_nav_time = 0; |
| 140 | EXPECT_TRUE(tab_proxy->GetLastNavigationTime(&last_nav_time)); |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 141 | EXPECT_TRUE(tab_proxy->OverrideEncoding("gb18030")); |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 142 | EXPECT_TRUE(tab_proxy->WaitForNavigation(last_nav_time)); |
| 143 | |
| 144 | // Re-get the encoding of page. It should be gb18030. |
| 145 | EXPECT_TRUE(tab_proxy->GetPageCurrentEncoding(&encoding)); |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 146 | EXPECT_EQ(encoding, "gb18030"); |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 147 | |
| 148 | // Dump the page, the content of dump page should be identical to the |
| 149 | // expected result file. |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 150 | FilePath full_file_name = save_dir_.AppendASCII(kTestFileName); |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 151 | // We save the page as way of complete HTML file, which requires a directory |
| 152 | // name to save sub resources in it. Although this test file does not have |
| 153 | // sub resources, but the directory name is still required. |
[email protected] | 828cabe | 2009-09-26 22:47:11 | [diff] [blame] | 154 | EXPECT_TRUE(tab_proxy->SavePage(full_file_name, temp_sub_resource_dir_, |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 155 | SavePackage::SAVE_AS_COMPLETE_HTML)); |
| 156 | scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
| 157 | ASSERT_TRUE(browser.get()); |
[email protected] | faf2ee4 | 2010-05-11 14:26:17 | [diff] [blame] | 158 | EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get())); |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 159 | FilePath expected_file_name = FilePath().AppendASCII(kOverrideTestDir); |
| 160 | expected_file_name = expected_file_name.AppendASCII(kExpectedFileName); |
| 161 | CheckFile(full_file_name, expected_file_name, true); |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | // The following encodings are excluded from the auto-detection test because |
| 165 | // it's a known issue that the current encoding detector does not detect them: |
| 166 | // ISO-8859-4 |
| 167 | // ISO-8859-13 |
| 168 | // KOI8-U |
| 169 | // macintosh |
| 170 | // windows-874 |
| 171 | // windows-1252 |
| 172 | // windows-1253 |
| 173 | // windows-1257 |
| 174 | // windows-1258 |
| 175 | |
| 176 | // For Hebrew, the expected encoding value is ISO-8859-8-I. See |
| 177 | // http://crbug.com/2927 for more details. |
[email protected] | dbb0203e | 2010-10-20 07:58:29 | [diff] [blame] | 178 | // FLAKY / Disabled on CrOS: see http://crbug.com/44666 |
| 179 | #if defined(OS_CHROMEOS) |
| 180 | #define MAYBE_TestEncodingAutoDetect DISABLED_TestEncodingAutoDetect |
| 181 | #else |
| 182 | #define MAYBE_TestEncodingAutoDetect FLAKY_TestEncodingAutoDetect |
| 183 | #endif |
| 184 | |
| 185 | TEST_F(BrowserEncodingTest, MAYBE_TestEncodingAutoDetect) { |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 186 | struct EncodingAutoDetectTestData { |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 187 | const char* test_file_name; // File name of test data. |
| 188 | const char* expected_result; // File name of expected results. |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 189 | const char* expected_encoding; // expected encoding. |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 190 | }; |
| 191 | const EncodingAutoDetectTestData kTestDatas[] = { |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 192 | { "Big5_with_no_encoding_specified.html", |
| 193 | "expected_Big5_saved_from_no_encoding_specified.html", |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 194 | "Big5" }, |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 195 | { "gb18030_with_no_encoding_specified.html", |
| 196 | "expected_gb18030_saved_from_no_encoding_specified.html", |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 197 | "gb18030" }, |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 198 | { "iso-8859-1_with_no_encoding_specified.html", |
| 199 | "expected_iso-8859-1_saved_from_no_encoding_specified.html", |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 200 | "ISO-8859-1" }, |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 201 | { "ISO-8859-5_with_no_encoding_specified.html", |
| 202 | "expected_ISO-8859-5_saved_from_no_encoding_specified.html", |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 203 | "ISO-8859-5" }, |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 204 | { "ISO-8859-6_with_no_encoding_specified.html", |
| 205 | "expected_ISO-8859-6_saved_from_no_encoding_specified.html", |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 206 | "ISO-8859-6" }, |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 207 | { "ISO-8859-7_with_no_encoding_specified.html", |
| 208 | "expected_ISO-8859-7_saved_from_no_encoding_specified.html", |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 209 | "ISO-8859-7" }, |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 210 | { "ISO-8859-8_with_no_encoding_specified.html", |
| 211 | "expected_ISO-8859-8_saved_from_no_encoding_specified.html", |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 212 | "ISO-8859-8-I" }, |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 213 | { "KOI8-R_with_no_encoding_specified.html", |
| 214 | "expected_KOI8-R_saved_from_no_encoding_specified.html", |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 215 | "KOI8-R" }, |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 216 | { "Shift-JIS_with_no_encoding_specified.html", |
| 217 | "expected_Shift-JIS_saved_from_no_encoding_specified.html", |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 218 | "Shift_JIS" }, |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 219 | { "UTF-8_with_no_encoding_specified.html", |
| 220 | "expected_UTF-8_saved_from_no_encoding_specified.html", |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 221 | "UTF-8" }, |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 222 | { "windows-949_with_no_encoding_specified.html", |
| 223 | "expected_windows-949_saved_from_no_encoding_specified.html", |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 224 | "windows-949" }, |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 225 | { "windows-1251_with_no_encoding_specified.html", |
| 226 | "expected_windows-1251_saved_from_no_encoding_specified.html", |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 227 | "windows-1251" }, |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 228 | { "windows-1254_with_no_encoding_specified.html", |
| 229 | "expected_windows-1254_saved_from_no_encoding_specified.html", |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 230 | "windows-1254" }, |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 231 | { "windows-1255_with_no_encoding_specified.html", |
| 232 | "expected_windows-1255_saved_from_no_encoding_specified.html", |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 233 | "windows-1255" }, |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 234 | { "windows-1256_with_no_encoding_specified.html", |
| 235 | "expected_windows-1256_saved_from_no_encoding_specified.html", |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 236 | "windows-1256" } |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 237 | }; |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 238 | const char* const kAutoDetectDir = "auto_detect"; |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 239 | // Directory of the files of expected results. |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 240 | const char* const kExpectedResultDir = "expected_results"; |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 241 | |
| 242 | // Full path of saved file. full_file_name = save_dir_ + file_name[i]; |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 243 | FilePath full_saved_file_name; |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 244 | |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 245 | FilePath test_dir_path = FilePath(kTestDir).AppendASCII(kAutoDetectDir); |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 246 | |
[email protected] | f73ebdf | 2009-09-22 02:31:04 | [diff] [blame] | 247 | scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
| 248 | ASSERT_TRUE(browser.get()); |
| 249 | // Set the default charset to one of encodings not supported by the current |
| 250 | // auto-detector (Please refer to the above comments) to make sure we |
| 251 | // incorrectly decode the page. Now we use ISO-8859-4. |
[email protected] | 6fd3535 | 2010-03-16 08:39:54 | [diff] [blame] | 252 | ASSERT_TRUE(browser->SetStringPreference(prefs::kDefaultCharset, |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 253 | "ISO-8859-4")); |
[email protected] | f73ebdf | 2009-09-22 02:31:04 | [diff] [blame] | 254 | scoped_refptr<TabProxy> tab(GetActiveTab()); |
| 255 | ASSERT_TRUE(tab.get()); |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 256 | |
[email protected] | f73ebdf | 2009-09-22 02:31:04 | [diff] [blame] | 257 | for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestDatas);i++) { |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 258 | FilePath test_file_path(test_dir_path); |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 259 | test_file_path = test_file_path.AppendASCII(kTestDatas[i].test_file_name); |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 260 | GURL url = |
[email protected] | 158a089 | 2009-10-14 20:32:19 | [diff] [blame] | 261 | URLRequestMockHTTPJob::GetMockUrl(test_file_path); |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 262 | ASSERT_TRUE(tab->NavigateToURL(url)); |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 263 | |
| 264 | // Disable auto detect if it is on. |
| 265 | EXPECT_TRUE( |
| 266 | browser->SetBooleanPreference(prefs::kWebKitUsesUniversalDetector, |
| 267 | false)); |
| 268 | EXPECT_TRUE(tab->Reload()); |
| 269 | |
| 270 | // Get the encoding used for the page, it must be the default charset we |
| 271 | // just set. |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 272 | std::string encoding; |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 273 | EXPECT_TRUE(tab->GetPageCurrentEncoding(&encoding)); |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 274 | EXPECT_EQ(encoding, "ISO-8859-4"); |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 275 | |
| 276 | // Enable the encoding auto detection. |
| 277 | EXPECT_TRUE(browser->SetBooleanPreference( |
| 278 | prefs::kWebKitUsesUniversalDetector, true)); |
| 279 | EXPECT_TRUE(tab->Reload()); |
| 280 | |
| 281 | // Re-get the encoding of page. It should return the real encoding now. |
| 282 | bool encoding_auto_detect = false; |
| 283 | EXPECT_TRUE( |
| 284 | browser->GetBooleanPreference(prefs::kWebKitUsesUniversalDetector, |
| 285 | &encoding_auto_detect)); |
| 286 | EXPECT_TRUE(encoding_auto_detect); |
| 287 | EXPECT_TRUE(tab->GetPageCurrentEncoding(&encoding)); |
| 288 | EXPECT_EQ(encoding, kTestDatas[i].expected_encoding); |
| 289 | |
| 290 | // Dump the page, the content of dump page should be equal with our expect |
| 291 | // result file. |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 292 | full_saved_file_name = save_dir_.AppendASCII(kTestDatas[i].test_file_name); |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 293 | // Full path of expect result file. |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 294 | FilePath expected_result_file_name = FilePath().AppendASCII(kAutoDetectDir); |
| 295 | expected_result_file_name = expected_result_file_name.AppendASCII( |
| 296 | kExpectedResultDir); |
| 297 | expected_result_file_name = expected_result_file_name.AppendASCII( |
| 298 | kTestDatas[i].expected_result); |
[email protected] | 828cabe | 2009-09-26 22:47:11 | [diff] [blame] | 299 | EXPECT_TRUE(tab->SavePage(full_saved_file_name, temp_sub_resource_dir_, |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 300 | SavePackage::SAVE_AS_COMPLETE_HTML)); |
[email protected] | faf2ee4 | 2010-05-11 14:26:17 | [diff] [blame] | 301 | EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get())); |
[email protected] | 719f973 | 2009-09-02 05:04:57 | [diff] [blame] | 302 | CheckFile(full_saved_file_name, expected_result_file_name, true); |
[email protected] | 8a60939 | 2009-08-22 08:28:47 | [diff] [blame] | 303 | } |
| 304 | } |