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

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

Issue 192017: Convert std::wstring encoding names to std::string in a bunch of files. (Closed)
Patch Set: mac and linux fixes Created 11 years, 3 months 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
« no previous file with comments | « chrome/browser/browser.cc ('k') | chrome/browser/browser_main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 }; 48 };
49 49
50 // TODO(jnd): 1. Some encodings are missing here. It'll be added later. See 50 // TODO(jnd): 1. Some encodings are missing here. It'll be added later. See
51 // http://crbug.com/13306. 51 // http://crbug.com/13306.
52 // 2. Add more files with multiple encoding name variants for each canonical 52 // 2. Add more files with multiple encoding name variants for each canonical
53 // encoding name). Webkit layout tests cover some, but testing in the UI test is 53 // encoding name). Webkit layout tests cover some, but testing in the UI test is
54 // also necessary. 54 // also necessary.
55 TEST_F(BrowserEncodingTest, TestEncodingAliasMapping) { 55 TEST_F(BrowserEncodingTest, TestEncodingAliasMapping) {
56 struct EncodingTestData { 56 struct EncodingTestData {
57 const char* file_name; 57 const char* file_name;
58 const wchar_t* encoding_name; 58 const char* encoding_name;
59 }; 59 };
60 60
61 const EncodingTestData kEncodingTestDatas[] = { 61 const EncodingTestData kEncodingTestDatas[] = {
62 { "Big5.html", L"Big5" }, 62 { "Big5.html", "Big5" },
63 { "EUC-JP.html", L"EUC-JP" }, 63 { "EUC-JP.html", "EUC-JP" },
64 { "gb18030.html", L"gb18030" }, 64 { "gb18030.html", "gb18030" },
65 { "iso-8859-1.html", L"ISO-8859-1" }, 65 { "iso-8859-1.html", "ISO-8859-1" },
66 { "ISO-8859-2.html", L"ISO-8859-2" }, 66 { "ISO-8859-2.html", "ISO-8859-2" },
67 { "ISO-8859-4.html", L"ISO-8859-4" }, 67 { "ISO-8859-4.html", "ISO-8859-4" },
68 { "ISO-8859-5.html", L"ISO-8859-5" }, 68 { "ISO-8859-5.html", "ISO-8859-5" },
69 { "ISO-8859-6.html", L"ISO-8859-6" }, 69 { "ISO-8859-6.html", "ISO-8859-6" },
70 { "ISO-8859-7.html", L"ISO-8859-7" }, 70 { "ISO-8859-7.html", "ISO-8859-7" },
71 { "ISO-8859-8.html", L"ISO-8859-8" }, 71 { "ISO-8859-8.html", "ISO-8859-8" },
72 { "ISO-8859-13.html", L"ISO-8859-13" }, 72 { "ISO-8859-13.html", "ISO-8859-13" },
73 { "ISO-8859-15.html", L"ISO-8859-15" }, 73 { "ISO-8859-15.html", "ISO-8859-15" },
74 { "KOI8-R.html", L"KOI8-R" }, 74 { "KOI8-R.html", "KOI8-R" },
75 { "KOI8-U.html", L"KOI8-U" }, 75 { "KOI8-U.html", "KOI8-U" },
76 { "macintosh.html", L"macintosh" }, 76 { "macintosh.html", "macintosh" },
77 { "Shift-JIS.html", L"Shift_JIS" }, 77 { "Shift-JIS.html", "Shift_JIS" },
78 { "US-ASCII.html", L"ISO-8859-1" }, // http://crbug.com/15801 78 { "US-ASCII.html", "ISO-8859-1" }, // http://crbug.com/15801
79 { "UTF-8.html", L"UTF-8" }, 79 { "UTF-8.html", "UTF-8" },
80 { "UTF-16LE.html", L"UTF-16LE" }, 80 { "UTF-16LE.html", "UTF-16LE" },
81 { "windows-874.html", L"windows-874" }, 81 { "windows-874.html", "windows-874" },
82 { "windows-949.html", L"windows-949" }, 82 { "windows-949.html", "windows-949" },
83 { "windows-1250.html", L"windows-1250" }, 83 { "windows-1250.html", "windows-1250" },
84 { "windows-1251.html", L"windows-1251" }, 84 { "windows-1251.html", "windows-1251" },
85 { "windows-1252.html", L"windows-1252" }, 85 { "windows-1252.html", "windows-1252" },
86 { "windows-1253.html", L"windows-1253" }, 86 { "windows-1253.html", "windows-1253" },
87 { "windows-1254.html", L"windows-1254" }, 87 { "windows-1254.html", "windows-1254" },
88 { "windows-1255.html", L"windows-1255" }, 88 { "windows-1255.html", "windows-1255" },
89 { "windows-1256.html", L"windows-1256" }, 89 { "windows-1256.html", "windows-1256" },
90 { "windows-1257.html", L"windows-1257" }, 90 { "windows-1257.html", "windows-1257" },
91 { "windows-1258.html", L"windows-1258" } 91 { "windows-1258.html", "windows-1258" }
92 }; 92 };
93 const char* const kAliasTestDir = "alias_mapping"; 93 const char* const kAliasTestDir = "alias_mapping";
94 94
95 FilePath test_dir_path = FilePath(kTestDir).AppendASCII(kAliasTestDir); 95 FilePath test_dir_path = FilePath(kTestDir).AppendASCII(kAliasTestDir);
96 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kEncodingTestDatas); ++i) { 96 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kEncodingTestDatas); ++i) {
97 FilePath test_file_path(test_dir_path); 97 FilePath test_file_path(test_dir_path);
98 test_file_path = test_file_path.AppendASCII( 98 test_file_path = test_file_path.AppendASCII(
99 kEncodingTestDatas[i].file_name); 99 kEncodingTestDatas[i].file_name);
100 GURL url = 100 GURL url =
101 URLRequestMockHTTPJob::GetMockUrl(test_file_path.ToWStringHack()); 101 URLRequestMockHTTPJob::GetMockUrl(test_file_path.ToWStringHack());
102 102
103 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); 103 scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
104 ASSERT_TRUE(tab_proxy.get()); 104 ASSERT_TRUE(tab_proxy.get());
105 ASSERT_TRUE(tab_proxy->NavigateToURL(url)); 105 ASSERT_TRUE(tab_proxy->NavigateToURL(url));
106 WaitUntilTabCount(1); 106 WaitUntilTabCount(1);
107 107
108 std::wstring 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 this test on MacOS and Linux because on those platforms
116 // AutomationProvider::OverrideEncoding is not implemented yet. 116 // AutomationProvider::OverrideEncoding is not implemented yet.
117 // TODO(port): Enable when encoding-related parts of Browser are ported. 117 // TODO(port): Enable when encoding-related parts of Browser are ported.
118 TEST_F(BrowserEncodingTest, TestOverrideEncoding) { 118 TEST_F(BrowserEncodingTest, TestOverrideEncoding) {
119 const char* const kTestFileName = "gb18030_with_iso88591_meta.html"; 119 const char* const kTestFileName = "gb18030_with_iso88591_meta.html";
120 const char* const kExpectedFileName = 120 const char* const kExpectedFileName =
121 "expected_gb18030_saved_from_iso88591_meta.html"; 121 "expected_gb18030_saved_from_iso88591_meta.html";
122 const char* const kOverrideTestDir = "user_override"; 122 const char* const kOverrideTestDir = "user_override";
123 123
124 FilePath test_dir_path = FilePath(kTestDir).AppendASCII(kOverrideTestDir); 124 FilePath test_dir_path = FilePath(kTestDir).AppendASCII(kOverrideTestDir);
125 test_dir_path = test_dir_path.AppendASCII(kTestFileName); 125 test_dir_path = test_dir_path.AppendASCII(kTestFileName);
126 GURL url = URLRequestMockHTTPJob::GetMockUrl(test_dir_path.ToWStringHack()); 126 GURL url = URLRequestMockHTTPJob::GetMockUrl(test_dir_path.ToWStringHack());
127 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); 127 scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
128 ASSERT_TRUE(tab_proxy.get()); 128 ASSERT_TRUE(tab_proxy.get());
129 ASSERT_TRUE(tab_proxy->NavigateToURL(url)); 129 ASSERT_TRUE(tab_proxy->NavigateToURL(url));
130 WaitUntilTabCount(1); 130 WaitUntilTabCount(1);
131 131
132 // Get the encoding declared in the page. 132 // Get the encoding declared in the page.
133 std::wstring encoding; 133 std::string encoding;
134 EXPECT_TRUE(tab_proxy->GetPageCurrentEncoding(&encoding)); 134 EXPECT_TRUE(tab_proxy->GetPageCurrentEncoding(&encoding));
135 EXPECT_EQ(encoding, L"ISO-8859-1"); 135 EXPECT_EQ(encoding, "ISO-8859-1");
136 136
137 // Override the encoding to "gb18030". 137 // Override the encoding to "gb18030".
138 int64 last_nav_time = 0; 138 int64 last_nav_time = 0;
139 EXPECT_TRUE(tab_proxy->GetLastNavigationTime(&last_nav_time)); 139 EXPECT_TRUE(tab_proxy->GetLastNavigationTime(&last_nav_time));
140 EXPECT_TRUE(tab_proxy->OverrideEncoding(L"gb18030")); 140 EXPECT_TRUE(tab_proxy->OverrideEncoding("gb18030"));
141 EXPECT_TRUE(tab_proxy->WaitForNavigation(last_nav_time)); 141 EXPECT_TRUE(tab_proxy->WaitForNavigation(last_nav_time));
142 142
143 // Re-get the encoding of page. It should be gb18030. 143 // Re-get the encoding of page. It should be gb18030.
144 EXPECT_TRUE(tab_proxy->GetPageCurrentEncoding(&encoding)); 144 EXPECT_TRUE(tab_proxy->GetPageCurrentEncoding(&encoding));
145 EXPECT_EQ(encoding, L"gb18030"); 145 EXPECT_EQ(encoding, "gb18030");
146 146
147 // Dump the page, the content of dump page should be identical to the 147 // Dump the page, the content of dump page should be identical to the
148 // expected result file. 148 // expected result file.
149 FilePath full_file_name = save_dir_.AppendASCII(kTestFileName); 149 FilePath full_file_name = save_dir_.AppendASCII(kTestFileName);
150 // We save the page as way of complete HTML file, which requires a directory 150 // We save the page as way of complete HTML file, which requires a directory
151 // name to save sub resources in it. Although this test file does not have 151 // name to save sub resources in it. Although this test file does not have
152 // sub resources, but the directory name is still required. 152 // sub resources, but the directory name is still required.
153 EXPECT_TRUE(tab_proxy->SavePage(full_file_name.ToWStringHack(), 153 EXPECT_TRUE(tab_proxy->SavePage(full_file_name.ToWStringHack(),
154 temp_sub_resource_dir_.ToWStringHack(), 154 temp_sub_resource_dir_.ToWStringHack(),
155 SavePackage::SAVE_AS_COMPLETE_HTML)); 155 SavePackage::SAVE_AS_COMPLETE_HTML));
(...skipping 17 matching lines...) Expand all
173 // windows-1253 173 // windows-1253
174 // windows-1257 174 // windows-1257
175 // windows-1258 175 // windows-1258
176 176
177 // For Hebrew, the expected encoding value is ISO-8859-8-I. See 177 // For Hebrew, the expected encoding value is ISO-8859-8-I. See
178 // http://crbug.com/2927 for more details. 178 // http://crbug.com/2927 for more details.
179 TEST_F(BrowserEncodingTest, TestEncodingAutoDetect) { 179 TEST_F(BrowserEncodingTest, TestEncodingAutoDetect) {
180 struct EncodingAutoDetectTestData { 180 struct EncodingAutoDetectTestData {
181 const char* test_file_name; // File name of test data. 181 const char* test_file_name; // File name of test data.
182 const char* expected_result; // File name of expected results. 182 const char* expected_result; // File name of expected results.
183 const wchar_t* expected_encoding; // expected encoding. 183 const char* expected_encoding; // expected encoding.
184 }; 184 };
185 const EncodingAutoDetectTestData kTestDatas[] = { 185 const EncodingAutoDetectTestData kTestDatas[] = {
186 { "Big5_with_no_encoding_specified.html", 186 { "Big5_with_no_encoding_specified.html",
187 "expected_Big5_saved_from_no_encoding_specified.html", 187 "expected_Big5_saved_from_no_encoding_specified.html",
188 L"Big5" }, 188 "Big5" },
189 { "gb18030_with_no_encoding_specified.html", 189 { "gb18030_with_no_encoding_specified.html",
190 "expected_gb18030_saved_from_no_encoding_specified.html", 190 "expected_gb18030_saved_from_no_encoding_specified.html",
191 L"gb18030" }, 191 "gb18030" },
192 { "iso-8859-1_with_no_encoding_specified.html", 192 { "iso-8859-1_with_no_encoding_specified.html",
193 "expected_iso-8859-1_saved_from_no_encoding_specified.html", 193 "expected_iso-8859-1_saved_from_no_encoding_specified.html",
194 L"ISO-8859-1" }, 194 "ISO-8859-1" },
195 { "ISO-8859-5_with_no_encoding_specified.html", 195 { "ISO-8859-5_with_no_encoding_specified.html",
196 "expected_ISO-8859-5_saved_from_no_encoding_specified.html", 196 "expected_ISO-8859-5_saved_from_no_encoding_specified.html",
197 L"ISO-8859-5" }, 197 "ISO-8859-5" },
198 { "ISO-8859-6_with_no_encoding_specified.html", 198 { "ISO-8859-6_with_no_encoding_specified.html",
199 "expected_ISO-8859-6_saved_from_no_encoding_specified.html", 199 "expected_ISO-8859-6_saved_from_no_encoding_specified.html",
200 L"ISO-8859-6" }, 200 "ISO-8859-6" },
201 { "ISO-8859-7_with_no_encoding_specified.html", 201 { "ISO-8859-7_with_no_encoding_specified.html",
202 "expected_ISO-8859-7_saved_from_no_encoding_specified.html", 202 "expected_ISO-8859-7_saved_from_no_encoding_specified.html",
203 L"ISO-8859-7" }, 203 "ISO-8859-7" },
204 { "ISO-8859-8_with_no_encoding_specified.html", 204 { "ISO-8859-8_with_no_encoding_specified.html",
205 "expected_ISO-8859-8_saved_from_no_encoding_specified.html", 205 "expected_ISO-8859-8_saved_from_no_encoding_specified.html",
206 L"ISO-8859-8-I" }, 206 "ISO-8859-8-I" },
207 { "KOI8-R_with_no_encoding_specified.html", 207 { "KOI8-R_with_no_encoding_specified.html",
208 "expected_KOI8-R_saved_from_no_encoding_specified.html", 208 "expected_KOI8-R_saved_from_no_encoding_specified.html",
209 L"KOI8-R" }, 209 "KOI8-R" },
210 { "Shift-JIS_with_no_encoding_specified.html", 210 { "Shift-JIS_with_no_encoding_specified.html",
211 "expected_Shift-JIS_saved_from_no_encoding_specified.html", 211 "expected_Shift-JIS_saved_from_no_encoding_specified.html",
212 L"Shift_JIS" }, 212 "Shift_JIS" },
213 { "UTF-8_with_no_encoding_specified.html", 213 { "UTF-8_with_no_encoding_specified.html",
214 "expected_UTF-8_saved_from_no_encoding_specified.html", 214 "expected_UTF-8_saved_from_no_encoding_specified.html",
215 L"UTF-8" }, 215 "UTF-8" },
216 { "windows-949_with_no_encoding_specified.html", 216 { "windows-949_with_no_encoding_specified.html",
217 "expected_windows-949_saved_from_no_encoding_specified.html", 217 "expected_windows-949_saved_from_no_encoding_specified.html",
218 L"windows-949" }, 218 "windows-949" },
219 { "windows-1251_with_no_encoding_specified.html", 219 { "windows-1251_with_no_encoding_specified.html",
220 "expected_windows-1251_saved_from_no_encoding_specified.html", 220 "expected_windows-1251_saved_from_no_encoding_specified.html",
221 L"windows-1251" }, 221 "windows-1251" },
222 { "windows-1254_with_no_encoding_specified.html", 222 { "windows-1254_with_no_encoding_specified.html",
223 "expected_windows-1254_saved_from_no_encoding_specified.html", 223 "expected_windows-1254_saved_from_no_encoding_specified.html",
224 L"windows-1254" }, 224 "windows-1254" },
225 { "windows-1255_with_no_encoding_specified.html", 225 { "windows-1255_with_no_encoding_specified.html",
226 "expected_windows-1255_saved_from_no_encoding_specified.html", 226 "expected_windows-1255_saved_from_no_encoding_specified.html",
227 L"windows-1255" }, 227 "windows-1255" },
228 { "windows-1256_with_no_encoding_specified.html", 228 { "windows-1256_with_no_encoding_specified.html",
229 "expected_windows-1256_saved_from_no_encoding_specified.html", 229 "expected_windows-1256_saved_from_no_encoding_specified.html",
230 L"windows-1256" } 230 "windows-1256" }
231 }; 231 };
232 const char* const kAutoDetectDir = "auto_detect"; 232 const char* const kAutoDetectDir = "auto_detect";
233 // Directory of the files of expected results. 233 // Directory of the files of expected results.
234 const char* const kExpectedResultDir = "expected_results"; 234 const char* const kExpectedResultDir = "expected_results";
235 235
236 // Full path of saved file. full_file_name = save_dir_ + file_name[i]; 236 // Full path of saved file. full_file_name = save_dir_ + file_name[i];
237 FilePath full_saved_file_name; 237 FilePath full_saved_file_name;
238 238
239 FilePath test_dir_path = FilePath(kTestDir).AppendASCII(kAutoDetectDir); 239 FilePath test_dir_path = FilePath(kTestDir).AppendASCII(kAutoDetectDir);
240 240
(...skipping 15 matching lines...) Expand all
256 WaitUntilTabCount(1); 256 WaitUntilTabCount(1);
257 257
258 // Disable auto detect if it is on. 258 // Disable auto detect if it is on.
259 EXPECT_TRUE( 259 EXPECT_TRUE(
260 browser->SetBooleanPreference(prefs::kWebKitUsesUniversalDetector, 260 browser->SetBooleanPreference(prefs::kWebKitUsesUniversalDetector,
261 false)); 261 false));
262 EXPECT_TRUE(tab->Reload()); 262 EXPECT_TRUE(tab->Reload());
263 263
264 // Get the encoding used for the page, it must be the default charset we 264 // Get the encoding used for the page, it must be the default charset we
265 // just set. 265 // just set.
266 std::wstring encoding; 266 std::string encoding;
267 EXPECT_TRUE(tab->GetPageCurrentEncoding(&encoding)); 267 EXPECT_TRUE(tab->GetPageCurrentEncoding(&encoding));
268 EXPECT_EQ(encoding, L"ISO-8859-4"); 268 EXPECT_EQ(encoding, "ISO-8859-4");
269 269
270 // Enable the encoding auto detection. 270 // Enable the encoding auto detection.
271 EXPECT_TRUE(browser->SetBooleanPreference( 271 EXPECT_TRUE(browser->SetBooleanPreference(
272 prefs::kWebKitUsesUniversalDetector, true)); 272 prefs::kWebKitUsesUniversalDetector, true));
273 EXPECT_TRUE(tab->Reload()); 273 EXPECT_TRUE(tab->Reload());
274 274
275 // Re-get the encoding of page. It should return the real encoding now. 275 // Re-get the encoding of page. It should return the real encoding now.
276 bool encoding_auto_detect = false; 276 bool encoding_auto_detect = false;
277 EXPECT_TRUE( 277 EXPECT_TRUE(
278 browser->GetBooleanPreference(prefs::kWebKitUsesUniversalDetector, 278 browser->GetBooleanPreference(prefs::kWebKitUsesUniversalDetector,
(...skipping 11 matching lines...) Expand all
290 kExpectedResultDir); 290 kExpectedResultDir);
291 expected_result_file_name = expected_result_file_name.AppendASCII( 291 expected_result_file_name = expected_result_file_name.AppendASCII(
292 kTestDatas[i].expected_result); 292 kTestDatas[i].expected_result);
293 EXPECT_TRUE(tab->SavePage(full_saved_file_name.ToWStringHack(), 293 EXPECT_TRUE(tab->SavePage(full_saved_file_name.ToWStringHack(),
294 temp_sub_resource_dir_.ToWStringHack(), 294 temp_sub_resource_dir_.ToWStringHack(),
295 SavePackage::SAVE_AS_COMPLETE_HTML)); 295 SavePackage::SAVE_AS_COMPLETE_HTML));
296 EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get())); 296 EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get()));
297 CheckFile(full_saved_file_name, expected_result_file_name, true); 297 CheckFile(full_saved_file_name, expected_result_file_name, true);
298 } 298 }
299 } 299 }
OLDNEW
« no previous file with comments | « chrome/browser/browser.cc ('k') | chrome/browser/browser_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698