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

Side by Side Diff: chrome/browser/ssl/ssl_browser_tests.cc

Issue 11085039: WebSocket test server migration on browser_tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 2 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
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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/path_service.h" 6 #include "base/path_service.h"
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "net/base/nss_cert_database.h" 48 #include "net/base/nss_cert_database.h"
49 #endif // defined(USE_NSS) 49 #endif // defined(USE_NSS)
50 50
51 using content::InterstitialPage; 51 using content::InterstitialPage;
52 using content::NavigationController; 52 using content::NavigationController;
53 using content::NavigationEntry; 53 using content::NavigationEntry;
54 using content::SSLStatus; 54 using content::SSLStatus;
55 using content::WebContents; 55 using content::WebContents;
56 56
57 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); 57 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data");
58 const FilePath::CharType kWsRoot[] = FILE_PATH_LITERAL("net/data/websocket");
wtc 2012/10/23 19:02:55 (NOTE: my comments in this file also apply to chro
Ryan Sleevi 2012/10/23 19:04:35 We do this for the SSL certs already. We could wr
Takashi Toyoshima 2012/10/24 05:29:08 I have a same idea with Ryan. But, the directory f
58 59
59 namespace { 60 namespace {
60 61
61 class ProvisionalLoadWaiter : public content::WebContentsObserver { 62 class ProvisionalLoadWaiter : public content::WebContentsObserver {
62 public: 63 public:
63 explicit ProvisionalLoadWaiter(WebContents* tab) 64 explicit ProvisionalLoadWaiter(WebContents* tab)
64 : WebContentsObserver(tab), waiting_(false), seen_(false) {} 65 : WebContentsObserver(tab), waiting_(false), seen_(false) {}
65 66
66 void Wait() { 67 void Wait() {
67 if (seen_) 68 if (seen_)
(...skipping 16 matching lines...) Expand all
84 } 85 }
85 86
86 private: 87 private:
87 bool waiting_; 88 bool waiting_;
88 bool seen_; 89 bool seen_;
89 }; 90 };
90 91
91 } // namespace 92 } // namespace
92 93
93 class SSLUITest : public InProcessBrowserTest { 94 class SSLUITest : public InProcessBrowserTest {
94 typedef net::TestServer::SSLOptions SSLOptions;
95
96 public: 95 public:
97 SSLUITest() 96 SSLUITest()
98 : https_server_(net::TestServer::TYPE_HTTPS, 97 : https_server_(net::TestServer::TYPE_HTTPS,
99 SSLOptions(SSLOptions::CERT_OK), 98 SSLOptions(SSLOptions::CERT_OK),
100 FilePath(kDocRoot)), 99 FilePath(kDocRoot)),
101 https_server_expired_(net::TestServer::TYPE_HTTPS, 100 https_server_expired_(net::TestServer::TYPE_HTTPS,
102 SSLOptions(SSLOptions::CERT_EXPIRED), 101 SSLOptions(SSLOptions::CERT_EXPIRED),
103 FilePath(kDocRoot)), 102 FilePath(kDocRoot)),
104 https_server_mismatched_(net::TestServer::TYPE_HTTPS, 103 https_server_mismatched_(net::TestServer::TYPE_HTTPS,
105 SSLOptions(SSLOptions::CERT_MISMATCHED_NAME), 104 SSLOptions(SSLOptions::CERT_MISMATCHED_NAME),
106 FilePath(kDocRoot)) {} 105 FilePath(kDocRoot)),
106 wss_server_expired_(net::TestServer::TYPE_WSS,
107 SSLOptions(SSLOptions::CERT_EXPIRED),
108 FilePath(kWsRoot)) {}
107 109
108 virtual void SetUpCommandLine(CommandLine* command_line) { 110 virtual void SetUpCommandLine(CommandLine* command_line) {
109 // Browser will both run and display insecure content. 111 // Browser will both run and display insecure content.
110 command_line->AppendSwitch(switches::kAllowRunningInsecureContent); 112 command_line->AppendSwitch(switches::kAllowRunningInsecureContent);
111 // Use process-per-site so that navigating to a same-site page in a 113 // Use process-per-site so that navigating to a same-site page in a
112 // new tab will use the same process. 114 // new tab will use the same process.
113 command_line->AppendSwitch(switches::kProcessPerSite); 115 command_line->AppendSwitch(switches::kProcessPerSite);
114 } 116 }
115 117
116 void CheckAuthenticatedState(WebContents* tab, 118 void CheckAuthenticatedState(WebContents* tab,
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 make_pair("REPLACE_WITH_UNSAFE_WORKER_PATH", unsafe_worker_path)); 291 make_pair("REPLACE_WITH_UNSAFE_WORKER_PATH", unsafe_worker_path));
290 return net::TestServer::GetFilePathWithReplacements( 292 return net::TestServer::GetFilePathWithReplacements(
291 "files/ssl/page_with_unsafe_worker.html", 293 "files/ssl/page_with_unsafe_worker.html",
292 replacement_text_for_page_with_unsafe_worker, 294 replacement_text_for_page_with_unsafe_worker,
293 page_with_unsafe_worker_path); 295 page_with_unsafe_worker_path);
294 } 296 }
295 297
296 net::TestServer https_server_; 298 net::TestServer https_server_;
297 net::TestServer https_server_expired_; 299 net::TestServer https_server_expired_;
298 net::TestServer https_server_mismatched_; 300 net::TestServer https_server_mismatched_;
301 net::TestServer wss_server_expired_;
302
303 protected:
304 typedef net::TestServer::SSLOptions SSLOptions;
wtc 2012/10/23 19:04:32 It seems that this typedef can be private. Does th
Takashi Toyoshima 2012/10/24 05:29:08 Oops. Thanks. You are right. I'll fix this.
299 305
300 private: 306 private:
301 DISALLOW_COPY_AND_ASSIGN(SSLUITest); 307 DISALLOW_COPY_AND_ASSIGN(SSLUITest);
302 }; 308 };
303 309
304 class SSLUITestBlock : public SSLUITest { 310 class SSLUITestBlock : public SSLUITest {
305 public: 311 public:
306 SSLUITestBlock() : SSLUITest() {} 312 SSLUITestBlock() : SSLUITest() {}
307 313
308 // Browser will neither run nor display insecure content. 314 // Browser will neither run nor display insecure content.
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 EXPECT_FALSE(tab->GetController().CanGoForward()); 549 EXPECT_FALSE(tab->GetController().CanGoForward());
544 NavigationEntry* entry4 = tab->GetController().GetActiveEntry(); 550 NavigationEntry* entry4 = tab->GetController().GetActiveEntry();
545 EXPECT_TRUE(entry2 == entry4); 551 EXPECT_TRUE(entry2 == entry4);
546 } 552 }
547 553
548 // Visit a HTTP page which request WSS connection to a server providing invalid 554 // Visit a HTTP page which request WSS connection to a server providing invalid
549 // certificate. Close the page while WSS connection waits for SSLManager's 555 // certificate. Close the page while WSS connection waits for SSLManager's
550 // response from UI thread. 556 // response from UI thread.
551 IN_PROC_BROWSER_TEST_F(SSLUITest, TestWSSInvalidCertAndClose) { 557 IN_PROC_BROWSER_TEST_F(SSLUITest, TestWSSInvalidCertAndClose) {
552 ASSERT_TRUE(test_server()->Start()); 558 ASSERT_TRUE(test_server()->Start());
553 ASSERT_TRUE(https_server_expired_.Start()); 559 ASSERT_TRUE(wss_server_expired_.Start());
554 560
555 // Setup page title observer. 561 // Setup page title observer.
556 WebContents* tab = chrome::GetActiveWebContents(browser()); 562 WebContents* tab = chrome::GetActiveWebContents(browser());
557 content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS")); 563 content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS"));
558 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); 564 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
559 565
560 // Create GURLs to test pages. 566 // Create GURLs to test pages.
561 std::string masterUrlPath = StringPrintf("%s?%d", 567 std::string masterUrlPath = StringPrintf("%s?%d",
562 test_server()->GetURL("files/ssl/wss_close.html").spec().c_str(), 568 test_server()->GetURL("files/ssl/wss_close.html").spec().c_str(),
563 https_server_expired_.host_port_pair().port()); 569 wss_server_expired_.host_port_pair().port());
564 GURL masterUrl(masterUrlPath); 570 GURL masterUrl(masterUrlPath);
565 std::string slaveUrlPath = StringPrintf("%s?%d", 571 std::string slaveUrlPath = StringPrintf("%s?%d",
566 test_server()->GetURL("files/ssl/wss_close_slave.html").spec().c_str(), 572 test_server()->GetURL("files/ssl/wss_close_slave.html").spec().c_str(),
567 https_server_expired_.host_port_pair().port()); 573 wss_server_expired_.host_port_pair().port());
568 GURL slaveUrl(slaveUrlPath); 574 GURL slaveUrl(slaveUrlPath);
569 575
570 // Create tabs and visit pages which keep on creating wss connections. 576 // Create tabs and visit pages which keep on creating wss connections.
571 TabContents* tabs[16]; 577 TabContents* tabs[16];
572 for (int i = 0; i < 16; ++i) { 578 for (int i = 0; i < 16; ++i) {
573 tabs[i] = chrome::AddSelectedTabWithURL(browser(), slaveUrl, 579 tabs[i] = chrome::AddSelectedTabWithURL(browser(), slaveUrl,
574 content::PAGE_TRANSITION_LINK); 580 content::PAGE_TRANSITION_LINK);
575 } 581 }
576 chrome::SelectNextTab(browser()); 582 chrome::SelectNextTab(browser());
577 583
578 // Visit a page which waits for one TLS handshake failure. 584 // Visit a page which waits for one TLS handshake failure.
579 // The title will be changed to 'PASS'. 585 // The title will be changed to 'PASS'.
580 ui_test_utils::NavigateToURL(browser(), masterUrl); 586 ui_test_utils::NavigateToURL(browser(), masterUrl);
581 const string16 result = watcher.WaitAndGetTitle(); 587 const string16 result = watcher.WaitAndGetTitle();
582 EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass")); 588 EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass"));
583 589
584 // Close tabs which contains the test page. 590 // Close tabs which contains the test page.
585 for (int i = 0; i < 16; ++i) 591 for (int i = 0; i < 16; ++i)
586 chrome::CloseWebContents(browser(), tabs[i]->web_contents()); 592 chrome::CloseWebContents(browser(), tabs[i]->web_contents());
587 chrome::CloseWebContents(browser(), tab); 593 chrome::CloseWebContents(browser(), tab);
588 } 594 }
589 595
590 // Visit a HTTPS page and proceeds despite an invalid certificate. The page 596 // Visit a HTTPS page and proceeds despite an invalid certificate. The page
591 // requests WSS connection to the same origin host to check if WSS connection 597 // requests WSS connection to the same origin host to check if WSS connection
592 // share certificates policy with HTTPS correcly. 598 // share certificates policy with HTTPS correcly.
593 IN_PROC_BROWSER_TEST_F(SSLUITest, TestWSSInvalidCertAndGoForward) { 599 IN_PROC_BROWSER_TEST_F(SSLUITest, TestWSSInvalidCertAndGoForward) {
594 ASSERT_TRUE(test_server()->Start()); 600 ASSERT_TRUE(test_server()->Start());
595 ASSERT_TRUE(https_server_expired_.Start()); 601 ASSERT_TRUE(wss_server_expired_.Start());
596
597 // Start pywebsocket with TLS.
598 content::TestWebSocketServer wss_server;
599 int port = wss_server.UseRandomPort();
600 wss_server.UseTLS();
601 FilePath wss_root_dir;
602 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &wss_root_dir));
603 ASSERT_TRUE(wss_server.Start(wss_root_dir));
604 602
605 // Setup page title observer. 603 // Setup page title observer.
606 WebContents* tab = chrome::GetActiveWebContents(browser()); 604 WebContents* tab = chrome::GetActiveWebContents(browser());
607 content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS")); 605 content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS"));
608 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); 606 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
609 607
610 // Visit bad HTTPS page. 608 // Visit bad HTTPS page.
611 std::string urlPath = 609 std::string scheme("https");
612 StringPrintf("%s%d%s", "https://localhost:", port, "/ws.html"); 610 GURL::Replacements replacements;
613 ui_test_utils::NavigateToURL(browser(), GURL(urlPath)); 611 replacements.SetSchemeStr(scheme);
wtc 2012/10/23 19:02:55 Just curious: why does this unit test need to repl
Takashi Toyoshima 2012/10/24 05:29:08 |wss_server_expired_| is launched with TYPE_WSS. S
wtc 2012/10/25 00:18:09 I see. Does this mean ui_test_utils::NavigateToURL
614 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, 612 ui_test_utils::NavigateToURL(
615 false, true); // Interstitial showing 613 browser(),
614 wss_server_expired_.GetURL(
615 "connect_check.html").ReplaceComponents(replacements));
616 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_DATE_INVALID, false,
617 true); // Interstitial showing
616 618
617 // Proceed anyway. 619 // Proceed anyway.
618 ProceedThroughInterstitial(tab); 620 ProceedThroughInterstitial(tab);
619 621
620 // Test page run a WebSocket wss connection test. The result will be shown 622 // Test page run a WebSocket wss connection test. The result will be shown
621 // as page title. 623 // as page title.
622 const string16 result = watcher.WaitAndGetTitle(); 624 const string16 result = watcher.WaitAndGetTitle();
623 EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass")); 625 EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass"));
624 } 626 }
625 627
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after
1570 https_server_.GetURL(replacement_path)); 1572 https_server_.GetURL(replacement_path));
1571 1573
1572 CheckAuthenticatedState(chrome::GetActiveWebContents(browser()), false); 1574 CheckAuthenticatedState(chrome::GetActiveWebContents(browser()), false);
1573 } 1575 }
1574 1576
1575 // Visit a page and establish a WebSocket connection over bad https with 1577 // Visit a page and establish a WebSocket connection over bad https with
1576 // --ignore-certificate-errors. The connection should be established without 1578 // --ignore-certificate-errors. The connection should be established without
1577 // interstitial page showing. 1579 // interstitial page showing.
1578 IN_PROC_BROWSER_TEST_F(SSLUITestIgnoreCertErrors, TestWSS) { 1580 IN_PROC_BROWSER_TEST_F(SSLUITestIgnoreCertErrors, TestWSS) {
1579 ASSERT_TRUE(test_server()->Start()); 1581 ASSERT_TRUE(test_server()->Start());
1580 ASSERT_TRUE(https_server_expired_.Start()); 1582 ASSERT_TRUE(wss_server_expired_.Start());
1581
1582 // Start pywebsocket with TLS.
1583 content::TestWebSocketServer wss_server;
1584 int port = wss_server.UseRandomPort();
1585 wss_server.UseTLS();
1586 FilePath wss_root_dir;
1587 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &wss_root_dir));
1588 ASSERT_TRUE(wss_server.Start(wss_root_dir));
1589 1583
1590 // Setup page title observer. 1584 // Setup page title observer.
1591 WebContents* tab = chrome::GetActiveWebContents(browser()); 1585 WebContents* tab = chrome::GetActiveWebContents(browser());
1592 content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS")); 1586 content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS"));
1593 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); 1587 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
1594 1588
1595 // Visit bad HTTPS page. 1589 // Visit bad HTTPS page.
1596 std::string url_path = 1590 std::string scheme("https");
1597 StringPrintf("%s%d%s", "https://localhost:", port, "/ws.html"); 1591 GURL::Replacements replacements;
1598 ui_test_utils::NavigateToURL(browser(), GURL(url_path)); 1592 replacements.SetSchemeStr(scheme);
1593 ui_test_utils::NavigateToURL(
1594 browser(),
1595 wss_server_expired_.GetURL(
1596 "connect_check.html").ReplaceComponents(replacements));
1599 1597
1600 // We shouldn't have an interstitial page showing here. 1598 // We shouldn't have an interstitial page showing here.
1601 1599
1602 // Test page run a WebSocket wss connection test. The result will be shown 1600 // Test page run a WebSocket wss connection test. The result will be shown
1603 // as page title. 1601 // as page title.
1604 const string16 result = watcher.WaitAndGetTitle(); 1602 const string16 result = watcher.WaitAndGetTitle();
1605 EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass")); 1603 EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass"));
1606 } 1604 }
1607 1605
1608 // TODO(jcampan): more tests to do below. 1606 // TODO(jcampan): more tests to do below.
1609 1607
1610 // Visit a page over https that contains a frame with a redirect. 1608 // Visit a page over https that contains a frame with a redirect.
1611 1609
1612 // XMLHttpRequest insecure content in synchronous mode. 1610 // XMLHttpRequest insecure content in synchronous mode.
1613 1611
1614 // XMLHttpRequest insecure content in asynchronous mode. 1612 // XMLHttpRequest insecure content in asynchronous mode.
1615 1613
1616 // XMLHttpRequest over bad ssl in synchronous mode. 1614 // XMLHttpRequest over bad ssl in synchronous mode.
1617 1615
1618 // XMLHttpRequest over OK ssl in synchronous mode. 1616 // XMLHttpRequest over OK ssl in synchronous mode.
OLDNEW
« no previous file with comments | « chrome/browser/net/proxy_browsertest.cc ('k') | chrome/test/data/http/tests/websocket/tests/echo_wsh.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698