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" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_commands.h" | 13 #include "chrome/browser/ui/browser_commands.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
16 #include "chrome/test/base/in_process_browser_test.h" | 16 #include "chrome/test/base/in_process_browser_test.h" |
17 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/browser/download_manager.h" | 19 #include "content/public/browser/download_manager.h" |
20 #include "content/public/browser/navigation_controller.h" | 20 #include "content/public/browser/navigation_controller.h" |
21 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
22 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
23 #include "content/public/browser/notification_types.h" | 23 #include "content/public/browser/notification_types.h" |
24 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
25 #include "content/public/test/test_navigation_observer.h" | 25 #include "content/public/test/test_navigation_observer.h" |
26 #include "content/test/net/url_request_mock_http_job.h" | 26 #include "net/test/url_request/url_request_mock_http_job.h" |
27 | 27 |
28 namespace { | 28 namespace { |
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" }, |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 // also necessary. | 157 // also necessary. |
158 IN_PROC_BROWSER_TEST_P(BrowserEncodingTest, TestEncodingAliasMapping) { | 158 IN_PROC_BROWSER_TEST_P(BrowserEncodingTest, TestEncodingAliasMapping) { |
159 const char* const kAliasTestDir = "alias_mapping"; | 159 const char* const kAliasTestDir = "alias_mapping"; |
160 | 160 |
161 base::FilePath test_dir_path = base::FilePath(kTestDir).AppendASCII( | 161 base::FilePath test_dir_path = base::FilePath(kTestDir).AppendASCII( |
162 kAliasTestDir); | 162 kAliasTestDir); |
163 base::FilePath test_file_path(test_dir_path); | 163 base::FilePath test_file_path(test_dir_path); |
164 test_file_path = test_file_path.AppendASCII( | 164 test_file_path = test_file_path.AppendASCII( |
165 GetParam().file_name); | 165 GetParam().file_name); |
166 | 166 |
167 GURL url = content::URLRequestMockHTTPJob::GetMockUrl(test_file_path); | 167 GURL url = net::URLRequestMockHTTPJob::GetMockUrl(test_file_path); |
168 ui_test_utils::NavigateToURL(browser(), url); | 168 ui_test_utils::NavigateToURL(browser(), url); |
169 EXPECT_EQ(GetParam().encoding_name, | 169 EXPECT_EQ(GetParam().encoding_name, |
170 browser()->tab_strip_model()->GetActiveWebContents()-> | 170 browser()->tab_strip_model()->GetActiveWebContents()-> |
171 GetEncoding()); | 171 GetEncoding()); |
172 } | 172 } |
173 | 173 |
174 INSTANTIATE_TEST_CASE_P(EncodingAliases, | 174 INSTANTIATE_TEST_CASE_P(EncodingAliases, |
175 BrowserEncodingTest, | 175 BrowserEncodingTest, |
176 testing::ValuesIn(kEncodingTestDatas)); | 176 testing::ValuesIn(kEncodingTestDatas)); |
177 | 177 |
178 // Marked as flaky: see http://crbug.com/44668 | 178 // Marked as flaky: see http://crbug.com/44668 |
179 IN_PROC_BROWSER_TEST_F(BrowserEncodingTest, TestOverrideEncoding) { | 179 IN_PROC_BROWSER_TEST_F(BrowserEncodingTest, TestOverrideEncoding) { |
180 const char* const kTestFileName = "gb18030_with_iso88591_meta.html"; | 180 const char* const kTestFileName = "gb18030_with_iso88591_meta.html"; |
181 const char* const kExpectedFileName = | 181 const char* const kExpectedFileName = |
182 "expected_gb18030_saved_from_iso88591_meta.html"; | 182 "expected_gb18030_saved_from_iso88591_meta.html"; |
183 const char* const kOverrideTestDir = "user_override"; | 183 const char* const kOverrideTestDir = "user_override"; |
184 | 184 |
185 base::FilePath test_dir_path = | 185 base::FilePath test_dir_path = |
186 base::FilePath(kTestDir).AppendASCII(kOverrideTestDir); | 186 base::FilePath(kTestDir).AppendASCII(kOverrideTestDir); |
187 test_dir_path = test_dir_path.AppendASCII(kTestFileName); | 187 test_dir_path = test_dir_path.AppendASCII(kTestFileName); |
188 GURL url = content::URLRequestMockHTTPJob::GetMockUrl(test_dir_path); | 188 GURL url = net::URLRequestMockHTTPJob::GetMockUrl(test_dir_path); |
189 ui_test_utils::NavigateToURL(browser(), url); | 189 ui_test_utils::NavigateToURL(browser(), url); |
190 content::WebContents* web_contents = | 190 content::WebContents* web_contents = |
191 browser()->tab_strip_model()->GetActiveWebContents(); | 191 browser()->tab_strip_model()->GetActiveWebContents(); |
192 EXPECT_EQ("ISO-8859-1", web_contents->GetEncoding()); | 192 EXPECT_EQ("ISO-8859-1", web_contents->GetEncoding()); |
193 | 193 |
194 // Override the encoding to "gb18030". | 194 // Override the encoding to "gb18030". |
195 const std::string selected_encoding = | 195 const std::string selected_encoding = |
196 CharacterEncoding::GetCanonicalEncodingNameByAliasName("gb18030"); | 196 CharacterEncoding::GetCanonicalEncodingNameByAliasName("gb18030"); |
197 content::TestNavigationObserver navigation_observer(web_contents); | 197 content::TestNavigationObserver navigation_observer(web_contents); |
198 web_contents->SetOverrideEncoding(selected_encoding); | 198 web_contents->SetOverrideEncoding(selected_encoding); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 | 296 |
297 content::WebContents* web_contents = | 297 content::WebContents* web_contents = |
298 browser()->tab_strip_model()->GetActiveWebContents(); | 298 browser()->tab_strip_model()->GetActiveWebContents(); |
299 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestDatas); ++i) { | 299 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestDatas); ++i) { |
300 // Disable auto detect if it is on. | 300 // Disable auto detect if it is on. |
301 browser()->profile()->GetPrefs()->SetBoolean( | 301 browser()->profile()->GetPrefs()->SetBoolean( |
302 prefs::kWebKitUsesUniversalDetector, false); | 302 prefs::kWebKitUsesUniversalDetector, false); |
303 | 303 |
304 base::FilePath test_file_path(test_dir_path); | 304 base::FilePath test_file_path(test_dir_path); |
305 test_file_path = test_file_path.AppendASCII(kTestDatas[i].test_file_name); | 305 test_file_path = test_file_path.AppendASCII(kTestDatas[i].test_file_name); |
306 GURL url = content::URLRequestMockHTTPJob::GetMockUrl(test_file_path); | 306 GURL url = net::URLRequestMockHTTPJob::GetMockUrl(test_file_path); |
307 ui_test_utils::NavigateToURL(browser(), url); | 307 ui_test_utils::NavigateToURL(browser(), url); |
308 | 308 |
309 // Get the encoding used for the page, it must be the default charset we | 309 // Get the encoding used for the page, it must be the default charset we |
310 // just set. | 310 // just set. |
311 EXPECT_EQ("ISO-8859-4", web_contents->GetEncoding()); | 311 EXPECT_EQ("ISO-8859-4", web_contents->GetEncoding()); |
312 | 312 |
313 // Enable the encoding auto detection. | 313 // Enable the encoding auto detection. |
314 browser()->profile()->GetPrefs()->SetBoolean( | 314 browser()->profile()->GetPrefs()->SetBoolean( |
315 prefs::kWebKitUsesUniversalDetector, true); | 315 prefs::kWebKitUsesUniversalDetector, true); |
316 | 316 |
317 content::TestNavigationObserver observer(web_contents); | 317 content::TestNavigationObserver observer(web_contents); |
318 chrome::Reload(browser(), CURRENT_TAB); | 318 chrome::Reload(browser(), CURRENT_TAB); |
319 observer.Wait(); | 319 observer.Wait(); |
320 | 320 |
321 // Re-get the encoding of page. It should return the real encoding now. | 321 // Re-get the encoding of page. It should return the real encoding now. |
322 EXPECT_EQ(kTestDatas[i].expected_encoding, web_contents->GetEncoding()); | 322 EXPECT_EQ(kTestDatas[i].expected_encoding, web_contents->GetEncoding()); |
323 | 323 |
324 // Dump the page, the content of dump page should be equal with our expect | 324 // Dump the page, the content of dump page should be equal with our expect |
325 // result file. | 325 // result file. |
326 base::FilePath expected_result_file_name = | 326 base::FilePath expected_result_file_name = |
327 base::FilePath().AppendASCII(kAutoDetectDir). | 327 base::FilePath().AppendASCII(kAutoDetectDir). |
328 AppendASCII(kExpectedResultDir). | 328 AppendASCII(kExpectedResultDir). |
329 AppendASCII(kTestDatas[i].expected_result); | 329 AppendASCII(kTestDatas[i].expected_result); |
330 SaveAndCompare(kTestDatas[i].test_file_name, expected_result_file_name); | 330 SaveAndCompare(kTestDatas[i].test_file_name, expected_result_file_name); |
331 } | 331 } |
332 } | 332 } |
OLD | NEW |