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

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

Issue 11412077: GTTF: Split BrowserEncodingTest.TestEncodingAliasMapping into smaller tests. (Closed) Base URL: svn://svn.chromium.org/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
« no previous file with comments | « no previous file | no next file » | 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) 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/files/scoped_temp_dir.h" 7 #include "base/files/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"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_commands.h" 13 #include "chrome/browser/ui/browser_commands.h"
14 #include "chrome/browser/ui/browser_tabstrip.h" 14 #include "chrome/browser/ui/browser_tabstrip.h"
15 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
16 #include "chrome/test/base/in_process_browser_test.h" 16 #include "chrome/test/base/in_process_browser_test.h"
17 #include "chrome/test/base/ui_test_utils.h" 17 #include "chrome/test/base/ui_test_utils.h"
18 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/navigation_controller.h" 19 #include "content/public/browser/navigation_controller.h"
20 #include "content/public/browser/notification_service.h" 20 #include "content/public/browser/notification_service.h"
21 #include "content/public/browser/notification_source.h" 21 #include "content/public/browser/notification_source.h"
22 #include "content/public/browser/notification_types.h" 22 #include "content/public/browser/notification_types.h"
23 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
24 #include "content/public/test/test_navigation_observer.h" 24 #include "content/public/test/test_navigation_observer.h"
25 #include "content/test/net/url_request_mock_http_job.h" 25 #include "content/test/net/url_request_mock_http_job.h"
26 26
27 namespace {
28
29 struct EncodingTestData {
30 const char* file_name;
31 const char* encoding_name;
32 };
33
34 const EncodingTestData kEncodingTestDatas[] = {
35 { "Big5.html", "Big5" },
36 { "EUC-JP.html", "EUC-JP" },
37 { "gb18030.html", "gb18030" },
38 { "iso-8859-1.html", "ISO-8859-1" },
39 { "ISO-8859-2.html", "ISO-8859-2" },
40 { "ISO-8859-4.html", "ISO-8859-4" },
41 { "ISO-8859-5.html", "ISO-8859-5" },
42 { "ISO-8859-6.html", "ISO-8859-6" },
43 { "ISO-8859-7.html", "ISO-8859-7" },
44 { "ISO-8859-8.html", "ISO-8859-8" },
45 { "ISO-8859-13.html", "ISO-8859-13" },
46 { "ISO-8859-15.html", "ISO-8859-15" },
47 { "KOI8-R.html", "KOI8-R" },
48 { "KOI8-U.html", "KOI8-U" },
49 { "macintosh.html", "macintosh" },
50 { "Shift-JIS.html", "Shift_JIS" },
51 { "US-ASCII.html", "ISO-8859-1" }, // http://crbug.com/15801
52 { "UTF-8.html", "UTF-8" },
53 { "UTF-16LE.html", "UTF-16LE" },
54 { "windows-874.html", "windows-874" },
55 // http://crbug.com/95963
56 // { "windows-949.html", "windows-949" },
57 { "windows-1250.html", "windows-1250" },
58 { "windows-1251.html", "windows-1251" },
59 { "windows-1252.html", "windows-1252" },
60 { "windows-1253.html", "windows-1253" },
61 { "windows-1254.html", "windows-1254" },
62 { "windows-1255.html", "windows-1255" },
63 { "windows-1256.html", "windows-1256" },
64 { "windows-1257.html", "windows-1257" },
65 { "windows-1258.html", "windows-1258" }
66 };
67
68 } // namespace
69
27 using content::BrowserThread; 70 using content::BrowserThread;
28 71
29 static const FilePath::CharType* kTestDir = FILE_PATH_LITERAL("encoding_tests"); 72 static const FilePath::CharType* kTestDir = FILE_PATH_LITERAL("encoding_tests");
30 73
31 class BrowserEncodingTest : public InProcessBrowserTest { 74 class BrowserEncodingTest
75 : public InProcessBrowserTest,
76 public testing::WithParamInterface<EncodingTestData> {
32 protected: 77 protected:
33 BrowserEncodingTest() {} 78 BrowserEncodingTest() {}
34 79
35 // Saves the current page and verifies that the output matches the expected 80 // Saves the current page and verifies that the output matches the expected
36 // result. 81 // result.
37 void SaveAndCompare(const char* filename_to_write, const FilePath& expected) { 82 void SaveAndCompare(const char* filename_to_write, const FilePath& expected) {
38 // Dump the page, the content of dump page should be identical to the 83 // Dump the page, the content of dump page should be identical to the
39 // expected result file. 84 // expected result file.
40 FilePath full_file_name = save_dir_.AppendASCII(filename_to_write); 85 FilePath full_file_name = save_dir_.AppendASCII(filename_to_write);
41 // We save the page as way of complete HTML file, which requires a directory 86 // We save the page as way of complete HTML file, which requires a directory
(...skipping 26 matching lines...) Expand all
68 base::ScopedTempDir temp_dir_; 113 base::ScopedTempDir temp_dir_;
69 FilePath save_dir_; 114 FilePath save_dir_;
70 FilePath temp_sub_resource_dir_; 115 FilePath temp_sub_resource_dir_;
71 }; 116 };
72 117
73 // TODO(jnd): 1. Some encodings are missing here. It'll be added later. See 118 // TODO(jnd): 1. Some encodings are missing here. It'll be added later. See
74 // http://crbug.com/13306. 119 // http://crbug.com/13306.
75 // 2. Add more files with multiple encoding name variants for each canonical 120 // 2. Add more files with multiple encoding name variants for each canonical
76 // encoding name). Webkit layout tests cover some, but testing in the UI test is 121 // encoding name). Webkit layout tests cover some, but testing in the UI test is
77 // also necessary. 122 // also necessary.
78 // SLOW_ is added for XP debug bots. These tests should really be unittests... 123 IN_PROC_BROWSER_TEST_P(BrowserEncodingTest, TestEncodingAliasMapping) {
79 IN_PROC_BROWSER_TEST_F(BrowserEncodingTest, SLOW_TestEncodingAliasMapping) {
80 struct EncodingTestData {
81 const char* file_name;
82 const char* encoding_name;
83 };
84
85 const EncodingTestData kEncodingTestDatas[] = {
86 { "Big5.html", "Big5" },
87 { "EUC-JP.html", "EUC-JP" },
88 { "gb18030.html", "gb18030" },
89 { "iso-8859-1.html", "ISO-8859-1" },
90 { "ISO-8859-2.html", "ISO-8859-2" },
91 { "ISO-8859-4.html", "ISO-8859-4" },
92 { "ISO-8859-5.html", "ISO-8859-5" },
93 { "ISO-8859-6.html", "ISO-8859-6" },
94 { "ISO-8859-7.html", "ISO-8859-7" },
95 { "ISO-8859-8.html", "ISO-8859-8" },
96 { "ISO-8859-13.html", "ISO-8859-13" },
97 { "ISO-8859-15.html", "ISO-8859-15" },
98 { "KOI8-R.html", "KOI8-R" },
99 { "KOI8-U.html", "KOI8-U" },
100 { "macintosh.html", "macintosh" },
101 { "Shift-JIS.html", "Shift_JIS" },
102 { "US-ASCII.html", "ISO-8859-1" }, // http://crbug.com/15801
103 { "UTF-8.html", "UTF-8" },
104 { "UTF-16LE.html", "UTF-16LE" },
105 { "windows-874.html", "windows-874" },
106 // http://crbug.com/95963
107 // { "windows-949.html", "windows-949" },
108 { "windows-1250.html", "windows-1250" },
109 { "windows-1251.html", "windows-1251" },
110 { "windows-1252.html", "windows-1252" },
111 { "windows-1253.html", "windows-1253" },
112 { "windows-1254.html", "windows-1254" },
113 { "windows-1255.html", "windows-1255" },
114 { "windows-1256.html", "windows-1256" },
115 { "windows-1257.html", "windows-1257" },
116 { "windows-1258.html", "windows-1258" }
117 };
118 const char* const kAliasTestDir = "alias_mapping"; 124 const char* const kAliasTestDir = "alias_mapping";
119 125
120 FilePath test_dir_path = FilePath(kTestDir).AppendASCII(kAliasTestDir); 126 FilePath test_dir_path = FilePath(kTestDir).AppendASCII(kAliasTestDir);
121 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kEncodingTestDatas); ++i) { 127 FilePath test_file_path(test_dir_path);
122 FilePath test_file_path(test_dir_path); 128 test_file_path = test_file_path.AppendASCII(
123 test_file_path = test_file_path.AppendASCII( 129 GetParam().file_name);
124 kEncodingTestDatas[i].file_name);
125 130
126 GURL url = content::URLRequestMockHTTPJob::GetMockUrl(test_file_path); 131 GURL url = content::URLRequestMockHTTPJob::GetMockUrl(test_file_path);
132 ui_test_utils::NavigateToURL(browser(), url);
133 EXPECT_EQ(GetParam().encoding_name,
134 chrome::GetActiveWebContents(browser())->GetEncoding());
135 }
127 136
128 // When looping through all the above files in one WebContents, there's a 137 INSTANTIATE_TEST_CASE_P(EncodingAliases,
129 // race condition on Windows trybots that causes the previous encoding to be 138 BrowserEncodingTest,
130 // seen sometimes. Create a new tab for each one. http://crbug.com/122053 139 testing::ValuesIn(kEncodingTestDatas));
131 ui_test_utils::NavigateToURLWithDisposition(
132 browser(), url, NEW_FOREGROUND_TAB,
133 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
134
135 EXPECT_EQ(kEncodingTestDatas[i].encoding_name,
136 chrome::GetActiveWebContents(browser())->GetEncoding());
137 chrome::CloseTab(browser());
138 }
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);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 181
182 // For Hebrew, the expected encoding value is ISO-8859-8-I. See 182 // For Hebrew, the expected encoding value is ISO-8859-8-I. See
183 // http://crbug.com/2927 for more details. 183 // http://crbug.com/2927 for more details.
184 // 184 //
185 // This test fails frequently on the win_rel trybot. See http://crbug.com/122053 185 // This test fails frequently on the win_rel trybot. See http://crbug.com/122053
186 #if defined(OS_WIN) 186 #if defined(OS_WIN)
187 #define MAYBE_TestEncodingAutoDetect DISABLED_TestEncodingAutoDetect 187 #define MAYBE_TestEncodingAutoDetect DISABLED_TestEncodingAutoDetect
188 #else 188 #else
189 #define MAYBE_TestEncodingAutoDetect TestEncodingAutoDetect 189 #define MAYBE_TestEncodingAutoDetect TestEncodingAutoDetect
190 #endif 190 #endif
191 // TODO(phajdan.jr): See if fix for http://crbug.com/122053 would help here.
191 IN_PROC_BROWSER_TEST_F(BrowserEncodingTest, MAYBE_TestEncodingAutoDetect) { 192 IN_PROC_BROWSER_TEST_F(BrowserEncodingTest, MAYBE_TestEncodingAutoDetect) {
192 struct EncodingAutoDetectTestData { 193 struct EncodingAutoDetectTestData {
193 const char* test_file_name; // File name of test data. 194 const char* test_file_name; // File name of test data.
194 const char* expected_result; // File name of expected results. 195 const char* expected_result; // File name of expected results.
195 const char* expected_encoding; // expected encoding. 196 const char* expected_encoding; // expected encoding.
196 }; 197 };
197 const EncodingAutoDetectTestData kTestDatas[] = { 198 const EncodingAutoDetectTestData kTestDatas[] = {
198 { "Big5_with_no_encoding_specified.html", 199 { "Big5_with_no_encoding_specified.html",
199 "expected_Big5_saved_from_no_encoding_specified.html", 200 "expected_Big5_saved_from_no_encoding_specified.html",
200 "Big5" }, 201 "Big5" },
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 EXPECT_EQ(kTestDatas[i].expected_encoding, web_contents->GetEncoding()); 283 EXPECT_EQ(kTestDatas[i].expected_encoding, web_contents->GetEncoding());
283 284
284 // Dump the page, the content of dump page should be equal with our expect 285 // Dump the page, the content of dump page should be equal with our expect
285 // result file. 286 // result file.
286 FilePath expected_result_file_name = 287 FilePath expected_result_file_name =
287 FilePath().AppendASCII(kAutoDetectDir).AppendASCII(kExpectedResultDir). 288 FilePath().AppendASCII(kAutoDetectDir).AppendASCII(kExpectedResultDir).
288 AppendASCII(kTestDatas[i].expected_result); 289 AppendASCII(kTestDatas[i].expected_result);
289 SaveAndCompare(kTestDatas[i].test_file_name, expected_result_file_name); 290 SaveAndCompare(kTestDatas[i].test_file_name, expected_result_file_name);
290 } 291 }
291 } 292 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698