OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "chrome/browser/character_encoding.h" | 9 #include "chrome/browser/character_encoding.h" |
10 #include "chrome/browser/net/url_request_mock_util.h" | 10 #include "chrome/browser/net/url_request_mock_util.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 struct EncodingTestData { | 30 struct EncodingTestData { |
31 const char* file_name; | 31 const char* file_name; |
32 const char* encoding_name; | 32 const char* encoding_name; |
33 }; | 33 }; |
34 | 34 |
35 const EncodingTestData kEncodingTestDatas[] = { | 35 const EncodingTestData kEncodingTestDatas[] = { |
36 { "Big5.html", "Big5" }, | 36 { "Big5.html", "Big5" }, |
37 { "EUC-JP.html", "EUC-JP" }, | 37 { "EUC-JP.html", "EUC-JP" }, |
38 { "gb18030.html", "gb18030" }, | 38 { "gb18030.html", "gb18030" }, |
39 #if 0 | |
40 // Disable temporarily until Blink CL | |
41 // (https://codereview.chromium.org/655083002/) is relanded. | |
42 { "iso-8859-1.html", "windows-1252" }, | 39 { "iso-8859-1.html", "windows-1252" }, |
43 #endif | |
44 { "ISO-8859-2.html", "ISO-8859-2" }, | 40 { "ISO-8859-2.html", "ISO-8859-2" }, |
45 { "ISO-8859-4.html", "ISO-8859-4" }, | 41 { "ISO-8859-4.html", "ISO-8859-4" }, |
46 { "ISO-8859-5.html", "ISO-8859-5" }, | 42 { "ISO-8859-5.html", "ISO-8859-5" }, |
47 { "ISO-8859-6.html", "ISO-8859-6" }, | 43 { "ISO-8859-6.html", "ISO-8859-6" }, |
48 { "ISO-8859-7.html", "ISO-8859-7" }, | 44 { "ISO-8859-7.html", "ISO-8859-7" }, |
49 { "ISO-8859-8.html", "ISO-8859-8" }, | 45 { "ISO-8859-8.html", "ISO-8859-8" }, |
50 { "ISO-8859-13.html", "ISO-8859-13" }, | 46 { "ISO-8859-13.html", "ISO-8859-13" }, |
51 { "ISO-8859-15.html", "ISO-8859-15" }, | 47 { "ISO-8859-15.html", "ISO-8859-15" }, |
52 { "KOI8-R.html", "KOI8-R" }, | 48 { "KOI8-R.html", "KOI8-R" }, |
53 { "KOI8-U.html", "KOI8-U" }, | 49 { "KOI8-U.html", "KOI8-U" }, |
54 { "macintosh.html", "macintosh" }, | 50 { "macintosh.html", "macintosh" }, |
55 { "Shift-JIS.html", "Shift_JIS" }, | 51 { "Shift-JIS.html", "Shift_JIS" }, |
56 #if 0 | |
57 // See the above. | |
58 { "US-ASCII.html", "windows-1252" }, // http://crbug.com/15801 | 52 { "US-ASCII.html", "windows-1252" }, // http://crbug.com/15801 |
59 #endif | |
60 { "UTF-8.html", "UTF-8" }, | 53 { "UTF-8.html", "UTF-8" }, |
61 { "UTF-16LE.html", "UTF-16LE" }, | 54 { "UTF-16LE.html", "UTF-16LE" }, |
62 { "windows-874.html", "windows-874" }, | 55 { "windows-874.html", "windows-874" }, |
63 { "EUC-KR.html", "EUC-KR" }, | 56 { "EUC-KR.html", "EUC-KR" }, |
64 { "windows-1250.html", "windows-1250" }, | 57 { "windows-1250.html", "windows-1250" }, |
65 { "windows-1251.html", "windows-1251" }, | 58 { "windows-1251.html", "windows-1251" }, |
66 { "windows-1252.html", "windows-1252" }, | 59 { "windows-1252.html", "windows-1252" }, |
67 { "windows-1253.html", "windows-1253" }, | 60 { "windows-1253.html", "windows-1253" }, |
68 { "windows-1254.html", "windows-1254" }, | 61 { "windows-1254.html", "windows-1254" }, |
69 { "windows-1255.html", "windows-1255" }, | 62 { "windows-1255.html", "windows-1255" }, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 content::BrowserContext::GetDownloadManager(browser()->profile()), | 125 content::BrowserContext::GetDownloadManager(browser()->profile()), |
133 loop_runner->QuitClosure()); | 126 loop_runner->QuitClosure()); |
134 browser()->tab_strip_model()->GetActiveWebContents()->SavePage( | 127 browser()->tab_strip_model()->GetActiveWebContents()->SavePage( |
135 full_file_name, temp_sub_resource_dir_, | 128 full_file_name, temp_sub_resource_dir_, |
136 content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML); | 129 content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML); |
137 loop_runner->Run(); | 130 loop_runner->Run(); |
138 | 131 |
139 base::FilePath expected_file_name = ui_test_utils::GetTestFilePath( | 132 base::FilePath expected_file_name = ui_test_utils::GetTestFilePath( |
140 base::FilePath(kTestDir), expected); | 133 base::FilePath(kTestDir), expected); |
141 | 134 |
142 EXPECT_TRUE(base::ContentsEqual(full_file_name, expected_file_name)); | 135 EXPECT_TRUE(base::ContentsEqual(full_file_name, expected_file_name)) << |
| 136 "generated_file = " << full_file_name.AsUTF8Unsafe() << |
| 137 ", expected_file = " << expected_file_name.AsUTF8Unsafe(); |
143 } | 138 } |
144 | 139 |
145 virtual void SetUpOnMainThread() override { | 140 virtual void SetUpOnMainThread() override { |
146 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 141 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
147 save_dir_ = temp_dir_.path(); | 142 save_dir_ = temp_dir_.path(); |
148 temp_sub_resource_dir_ = save_dir_.AppendASCII("sub_resource_files"); | 143 temp_sub_resource_dir_ = save_dir_.AppendASCII("sub_resource_files"); |
149 | 144 |
150 BrowserThread::PostTask( | 145 BrowserThread::PostTask( |
151 BrowserThread::IO, FROM_HERE, | 146 BrowserThread::IO, FROM_HERE, |
152 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); | 147 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 "expected_gb18030_saved_from_iso88591_meta.html"; | 184 "expected_gb18030_saved_from_iso88591_meta.html"; |
190 const char* const kOverrideTestDir = "user_override"; | 185 const char* const kOverrideTestDir = "user_override"; |
191 | 186 |
192 base::FilePath test_dir_path = | 187 base::FilePath test_dir_path = |
193 base::FilePath(kTestDir).AppendASCII(kOverrideTestDir); | 188 base::FilePath(kTestDir).AppendASCII(kOverrideTestDir); |
194 test_dir_path = test_dir_path.AppendASCII(kTestFileName); | 189 test_dir_path = test_dir_path.AppendASCII(kTestFileName); |
195 GURL url = net::URLRequestMockHTTPJob::GetMockUrl(test_dir_path); | 190 GURL url = net::URLRequestMockHTTPJob::GetMockUrl(test_dir_path); |
196 ui_test_utils::NavigateToURL(browser(), url); | 191 ui_test_utils::NavigateToURL(browser(), url); |
197 content::WebContents* web_contents = | 192 content::WebContents* web_contents = |
198 browser()->tab_strip_model()->GetActiveWebContents(); | 193 browser()->tab_strip_model()->GetActiveWebContents(); |
199 #if 0 | |
200 // Temporarily disable until the Blink CL to use windows-1252 is relanded. | |
201 EXPECT_EQ("windows-1252", web_contents->GetEncoding()); | 194 EXPECT_EQ("windows-1252", web_contents->GetEncoding()); |
202 #endif | |
203 | 195 |
204 // Override the encoding to "gb18030". | 196 // Override the encoding to "gb18030". |
205 const std::string selected_encoding = | 197 const std::string selected_encoding = |
206 CharacterEncoding::GetCanonicalEncodingNameByAliasName("gb18030"); | 198 CharacterEncoding::GetCanonicalEncodingNameByAliasName("gb18030"); |
207 content::TestNavigationObserver navigation_observer(web_contents); | 199 content::TestNavigationObserver navigation_observer(web_contents); |
208 web_contents->SetOverrideEncoding(selected_encoding); | 200 web_contents->SetOverrideEncoding(selected_encoding); |
209 navigation_observer.Wait(); | 201 navigation_observer.Wait(); |
210 EXPECT_EQ("gb18030", web_contents->GetEncoding()); | 202 EXPECT_EQ("gb18030", web_contents->GetEncoding()); |
211 | 203 |
212 base::FilePath expected_filename = | 204 base::FilePath expected_filename = |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 const char* expected_result; // File name of expected results. | 236 const char* expected_result; // File name of expected results. |
245 const char* expected_encoding; // expected encoding. | 237 const char* expected_encoding; // expected encoding. |
246 }; | 238 }; |
247 const EncodingAutoDetectTestData kTestDatas[] = { | 239 const EncodingAutoDetectTestData kTestDatas[] = { |
248 { "Big5_with_no_encoding_specified.html", | 240 { "Big5_with_no_encoding_specified.html", |
249 "expected_Big5_saved_from_no_encoding_specified.html", | 241 "expected_Big5_saved_from_no_encoding_specified.html", |
250 "Big5" }, | 242 "Big5" }, |
251 { "gb18030_with_no_encoding_specified.html", | 243 { "gb18030_with_no_encoding_specified.html", |
252 "expected_gb18030_saved_from_no_encoding_specified.html", | 244 "expected_gb18030_saved_from_no_encoding_specified.html", |
253 "gb18030" }, | 245 "gb18030" }, |
254 #if 0 | |
255 // Disable until the Blink CL to use 'windows-1252' is relanded. | |
256 { "iso-8859-1_with_no_encoding_specified.html", | 246 { "iso-8859-1_with_no_encoding_specified.html", |
257 "expected_iso-8859-1_saved_from_no_encoding_specified.html", | 247 "expected_iso-8859-1_saved_from_no_encoding_specified.html", |
258 "windows-1252" }, | 248 "windows-1252" }, |
259 #endif | |
260 { "ISO-8859-5_with_no_encoding_specified.html", | 249 { "ISO-8859-5_with_no_encoding_specified.html", |
261 "expected_ISO-8859-5_saved_from_no_encoding_specified.html", | 250 "expected_ISO-8859-5_saved_from_no_encoding_specified.html", |
262 "ISO-8859-5" }, | 251 "ISO-8859-5" }, |
263 { "ISO-8859-6_with_no_encoding_specified.html", | 252 { "ISO-8859-6_with_no_encoding_specified.html", |
264 "expected_ISO-8859-6_saved_from_no_encoding_specified.html", | 253 "expected_ISO-8859-6_saved_from_no_encoding_specified.html", |
265 "ISO-8859-6" }, | 254 "ISO-8859-6" }, |
266 { "ISO-8859-7_with_no_encoding_specified.html", | 255 { "ISO-8859-7_with_no_encoding_specified.html", |
267 "expected_ISO-8859-7_saved_from_no_encoding_specified.html", | 256 "expected_ISO-8859-7_saved_from_no_encoding_specified.html", |
268 "ISO-8859-7" }, | 257 "ISO-8859-7" }, |
269 { "ISO-8859-8_with_no_encoding_specified.html", | 258 { "ISO-8859-8_with_no_encoding_specified.html", |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 | 325 |
337 // Dump the page, the content of dump page should be equal with our expect | 326 // Dump the page, the content of dump page should be equal with our expect |
338 // result file. | 327 // result file. |
339 base::FilePath expected_result_file_name = | 328 base::FilePath expected_result_file_name = |
340 base::FilePath().AppendASCII(kAutoDetectDir). | 329 base::FilePath().AppendASCII(kAutoDetectDir). |
341 AppendASCII(kExpectedResultDir). | 330 AppendASCII(kExpectedResultDir). |
342 AppendASCII(kTestDatas[i].expected_result); | 331 AppendASCII(kTestDatas[i].expected_result); |
343 SaveAndCompare(kTestDatas[i].test_file_name, expected_result_file_name); | 332 SaveAndCompare(kTestDatas[i].test_file_name, expected_result_file_name); |
344 } | 333 } |
345 } | 334 } |
OLD | NEW |