| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "chrome/browser/character_encoding.h" | |
| 13 #include "chrome/browser/net/url_request_mock_util.h" | 12 #include "chrome/browser/net/url_request_mock_util.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_commands.h" | 15 #include "chrome/browser/ui/browser_commands.h" |
| 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 18 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 19 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
| 20 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
| 21 #include "components/prefs/pref_service.h" | 20 #include "components/prefs/pref_service.h" |
| 22 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 ui_test_utils::NavigateToURL(browser(), url); | 174 ui_test_utils::NavigateToURL(browser(), url); |
| 176 EXPECT_EQ(GetParam().encoding_name, | 175 EXPECT_EQ(GetParam().encoding_name, |
| 177 browser()->tab_strip_model()->GetActiveWebContents()-> | 176 browser()->tab_strip_model()->GetActiveWebContents()-> |
| 178 GetEncoding()); | 177 GetEncoding()); |
| 179 } | 178 } |
| 180 | 179 |
| 181 INSTANTIATE_TEST_CASE_P(EncodingAliases, | 180 INSTANTIATE_TEST_CASE_P(EncodingAliases, |
| 182 BrowserEncodingTest, | 181 BrowserEncodingTest, |
| 183 testing::ValuesIn(kEncodingTestDatas)); | 182 testing::ValuesIn(kEncodingTestDatas)); |
| 184 | 183 |
| 185 // Marked as flaky: see http://crbug.com/44668 | |
| 186 IN_PROC_BROWSER_TEST_F(BrowserEncodingTest, DISABLED_TestOverrideEncoding) { | |
| 187 const char* const kTestFileName = "gb18030_with_iso88591_meta.html"; | |
| 188 const char* const kExpectedFileName = | |
| 189 "expected_gb18030_saved_from_iso88591_meta.html"; | |
| 190 const char* const kOverrideTestDir = "user_override"; | |
| 191 | |
| 192 base::FilePath test_dir_path = | |
| 193 base::FilePath(kTestDir).AppendASCII(kOverrideTestDir); | |
| 194 test_dir_path = test_dir_path.AppendASCII(kTestFileName); | |
| 195 GURL url = | |
| 196 net::URLRequestMockHTTPJob::GetMockUrl(test_dir_path.MaybeAsASCII()); | |
| 197 ui_test_utils::NavigateToURL(browser(), url); | |
| 198 content::WebContents* web_contents = | |
| 199 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 200 EXPECT_EQ("windows-1252", web_contents->GetEncoding()); | |
| 201 | |
| 202 // Override the encoding to "gb18030". | |
| 203 const std::string selected_encoding = | |
| 204 CharacterEncoding::GetCanonicalEncodingNameByAliasName("gb18030"); | |
| 205 content::TestNavigationObserver navigation_observer(web_contents); | |
| 206 web_contents->SetOverrideEncoding(selected_encoding); | |
| 207 navigation_observer.Wait(); | |
| 208 EXPECT_EQ("gb18030", web_contents->GetEncoding()); | |
| 209 | |
| 210 base::FilePath expected_filename = | |
| 211 base::FilePath().AppendASCII(kOverrideTestDir).AppendASCII( | |
| 212 kExpectedFileName); | |
| 213 SaveAndCompare(kTestFileName, expected_filename); | |
| 214 } | |
| 215 | |
| 216 // The following encodings are excluded from the auto-detection test because | 184 // The following encodings are excluded from the auto-detection test because |
| 217 // it's a known issue that the current encoding detector does not detect them: | 185 // it's a known issue that the current encoding detector does not detect them: |
| 218 // ISO-8859-4 | 186 // ISO-8859-4 |
| 219 // ISO-8859-13 | 187 // ISO-8859-13 |
| 220 // KOI8-U | 188 // KOI8-U |
| 221 // macintosh | 189 // macintosh |
| 222 // windows-874 | 190 // windows-874 |
| 223 // windows-1252 | 191 // windows-1252 |
| 224 // windows-1253 | 192 // windows-1253 |
| 225 // windows-1257 | 193 // windows-1257 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 | 267 |
| 300 // Set the default charset to one of encodings not supported by the current | 268 // Set the default charset to one of encodings not supported by the current |
| 301 // auto-detector (Please refer to the above comments) to make sure we | 269 // auto-detector (Please refer to the above comments) to make sure we |
| 302 // incorrectly decode the page. Now we use ISO-8859-4. | 270 // incorrectly decode the page. Now we use ISO-8859-4. |
| 303 browser()->profile()->GetPrefs()->SetString(prefs::kDefaultCharset, | 271 browser()->profile()->GetPrefs()->SetString(prefs::kDefaultCharset, |
| 304 "ISO-8859-4"); | 272 "ISO-8859-4"); |
| 305 | 273 |
| 306 content::WebContents* web_contents = | 274 content::WebContents* web_contents = |
| 307 browser()->tab_strip_model()->GetActiveWebContents(); | 275 browser()->tab_strip_model()->GetActiveWebContents(); |
| 308 for (size_t i = 0; i < arraysize(kTestDatas); ++i) { | 276 for (size_t i = 0; i < arraysize(kTestDatas); ++i) { |
| 309 // Disable auto detect if it is on. | 277 // Enable auto detect. |
| 310 browser()->profile()->GetPrefs()->SetBoolean( | 278 browser()->profile()->GetPrefs()->SetBoolean( |
| 311 prefs::kWebKitUsesUniversalDetector, false); | 279 prefs::kWebKitUsesUniversalDetector, true); |
| 312 | 280 |
| 313 base::FilePath test_file_path(test_dir_path); | 281 base::FilePath test_file_path(test_dir_path); |
| 314 test_file_path = test_file_path.AppendASCII(kTestDatas[i].test_file_name); | 282 test_file_path = test_file_path.AppendASCII(kTestDatas[i].test_file_name); |
| 315 GURL url = | 283 GURL url = |
| 316 net::URLRequestMockHTTPJob::GetMockUrl(test_file_path.MaybeAsASCII()); | 284 net::URLRequestMockHTTPJob::GetMockUrl(test_file_path.MaybeAsASCII()); |
| 317 ui_test_utils::NavigateToURL(browser(), url); | 285 ui_test_utils::NavigateToURL(browser(), url); |
| 318 | 286 |
| 319 // Get the encoding used for the page, it must be the default charset we | 287 // Get the encoding of page. It should return the real encoding now. |
| 320 // just set. | |
| 321 EXPECT_EQ("ISO-8859-4", web_contents->GetEncoding()); | |
| 322 | |
| 323 // Enable the encoding auto detection. | |
| 324 browser()->profile()->GetPrefs()->SetBoolean( | |
| 325 prefs::kWebKitUsesUniversalDetector, true); | |
| 326 | |
| 327 content::TestNavigationObserver observer(web_contents); | |
| 328 chrome::Reload(browser(), CURRENT_TAB); | |
| 329 observer.Wait(); | |
| 330 | |
| 331 // Re-get the encoding of page. It should return the real encoding now. | |
| 332 EXPECT_EQ(kTestDatas[i].expected_encoding, web_contents->GetEncoding()); | 288 EXPECT_EQ(kTestDatas[i].expected_encoding, web_contents->GetEncoding()); |
| 333 | 289 |
| 334 // Dump the page, the content of dump page should be equal with our expect | 290 // Dump the page, the content of dump page should be equal with our expect |
| 335 // result file. | 291 // result file. |
| 336 base::FilePath expected_result_file_name = | 292 base::FilePath expected_result_file_name = |
| 337 base::FilePath().AppendASCII(kAutoDetectDir). | 293 base::FilePath().AppendASCII(kAutoDetectDir). |
| 338 AppendASCII(kExpectedResultDir). | 294 AppendASCII(kExpectedResultDir). |
| 339 AppendASCII(kTestDatas[i].expected_result); | 295 AppendASCII(kTestDatas[i].expected_result); |
| 340 SaveAndCompare(kTestDatas[i].test_file_name, expected_result_file_name); | 296 SaveAndCompare(kTestDatas[i].test_file_name, expected_result_file_name); |
| 341 } | 297 } |
| 342 } | 298 } |
| OLD | NEW |