| OLD | NEW |
| 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 Loading... |
| 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 these tests on MacOS and Linux because on those platforms | 115 // We are disabling this test on MacOS and Linux because on those platforms |
| 116 // AutomationProvider::OverrideEncoding and ToggleEncodingAutoDetect are not | 116 // AutomationProvider::OverrideEncoding is not implemented yet. |
| 117 // implemented yet. | |
| 118 // TODO(port): Enable when encoding-related parts of Browser are ported. | 117 // TODO(port): Enable when encoding-related parts of Browser are ported. |
| 119 TEST_F(BrowserEncodingTest, TestOverrideEncoding) { | 118 TEST_F(BrowserEncodingTest, TestOverrideEncoding) { |
| 120 const char* const kTestFileName = "gb18030_with_iso88591_meta.html"; | 119 const char* const kTestFileName = "gb18030_with_iso88591_meta.html"; |
| 121 const char* const kExpectedFileName = | 120 const char* const kExpectedFileName = |
| 122 "expected_gb18030_saved_from_iso88591_meta.html"; | 121 "expected_gb18030_saved_from_iso88591_meta.html"; |
| 123 const char* const kOverrideTestDir = "user_override"; | 122 const char* const kOverrideTestDir = "user_override"; |
| 124 | 123 |
| 125 FilePath test_dir_path = FilePath(kTestDir).AppendASCII(kOverrideTestDir); | 124 FilePath test_dir_path = FilePath(kTestDir).AppendASCII(kOverrideTestDir); |
| 126 test_dir_path = test_dir_path.AppendASCII(kTestFileName); | 125 test_dir_path = test_dir_path.AppendASCII(kTestFileName); |
| 127 GURL url = URLRequestMockHTTPJob::GetMockUrl(test_dir_path); | 126 GURL url = URLRequestMockHTTPJob::GetMockUrl(test_dir_path); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 153 // sub resources, but the directory name is still required. | 152 // sub resources, but the directory name is still required. |
| 154 EXPECT_TRUE(tab_proxy->SavePage(full_file_name, temp_sub_resource_dir_, | 153 EXPECT_TRUE(tab_proxy->SavePage(full_file_name, temp_sub_resource_dir_, |
| 155 SavePackage::SAVE_AS_COMPLETE_HTML)); | 154 SavePackage::SAVE_AS_COMPLETE_HTML)); |
| 156 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 155 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
| 157 ASSERT_TRUE(browser.get()); | 156 ASSERT_TRUE(browser.get()); |
| 158 EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get())); | 157 EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get())); |
| 159 FilePath expected_file_name = FilePath().AppendASCII(kOverrideTestDir); | 158 FilePath expected_file_name = FilePath().AppendASCII(kOverrideTestDir); |
| 160 expected_file_name = expected_file_name.AppendASCII(kExpectedFileName); | 159 expected_file_name = expected_file_name.AppendASCII(kExpectedFileName); |
| 161 CheckFile(full_file_name, expected_file_name, true); | 160 CheckFile(full_file_name, expected_file_name, true); |
| 162 } | 161 } |
| 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. | |
| 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 } | |
| 249 #endif // defined(OS_WIN) | 162 #endif // defined(OS_WIN) |
| 250 | 163 |
| 251 // The following encodings are excluded from the auto-detection test because | 164 // The following encodings are excluded from the auto-detection test because |
| 252 // it's a known issue that the current encoding detector does not detect them: | 165 // it's a known issue that the current encoding detector does not detect them: |
| 253 // ISO-8859-4 | 166 // ISO-8859-4 |
| 254 // ISO-8859-13 | 167 // ISO-8859-13 |
| 255 // KOI8-U | 168 // KOI8-U |
| 256 // macintosh | 169 // macintosh |
| 257 // windows-874 | 170 // windows-874 |
| 258 // windows-1252 | 171 // windows-1252 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 expected_result_file_name = expected_result_file_name.AppendASCII( | 288 expected_result_file_name = expected_result_file_name.AppendASCII( |
| 376 kExpectedResultDir); | 289 kExpectedResultDir); |
| 377 expected_result_file_name = expected_result_file_name.AppendASCII( | 290 expected_result_file_name = expected_result_file_name.AppendASCII( |
| 378 kTestDatas[i].expected_result); | 291 kTestDatas[i].expected_result); |
| 379 EXPECT_TRUE(tab->SavePage(full_saved_file_name, temp_sub_resource_dir_, | 292 EXPECT_TRUE(tab->SavePage(full_saved_file_name, temp_sub_resource_dir_, |
| 380 SavePackage::SAVE_AS_COMPLETE_HTML)); | 293 SavePackage::SAVE_AS_COMPLETE_HTML)); |
| 381 EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get())); | 294 EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get())); |
| 382 CheckFile(full_saved_file_name, expected_result_file_name, true); | 295 CheckFile(full_saved_file_name, expected_result_file_name, true); |
| 383 } | 296 } |
| 384 } | 297 } |
| OLD | NEW |