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

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

Issue 18417: Add a UI test for "Encoding" menu Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/download/save_page_uitest.cc » ('j') | chrome/test/ui/ui_test.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/file_util.h"
6 #include "base/path_service.h"
7 #include "base/string_util.h"
8 #include "chrome/browser/automation/url_request_mock_http_job.h"
9 #include "chrome/browser/download/save_package.h"
10 #include "chrome/common/chrome_paths.h"
11 #include "chrome/test/automation/automation_messages.h"
12 #include "chrome/test/automation/automation_proxy.h"
13 #include "chrome/test/automation/browser_proxy.h"
14 #include "chrome/test/automation/tab_proxy.h"
15 #include "chrome/test/ui/ui_test.h"
16 #include "net/url_request/url_request_unittest.h"
17 #include "chrome/common/pref_names.h"
18
19 const std::wstring kTestDir = L"encoding_tests";
20
21 class BrowserEncodingTest : public UITest {
22 protected:
23 BrowserEncodingTest() : UITest() {}
24
25 // Make sure the content of the page are expected
26 // after override or auto-detect
27 void CheckFile(const std::wstring& generated_file,
Johnny(Jianning) Ding 2009/03/09 12:31:46 would please move this function to UITest with add
28 const std::wstring& expect_result_file,
29 bool check_equal) {
30 std::wstring expect_result_filepath =
31 UITest::GetTestFilePath(kTestDir, expect_result_file);
32
33 ASSERT_TRUE(file_util::PathExists(expect_result_filepath));
34 WaitForGeneratedFileAndCheck(generated_file,
35 expect_result_filepath,
36 check_equal, true);
37 }
38
39 virtual void SetUp() {
40 UITest::SetUp();
41 EXPECT_TRUE(file_util::CreateNewTempDirectory(L"", &save_dir_));
42 save_dir_ += FilePath::kSeparators[0];
43 }
44
45 std::wstring save_dir_;
46 std::wstring encoding_;
47 GURL url;
48 };
49
50 // Below encodings are ignored because I don't have an editor to
51 // create corresponding encoded test file for now :
52 // GBK
53 // Big5-HKSCS
54 // ISO-2022-JP
55 // ISO-8859-2
56 // ISO-8859-3
57 // ISO-8859-10
58 // ISO-8859-14
59 // ISO-8859-16
Johnny(Jianning) Ding 2009/03/09 12:31:46 would you please file a bug for those encoding, th
60 TEST_F(BrowserEncodingTest, TestEncodingAliasMapping) {
61 struct EncodingTestData {
Johnny(Jianning) Ding 2009/03/09 12:31:46 you can move the definition to class BrowserEncodi
62 const wchar_t* file_name;
63 const wchar_t* encoding_name;
64 };
65
66 EncodingTestData encoding_test_data[] = {
67 { L"encoding-UTF-8.htm", L"UTF-8" },
68 { L"encoding-UTF-16LE.htm", L"UTF-16LE" },
69 { L"encoding-iso-8859-1.htm", L"ISO-8859-1" },
70 { L"encoding-windows-1252.htm", L"windows-1252" },
71 { L"encoding-gb18030.htm", L"gb18030" },
72 { L"encoding-Big5.htm", L"Big5" },
73 { L"encoding-windows-949.htm", L"windows-949" },
74 { L"encoding-Shift-JIS.htm", L"Shift_JIS" },
75 { L"encoding-EUC-JP.htm", L"EUC-JP" },
76 { L"encoding-windows-874.htm", L"windows-874" },
77 { L"encoding-ISO-8859-15.htm", L"ISO-8859-15" },
78 { L"encoding-macintosh.htm", L"macintosh" },
79 { L"encoding-ISO-8859-2.htm", L"ISO-8859-2" },
80 { L"encoding-windows-1250.htm", L"windows-1250" },
81 { L"encoding-ISO-8859-5.htm", L"ISO-8859-5" },
82 { L"encoding-windows-1251.htm", L"windows-1251" },
83 { L"encoding-KOI8-R.htm", L"KOI8-R" },
84 { L"encoding-KOI8-U.htm", L"KOI8-U" },
85 { L"encoding-ISO-8859-7.htm", L"ISO-8859-7" },
86 { L"encoding-windows-1253.htm", L"windows-1253" },
87 { L"encoding-windows-1254.htm", L"windows-1254" },
88 { L"encoding-ISO-8859-6.htm", L"ISO-8859-6" },
89 { L"encoding-windows-1256.htm", L"windows-1256" },
90 { L"encoding-ISO-8859-8.htm", L"ISO-8859-8" },
91 { L"encoding-windows-1255.htm", L"windows-1255" },
92 { L"encoding-windows-1258.htm", L"windows-1258" },
93 { L"encoding-ISO-8859-4.htm", L"ISO-8859-4" },
94 { L"encoding-ISO-8859-13.htm", L"ISO-8859-13" },
95 { L"encoding-windows-1257.htm", L"windows-1257" },
96 };
97
98 for (int i = 0;i < arraysize (encoding_test_data); i++) {
99 url = URLRequestMockHTTPJob::GetMockUrl(
100 kTestDir + L"/encoding_alias_mapping/" + encoding_test_data[i].file_name);
Johnny(Jianning) Ding 2009/03/09 12:31:46 needs 4 spaces indent, you can write it like url =
101
102 scoped_ptr<TabProxy> tab(GetActiveTab());
103 ASSERT_TRUE(tab->NavigateToURL(url));
104 WaitUntilTabCount(1);
105
106 EXPECT_TRUE(tab->GetPageCurrentEncoding(&encoding_));
107 EXPECT_EQ(encoding_, encoding_test_data[i].encoding_name);
108 }
109 }
110
111 TEST_F(BrowserEncodingTest, TestOverrideEncoding) {
112 std::wstring file_name = L"gb18030_content_with_encoding_iso88591.htm";
113 std::wstring expect_file_name =
114 L"encoding_user_override\\expect_gb18030_content_save_from_iso88591.htm";
115
116 url = URLRequestMockHTTPJob::GetMockUrl(
117 kTestDir + L"/encoding_user_override/" + file_name);
Johnny(Jianning) Ding 2009/03/09 12:31:46 4 spaces indent
118 scoped_ptr<TabProxy> tab(GetActiveTab());
119 ASSERT_TRUE(tab->NavigateToURL(url));
120 WaitUntilTabCount(1);
121
122 // Get the original defined encoding in the page
123 // std::wstring encoding;
124 EXPECT_TRUE(tab->GetPageCurrentEncoding(&encoding_));
125 EXPECT_EQ(encoding_, L"ISO-8859-1");
126
127 // Override the encoding to "gb18030".
128 int64 last_nav_time = 0;
129 EXPECT_TRUE(tab->GetLastNavigationTime(&last_nav_time));
130 EXPECT_TRUE(tab->OverrideEncoding(L"gb18030"));
131 EXPECT_TRUE(tab->WaitForNavigation(last_nav_time));
132
133 // Re-get the encoding of page. It should be gb18030.
134 EXPECT_TRUE(tab->GetPageCurrentEncoding(&encoding_));
135 EXPECT_EQ(encoding_, L"gb18030");
136
137 // Dump the page, the content of dump page should be equal with our expect
138 // result file gb18030_content_with_encoding_gb18030.htm.
139 std::wstring full_file_name = save_dir_ + file_name;
140 std::wstring dir = save_dir_ +
141 L"gb18030_content_with_encoding_iso88591_files";
142 EXPECT_TRUE(tab->SavePage(full_file_name, dir,
143 SavePackage::SAVE_AS_COMPLETE_HTML));
144 EXPECT_TRUE(WaitForDownloadShelfVisible(tab.get()));
145 CheckFile(full_file_name, expect_file_name, true);
146 }
147
148 // Below encoding are disabled because it is known issue that
149 // auto detect doesn't return right value for them
150 // ISO-8859-4
151 // ISO-8859-13
152 // windows-1257
153 // KOI8-U
154 // macintosh
155 // windows-1252
156
Johnny(Jianning) Ding 2009/03/09 12:31:46 please remove this empty line.
157 // Also disabled Thai and Vietnamese because auto detect doesn't work for them
158 // windows-874
159 // windows-1258
160 // windows-1253
161
Johnny(Jianning) Ding 2009/03/09 12:31:46 please remove this empty line.
162 // For Hebrew, I made the expecting encoding value as ISO-8859-8-I because of
163 // bug crbug.com/2927
164
165 TEST_F(BrowserEncodingTest, TestEncodingAutoDetect) {
166 // Test file name
167 const wchar_t* file_name[] = {
Johnny(Jianning) Ding 2009/03/09 12:31:46 please use the previous defined "EncodingTestData"
168 L"Big5_content_without_encoding_declaration.htm",
169 L"gb18030_content_without_encoding_declaration.htm",
170 L"iso-8859-1_content_without_encoding_declaration.htm",
171 L"ISO-8859-5_content_without_encoding_declaration.htm",
172 L"ISO-8859-6_content_without_encoding_declaration.htm",
173 L"ISO-8859-7_content_without_encoding_declaration.htm",
174 L"ISO-8859-8_content_without_encoding_declaration.htm",
175 L"KOI8-R_content_without_encoding_declaration.htm",
176 L"Shift-JIS_content_without_encoding_declaration.htm",
177 L"UTF-8_content_without_encoding_declaration.htm",
178 L"windows-949_content_without_encoding_declaration.htm",
179 L"windows-1251_content_without_encoding_declaration.htm",
180 L"windows-1254_content_without_encoding_declaration.htm",
181 L"windows-1255_content_without_encoding_declaration.htm",
182 L"windows-1256_content_without_encoding_declaration.htm",
183 };
184
185 // Expect file directory and file name
186 std::wstring expect_folder_name = L"encoding_auto_detect\\expect_results\\";
187 const wchar_t* expect_file_name[] = {
188 L"expect_Big5_content_save_from_without_encoding_declaration.htm",
189 L"expect_gb18030_content_save_from_without_encoding_declaration.htm",
190 L"expect_iso-8859-1_content_save_from_without_encoding_declaration.htm",
191 L"expect_ISO-8859-5_content_save_from_without_encoding_declaration.htm",
192 L"expect_ISO-8859-6_content_save_from_without_encoding_declaration.htm",
193 L"expect_ISO-8859-7_content_save_from_without_encoding_declaration.htm",
194 L"expect_ISO-8859-8_content_save_from_without_encoding_declaration.htm",
195 L"expect_KOI8-R_content_save_from_without_encoding_declaration.htm",
196 L"expect_Shift-JIS_content_save_from_without_encoding_declaration.htm",
197 L"expect_UTF-8_content_save_from_without_encoding_declaration.htm",
198 L"expect_windows-949_content_save_from_without_encoding_declaration.htm",
199 L"expect_windows-1251_content_save_from_without_encoding_declaration.htm",
200 L"expect_windows-1254_content_save_from_without_encoding_declaration.htm",
201 L"expect_windows-1255_content_save_from_without_encoding_declaration.htm",
202 L"expect_windows-1256_content_save_from_without_encoding_declaration.htm",
203 };
204
205 // Real expect file name
206 std::wstring full_expect_file_name;
207
208 // Expected encoding
209 const wchar_t* expect_encoding[] = {L"Big5",
210 L"gb18030",
211 L"ISO-8859-1",
212 L"ISO-8859-5",
213 L"ISO-8859-6",
214 L"ISO-8859-7",
215 L"ISO-8859-8-I",
216 L"KOI8-R",
217 L"Shift_JIS",
218 L"UTF-8",
219 L"windows-949",
220 L"windows-1251",
221 L"windows-1254",
222 L"windows-1255",
223 L"windows-1256",
224 };
225
226 // Save as file directory
227 const wchar_t* save_dir_sub[] = {
228 L"Big5_content_without_encoding_declaration_files",
Johnny(Jianning) Ding 2009/03/09 12:31:46 you can define the prefix name like EncodingTestDa
229 L"gb18030_content_without_encoding_declaration_files",
230 L"iso-8859-1_content_without_encoding_declaration_files",
231 L"ISO-8859-5_content_without_encoding_declaration_files",
232 L"ISO-8859-6_content_without_encoding_declaration_files",
233 L"ISO-8859-7_content_without_encoding_declaration_files",
234 L"ISO-8859-8_content_without_encoding_declaration_files",
235 L"KOI8-R_content_without_encoding_declaration_files",
236 L"Shift-JIS_content_without_encoding_declaration_files",
237 L"UTF-8_content_without_encoding_declaration_files",
238 L"windows-949_content_without_encoding_declaration_files",
239 L"windows-1251_content_without_encoding_declaration_files",
240 L"windows-1254_content_without_encoding_declaration_files",
241 L"windows-1255_content_without_encoding_declaration_files",
242 L"windows-1256_content_without_encoding_declaration_files",
243 };
244
245 // Real save as location: dir = save_dir_ + save_dir_sub[i];
246 std::wstring dir;
247
248 // Real save as file name: full_file_name = save_dir_ + file_name[i];
249 std::wstring full_file_name;
250
251 int64 last_nav_time;
252 bool encoding_auto_detect = false;
253 bool new_encoding_auto_detect = false;
254
255 for(int i = 0;i < arraysize (file_name);i++) {
256 scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
257 ASSERT_TRUE(browser.get());
258
259 // Set the default charset to non-GB related encoding to make sure we
260 // incorrectly decode the page.
261 browser->SetStringPreference(prefs::kDefaultCharset, L"ISO-8859-1");
262
263 url = URLRequestMockHTTPJob::GetMockUrl(
264 kTestDir + L"/encoding_auto_detect/" + file_name[i]);
Johnny(Jianning) Ding 2009/03/09 12:31:46 4 spaces indent
265 scoped_ptr<TabProxy> tab(GetActiveTab());
266 ASSERT_TRUE(tab->NavigateToURL(url));
267 WaitUntilTabCount(1);
268
269 // Disable auto detect if it is on
270 last_nav_time = 0;
271 EXPECT_TRUE(browser->SetBooleanPreference(
272 prefs::kWebKitUsesUniversalDetector, encoding_auto_detect));
273 EXPECT_TRUE(tab->Reload());
274
275 // Get the encoding used for the page, it must be the default charset we
276 // just set
277 // std::wstring encoding;
278 EXPECT_TRUE(tab->GetPageCurrentEncoding(&encoding_));
279 EXPECT_EQ(encoding_, L"ISO-8859-1");
280
281 // Enable the encoding auto detection.
282 last_nav_time = 0;
283 EXPECT_TRUE(browser->SetBooleanPreference(
284 prefs::kWebKitUsesUniversalDetector, !encoding_auto_detect));
285 EXPECT_TRUE(tab->Reload());
286
287 // Re-get the encoding of page. It should return the real encoding now.
288 EXPECT_TRUE(browser->GetBooleanPreference(
289 prefs::kWebKitUsesUniversalDetector, &new_encoding_auto_detect));
290 EXPECT_EQ(new_encoding_auto_detect, !encoding_auto_detect);
291 EXPECT_TRUE(tab->GetPageCurrentEncoding(&encoding_));
292 EXPECT_EQ(encoding_, expect_encoding[i]);
293
294 // Dump the page, the content of dump page should be equal with our expect
295 // result file gb18030_content_with_encoding_gb18030.htm.
296 full_file_name = save_dir_ + file_name[i];
297 dir = save_dir_ + save_dir_sub[i];
298 full_expect_file_name = expect_folder_name + expect_file_name[i];
299
300 EXPECT_TRUE(tab->SavePage(full_file_name, dir,
301 SavePackage::SAVE_AS_COMPLETE_HTML));
302 EXPECT_TRUE(WaitForDownloadShelfVisible(tab.get()));
303
304 CheckFile(full_file_name, full_expect_file_name, true);
305 }
306 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/save_page_uitest.cc » ('j') | chrome/test/ui/ui_test.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698