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

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

Issue 255057: Unit Test for Toggling of Encoding Auto-Detect (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 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) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 #include <string> 4 #include <string>
5 5
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/net/url_request_mock_http_job.h" 8 #include "chrome/browser/net/url_request_mock_http_job.h"
9 #include "chrome/browser/download/save_package.h" 9 #include "chrome/browser/download/save_package.h"
10 #include "chrome/common/pref_names.h" 10 #include "chrome/common/pref_names.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 ASSERT_TRUE(tab_proxy->NavigateToURL(url)); 105 ASSERT_TRUE(tab_proxy->NavigateToURL(url));
106 WaitUntilTabCount(1); 106 WaitUntilTabCount(1);
107 107
108 std::string encoding; 108 std::string encoding;
109 EXPECT_TRUE(tab_proxy->GetPageCurrentEncoding(&encoding)); 109 EXPECT_TRUE(tab_proxy->GetPageCurrentEncoding(&encoding));
110 EXPECT_EQ(encoding, kEncodingTestDatas[i].encoding_name); 110 EXPECT_EQ(encoding, kEncodingTestDatas[i].encoding_name);
111 } 111 }
112 } 112 }
113 113
114 #if defined(OS_WIN) 114 #if defined(OS_WIN)
115 // We are disabling this test on MacOS and Linux because on those platforms 115 // We are disabling these tests on MacOS and Linux because on those platforms
116 // AutomationProvider::OverrideEncoding is not implemented yet. 116 // AutomationProvider::OverrideEncoding and ToggleEncodingAutoDetect are not
117 // implemented yet.
117 // TODO(port): Enable when encoding-related parts of Browser are ported. 118 // TODO(port): Enable when encoding-related parts of Browser are ported.
118 TEST_F(BrowserEncodingTest, TestOverrideEncoding) { 119 TEST_F(BrowserEncodingTest, TestOverrideEncoding) {
119 const char* const kTestFileName = "gb18030_with_iso88591_meta.html"; 120 const char* const kTestFileName = "gb18030_with_iso88591_meta.html";
120 const char* const kExpectedFileName = 121 const char* const kExpectedFileName =
121 "expected_gb18030_saved_from_iso88591_meta.html"; 122 "expected_gb18030_saved_from_iso88591_meta.html";
122 const char* const kOverrideTestDir = "user_override"; 123 const char* const kOverrideTestDir = "user_override";
123 124
124 FilePath test_dir_path = FilePath(kTestDir).AppendASCII(kOverrideTestDir); 125 FilePath test_dir_path = FilePath(kTestDir).AppendASCII(kOverrideTestDir);
125 test_dir_path = test_dir_path.AppendASCII(kTestFileName); 126 test_dir_path = test_dir_path.AppendASCII(kTestFileName);
126 GURL url = URLRequestMockHTTPJob::GetMockUrl(test_dir_path); 127 GURL url = URLRequestMockHTTPJob::GetMockUrl(test_dir_path);
(...skipping 25 matching lines...) Expand all
152 // sub resources, but the directory name is still required. 153 // sub resources, but the directory name is still required.
153 EXPECT_TRUE(tab_proxy->SavePage(full_file_name, temp_sub_resource_dir_, 154 EXPECT_TRUE(tab_proxy->SavePage(full_file_name, temp_sub_resource_dir_,
154 SavePackage::SAVE_AS_COMPLETE_HTML)); 155 SavePackage::SAVE_AS_COMPLETE_HTML));
155 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); 156 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
156 ASSERT_TRUE(browser.get()); 157 ASSERT_TRUE(browser.get());
157 EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get())); 158 EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get()));
158 FilePath expected_file_name = FilePath().AppendASCII(kOverrideTestDir); 159 FilePath expected_file_name = FilePath().AppendASCII(kOverrideTestDir);
159 expected_file_name = expected_file_name.AppendASCII(kExpectedFileName); 160 expected_file_name = expected_file_name.AppendASCII(kExpectedFileName);
160 CheckFile(full_file_name, expected_file_name, true); 161 CheckFile(full_file_name, expected_file_name, true);
161 } 162 }
163
164 // Test for fix to issue 2932 (http://crbug.com/2932)
165 // as described in http://codereview.chromium.org/173265
166 TEST_F(BrowserEncodingTest, TestToggleAutoDetect) {
167 const char* const kTestFileName = "gb18030_with_no_encoding_specified.html";
168 const char* const kToggleTestDir = "auto_detect";
169
170 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
171 ASSERT_TRUE(browser.get());
172
173 browser->SetStringPreference(prefs::kDefaultCharset, L"ISO-8859-1");
174
175 // turn off auto-detect before loading the file
Johnny(Jianning) Ding 2009/11/07 11:09:14 The first character should be in uppercase in comm
176 EXPECT_TRUE(
177 browser->SetBooleanPreference(prefs::kWebKitUsesUniversalDetector,
178 false));
179
180 FilePath test_dir_path = FilePath(kTestDir).AppendASCII(kToggleTestDir);
181 test_dir_path = test_dir_path.AppendASCII(kTestFileName);
182 GURL url = URLRequestMockHTTPJob::GetMockUrl(test_dir_path);
183 scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
184 ASSERT_TRUE(tab_proxy.get());
185 ASSERT_TRUE(tab_proxy->NavigateToURL(url));
186 WaitUntilTabCount(1);
187
188 // Verify that file got default encoding.
189 std::string encoding;
190 EXPECT_TRUE(tab_proxy->GetPageCurrentEncoding(&encoding));
191 EXPECT_EQ(encoding, "ISO-8859-1");
192
193 // Turn on auto-detect and verify that encoding changed.
194 int64 prev_nav_time = 0;
195 bool encoding_auto_detect = false;
196 EXPECT_TRUE(tab_proxy->GetLastNavigationTime(&prev_nav_time));
197 EXPECT_TRUE(tab_proxy->ToggleEncodingAutoDetect());
198 EXPECT_TRUE(tab_proxy->WaitForNavigation(prev_nav_time));
199 EXPECT_TRUE(tab_proxy->GetPageCurrentEncoding(&encoding));
200 EXPECT_EQ(encoding, "gb18030");
201 EXPECT_TRUE(
202 browser->GetBooleanPreference(prefs::kWebKitUsesUniversalDetector,
203 &encoding_auto_detect));
204 EXPECT_TRUE(encoding_auto_detect);
205
206 // Turn off auto-detect and verify that no navigation occurs.
207 // The encoding shouldn't change as well.
208 int64 last_nav_time = 0;
209 EXPECT_TRUE(tab_proxy->GetLastNavigationTime(&prev_nav_time));
210 EXPECT_TRUE(tab_proxy->ToggleEncodingAutoDetect());
211 // TODO(rolandsteiner): HACK! this assumes the navigation (if any) will be
212 // completed in 500ms. Need a better way to ascertain that no navigation
213 // was triggered.
214 EXPECT_TRUE(CrashAwareSleep(500));
215 EXPECT_TRUE(tab_proxy->GetLastNavigationTime(&last_nav_time));
216 EXPECT_EQ(prev_nav_time, last_nav_time);
217 EXPECT_TRUE(
218 browser->GetBooleanPreference(prefs::kWebKitUsesUniversalDetector,
219 &encoding_auto_detect));
220 EXPECT_FALSE(encoding_auto_detect);
221
222 // Choose another encoding and verify that page is reloaded and the new
223 // encoding set. Auto-detect encoding should still be off.
224 EXPECT_TRUE(tab_proxy->GetLastNavigationTime(&prev_nav_time));
225 EXPECT_TRUE(tab_proxy->OverrideEncoding("ISO-8859-13"));
226 EXPECT_TRUE(tab_proxy->WaitForNavigation(prev_nav_time));
227 EXPECT_TRUE(tab_proxy->GetPageCurrentEncoding(&encoding));
228 EXPECT_EQ(encoding, "ISO-8859-13");
229 EXPECT_TRUE(
230 browser->GetBooleanPreference(prefs::kWebKitUsesUniversalDetector,
231 &encoding_auto_detect));
232 EXPECT_FALSE(encoding_auto_detect);
233
234 // Turn on auto-detect again and verify that encoding changed back
235 // to Chinese.
236 EXPECT_TRUE(tab_proxy->GetLastNavigationTime(&prev_nav_time));
237 EXPECT_TRUE(tab_proxy->ToggleEncodingAutoDetect());
238 EXPECT_TRUE(tab_proxy->WaitForNavigation(prev_nav_time));
239 EXPECT_TRUE(tab_proxy->GetPageCurrentEncoding(&encoding));
240 EXPECT_EQ(encoding, "gb18030");
241 EXPECT_TRUE(
242 browser->GetBooleanPreference(prefs::kWebKitUsesUniversalDetector,
243 &encoding_auto_detect));
244 EXPECT_TRUE(encoding_auto_detect);
245
246 // Close the tab explicitely (avoids spurious "leak" crash on exit)
247 EXPECT_TRUE(tab_proxy->Close(true));
248 }
162 #endif // defined(OS_WIN) 249 #endif // defined(OS_WIN)
163 250
164 // The following encodings are excluded from the auto-detection test because 251 // The following encodings are excluded from the auto-detection test because
165 // it's a known issue that the current encoding detector does not detect them: 252 // it's a known issue that the current encoding detector does not detect them:
166 // ISO-8859-4 253 // ISO-8859-4
167 // ISO-8859-13 254 // ISO-8859-13
168 // KOI8-U 255 // KOI8-U
169 // macintosh 256 // macintosh
170 // windows-874 257 // windows-874
171 // windows-1252 258 // windows-1252
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 expected_result_file_name = expected_result_file_name.AppendASCII( 375 expected_result_file_name = expected_result_file_name.AppendASCII(
289 kExpectedResultDir); 376 kExpectedResultDir);
290 expected_result_file_name = expected_result_file_name.AppendASCII( 377 expected_result_file_name = expected_result_file_name.AppendASCII(
291 kTestDatas[i].expected_result); 378 kTestDatas[i].expected_result);
292 EXPECT_TRUE(tab->SavePage(full_saved_file_name, temp_sub_resource_dir_, 379 EXPECT_TRUE(tab->SavePage(full_saved_file_name, temp_sub_resource_dir_,
293 SavePackage::SAVE_AS_COMPLETE_HTML)); 380 SavePackage::SAVE_AS_COMPLETE_HTML));
294 EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get())); 381 EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get()));
295 CheckFile(full_saved_file_name, expected_result_file_name, true); 382 CheckFile(full_saved_file_name, expected_result_file_name, true);
296 } 383 }
297 } 384 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/automation_provider.cc ('k') | chrome/test/automation/automation_messages_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698