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

Side by Side Diff: chrome/browser/translate/translate_browsertest.cc

Issue 1378123003: Adding SSL ETS Tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ets
Patch Set: Rebase. Created 5 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
OLDNEW
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 // This entire test suite relies on the translate infobar which has been removed 5 // This entire test suite relies on the translate infobar which has been removed
6 // from Aura. The file should be ported to use the bubble. 6 // from Aura. The file should be ported to use the bubble.
7 #if !defined(USE_AURA) 7 #if !defined(USE_AURA)
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/infobars/infobar_service.h" 14 #include "chrome/browser/infobars/infobar_service.h"
15 #include "chrome/browser/translate/translate_service.h" 15 #include "chrome/browser/translate/translate_service.h"
16 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" 17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/test/base/in_process_browser_test.h" 18 #include "chrome/test/base/in_process_browser_test.h"
19 #include "chrome/test/base/test_switches.h" 19 #include "chrome/test/base/test_switches.h"
20 #include "chrome/test/base/ui_test_utils.h" 20 #include "chrome/test/base/ui_test_utils.h"
21 #include "components/infobars/core/infobar.h" 21 #include "components/infobars/core/infobar.h"
22 #include "components/translate/core/browser/translate_infobar_delegate.h" 22 #include "components/translate/core/browser/translate_infobar_delegate.h"
23 #include "components/translate/core/browser/translate_manager.h" 23 #include "components/translate/core/browser/translate_manager.h"
24 #include "components/translate/core/browser/translate_script.h" 24 #include "components/translate/core/browser/translate_script.h"
25 #include "components/translate/core/common/translate_switches.h" 25 #include "components/translate/core/common/translate_switches.h"
26 #include "content/public/browser/notification_service.h" 26 #include "content/public/browser/notification_service.h"
27 #include "content/public/test/browser_test_utils.h" 27 #include "content/public/test/browser_test_utils.h"
28 #include "net/http/http_status_code.h" 28 #include "net/http/http_status_code.h"
29 #include "net/test/embedded_test_server/embedded_test_server.h" 29 #include "net/test/embedded_test_server/embedded_test_server.h"
30 #include "net/test/spawned_test_server/spawned_test_server.h"
31 #include "net/url_request/test_url_fetcher_factory.h" 30 #include "net/url_request/test_url_fetcher_factory.h"
32 #include "net/url_request/url_fetcher_delegate.h" 31 #include "net/url_request/url_fetcher_delegate.h"
33 32
34 namespace { 33 namespace {
35 34
36 const base::FilePath::CharType kTranslateRoot[] = 35 const base::FilePath::CharType kTranslateRoot[] =
37 FILE_PATH_LITERAL("chrome/test/data/translate"); 36 FILE_PATH_LITERAL("chrome/test/data/translate");
38 const char kNonSecurePrefix[] = "/translate/"; 37 const char kNonSecurePrefix[] = "/translate/";
39 const char kSecurePrefix[] = "files/"; 38 const char kSecurePrefix[] = "/";
40 const char kFrenchTestPath[] = "fr_test.html"; 39 const char kFrenchTestPath[] = "fr_test.html";
41 const char kRefreshMetaTagTestPath[] = "refresh_meta_tag.html"; 40 const char kRefreshMetaTagTestPath[] = "refresh_meta_tag.html";
42 const char kRefreshMetaTagCaseInsensitiveTestPath[] = 41 const char kRefreshMetaTagCaseInsensitiveTestPath[] =
43 "refresh_meta_tag_casei.html"; 42 "refresh_meta_tag_casei.html";
44 const char kRefreshMetaTagAtOnloadTestPath[] = 43 const char kRefreshMetaTagAtOnloadTestPath[] =
45 "refresh_meta_tag_at_onload.html"; 44 "refresh_meta_tag_at_onload.html";
46 const char kUpdateLocationTestPath[] = "update_location.html"; 45 const char kUpdateLocationTestPath[] = "update_location.html";
47 const char kUpdateLocationAtOnloadTestPath[] = "update_location_at_onload.html"; 46 const char kUpdateLocationAtOnloadTestPath[] = "update_location_at_onload.html";
48 const char kMainScriptPath[] = "pseudo_main.js"; 47 const char kMainScriptPath[] = "pseudo_main.js";
49 const char kElementMainScriptPath[] = "pseudo_element_main.js"; 48 const char kElementMainScriptPath[] = "pseudo_element_main.js";
50 49
51 }; // namespace 50 }; // namespace
52 51
53 class TranslateBrowserTest : public InProcessBrowserTest { 52 class TranslateBrowserTest : public InProcessBrowserTest {
54 public: 53 public:
55 TranslateBrowserTest() 54 TranslateBrowserTest()
56 : https_server_(net::SpawnedTestServer::TYPE_HTTPS, 55 : https_server_(net::EmbeddedTestServer::TYPE_HTTPS),
57 SSLOptions(SSLOptions::CERT_OK),
58 base::FilePath(kTranslateRoot)),
59 infobar_service_(NULL) {} 56 infobar_service_(NULL) {}
60 57
61 void SetUp() override { 58 void SetUp() override {
62 translate::TranslateManager::SetIgnoreMissingKeyForTesting(true); 59 translate::TranslateManager::SetIgnoreMissingKeyForTesting(true);
60 https_server_.ServeFilesFromSourceDirectory(base::FilePath(kTranslateRoot));
61 ASSERT_TRUE(https_server_.InitializeAndListen());
63 InProcessBrowserTest::SetUp(); 62 InProcessBrowserTest::SetUp();
64 } 63 }
65 64
66 void SetUpCommandLine(base::CommandLine* command_line) override { 65 void SetUpCommandLine(base::CommandLine* command_line) override {
67 ASSERT_TRUE(https_server_.Start());
68 // Setup alternate security origin for testing in order to allow XHR against 66 // Setup alternate security origin for testing in order to allow XHR against
69 // local test server. Note that this flag shows a confirm infobar in tests. 67 // local test server. Note that this flag shows a confirm infobar in tests.
70 GURL base_url = GetSecureURL(""); 68 GURL base_url = GetSecureURL("");
71 command_line->AppendSwitchASCII( 69 command_line->AppendSwitchASCII(
72 translate::switches::kTranslateSecurityOrigin, 70 translate::switches::kTranslateSecurityOrigin,
73 base_url.GetOrigin().spec()); 71 base_url.GetOrigin().spec());
74 } 72 }
75 73
74 void SetUpOnMainThread() override {
75 InProcessBrowserTest::SetUpOnMainThread();
76
77 https_server_.StartAcceptingConnections();
78 }
79
76 protected: 80 protected:
77 GURL GetNonSecureURL(const std::string& path) const { 81 GURL GetNonSecureURL(const std::string& path) const {
78 std::string prefix(kNonSecurePrefix); 82 std::string prefix(kNonSecurePrefix);
79 return embedded_test_server()->GetURL(prefix + path); 83 return embedded_test_server()->GetURL(prefix + path);
80 } 84 }
81 85
82 GURL GetSecureURL(const std::string& path) const { 86 GURL GetSecureURL(const std::string& path) const {
83 std::string prefix(kSecurePrefix); 87 std::string prefix(kSecurePrefix);
84 return https_server_.GetURL(prefix + path); 88 return https_server_.GetURL(prefix + path);
85 } 89 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 continue; 121 continue;
118 } 122 }
119 123
120 // Other infobar should not be shown. 124 // Other infobar should not be shown.
121 EXPECT_TRUE(delegate); 125 EXPECT_TRUE(delegate);
122 } 126 }
123 return delegate; 127 return delegate;
124 } 128 }
125 129
126 private: 130 private:
127 net::SpawnedTestServer https_server_; 131 net::EmbeddedTestServer https_server_;
128 InfoBarService* infobar_service_; 132 InfoBarService* infobar_service_;
129 133
130 typedef net::SpawnedTestServer::SSLOptions SSLOptions;
131
132 DISALLOW_COPY_AND_ASSIGN(TranslateBrowserTest); 134 DISALLOW_COPY_AND_ASSIGN(TranslateBrowserTest);
133 }; 135 };
134 136
135 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, TranslateInIsolatedWorld) { 137 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, TranslateInIsolatedWorld) {
136 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 138 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235
137 if (TranslateService::IsTranslateBubbleEnabled()) 139 if (TranslateService::IsTranslateBubbleEnabled())
138 return; 140 return;
139 141
140 net::TestURLFetcherFactory factory; 142 net::TestURLFetcherFactory factory;
141 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 143 ASSERT_TRUE(embedded_test_server()->Start());
142 144
143 // Check if there is no Translate infobar. 145 // Check if there is no Translate infobar.
144 translate::TranslateInfoBarDelegate* translate = 146 translate::TranslateInfoBarDelegate* translate =
145 GetExistingTranslateInfoBarDelegate(); 147 GetExistingTranslateInfoBarDelegate();
146 EXPECT_FALSE(translate); 148 EXPECT_FALSE(translate);
147 149
148 // Setup infobar observer. 150 // Setup infobar observer.
149 content::WindowedNotificationObserver infobar( 151 content::WindowedNotificationObserver infobar(
150 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, 152 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
151 content::NotificationService::AllSources()); 153 content::NotificationService::AllSources());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 // Wait for the page title is changed after the test finished. 198 // Wait for the page title is changed after the test finished.
197 const base::string16 result = watcher.WaitAndGetTitle(); 199 const base::string16 result = watcher.WaitAndGetTitle();
198 EXPECT_EQ("PASS", base::UTF16ToASCII(result)); 200 EXPECT_EQ("PASS", base::UTF16ToASCII(result));
199 } 201 }
200 202
201 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, IgnoreRefreshMetaTag) { 203 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, IgnoreRefreshMetaTag) {
202 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 204 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235
203 if (TranslateService::IsTranslateBubbleEnabled()) 205 if (TranslateService::IsTranslateBubbleEnabled())
204 return; 206 return;
205 207
206 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 208 ASSERT_TRUE(embedded_test_server()->Start());
207 209
208 // Check if there is no Translate infobar. 210 // Check if there is no Translate infobar.
209 translate::TranslateInfoBarDelegate* translate = 211 translate::TranslateInfoBarDelegate* translate =
210 GetExistingTranslateInfoBarDelegate(); 212 GetExistingTranslateInfoBarDelegate();
211 EXPECT_FALSE(translate); 213 EXPECT_FALSE(translate);
212 214
213 // Setup page title observer. 215 // Setup page title observer.
214 content::WebContents* web_contents = 216 content::WebContents* web_contents =
215 browser()->tab_strip_model()->GetActiveWebContents(); 217 browser()->tab_strip_model()->GetActiveWebContents();
216 ASSERT_TRUE(web_contents); 218 ASSERT_TRUE(web_contents);
(...skipping 13 matching lines...) Expand all
230 translate = GetExistingTranslateInfoBarDelegate(); 232 translate = GetExistingTranslateInfoBarDelegate();
231 EXPECT_FALSE(translate); 233 EXPECT_FALSE(translate);
232 } 234 }
233 235
234 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, 236 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest,
235 IgnoreRefreshMetaTagInCaseInsensitive) { 237 IgnoreRefreshMetaTagInCaseInsensitive) {
236 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 238 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235
237 if (TranslateService::IsTranslateBubbleEnabled()) 239 if (TranslateService::IsTranslateBubbleEnabled())
238 return; 240 return;
239 241
240 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 242 ASSERT_TRUE(embedded_test_server()->Start());
241 243
242 // Check if there is no Translate infobar. 244 // Check if there is no Translate infobar.
243 translate::TranslateInfoBarDelegate* translate = 245 translate::TranslateInfoBarDelegate* translate =
244 GetExistingTranslateInfoBarDelegate(); 246 GetExistingTranslateInfoBarDelegate();
245 EXPECT_FALSE(translate); 247 EXPECT_FALSE(translate);
246 248
247 // Setup page title observer. 249 // Setup page title observer.
248 content::WebContents* web_contents = 250 content::WebContents* web_contents =
249 browser()->tab_strip_model()->GetActiveWebContents(); 251 browser()->tab_strip_model()->GetActiveWebContents();
250 ASSERT_TRUE(web_contents); 252 ASSERT_TRUE(web_contents);
(...skipping 12 matching lines...) Expand all
263 // Check if there is no Translate infobar. 265 // Check if there is no Translate infobar.
264 translate = GetExistingTranslateInfoBarDelegate(); 266 translate = GetExistingTranslateInfoBarDelegate();
265 EXPECT_FALSE(translate); 267 EXPECT_FALSE(translate);
266 } 268 }
267 269
268 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, IgnoreRefreshMetaTagAtOnload) { 270 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, IgnoreRefreshMetaTagAtOnload) {
269 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 271 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235
270 if (TranslateService::IsTranslateBubbleEnabled()) 272 if (TranslateService::IsTranslateBubbleEnabled())
271 return; 273 return;
272 274
273 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 275 ASSERT_TRUE(embedded_test_server()->Start());
274 276
275 // Check if there is no Translate infobar. 277 // Check if there is no Translate infobar.
276 translate::TranslateInfoBarDelegate* translate = 278 translate::TranslateInfoBarDelegate* translate =
277 GetExistingTranslateInfoBarDelegate(); 279 GetExistingTranslateInfoBarDelegate();
278 EXPECT_FALSE(translate); 280 EXPECT_FALSE(translate);
279 281
280 // Setup page title observer. 282 // Setup page title observer.
281 content::WebContents* web_contents = 283 content::WebContents* web_contents =
282 browser()->tab_strip_model()->GetActiveWebContents(); 284 browser()->tab_strip_model()->GetActiveWebContents();
283 ASSERT_TRUE(web_contents); 285 ASSERT_TRUE(web_contents);
(...skipping 12 matching lines...) Expand all
296 // Check if there is no Translate infobar. 298 // Check if there is no Translate infobar.
297 translate = GetExistingTranslateInfoBarDelegate(); 299 translate = GetExistingTranslateInfoBarDelegate();
298 EXPECT_FALSE(translate); 300 EXPECT_FALSE(translate);
299 } 301 }
300 302
301 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, UpdateLocation) { 303 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, UpdateLocation) {
302 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 304 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235
303 if (TranslateService::IsTranslateBubbleEnabled()) 305 if (TranslateService::IsTranslateBubbleEnabled())
304 return; 306 return;
305 307
306 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 308 ASSERT_TRUE(embedded_test_server()->Start());
307 309
308 // Check if there is no Translate infobar. 310 // Check if there is no Translate infobar.
309 translate::TranslateInfoBarDelegate* translate = 311 translate::TranslateInfoBarDelegate* translate =
310 GetExistingTranslateInfoBarDelegate(); 312 GetExistingTranslateInfoBarDelegate();
311 EXPECT_FALSE(translate); 313 EXPECT_FALSE(translate);
312 314
313 // Setup page title observer. 315 // Setup page title observer.
314 content::WebContents* web_contents = 316 content::WebContents* web_contents =
315 browser()->tab_strip_model()->GetActiveWebContents(); 317 browser()->tab_strip_model()->GetActiveWebContents();
316 ASSERT_TRUE(web_contents); 318 ASSERT_TRUE(web_contents);
(...skipping 12 matching lines...) Expand all
329 // Check if there is no Translate infobar. 331 // Check if there is no Translate infobar.
330 translate = GetExistingTranslateInfoBarDelegate(); 332 translate = GetExistingTranslateInfoBarDelegate();
331 EXPECT_FALSE(translate); 333 EXPECT_FALSE(translate);
332 } 334 }
333 335
334 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, UpdateLocationAtOnload) { 336 IN_PROC_BROWSER_TEST_F(TranslateBrowserTest, UpdateLocationAtOnload) {
335 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 337 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235
336 if (TranslateService::IsTranslateBubbleEnabled()) 338 if (TranslateService::IsTranslateBubbleEnabled())
337 return; 339 return;
338 340
339 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 341 ASSERT_TRUE(embedded_test_server()->Start());
340 342
341 // Check if there is no Translate infobar. 343 // Check if there is no Translate infobar.
342 translate::TranslateInfoBarDelegate* translate = 344 translate::TranslateInfoBarDelegate* translate =
343 GetExistingTranslateInfoBarDelegate(); 345 GetExistingTranslateInfoBarDelegate();
344 EXPECT_FALSE(translate); 346 EXPECT_FALSE(translate);
345 347
346 // Setup page title observer. 348 // Setup page title observer.
347 content::WebContents* web_contents = 349 content::WebContents* web_contents =
348 browser()->tab_strip_model()->GetActiveWebContents(); 350 browser()->tab_strip_model()->GetActiveWebContents();
349 ASSERT_TRUE(web_contents); 351 ASSERT_TRUE(web_contents);
350 content::TitleWatcher watcher(web_contents, base::ASCIIToUTF16("PASS")); 352 content::TitleWatcher watcher(web_contents, base::ASCIIToUTF16("PASS"));
351 watcher.AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); 353 watcher.AlsoWaitForTitle(base::ASCIIToUTF16("FAIL"));
352 354
353 // Visit a test page. 355 // Visit a test page.
354 ui_test_utils::NavigateToURL( 356 ui_test_utils::NavigateToURL(
355 browser(), 357 browser(),
356 GetNonSecureURL(kUpdateLocationAtOnloadTestPath)); 358 GetNonSecureURL(kUpdateLocationAtOnloadTestPath));
357 359
358 // Wait for the page title is changed after the test finished. 360 // Wait for the page title is changed after the test finished.
359 const base::string16 result = watcher.WaitAndGetTitle(); 361 const base::string16 result = watcher.WaitAndGetTitle();
360 EXPECT_EQ("PASS", base::UTF16ToASCII(result)); 362 EXPECT_EQ("PASS", base::UTF16ToASCII(result));
361 363
362 // Check if there is no Translate infobar. 364 // Check if there is no Translate infobar.
363 translate = GetExistingTranslateInfoBarDelegate(); 365 translate = GetExistingTranslateInfoBarDelegate();
364 EXPECT_FALSE(translate); 366 EXPECT_FALSE(translate);
365 } 367 }
366 #endif // !defined(USE_AURA) 368 #endif // !defined(USE_AURA)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698