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/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/scoped_temp_dir.h" | 7 #include "base/scoped_temp_dir.h" |
8 #include "chrome/browser/character_encoding.h" | 8 #include "chrome/browser/character_encoding.h" |
9 #include "chrome/browser/net/url_request_mock_util.h" | 9 #include "chrome/browser/net/url_request_mock_util.h" |
10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.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/browser_tabstrip.h" |
14 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
15 #include "chrome/test/base/in_process_browser_test.h" | 16 #include "chrome/test/base/in_process_browser_test.h" |
16 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/browser/navigation_controller.h" | 19 #include "content/public/browser/navigation_controller.h" |
19 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
20 #include "content/public/browser/notification_source.h" | 21 #include "content/public/browser/notification_source.h" |
21 #include "content/public/browser/notification_types.h" | 22 #include "content/public/browser/notification_types.h" |
22 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
23 #include "content/public/test/test_navigation_observer.h" | 24 #include "content/public/test/test_navigation_observer.h" |
(...skipping 12 matching lines...) Expand all Loading... |
36 void SaveAndCompare(const char* filename_to_write, const FilePath& expected) { | 37 void SaveAndCompare(const char* filename_to_write, const FilePath& expected) { |
37 // Dump the page, the content of dump page should be identical to the | 38 // Dump the page, the content of dump page should be identical to the |
38 // expected result file. | 39 // expected result file. |
39 FilePath full_file_name = save_dir_.AppendASCII(filename_to_write); | 40 FilePath full_file_name = save_dir_.AppendASCII(filename_to_write); |
40 // We save the page as way of complete HTML file, which requires a directory | 41 // We save the page as way of complete HTML file, which requires a directory |
41 // name to save sub resources in it. Although this test file does not have | 42 // name to save sub resources in it. Although this test file does not have |
42 // sub resources, but the directory name is still required. | 43 // sub resources, but the directory name is still required. |
43 ui_test_utils::WindowedNotificationObserver observer( | 44 ui_test_utils::WindowedNotificationObserver observer( |
44 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, | 45 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, |
45 content::NotificationService::AllSources()); | 46 content::NotificationService::AllSources()); |
46 browser()->GetActiveWebContents()->SavePage( | 47 chrome::GetActiveWebContents(browser())->SavePage( |
47 full_file_name, temp_sub_resource_dir_, | 48 full_file_name, temp_sub_resource_dir_, |
48 content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML); | 49 content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML); |
49 observer.Wait(); | 50 observer.Wait(); |
50 | 51 |
51 FilePath expected_file_name = ui_test_utils::GetTestFilePath( | 52 FilePath expected_file_name = ui_test_utils::GetTestFilePath( |
52 FilePath(kTestDir), expected); | 53 FilePath(kTestDir), expected); |
53 | 54 |
54 EXPECT_TRUE(file_util::ContentsEqual(full_file_name, expected_file_name)); | 55 EXPECT_TRUE(file_util::ContentsEqual(full_file_name, expected_file_name)); |
55 } | 56 } |
56 | 57 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 GURL url = URLRequestMockHTTPJob::GetMockUrl(test_file_path); | 133 GURL url = URLRequestMockHTTPJob::GetMockUrl(test_file_path); |
133 | 134 |
134 // When looping through all the above files in one WebContents, there's a | 135 // When looping through all the above files in one WebContents, there's a |
135 // race condition on Windows trybots that causes the previous encoding to be | 136 // race condition on Windows trybots that causes the previous encoding to be |
136 // seen sometimes. Create a new tab for each one. http://crbug.com/122053 | 137 // seen sometimes. Create a new tab for each one. http://crbug.com/122053 |
137 ui_test_utils::NavigateToURLWithDisposition( | 138 ui_test_utils::NavigateToURLWithDisposition( |
138 browser(), url, NEW_FOREGROUND_TAB, | 139 browser(), url, NEW_FOREGROUND_TAB, |
139 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 140 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
140 | 141 |
141 EXPECT_EQ(kEncodingTestDatas[i].encoding_name, | 142 EXPECT_EQ(kEncodingTestDatas[i].encoding_name, |
142 browser()->GetActiveWebContents()->GetEncoding()); | 143 chrome::GetActiveWebContents(browser())->GetEncoding()); |
143 chrome::CloseTab(browser()); | 144 chrome::CloseTab(browser()); |
144 } | 145 } |
145 } | 146 } |
146 | 147 |
147 // Marked as flaky: see http://crbug.com/44668 | 148 // Marked as flaky: see http://crbug.com/44668 |
148 IN_PROC_BROWSER_TEST_F(BrowserEncodingTest, TestOverrideEncoding) { | 149 IN_PROC_BROWSER_TEST_F(BrowserEncodingTest, TestOverrideEncoding) { |
149 const char* const kTestFileName = "gb18030_with_iso88591_meta.html"; | 150 const char* const kTestFileName = "gb18030_with_iso88591_meta.html"; |
150 const char* const kExpectedFileName = | 151 const char* const kExpectedFileName = |
151 "expected_gb18030_saved_from_iso88591_meta.html"; | 152 "expected_gb18030_saved_from_iso88591_meta.html"; |
152 const char* const kOverrideTestDir = "user_override"; | 153 const char* const kOverrideTestDir = "user_override"; |
153 | 154 |
154 FilePath test_dir_path = FilePath(kTestDir).AppendASCII(kOverrideTestDir); | 155 FilePath test_dir_path = FilePath(kTestDir).AppendASCII(kOverrideTestDir); |
155 test_dir_path = test_dir_path.AppendASCII(kTestFileName); | 156 test_dir_path = test_dir_path.AppendASCII(kTestFileName); |
156 GURL url = URLRequestMockHTTPJob::GetMockUrl(test_dir_path); | 157 GURL url = URLRequestMockHTTPJob::GetMockUrl(test_dir_path); |
157 ui_test_utils::NavigateToURL(browser(), url); | 158 ui_test_utils::NavigateToURL(browser(), url); |
158 content::WebContents* web_contents = browser()->GetActiveWebContents(); | 159 content::WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
159 EXPECT_EQ("ISO-8859-1", web_contents->GetEncoding()); | 160 EXPECT_EQ("ISO-8859-1", web_contents->GetEncoding()); |
160 | 161 |
161 // Override the encoding to "gb18030". | 162 // Override the encoding to "gb18030". |
162 const std::string selected_encoding = | 163 const std::string selected_encoding = |
163 CharacterEncoding::GetCanonicalEncodingNameByAliasName("gb18030"); | 164 CharacterEncoding::GetCanonicalEncodingNameByAliasName("gb18030"); |
164 content::TestNavigationObserver navigation_observer( | 165 content::TestNavigationObserver navigation_observer( |
165 content::Source<content::NavigationController>( | 166 content::Source<content::NavigationController>( |
166 &web_contents->GetController())); | 167 &web_contents->GetController())); |
167 web_contents->SetOverrideEncoding(selected_encoding); | 168 web_contents->SetOverrideEncoding(selected_encoding); |
168 navigation_observer.Wait(); | 169 navigation_observer.Wait(); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 const char* const kExpectedResultDir = "expected_results"; | 253 const char* const kExpectedResultDir = "expected_results"; |
253 | 254 |
254 FilePath test_dir_path = FilePath(kTestDir).AppendASCII(kAutoDetectDir); | 255 FilePath test_dir_path = FilePath(kTestDir).AppendASCII(kAutoDetectDir); |
255 | 256 |
256 // Set the default charset to one of encodings not supported by the current | 257 // Set the default charset to one of encodings not supported by the current |
257 // auto-detector (Please refer to the above comments) to make sure we | 258 // auto-detector (Please refer to the above comments) to make sure we |
258 // incorrectly decode the page. Now we use ISO-8859-4. | 259 // incorrectly decode the page. Now we use ISO-8859-4. |
259 browser()->profile()->GetPrefs()->SetString(prefs::kDefaultCharset, | 260 browser()->profile()->GetPrefs()->SetString(prefs::kDefaultCharset, |
260 "ISO-8859-4"); | 261 "ISO-8859-4"); |
261 | 262 |
262 content::WebContents* web_contents = browser()->GetActiveWebContents(); | 263 content::WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
263 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestDatas); ++i) { | 264 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestDatas); ++i) { |
264 // Disable auto detect if it is on. | 265 // Disable auto detect if it is on. |
265 browser()->profile()->GetPrefs()->SetBoolean( | 266 browser()->profile()->GetPrefs()->SetBoolean( |
266 prefs::kWebKitUsesUniversalDetector, false); | 267 prefs::kWebKitUsesUniversalDetector, false); |
267 | 268 |
268 FilePath test_file_path(test_dir_path); | 269 FilePath test_file_path(test_dir_path); |
269 test_file_path = test_file_path.AppendASCII(kTestDatas[i].test_file_name); | 270 test_file_path = test_file_path.AppendASCII(kTestDatas[i].test_file_name); |
270 GURL url = URLRequestMockHTTPJob::GetMockUrl(test_file_path); | 271 GURL url = URLRequestMockHTTPJob::GetMockUrl(test_file_path); |
271 ui_test_utils::NavigateToURL(browser(), url); | 272 ui_test_utils::NavigateToURL(browser(), url); |
272 | 273 |
(...skipping 15 matching lines...) Expand all Loading... |
288 EXPECT_EQ(kTestDatas[i].expected_encoding, web_contents->GetEncoding()); | 289 EXPECT_EQ(kTestDatas[i].expected_encoding, web_contents->GetEncoding()); |
289 | 290 |
290 // Dump the page, the content of dump page should be equal with our expect | 291 // Dump the page, the content of dump page should be equal with our expect |
291 // result file. | 292 // result file. |
292 FilePath expected_result_file_name = | 293 FilePath expected_result_file_name = |
293 FilePath().AppendASCII(kAutoDetectDir).AppendASCII(kExpectedResultDir). | 294 FilePath().AppendASCII(kAutoDetectDir).AppendASCII(kExpectedResultDir). |
294 AppendASCII(kTestDatas[i].expected_result); | 295 AppendASCII(kTestDatas[i].expected_result); |
295 SaveAndCompare(kTestDatas[i].test_file_name, expected_result_file_name); | 296 SaveAndCompare(kTestDatas[i].test_file_name, expected_result_file_name); |
296 } | 297 } |
297 } | 298 } |
OLD | NEW |