OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_BROWSERTEST_H_ | 5 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_BROWSERTEST_H_ |
6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_BROWSERTEST_H_ | 6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_BROWSERTEST_H_ |
7 | 7 |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "net/url_request/url_fetcher_delegate.h" | 24 #include "net/url_request/url_fetcher_delegate.h" |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 const base::FilePath::CharType kTranslateRoot[] = | 28 const base::FilePath::CharType kTranslateRoot[] = |
29 FILE_PATH_LITERAL("chrome/test/data/translate"); | 29 FILE_PATH_LITERAL("chrome/test/data/translate"); |
30 const char kNonSecurePrefix[] = "files/translate/"; | 30 const char kNonSecurePrefix[] = "files/translate/"; |
31 const char kSecurePrefix[] = "files/"; | 31 const char kSecurePrefix[] = "files/"; |
32 const char kFrenchTestPath[] = "fr_test.html"; | 32 const char kFrenchTestPath[] = "fr_test.html"; |
33 const char kRefreshMetaTagTestPath[] = "refresh_meta_tag.html"; | 33 const char kRefreshMetaTagTestPath[] = "refresh_meta_tag.html"; |
| 34 const char kRefreshMetaTagCaseInsensitiveTestPath[] = |
| 35 "refresh_meta_tag_casei.html"; |
34 const char kRefreshMetaTagAtOnloadTestPath[] = | 36 const char kRefreshMetaTagAtOnloadTestPath[] = |
35 "refresh_meta_tag_at_onload.html"; | 37 "refresh_meta_tag_at_onload.html"; |
36 const char kUpdateLocationTestPath[] = "update_location.html"; | 38 const char kUpdateLocationTestPath[] = "update_location.html"; |
37 const char kUpdateLocationAtOnloadTestPath[] = "update_location_at_onload.html"; | 39 const char kUpdateLocationAtOnloadTestPath[] = "update_location_at_onload.html"; |
38 const char kMainScriptPath[] = "pseudo_main.js"; | 40 const char kMainScriptPath[] = "pseudo_main.js"; |
39 const char kElementMainScriptPath[] = "pseudo_element_main.js"; | 41 const char kElementMainScriptPath[] = "pseudo_element_main.js"; |
40 | 42 |
41 }; // namespace | 43 }; // namespace |
42 | 44 |
43 class TranslateBrowserTest : public InProcessBrowserTest { | 45 class TranslateBrowserTest : public InProcessBrowserTest { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 content::WebContents* web_contents = | 78 content::WebContents* web_contents = |
77 browser()->tab_strip_model()->GetActiveWebContents(); | 79 browser()->tab_strip_model()->GetActiveWebContents(); |
78 ASSERT_TRUE(web_contents); | 80 ASSERT_TRUE(web_contents); |
79 | 81 |
80 net::TestURLFetcherFactory factory; | 82 net::TestURLFetcherFactory factory; |
81 | 83 |
82 // Setup infobar observer. | 84 // Setup infobar observer. |
83 InfoBarService* infobar_service = | 85 InfoBarService* infobar_service = |
84 InfoBarService::FromWebContents(web_contents); | 86 InfoBarService::FromWebContents(web_contents); |
85 ASSERT_TRUE(infobar_service); | 87 ASSERT_TRUE(infobar_service); |
86 ASSERT_EQ(0U, infobar_service->infobar_count()); | 88 EXPECT_EQ(0U, infobar_service->infobar_count()); |
87 content::WindowedNotificationObserver infobar( | 89 content::WindowedNotificationObserver infobar( |
88 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | 90 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
89 content::NotificationService::AllSources()); | 91 content::NotificationService::AllSources()); |
90 | 92 |
91 // Setup page title observer. | 93 // Setup page title observer. |
92 content::TitleWatcher watcher(web_contents, ASCIIToUTF16("PASS")); | 94 content::TitleWatcher watcher(web_contents, ASCIIToUTF16("PASS")); |
93 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); | 95 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); |
94 | 96 |
95 // Visit non-secure page which is going to be translated. | 97 // Visit non-secure page which is going to be translated. |
96 ui_test_utils::NavigateToURL(browser(), GetNonSecureURL(kFrenchTestPath)); | 98 ui_test_utils::NavigateToURL(browser(), GetNonSecureURL(kFrenchTestPath)); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 net::URLRequestStatus status; | 130 net::URLRequestStatus status; |
129 status.set_status(net::URLRequestStatus::SUCCESS); | 131 status.set_status(net::URLRequestStatus::SUCCESS); |
130 fetcher->set_status(status); | 132 fetcher->set_status(status); |
131 fetcher->set_url(fetcher->GetOriginalURL()); | 133 fetcher->set_url(fetcher->GetOriginalURL()); |
132 fetcher->set_response_code(net::HTTP_OK); | 134 fetcher->set_response_code(net::HTTP_OK); |
133 fetcher->SetResponseString(element_js); | 135 fetcher->SetResponseString(element_js); |
134 fetcher->delegate()->OnURLFetchComplete(fetcher); | 136 fetcher->delegate()->OnURLFetchComplete(fetcher); |
135 | 137 |
136 // Wait for the page title is changed after the test finished. | 138 // Wait for the page title is changed after the test finished. |
137 const string16 result = watcher.WaitAndGetTitle(); | 139 const string16 result = watcher.WaitAndGetTitle(); |
138 EXPECT_TRUE(EqualsASCII(result, "PASS")); | 140 EXPECT_EQ("PASS", UTF16ToASCII(result)); |
139 } | 141 } |
140 | 142 |
141 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, IgnoreRefreshMetaTag) { | 143 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, IgnoreRefreshMetaTag) { |
142 ASSERT_TRUE(test_server()->Start()); | 144 ASSERT_TRUE(test_server()->Start()); |
143 | 145 |
144 content::WebContents* web_contents = | 146 content::WebContents* web_contents = |
145 browser()->tab_strip_model()->GetActiveWebContents(); | 147 browser()->tab_strip_model()->GetActiveWebContents(); |
146 ASSERT_TRUE(web_contents); | 148 ASSERT_TRUE(web_contents); |
147 | 149 |
148 // Check infobar count. | 150 // Check infobar count. |
149 InfoBarService* infobar_service = | 151 InfoBarService* infobar_service = |
150 InfoBarService::FromWebContents(web_contents); | 152 InfoBarService::FromWebContents(web_contents); |
151 ASSERT_TRUE(infobar_service); | 153 ASSERT_TRUE(infobar_service); |
152 ASSERT_EQ(0U, infobar_service->infobar_count()); | 154 EXPECT_EQ(0U, infobar_service->infobar_count()); |
153 | 155 |
154 // Setup page title observer. | 156 // Setup page title observer. |
155 content::TitleWatcher watcher(web_contents, ASCIIToUTF16("PASS")); | 157 content::TitleWatcher watcher(web_contents, ASCIIToUTF16("PASS")); |
156 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); | 158 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); |
157 | 159 |
158 // Visit a test page. | 160 // Visit a test page. |
159 ui_test_utils::NavigateToURL( | 161 ui_test_utils::NavigateToURL( |
160 browser(), | 162 browser(), |
161 GetNonSecureURL(kRefreshMetaTagTestPath)); | 163 GetNonSecureURL(kRefreshMetaTagTestPath)); |
162 | 164 |
163 // Wait for the page title is changed after the test finished. | 165 // Wait for the page title is changed after the test finished. |
164 const string16 result = watcher.WaitAndGetTitle(); | 166 const string16 result = watcher.WaitAndGetTitle(); |
165 EXPECT_TRUE(EqualsASCII(result, "PASS")); | 167 EXPECT_EQ("PASS", UTF16ToASCII(result)); |
166 | 168 |
167 // Check there is not infobar. | 169 // Check there is not infobar. |
168 ASSERT_EQ(0U, infobar_service->infobar_count()); | 170 EXPECT_EQ(0U, infobar_service->infobar_count()); |
| 171 } |
| 172 |
| 173 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, |
| 174 IgnoreRefreshMetaTagInCaseInsensitive) { |
| 175 ASSERT_TRUE(test_server()->Start()); |
| 176 |
| 177 content::WebContents* web_contents = |
| 178 browser()->tab_strip_model()->GetActiveWebContents(); |
| 179 ASSERT_TRUE(web_contents); |
| 180 |
| 181 // Check infobar count. |
| 182 InfoBarService* infobar_service = |
| 183 InfoBarService::FromWebContents(web_contents); |
| 184 ASSERT_TRUE(infobar_service); |
| 185 EXPECT_EQ(0U, infobar_service->infobar_count()); |
| 186 |
| 187 // Setup page title observer. |
| 188 content::TitleWatcher watcher(web_contents, ASCIIToUTF16("PASS")); |
| 189 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); |
| 190 |
| 191 // Visit a test page. |
| 192 ui_test_utils::NavigateToURL( |
| 193 browser(), |
| 194 GetNonSecureURL(kRefreshMetaTagCaseInsensitiveTestPath)); |
| 195 |
| 196 // Wait for the page title is changed after the test finished. |
| 197 const string16 result = watcher.WaitAndGetTitle(); |
| 198 EXPECT_EQ("PASS", UTF16ToASCII(result)); |
| 199 |
| 200 // Check there is not infobar. |
| 201 EXPECT_EQ(0U, infobar_service->infobar_count()); |
169 } | 202 } |
170 | 203 |
171 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, IgnoreRefreshMetaTagAtOnload) { | 204 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, IgnoreRefreshMetaTagAtOnload) { |
172 ASSERT_TRUE(test_server()->Start()); | 205 ASSERT_TRUE(test_server()->Start()); |
173 | 206 |
174 content::WebContents* web_contents = | 207 content::WebContents* web_contents = |
175 browser()->tab_strip_model()->GetActiveWebContents(); | 208 browser()->tab_strip_model()->GetActiveWebContents(); |
176 ASSERT_TRUE(web_contents); | 209 ASSERT_TRUE(web_contents); |
177 | 210 |
178 // Check infobar count. | 211 // Check infobar count. |
179 InfoBarService* infobar_service = | 212 InfoBarService* infobar_service = |
180 InfoBarService::FromWebContents(web_contents); | 213 InfoBarService::FromWebContents(web_contents); |
181 ASSERT_TRUE(infobar_service); | 214 ASSERT_TRUE(infobar_service); |
182 ASSERT_EQ(0U, infobar_service->infobar_count()); | 215 EXPECT_EQ(0U, infobar_service->infobar_count()); |
183 | 216 |
184 // Setup page title observer. | 217 // Setup page title observer. |
185 content::TitleWatcher watcher(web_contents, ASCIIToUTF16("PASS")); | 218 content::TitleWatcher watcher(web_contents, ASCIIToUTF16("PASS")); |
186 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); | 219 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); |
187 | 220 |
188 // Visit a test page. | 221 // Visit a test page. |
189 ui_test_utils::NavigateToURL( | 222 ui_test_utils::NavigateToURL( |
190 browser(), | 223 browser(), |
191 GetNonSecureURL(kRefreshMetaTagAtOnloadTestPath)); | 224 GetNonSecureURL(kRefreshMetaTagAtOnloadTestPath)); |
192 | 225 |
193 // Wait for the page title is changed after the test finished. | 226 // Wait for the page title is changed after the test finished. |
194 const string16 result = watcher.WaitAndGetTitle(); | 227 const string16 result = watcher.WaitAndGetTitle(); |
195 EXPECT_TRUE(EqualsASCII(result, "PASS")); | 228 EXPECT_EQ("PASS", UTF16ToASCII(result)); |
196 | 229 |
197 // Check there is not infobar. | 230 // Check there is not infobar. |
198 ASSERT_EQ(0U, infobar_service->infobar_count()); | 231 EXPECT_EQ(0U, infobar_service->infobar_count()); |
199 } | 232 } |
200 | 233 |
201 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, UpdateLocation) { | 234 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, UpdateLocation) { |
202 ASSERT_TRUE(test_server()->Start()); | 235 ASSERT_TRUE(test_server()->Start()); |
203 | 236 |
204 content::WebContents* web_contents = | 237 content::WebContents* web_contents = |
205 browser()->tab_strip_model()->GetActiveWebContents(); | 238 browser()->tab_strip_model()->GetActiveWebContents(); |
206 ASSERT_TRUE(web_contents); | 239 ASSERT_TRUE(web_contents); |
207 | 240 |
208 // Check infobar count. | 241 // Check infobar count. |
209 InfoBarService* infobar_service = | 242 InfoBarService* infobar_service = |
210 InfoBarService::FromWebContents(web_contents); | 243 InfoBarService::FromWebContents(web_contents); |
211 ASSERT_TRUE(infobar_service); | 244 ASSERT_TRUE(infobar_service); |
212 ASSERT_EQ(0U, infobar_service->infobar_count()); | 245 EXPECT_EQ(0U, infobar_service->infobar_count()); |
213 | 246 |
214 // Setup page title observer. | 247 // Setup page title observer. |
215 content::TitleWatcher watcher(web_contents, ASCIIToUTF16("PASS")); | 248 content::TitleWatcher watcher(web_contents, ASCIIToUTF16("PASS")); |
216 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); | 249 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); |
217 | 250 |
218 // Visit a test page. | 251 // Visit a test page. |
219 ui_test_utils::NavigateToURL( | 252 ui_test_utils::NavigateToURL( |
220 browser(), | 253 browser(), |
221 GetNonSecureURL(kUpdateLocationTestPath)); | 254 GetNonSecureURL(kUpdateLocationTestPath)); |
222 | 255 |
223 // Wait for the page title is changed after the test finished. | 256 // Wait for the page title is changed after the test finished. |
224 const string16 result = watcher.WaitAndGetTitle(); | 257 const string16 result = watcher.WaitAndGetTitle(); |
225 EXPECT_TRUE(EqualsASCII(result, "PASS")); | 258 EXPECT_EQ("PASS", UTF16ToASCII(result)); |
226 | 259 |
227 // Check there is not infobar. | 260 // Check there is not infobar. |
228 ASSERT_EQ(0U, infobar_service->infobar_count()); | 261 EXPECT_EQ(0U, infobar_service->infobar_count()); |
229 } | 262 } |
230 | 263 |
231 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, UpdateLocationAtOnload) { | 264 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, UpdateLocationAtOnload) { |
232 ASSERT_TRUE(test_server()->Start()); | 265 ASSERT_TRUE(test_server()->Start()); |
233 | 266 |
234 content::WebContents* web_contents = | 267 content::WebContents* web_contents = |
235 browser()->tab_strip_model()->GetActiveWebContents(); | 268 browser()->tab_strip_model()->GetActiveWebContents(); |
236 ASSERT_TRUE(web_contents); | 269 ASSERT_TRUE(web_contents); |
237 | 270 |
238 // Check infobar count. | 271 // Check infobar count. |
239 InfoBarService* infobar_service = | 272 InfoBarService* infobar_service = |
240 InfoBarService::FromWebContents(web_contents); | 273 InfoBarService::FromWebContents(web_contents); |
241 ASSERT_TRUE(infobar_service); | 274 ASSERT_TRUE(infobar_service); |
242 ASSERT_EQ(0U, infobar_service->infobar_count()); | 275 EXPECT_EQ(0U, infobar_service->infobar_count()); |
243 | 276 |
244 // Setup page title observer. | 277 // Setup page title observer. |
245 content::TitleWatcher watcher(web_contents, ASCIIToUTF16("PASS")); | 278 content::TitleWatcher watcher(web_contents, ASCIIToUTF16("PASS")); |
246 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); | 279 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); |
247 | 280 |
248 // Visit a test page. | 281 // Visit a test page. |
249 ui_test_utils::NavigateToURL( | 282 ui_test_utils::NavigateToURL( |
250 browser(), | 283 browser(), |
251 GetNonSecureURL(kUpdateLocationAtOnloadTestPath)); | 284 GetNonSecureURL(kUpdateLocationAtOnloadTestPath)); |
252 | 285 |
253 // Wait for the page title is changed after the test finished. | 286 // Wait for the page title is changed after the test finished. |
254 const string16 result = watcher.WaitAndGetTitle(); | 287 const string16 result = watcher.WaitAndGetTitle(); |
255 EXPECT_TRUE(EqualsASCII(result, "PASS")); | 288 EXPECT_EQ("PASS", UTF16ToASCII(result)); |
256 | 289 |
257 // Check there is not infobar. | 290 // Check there is not infobar. |
258 ASSERT_EQ(0U, infobar_service->infobar_count()); | 291 EXPECT_EQ(0U, infobar_service->infobar_count()); |
259 } | 292 } |
260 | 293 |
261 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_BROWSERTEST_H_ | 294 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_BROWSERTEST_H_ |
OLD | NEW |