Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Side by Side Diff: chrome/browser/browser_encoding_browsertest.cc

Issue 11346016: Move remaining content test code into the content namespace. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 { "windows-1258.html", "windows-1258" } 116 { "windows-1258.html", "windows-1258" }
117 }; 117 };
118 const char* const kAliasTestDir = "alias_mapping"; 118 const char* const kAliasTestDir = "alias_mapping";
119 119
120 FilePath test_dir_path = FilePath(kTestDir).AppendASCII(kAliasTestDir); 120 FilePath test_dir_path = FilePath(kTestDir).AppendASCII(kAliasTestDir);
121 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kEncodingTestDatas); ++i) { 121 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kEncodingTestDatas); ++i) {
122 FilePath test_file_path(test_dir_path); 122 FilePath test_file_path(test_dir_path);
123 test_file_path = test_file_path.AppendASCII( 123 test_file_path = test_file_path.AppendASCII(
124 kEncodingTestDatas[i].file_name); 124 kEncodingTestDatas[i].file_name);
125 125
126 GURL url = URLRequestMockHTTPJob::GetMockUrl(test_file_path); 126 GURL url = content::URLRequestMockHTTPJob::GetMockUrl(test_file_path);
127 127
128 // When looping through all the above files in one WebContents, there's a 128 // When looping through all the above files in one WebContents, there's a
129 // race condition on Windows trybots that causes the previous encoding to be 129 // race condition on Windows trybots that causes the previous encoding to be
130 // seen sometimes. Create a new tab for each one. http://crbug.com/122053 130 // seen sometimes. Create a new tab for each one. http://crbug.com/122053
131 ui_test_utils::NavigateToURLWithDisposition( 131 ui_test_utils::NavigateToURLWithDisposition(
132 browser(), url, NEW_FOREGROUND_TAB, 132 browser(), url, NEW_FOREGROUND_TAB,
133 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 133 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
134 134
135 EXPECT_EQ(kEncodingTestDatas[i].encoding_name, 135 EXPECT_EQ(kEncodingTestDatas[i].encoding_name,
136 chrome::GetActiveWebContents(browser())->GetEncoding()); 136 chrome::GetActiveWebContents(browser())->GetEncoding());
137 chrome::CloseTab(browser()); 137 chrome::CloseTab(browser());
138 } 138 }
139 } 139 }
140 140
141 // Marked as flaky: see http://crbug.com/44668 141 // Marked as flaky: see http://crbug.com/44668
142 IN_PROC_BROWSER_TEST_F(BrowserEncodingTest, TestOverrideEncoding) { 142 IN_PROC_BROWSER_TEST_F(BrowserEncodingTest, TestOverrideEncoding) {
143 const char* const kTestFileName = "gb18030_with_iso88591_meta.html"; 143 const char* const kTestFileName = "gb18030_with_iso88591_meta.html";
144 const char* const kExpectedFileName = 144 const char* const kExpectedFileName =
145 "expected_gb18030_saved_from_iso88591_meta.html"; 145 "expected_gb18030_saved_from_iso88591_meta.html";
146 const char* const kOverrideTestDir = "user_override"; 146 const char* const kOverrideTestDir = "user_override";
147 147
148 FilePath test_dir_path = FilePath(kTestDir).AppendASCII(kOverrideTestDir); 148 FilePath test_dir_path = FilePath(kTestDir).AppendASCII(kOverrideTestDir);
149 test_dir_path = test_dir_path.AppendASCII(kTestFileName); 149 test_dir_path = test_dir_path.AppendASCII(kTestFileName);
150 GURL url = URLRequestMockHTTPJob::GetMockUrl(test_dir_path); 150 GURL url = content::URLRequestMockHTTPJob::GetMockUrl(test_dir_path);
151 ui_test_utils::NavigateToURL(browser(), url); 151 ui_test_utils::NavigateToURL(browser(), url);
152 content::WebContents* web_contents = chrome::GetActiveWebContents(browser()); 152 content::WebContents* web_contents = chrome::GetActiveWebContents(browser());
153 EXPECT_EQ("ISO-8859-1", web_contents->GetEncoding()); 153 EXPECT_EQ("ISO-8859-1", web_contents->GetEncoding());
154 154
155 // Override the encoding to "gb18030". 155 // Override the encoding to "gb18030".
156 const std::string selected_encoding = 156 const std::string selected_encoding =
157 CharacterEncoding::GetCanonicalEncodingNameByAliasName("gb18030"); 157 CharacterEncoding::GetCanonicalEncodingNameByAliasName("gb18030");
158 content::TestNavigationObserver navigation_observer( 158 content::TestNavigationObserver navigation_observer(
159 content::Source<content::NavigationController>( 159 content::Source<content::NavigationController>(
160 &web_contents->GetController())); 160 &web_contents->GetController()));
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 "ISO-8859-4"); 254 "ISO-8859-4");
255 255
256 content::WebContents* web_contents = chrome::GetActiveWebContents(browser()); 256 content::WebContents* web_contents = chrome::GetActiveWebContents(browser());
257 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestDatas); ++i) { 257 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestDatas); ++i) {
258 // Disable auto detect if it is on. 258 // Disable auto detect if it is on.
259 browser()->profile()->GetPrefs()->SetBoolean( 259 browser()->profile()->GetPrefs()->SetBoolean(
260 prefs::kWebKitUsesUniversalDetector, false); 260 prefs::kWebKitUsesUniversalDetector, false);
261 261
262 FilePath test_file_path(test_dir_path); 262 FilePath test_file_path(test_dir_path);
263 test_file_path = test_file_path.AppendASCII(kTestDatas[i].test_file_name); 263 test_file_path = test_file_path.AppendASCII(kTestDatas[i].test_file_name);
264 GURL url = URLRequestMockHTTPJob::GetMockUrl(test_file_path); 264 GURL url = content::URLRequestMockHTTPJob::GetMockUrl(test_file_path);
265 ui_test_utils::NavigateToURL(browser(), url); 265 ui_test_utils::NavigateToURL(browser(), url);
266 266
267 // Get the encoding used for the page, it must be the default charset we 267 // Get the encoding used for the page, it must be the default charset we
268 // just set. 268 // just set.
269 EXPECT_EQ("ISO-8859-4", web_contents->GetEncoding()); 269 EXPECT_EQ("ISO-8859-4", web_contents->GetEncoding());
270 270
271 // Enable the encoding auto detection. 271 // Enable the encoding auto detection.
272 browser()->profile()->GetPrefs()->SetBoolean( 272 browser()->profile()->GetPrefs()->SetBoolean(
273 prefs::kWebKitUsesUniversalDetector, true); 273 prefs::kWebKitUsesUniversalDetector, true);
274 274
275 content::TestNavigationObserver observer( 275 content::TestNavigationObserver observer(
276 content::Source<content::NavigationController>( 276 content::Source<content::NavigationController>(
277 &web_contents->GetController())); 277 &web_contents->GetController()));
278 chrome::Reload(browser(), CURRENT_TAB); 278 chrome::Reload(browser(), CURRENT_TAB);
279 observer.Wait(); 279 observer.Wait();
280 280
281 // Re-get the encoding of page. It should return the real encoding now. 281 // Re-get the encoding of page. It should return the real encoding now.
282 EXPECT_EQ(kTestDatas[i].expected_encoding, web_contents->GetEncoding()); 282 EXPECT_EQ(kTestDatas[i].expected_encoding, web_contents->GetEncoding());
283 283
284 // Dump the page, the content of dump page should be equal with our expect 284 // Dump the page, the content of dump page should be equal with our expect
285 // result file. 285 // result file.
286 FilePath expected_result_file_name = 286 FilePath expected_result_file_name =
287 FilePath().AppendASCII(kAutoDetectDir).AppendASCII(kExpectedResultDir). 287 FilePath().AppendASCII(kAutoDetectDir).AppendASCII(kExpectedResultDir).
288 AppendASCII(kTestDatas[i].expected_result); 288 AppendASCII(kTestDatas[i].expected_result);
289 SaveAndCompare(kTestDatas[i].test_file_name, expected_result_file_name); 289 SaveAndCompare(kTestDatas[i].test_file_name, expected_result_file_name);
290 } 290 }
291 } 291 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698