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/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/infobars/infobar_service.h" | 11 #include "chrome/browser/infobars/infobar_service.h" |
12 #include "chrome/browser/translate/translate_infobar_delegate.h" | 12 #include "chrome/browser/translate/translate_infobar_delegate.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
18 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
19 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
20 #include "content/public/test/browser_test_utils.h" | 20 #include "content/public/test/browser_test_utils.h" |
21 #include "net/http/http_status_code.h" | 21 #include "net/http/http_status_code.h" |
| 22 #include "net/test/embedded_test_server/embedded_test_server.h" |
22 #include "net/test/spawned_test_server/spawned_test_server.h" | 23 #include "net/test/spawned_test_server/spawned_test_server.h" |
23 #include "net/url_request/test_url_fetcher_factory.h" | 24 #include "net/url_request/test_url_fetcher_factory.h" |
24 #include "net/url_request/url_fetcher_delegate.h" | 25 #include "net/url_request/url_fetcher_delegate.h" |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 const base::FilePath::CharType kTranslateRoot[] = | 29 const base::FilePath::CharType kTranslateRoot[] = |
29 FILE_PATH_LITERAL("chrome/test/data/translate"); | 30 FILE_PATH_LITERAL("chrome/test/data/translate"); |
30 const char kNonSecurePrefix[] = "files/translate/"; | 31 const char kNonSecurePrefix[] = "/translate/"; |
31 const char kSecurePrefix[] = "files/"; | 32 const char kSecurePrefix[] = "files/"; |
32 const char kFrenchTestPath[] = "fr_test.html"; | 33 const char kFrenchTestPath[] = "fr_test.html"; |
33 const char kRefreshMetaTagTestPath[] = "refresh_meta_tag.html"; | 34 const char kRefreshMetaTagTestPath[] = "refresh_meta_tag.html"; |
34 const char kRefreshMetaTagCaseInsensitiveTestPath[] = | 35 const char kRefreshMetaTagCaseInsensitiveTestPath[] = |
35 "refresh_meta_tag_casei.html"; | 36 "refresh_meta_tag_casei.html"; |
36 const char kRefreshMetaTagAtOnloadTestPath[] = | 37 const char kRefreshMetaTagAtOnloadTestPath[] = |
37 "refresh_meta_tag_at_onload.html"; | 38 "refresh_meta_tag_at_onload.html"; |
38 const char kUpdateLocationTestPath[] = "update_location.html"; | 39 const char kUpdateLocationTestPath[] = "update_location.html"; |
39 const char kUpdateLocationAtOnloadTestPath[] = "update_location_at_onload.html"; | 40 const char kUpdateLocationAtOnloadTestPath[] = "update_location_at_onload.html"; |
40 const char kMainScriptPath[] = "pseudo_main.js"; | 41 const char kMainScriptPath[] = "pseudo_main.js"; |
41 const char kElementMainScriptPath[] = "pseudo_element_main.js"; | 42 const char kElementMainScriptPath[] = "pseudo_element_main.js"; |
42 | 43 |
43 }; // namespace | 44 }; // namespace |
44 | 45 |
45 class TranslateBrowserTest : public InProcessBrowserTest { | 46 class TranslateBrowserTest : public InProcessBrowserTest { |
46 public: | 47 public: |
47 TranslateBrowserTest() | 48 TranslateBrowserTest() |
48 : https_server_(net::SpawnedTestServer::TYPE_HTTPS, | 49 : https_server_(net::SpawnedTestServer::TYPE_HTTPS, |
49 SSLOptions(SSLOptions::CERT_OK), | 50 SSLOptions(SSLOptions::CERT_OK), |
50 base::FilePath(kTranslateRoot)) {} | 51 base::FilePath(kTranslateRoot)) {} |
51 | 52 |
52 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 53 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
53 ASSERT_TRUE(https_server_.Start()); | 54 ASSERT_TRUE(https_server_.Start()); |
54 } | 55 } |
55 | 56 |
56 protected: | 57 protected: |
57 GURL GetNonSecureURL(const std::string& path) const { | 58 GURL GetNonSecureURL(const std::string& path) const { |
58 std::string prefix(kNonSecurePrefix); | 59 std::string prefix(kNonSecurePrefix); |
59 return test_server()->GetURL(prefix + path); | 60 return embedded_test_server()->GetURL(prefix + path); |
60 } | 61 } |
61 | 62 |
62 GURL GetSecureURL(const std::string& path) const { | 63 GURL GetSecureURL(const std::string& path) const { |
63 std::string prefix(kSecurePrefix); | 64 std::string prefix(kSecurePrefix); |
64 return https_server_.GetURL(prefix + path); | 65 return https_server_.GetURL(prefix + path); |
65 } | 66 } |
66 | 67 |
67 private: | 68 private: |
68 net::SpawnedTestServer https_server_; | 69 net::SpawnedTestServer https_server_; |
69 | 70 |
70 typedef net::SpawnedTestServer::SSLOptions SSLOptions; | 71 typedef net::SpawnedTestServer::SSLOptions SSLOptions; |
71 | 72 |
72 DISALLOW_COPY_AND_ASSIGN(TranslateBrowserTest); | 73 DISALLOW_COPY_AND_ASSIGN(TranslateBrowserTest); |
73 }; | 74 }; |
74 | 75 |
75 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, Translate) { | 76 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, Translate) { |
76 ASSERT_TRUE(test_server()->Start()); | 77 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
77 | 78 |
78 content::WebContents* web_contents = | 79 content::WebContents* web_contents = |
79 browser()->tab_strip_model()->GetActiveWebContents(); | 80 browser()->tab_strip_model()->GetActiveWebContents(); |
80 ASSERT_TRUE(web_contents); | 81 ASSERT_TRUE(web_contents); |
81 | 82 |
82 net::TestURLFetcherFactory factory; | 83 net::TestURLFetcherFactory factory; |
83 | 84 |
84 // Setup infobar observer. | 85 // Setup infobar observer. |
85 InfoBarService* infobar_service = | 86 InfoBarService* infobar_service = |
86 InfoBarService::FromWebContents(web_contents); | 87 InfoBarService::FromWebContents(web_contents); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 fetcher->set_response_code(net::HTTP_OK); | 135 fetcher->set_response_code(net::HTTP_OK); |
135 fetcher->SetResponseString(element_js); | 136 fetcher->SetResponseString(element_js); |
136 fetcher->delegate()->OnURLFetchComplete(fetcher); | 137 fetcher->delegate()->OnURLFetchComplete(fetcher); |
137 | 138 |
138 // Wait for the page title is changed after the test finished. | 139 // Wait for the page title is changed after the test finished. |
139 const string16 result = watcher.WaitAndGetTitle(); | 140 const string16 result = watcher.WaitAndGetTitle(); |
140 EXPECT_EQ("PASS", UTF16ToASCII(result)); | 141 EXPECT_EQ("PASS", UTF16ToASCII(result)); |
141 } | 142 } |
142 | 143 |
143 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, IgnoreRefreshMetaTag) { | 144 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, IgnoreRefreshMetaTag) { |
144 ASSERT_TRUE(test_server()->Start()); | 145 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
145 | 146 |
146 content::WebContents* web_contents = | 147 content::WebContents* web_contents = |
147 browser()->tab_strip_model()->GetActiveWebContents(); | 148 browser()->tab_strip_model()->GetActiveWebContents(); |
148 ASSERT_TRUE(web_contents); | 149 ASSERT_TRUE(web_contents); |
149 | 150 |
150 // Check infobar count. | 151 // Check infobar count. |
151 InfoBarService* infobar_service = | 152 InfoBarService* infobar_service = |
152 InfoBarService::FromWebContents(web_contents); | 153 InfoBarService::FromWebContents(web_contents); |
153 ASSERT_TRUE(infobar_service); | 154 ASSERT_TRUE(infobar_service); |
154 EXPECT_EQ(0U, infobar_service->infobar_count()); | 155 EXPECT_EQ(0U, infobar_service->infobar_count()); |
(...skipping 10 matching lines...) Expand all Loading... |
165 // Wait for the page title is changed after the test finished. | 166 // Wait for the page title is changed after the test finished. |
166 const string16 result = watcher.WaitAndGetTitle(); | 167 const string16 result = watcher.WaitAndGetTitle(); |
167 EXPECT_EQ("PASS", UTF16ToASCII(result)); | 168 EXPECT_EQ("PASS", UTF16ToASCII(result)); |
168 | 169 |
169 // Check there is not infobar. | 170 // Check there is not infobar. |
170 EXPECT_EQ(0U, infobar_service->infobar_count()); | 171 EXPECT_EQ(0U, infobar_service->infobar_count()); |
171 } | 172 } |
172 | 173 |
173 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, | 174 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, |
174 IgnoreRefreshMetaTagInCaseInsensitive) { | 175 IgnoreRefreshMetaTagInCaseInsensitive) { |
175 ASSERT_TRUE(test_server()->Start()); | 176 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
176 | 177 |
177 content::WebContents* web_contents = | 178 content::WebContents* web_contents = |
178 browser()->tab_strip_model()->GetActiveWebContents(); | 179 browser()->tab_strip_model()->GetActiveWebContents(); |
179 ASSERT_TRUE(web_contents); | 180 ASSERT_TRUE(web_contents); |
180 | 181 |
181 // Check infobar count. | 182 // Check infobar count. |
182 InfoBarService* infobar_service = | 183 InfoBarService* infobar_service = |
183 InfoBarService::FromWebContents(web_contents); | 184 InfoBarService::FromWebContents(web_contents); |
184 ASSERT_TRUE(infobar_service); | 185 ASSERT_TRUE(infobar_service); |
185 EXPECT_EQ(0U, infobar_service->infobar_count()); | 186 EXPECT_EQ(0U, infobar_service->infobar_count()); |
186 | 187 |
187 // Setup page title observer. | 188 // Setup page title observer. |
188 content::TitleWatcher watcher(web_contents, ASCIIToUTF16("PASS")); | 189 content::TitleWatcher watcher(web_contents, ASCIIToUTF16("PASS")); |
189 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); | 190 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); |
190 | 191 |
191 // Visit a test page. | 192 // Visit a test page. |
192 ui_test_utils::NavigateToURL( | 193 ui_test_utils::NavigateToURL( |
193 browser(), | 194 browser(), |
194 GetNonSecureURL(kRefreshMetaTagCaseInsensitiveTestPath)); | 195 GetNonSecureURL(kRefreshMetaTagCaseInsensitiveTestPath)); |
195 | 196 |
196 // Wait for the page title is changed after the test finished. | 197 // Wait for the page title is changed after the test finished. |
197 const string16 result = watcher.WaitAndGetTitle(); | 198 const string16 result = watcher.WaitAndGetTitle(); |
198 EXPECT_EQ("PASS", UTF16ToASCII(result)); | 199 EXPECT_EQ("PASS", UTF16ToASCII(result)); |
199 | 200 |
200 // Check there is not infobar. | 201 // Check there is not infobar. |
201 EXPECT_EQ(0U, infobar_service->infobar_count()); | 202 EXPECT_EQ(0U, infobar_service->infobar_count()); |
202 } | 203 } |
203 | 204 |
204 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, IgnoreRefreshMetaTagAtOnload) { | 205 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, IgnoreRefreshMetaTagAtOnload) { |
205 ASSERT_TRUE(test_server()->Start()); | 206 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
206 | 207 |
207 content::WebContents* web_contents = | 208 content::WebContents* web_contents = |
208 browser()->tab_strip_model()->GetActiveWebContents(); | 209 browser()->tab_strip_model()->GetActiveWebContents(); |
209 ASSERT_TRUE(web_contents); | 210 ASSERT_TRUE(web_contents); |
210 | 211 |
211 // Check infobar count. | 212 // Check infobar count. |
212 InfoBarService* infobar_service = | 213 InfoBarService* infobar_service = |
213 InfoBarService::FromWebContents(web_contents); | 214 InfoBarService::FromWebContents(web_contents); |
214 ASSERT_TRUE(infobar_service); | 215 ASSERT_TRUE(infobar_service); |
215 EXPECT_EQ(0U, infobar_service->infobar_count()); | 216 EXPECT_EQ(0U, infobar_service->infobar_count()); |
216 | 217 |
217 // Setup page title observer. | 218 // Setup page title observer. |
218 content::TitleWatcher watcher(web_contents, ASCIIToUTF16("PASS")); | 219 content::TitleWatcher watcher(web_contents, ASCIIToUTF16("PASS")); |
219 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); | 220 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); |
220 | 221 |
221 // Visit a test page. | 222 // Visit a test page. |
222 ui_test_utils::NavigateToURL( | 223 ui_test_utils::NavigateToURL( |
223 browser(), | 224 browser(), |
224 GetNonSecureURL(kRefreshMetaTagAtOnloadTestPath)); | 225 GetNonSecureURL(kRefreshMetaTagAtOnloadTestPath)); |
225 | 226 |
226 // Wait for the page title is changed after the test finished. | 227 // Wait for the page title is changed after the test finished. |
227 const string16 result = watcher.WaitAndGetTitle(); | 228 const string16 result = watcher.WaitAndGetTitle(); |
228 EXPECT_EQ("PASS", UTF16ToASCII(result)); | 229 EXPECT_EQ("PASS", UTF16ToASCII(result)); |
229 | 230 |
230 // Check there is not infobar. | 231 // Check there is not infobar. |
231 EXPECT_EQ(0U, infobar_service->infobar_count()); | 232 EXPECT_EQ(0U, infobar_service->infobar_count()); |
232 } | 233 } |
233 | 234 |
234 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, UpdateLocation) { | 235 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, UpdateLocation) { |
235 ASSERT_TRUE(test_server()->Start()); | 236 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
236 | 237 |
237 content::WebContents* web_contents = | 238 content::WebContents* web_contents = |
238 browser()->tab_strip_model()->GetActiveWebContents(); | 239 browser()->tab_strip_model()->GetActiveWebContents(); |
239 ASSERT_TRUE(web_contents); | 240 ASSERT_TRUE(web_contents); |
240 | 241 |
241 // Check infobar count. | 242 // Check infobar count. |
242 InfoBarService* infobar_service = | 243 InfoBarService* infobar_service = |
243 InfoBarService::FromWebContents(web_contents); | 244 InfoBarService::FromWebContents(web_contents); |
244 ASSERT_TRUE(infobar_service); | 245 ASSERT_TRUE(infobar_service); |
245 EXPECT_EQ(0U, infobar_service->infobar_count()); | 246 EXPECT_EQ(0U, infobar_service->infobar_count()); |
246 | 247 |
247 // Setup page title observer. | 248 // Setup page title observer. |
248 content::TitleWatcher watcher(web_contents, ASCIIToUTF16("PASS")); | 249 content::TitleWatcher watcher(web_contents, ASCIIToUTF16("PASS")); |
249 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); | 250 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); |
250 | 251 |
251 // Visit a test page. | 252 // Visit a test page. |
252 ui_test_utils::NavigateToURL( | 253 ui_test_utils::NavigateToURL( |
253 browser(), | 254 browser(), |
254 GetNonSecureURL(kUpdateLocationTestPath)); | 255 GetNonSecureURL(kUpdateLocationTestPath)); |
255 | 256 |
256 // Wait for the page title is changed after the test finished. | 257 // Wait for the page title is changed after the test finished. |
257 const string16 result = watcher.WaitAndGetTitle(); | 258 const string16 result = watcher.WaitAndGetTitle(); |
258 EXPECT_EQ("PASS", UTF16ToASCII(result)); | 259 EXPECT_EQ("PASS", UTF16ToASCII(result)); |
259 | 260 |
260 // Check there is not infobar. | 261 // Check there is not infobar. |
261 EXPECT_EQ(0U, infobar_service->infobar_count()); | 262 EXPECT_EQ(0U, infobar_service->infobar_count()); |
262 } | 263 } |
263 | 264 |
264 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, UpdateLocationAtOnload) { | 265 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, UpdateLocationAtOnload) { |
265 ASSERT_TRUE(test_server()->Start()); | 266 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
266 | 267 |
267 content::WebContents* web_contents = | 268 content::WebContents* web_contents = |
268 browser()->tab_strip_model()->GetActiveWebContents(); | 269 browser()->tab_strip_model()->GetActiveWebContents(); |
269 ASSERT_TRUE(web_contents); | 270 ASSERT_TRUE(web_contents); |
270 | 271 |
271 // Check infobar count. | 272 // Check infobar count. |
272 InfoBarService* infobar_service = | 273 InfoBarService* infobar_service = |
273 InfoBarService::FromWebContents(web_contents); | 274 InfoBarService::FromWebContents(web_contents); |
274 ASSERT_TRUE(infobar_service); | 275 ASSERT_TRUE(infobar_service); |
275 EXPECT_EQ(0U, infobar_service->infobar_count()); | 276 EXPECT_EQ(0U, infobar_service->infobar_count()); |
276 | 277 |
277 // Setup page title observer. | 278 // Setup page title observer. |
278 content::TitleWatcher watcher(web_contents, ASCIIToUTF16("PASS")); | 279 content::TitleWatcher watcher(web_contents, ASCIIToUTF16("PASS")); |
279 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); | 280 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); |
280 | 281 |
281 // Visit a test page. | 282 // Visit a test page. |
282 ui_test_utils::NavigateToURL( | 283 ui_test_utils::NavigateToURL( |
283 browser(), | 284 browser(), |
284 GetNonSecureURL(kUpdateLocationAtOnloadTestPath)); | 285 GetNonSecureURL(kUpdateLocationAtOnloadTestPath)); |
285 | 286 |
286 // Wait for the page title is changed after the test finished. | 287 // Wait for the page title is changed after the test finished. |
287 const string16 result = watcher.WaitAndGetTitle(); | 288 const string16 result = watcher.WaitAndGetTitle(); |
288 EXPECT_EQ("PASS", UTF16ToASCII(result)); | 289 EXPECT_EQ("PASS", UTF16ToASCII(result)); |
289 | 290 |
290 // Check there is not infobar. | 291 // Check there is not infobar. |
291 EXPECT_EQ(0U, infobar_service->infobar_count()); | 292 EXPECT_EQ(0U, infobar_service->infobar_count()); |
292 } | 293 } |
293 | 294 |
294 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_BROWSERTEST_H_ | 295 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_BROWSERTEST_H_ |
OLD | NEW |