OLD | NEW |
---|---|
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 29 matching lines...) Expand all Loading... | |
40 #include "net/base/cert_status_flags.h" | 40 #include "net/base/cert_status_flags.h" |
41 #include "net/test/test_server.h" | 41 #include "net/test/test_server.h" |
42 | 42 |
43 using content::InterstitialPage; | 43 using content::InterstitialPage; |
44 using content::NavigationController; | 44 using content::NavigationController; |
45 using content::NavigationEntry; | 45 using content::NavigationEntry; |
46 using content::SSLStatus; | 46 using content::SSLStatus; |
47 using content::WebContents; | 47 using content::WebContents; |
48 | 48 |
49 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); | 49 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); |
50 const FilePath::CharType kWsRoot[] = FILE_PATH_LITERAL("net/data/websocket"); | |
50 | 51 |
51 namespace { | 52 namespace { |
52 | 53 |
53 class ProvisionalLoadWaiter : public content::WebContentsObserver { | 54 class ProvisionalLoadWaiter : public content::WebContentsObserver { |
54 public: | 55 public: |
55 explicit ProvisionalLoadWaiter(WebContents* tab) | 56 explicit ProvisionalLoadWaiter(WebContents* tab) |
56 : WebContentsObserver(tab), waiting_(false), seen_(false) {} | 57 : WebContentsObserver(tab), waiting_(false), seen_(false) {} |
57 | 58 |
58 void Wait() { | 59 void Wait() { |
59 if (seen_) | 60 if (seen_) |
(...skipping 16 matching lines...) Expand all Loading... | |
76 } | 77 } |
77 | 78 |
78 private: | 79 private: |
79 bool waiting_; | 80 bool waiting_; |
80 bool seen_; | 81 bool seen_; |
81 }; | 82 }; |
82 | 83 |
83 } // namespace | 84 } // namespace |
84 | 85 |
85 class SSLUITest : public InProcessBrowserTest { | 86 class SSLUITest : public InProcessBrowserTest { |
87 protected: | |
86 typedef net::TestServer::SSLOptions SSLOptions; | 88 typedef net::TestServer::SSLOptions SSLOptions; |
Ryan Sleevi
2012/10/10 17:59:57
style bug: Public -> Protected -> Private.
I real
Takashi Toyoshima
2012/10/11 05:53:28
You are right.
I moved this later in the file.
It
| |
87 | 89 |
88 public: | 90 public: |
89 SSLUITest() | 91 SSLUITest() |
90 : https_server_(net::TestServer::TYPE_HTTPS, | 92 : https_server_(net::TestServer::TYPE_HTTPS, |
91 SSLOptions(SSLOptions::CERT_OK), | 93 SSLOptions(SSLOptions::CERT_OK), |
92 FilePath(kDocRoot)), | 94 FilePath(kDocRoot)), |
93 https_server_expired_(net::TestServer::TYPE_HTTPS, | 95 https_server_expired_(net::TestServer::TYPE_HTTPS, |
94 SSLOptions(SSLOptions::CERT_EXPIRED), | 96 SSLOptions(SSLOptions::CERT_EXPIRED), |
95 FilePath(kDocRoot)), | 97 FilePath(kDocRoot)), |
96 https_server_mismatched_(net::TestServer::TYPE_HTTPS, | 98 https_server_mismatched_(net::TestServer::TYPE_HTTPS, |
97 SSLOptions(SSLOptions::CERT_MISMATCHED_NAME), | 99 SSLOptions(SSLOptions::CERT_MISMATCHED_NAME), |
98 FilePath(kDocRoot)) {} | 100 FilePath(kDocRoot)), |
101 wss_server_expired_(net::TestServer::TYPE_WSS, | |
102 SSLOptions(SSLOptions::CERT_EXPIRED), | |
103 FilePath(kWsRoot)) {} | |
Takashi Toyoshima
2012/10/10 08:14:44
I just follow existing style here.
What do you thi
Jay Civelli
2012/10/10 15:39:46
I am not sure I understand what you mean.
Takashi Toyoshima
2012/10/11 04:53:21
Sorry for vague comment.
Ryan and I have seen two
| |
99 | 104 |
100 virtual void SetUpCommandLine(CommandLine* command_line) { | 105 virtual void SetUpCommandLine(CommandLine* command_line) { |
101 // Browser will both run and display insecure content. | 106 // Browser will both run and display insecure content. |
102 command_line->AppendSwitch(switches::kAllowRunningInsecureContent); | 107 command_line->AppendSwitch(switches::kAllowRunningInsecureContent); |
103 // Use process-per-site so that navigating to a same-site page in a | 108 // Use process-per-site so that navigating to a same-site page in a |
104 // new tab will use the same process. | 109 // new tab will use the same process. |
105 command_line->AppendSwitch(switches::kProcessPerSite); | 110 command_line->AppendSwitch(switches::kProcessPerSite); |
106 } | 111 } |
107 | 112 |
108 void CheckAuthenticatedState(WebContents* tab, | 113 void CheckAuthenticatedState(WebContents* tab, |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 make_pair("REPLACE_WITH_UNSAFE_WORKER_PATH", unsafe_worker_path)); | 286 make_pair("REPLACE_WITH_UNSAFE_WORKER_PATH", unsafe_worker_path)); |
282 return net::TestServer::GetFilePathWithReplacements( | 287 return net::TestServer::GetFilePathWithReplacements( |
283 "files/ssl/page_with_unsafe_worker.html", | 288 "files/ssl/page_with_unsafe_worker.html", |
284 replacement_text_for_page_with_unsafe_worker, | 289 replacement_text_for_page_with_unsafe_worker, |
285 page_with_unsafe_worker_path); | 290 page_with_unsafe_worker_path); |
286 } | 291 } |
287 | 292 |
288 net::TestServer https_server_; | 293 net::TestServer https_server_; |
289 net::TestServer https_server_expired_; | 294 net::TestServer https_server_expired_; |
290 net::TestServer https_server_mismatched_; | 295 net::TestServer https_server_mismatched_; |
296 net::TestServer wss_server_expired_; | |
291 | 297 |
292 private: | 298 private: |
293 DISALLOW_COPY_AND_ASSIGN(SSLUITest); | 299 DISALLOW_COPY_AND_ASSIGN(SSLUITest); |
294 }; | 300 }; |
295 | 301 |
296 class SSLUITestBlock : public SSLUITest { | 302 class SSLUITestBlock : public SSLUITest { |
297 public: | 303 public: |
298 SSLUITestBlock() : SSLUITest() {} | 304 SSLUITestBlock() : SSLUITest() {} |
299 | 305 |
300 // Browser will neither run nor display insecure content. | 306 // Browser will neither run nor display insecure content. |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
535 EXPECT_FALSE(tab->GetController().CanGoForward()); | 541 EXPECT_FALSE(tab->GetController().CanGoForward()); |
536 NavigationEntry* entry4 = tab->GetController().GetActiveEntry(); | 542 NavigationEntry* entry4 = tab->GetController().GetActiveEntry(); |
537 EXPECT_TRUE(entry2 == entry4); | 543 EXPECT_TRUE(entry2 == entry4); |
538 } | 544 } |
539 | 545 |
540 // Visit a HTTP page which request WSS connection to a server providing invalid | 546 // Visit a HTTP page which request WSS connection to a server providing invalid |
541 // certificate. Close the page while WSS connection waits for SSLManager's | 547 // certificate. Close the page while WSS connection waits for SSLManager's |
542 // response from UI thread. | 548 // response from UI thread. |
543 IN_PROC_BROWSER_TEST_F(SSLUITest, TestWSSInvalidCertAndClose) { | 549 IN_PROC_BROWSER_TEST_F(SSLUITest, TestWSSInvalidCertAndClose) { |
544 ASSERT_TRUE(test_server()->Start()); | 550 ASSERT_TRUE(test_server()->Start()); |
545 ASSERT_TRUE(https_server_expired_.Start()); | 551 ASSERT_TRUE(wss_server_expired_.Start()); |
546 | 552 |
547 // Setup page title observer. | 553 // Setup page title observer. |
548 WebContents* tab = chrome::GetActiveWebContents(browser()); | 554 WebContents* tab = chrome::GetActiveWebContents(browser()); |
549 content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS")); | 555 content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS")); |
550 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); | 556 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); |
551 | 557 |
552 // Create GURLs to test pages. | 558 // Create GURLs to test pages. |
553 std::string masterUrlPath = StringPrintf("%s?%d", | 559 std::string masterUrlPath = StringPrintf("%s?%d", |
554 test_server()->GetURL("files/ssl/wss_close.html").spec().c_str(), | 560 test_server()->GetURL("files/ssl/wss_close.html").spec().c_str(), |
555 https_server_expired_.host_port_pair().port()); | 561 wss_server_expired_.host_port_pair().port()); |
556 GURL masterUrl(masterUrlPath); | 562 GURL masterUrl(masterUrlPath); |
557 std::string slaveUrlPath = StringPrintf("%s?%d", | 563 std::string slaveUrlPath = StringPrintf("%s?%d", |
558 test_server()->GetURL("files/ssl/wss_close_slave.html").spec().c_str(), | 564 test_server()->GetURL("files/ssl/wss_close_slave.html").spec().c_str(), |
559 https_server_expired_.host_port_pair().port()); | 565 wss_server_expired_.host_port_pair().port()); |
560 GURL slaveUrl(slaveUrlPath); | 566 GURL slaveUrl(slaveUrlPath); |
561 | 567 |
562 // Create tabs and visit pages which keep on creating wss connections. | 568 // Create tabs and visit pages which keep on creating wss connections. |
563 TabContents* tabs[16]; | 569 TabContents* tabs[16]; |
564 for (int i = 0; i < 16; ++i) { | 570 for (int i = 0; i < 16; ++i) { |
565 tabs[i] = chrome::AddSelectedTabWithURL(browser(), slaveUrl, | 571 tabs[i] = chrome::AddSelectedTabWithURL(browser(), slaveUrl, |
566 content::PAGE_TRANSITION_LINK); | 572 content::PAGE_TRANSITION_LINK); |
567 } | 573 } |
568 chrome::SelectNextTab(browser()); | 574 chrome::SelectNextTab(browser()); |
569 | 575 |
570 // Visit a page which waits for one TLS handshake failure. | 576 // Visit a page which waits for one TLS handshake failure. |
571 // The title will be changed to 'PASS'. | 577 // The title will be changed to 'PASS'. |
572 ui_test_utils::NavigateToURL(browser(), masterUrl); | 578 ui_test_utils::NavigateToURL(browser(), masterUrl); |
573 const string16 result = watcher.WaitAndGetTitle(); | 579 const string16 result = watcher.WaitAndGetTitle(); |
574 EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass")); | 580 EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass")); |
575 | 581 |
576 // Close tabs which contains the test page. | 582 // Close tabs which contains the test page. |
577 for (int i = 0; i < 16; ++i) | 583 for (int i = 0; i < 16; ++i) |
578 chrome::CloseWebContents(browser(), tabs[i]->web_contents()); | 584 chrome::CloseWebContents(browser(), tabs[i]->web_contents()); |
579 chrome::CloseWebContents(browser(), tab); | 585 chrome::CloseWebContents(browser(), tab); |
580 } | 586 } |
581 | 587 |
582 // Visit a HTTPS page and proceeds despite an invalid certificate. The page | 588 // Visit a HTTPS page and proceeds despite an invalid certificate. The page |
583 // requests WSS connection to the same origin host to check if WSS connection | 589 // requests WSS connection to the same origin host to check if WSS connection |
584 // share certificates policy with HTTPS correcly. | 590 // share certificates policy with HTTPS correcly. |
585 IN_PROC_BROWSER_TEST_F(SSLUITest, TestWSSInvalidCertAndGoForward) { | 591 IN_PROC_BROWSER_TEST_F(SSLUITest, TestWSSInvalidCertAndGoForward) { |
586 ASSERT_TRUE(test_server()->Start()); | 592 ASSERT_TRUE(test_server()->Start()); |
587 ASSERT_TRUE(https_server_expired_.Start()); | 593 ASSERT_TRUE(wss_server_expired_.Start()); |
588 | |
589 // Start pywebsocket with TLS. | |
590 content::TestWebSocketServer wss_server; | |
591 int port = wss_server.UseRandomPort(); | |
592 wss_server.UseTLS(); | |
593 FilePath wss_root_dir; | |
594 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &wss_root_dir)); | |
595 ASSERT_TRUE(wss_server.Start(wss_root_dir)); | |
596 | 594 |
597 // Setup page title observer. | 595 // Setup page title observer. |
598 WebContents* tab = chrome::GetActiveWebContents(browser()); | 596 WebContents* tab = chrome::GetActiveWebContents(browser()); |
599 content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS")); | 597 content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS")); |
600 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); | 598 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); |
601 | 599 |
602 // Visit bad HTTPS page. | 600 // Visit bad HTTPS page. |
603 std::string urlPath = | 601 ui_test_utils::NavigateToURL( |
604 StringPrintf("%s%d%s", "https://localhost:", port, "/ws.html"); | 602 browser(), wss_server_expired_.GetAlternateURL("connect_check.html")); |
605 ui_test_utils::NavigateToURL(browser(), GURL(urlPath)); | 603 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_DATE_INVALID, false, |
606 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, | 604 true); // Interstitial showing |
607 false, true); // Interstitial showing | |
608 | 605 |
609 // Proceed anyway. | 606 // Proceed anyway. |
610 ProceedThroughInterstitial(tab); | 607 ProceedThroughInterstitial(tab); |
611 | 608 |
612 // Test page run a WebSocket wss connection test. The result will be shown | 609 // Test page run a WebSocket wss connection test. The result will be shown |
613 // as page title. | 610 // as page title. |
614 const string16 result = watcher.WaitAndGetTitle(); | 611 const string16 result = watcher.WaitAndGetTitle(); |
615 EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass")); | 612 EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass")); |
616 } | 613 } |
617 | 614 |
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1487 https_server_.GetURL(replacement_path)); | 1484 https_server_.GetURL(replacement_path)); |
1488 | 1485 |
1489 CheckAuthenticatedState(chrome::GetActiveWebContents(browser()), false); | 1486 CheckAuthenticatedState(chrome::GetActiveWebContents(browser()), false); |
1490 } | 1487 } |
1491 | 1488 |
1492 // Visit a page and establish a WebSocket connection over bad https with | 1489 // Visit a page and establish a WebSocket connection over bad https with |
1493 // --ignore-certificate-errors. The connection should be established without | 1490 // --ignore-certificate-errors. The connection should be established without |
1494 // interstitial page showing. | 1491 // interstitial page showing. |
1495 IN_PROC_BROWSER_TEST_F(SSLUITestIgnoreCertErrors, TestWSS) { | 1492 IN_PROC_BROWSER_TEST_F(SSLUITestIgnoreCertErrors, TestWSS) { |
1496 ASSERT_TRUE(test_server()->Start()); | 1493 ASSERT_TRUE(test_server()->Start()); |
1497 ASSERT_TRUE(https_server_expired_.Start()); | 1494 ASSERT_TRUE(wss_server_expired_.Start()); |
1498 | |
1499 // Start pywebsocket with TLS. | |
1500 content::TestWebSocketServer wss_server; | |
1501 int port = wss_server.UseRandomPort(); | |
1502 wss_server.UseTLS(); | |
1503 FilePath wss_root_dir; | |
1504 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &wss_root_dir)); | |
1505 ASSERT_TRUE(wss_server.Start(wss_root_dir)); | |
1506 | 1495 |
1507 // Setup page title observer. | 1496 // Setup page title observer. |
1508 WebContents* tab = chrome::GetActiveWebContents(browser()); | 1497 WebContents* tab = chrome::GetActiveWebContents(browser()); |
1509 content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS")); | 1498 content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS")); |
1510 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); | 1499 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); |
1511 | 1500 |
1512 // Visit bad HTTPS page. | 1501 // Visit bad HTTPS page. |
1513 std::string url_path = | 1502 ui_test_utils::NavigateToURL( |
1514 StringPrintf("%s%d%s", "https://localhost:", port, "/ws.html"); | 1503 browser(), wss_server_expired_.GetAlternateURL("connect_check.html")); |
1515 ui_test_utils::NavigateToURL(browser(), GURL(url_path)); | |
1516 | 1504 |
1517 // We shouldn't have an interstitial page showing here. | 1505 // We shouldn't have an interstitial page showing here. |
1518 | 1506 |
1519 // Test page run a WebSocket wss connection test. The result will be shown | 1507 // Test page run a WebSocket wss connection test. The result will be shown |
1520 // as page title. | 1508 // as page title. |
1521 const string16 result = watcher.WaitAndGetTitle(); | 1509 const string16 result = watcher.WaitAndGetTitle(); |
1522 EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass")); | 1510 EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass")); |
1523 } | 1511 } |
1524 | 1512 |
1525 // TODO(jcampan): more tests to do below. | 1513 // TODO(jcampan): more tests to do below. |
1526 | 1514 |
1527 // Visit a page over https that contains a frame with a redirect. | 1515 // Visit a page over https that contains a frame with a redirect. |
1528 | 1516 |
1529 // XMLHttpRequest insecure content in synchronous mode. | 1517 // XMLHttpRequest insecure content in synchronous mode. |
1530 | 1518 |
1531 // XMLHttpRequest insecure content in asynchronous mode. | 1519 // XMLHttpRequest insecure content in asynchronous mode. |
1532 | 1520 |
1533 // XMLHttpRequest over bad ssl in synchronous mode. | 1521 // XMLHttpRequest over bad ssl in synchronous mode. |
1534 | 1522 |
1535 // XMLHttpRequest over OK ssl in synchronous mode. | 1523 // XMLHttpRequest over OK ssl in synchronous mode. |
OLD | NEW |