OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/time.h" | 6 #include "base/time.h" |
6 #include "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
7 #include "chrome/browser/tabs/tab_strip_model.h" | 8 #include "chrome/browser/tabs/tab_strip_model.h" |
8 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/browser_navigator.h" | 10 #include "chrome/browser/ui/browser_navigator.h" |
10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 12 #include "chrome/common/chrome_switches.h" |
11 #include "chrome/test/in_process_browser_test.h" | 13 #include "chrome/test/in_process_browser_test.h" |
12 #include "chrome/test/ui_test_utils.h" | 14 #include "chrome/test/ui_test_utils.h" |
13 #include "content/browser/renderer_host/render_view_host.h" | 15 #include "content/browser/renderer_host/render_view_host.h" |
14 #include "content/browser/tab_contents/interstitial_page.h" | 16 #include "content/browser/tab_contents/interstitial_page.h" |
15 #include "content/browser/tab_contents/navigation_entry.h" | 17 #include "content/browser/tab_contents/navigation_entry.h" |
16 #include "content/browser/tab_contents/tab_contents.h" | 18 #include "content/browser/tab_contents/tab_contents.h" |
17 #include "net/base/cert_status_flags.h" | 19 #include "net/base/cert_status_flags.h" |
18 #include "net/test/test_server.h" | 20 #include "net/test/test_server.h" |
19 | 21 |
20 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); | 22 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); |
21 | 23 |
22 class SSLUITest : public InProcessBrowserTest { | 24 class SSLUITest : public InProcessBrowserTest { |
23 typedef net::TestServer::HTTPSOptions HTTPSOptions; | 25 typedef net::TestServer::HTTPSOptions HTTPSOptions; |
24 | 26 |
25 public: | 27 public: |
26 SSLUITest() | 28 SSLUITest() |
27 : https_server_( | 29 : https_server_( |
28 HTTPSOptions(HTTPSOptions::CERT_OK), FilePath(kDocRoot)), | 30 HTTPSOptions(HTTPSOptions::CERT_OK), FilePath(kDocRoot)), |
29 https_server_expired_( | 31 https_server_expired_( |
30 HTTPSOptions(HTTPSOptions::CERT_EXPIRED), FilePath(kDocRoot)), | 32 HTTPSOptions(HTTPSOptions::CERT_EXPIRED), FilePath(kDocRoot)), |
31 https_server_mismatched_( | 33 https_server_mismatched_( |
32 HTTPSOptions(HTTPSOptions::CERT_MISMATCHED_NAME), | 34 HTTPSOptions(HTTPSOptions::CERT_MISMATCHED_NAME), |
33 FilePath(kDocRoot)) { | 35 FilePath(kDocRoot)) { |
34 EnableDOMAutomation(); | 36 EnableDOMAutomation(); |
35 } | 37 } |
36 | 38 |
| 39 // Browser will both run and display insecure content. |
| 40 virtual void SetUpCommandLine(CommandLine* command_line) { |
| 41 command_line->AppendSwitch(switches::kAllowRunningInsecureContent); |
| 42 } |
| 43 |
37 void CheckAuthenticatedState(TabContents* tab, | 44 void CheckAuthenticatedState(TabContents* tab, |
38 bool displayed_insecure_content) { | 45 bool displayed_insecure_content) { |
39 NavigationEntry* entry = tab->controller().GetActiveEntry(); | 46 NavigationEntry* entry = tab->controller().GetActiveEntry(); |
40 ASSERT_TRUE(entry); | 47 ASSERT_TRUE(entry); |
41 EXPECT_EQ(NORMAL_PAGE, entry->page_type()); | 48 EXPECT_EQ(NORMAL_PAGE, entry->page_type()); |
42 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATED, entry->ssl().security_style()); | 49 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATED, entry->ssl().security_style()); |
43 EXPECT_EQ(0, entry->ssl().cert_status() & net::CERT_STATUS_ALL_ERRORS); | 50 EXPECT_EQ(0, entry->ssl().cert_status() & net::CERT_STATUS_ALL_ERRORS); |
44 EXPECT_EQ(displayed_insecure_content, | 51 EXPECT_EQ(displayed_insecure_content, |
45 entry->ssl().displayed_insecure_content()); | 52 entry->ssl().displayed_insecure_content()); |
46 EXPECT_FALSE(entry->ssl().ran_insecure_content()); | 53 EXPECT_FALSE(entry->ssl().ran_insecure_content()); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 } | 197 } |
191 | 198 |
192 net::TestServer https_server_; | 199 net::TestServer https_server_; |
193 net::TestServer https_server_expired_; | 200 net::TestServer https_server_expired_; |
194 net::TestServer https_server_mismatched_; | 201 net::TestServer https_server_mismatched_; |
195 | 202 |
196 private: | 203 private: |
197 DISALLOW_COPY_AND_ASSIGN(SSLUITest); | 204 DISALLOW_COPY_AND_ASSIGN(SSLUITest); |
198 }; | 205 }; |
199 | 206 |
| 207 class SSLUITestBlock : public SSLUITest { |
| 208 public: |
| 209 SSLUITestBlock() : SSLUITest() {} |
| 210 |
| 211 // Browser will neither run nor display insecure content. |
| 212 virtual void SetUpCommandLine(CommandLine* command_line) { |
| 213 command_line->AppendSwitch(switches::kNoDisplayingInsecureContent); |
| 214 } |
| 215 }; |
| 216 |
200 // Visits a regular page over http. | 217 // Visits a regular page over http. |
201 IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTP) { | 218 IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTP) { |
202 ASSERT_TRUE(test_server()->Start()); | 219 ASSERT_TRUE(test_server()->Start()); |
203 | 220 |
204 ui_test_utils::NavigateToURL(browser(), | 221 ui_test_utils::NavigateToURL(browser(), |
205 test_server()->GetURL("files/ssl/google.html")); | 222 test_server()->GetURL("files/ssl/google.html")); |
206 | 223 |
207 CheckUnauthenticatedState(browser()->GetSelectedTabContents()); | 224 CheckUnauthenticatedState(browser()->GetSelectedTabContents()); |
208 } | 225 } |
209 | 226 |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 // Load a page that displays insecure content. | 465 // Load a page that displays insecure content. |
449 ui_test_utils::NavigateToURL(browser(), | 466 ui_test_utils::NavigateToURL(browser(), |
450 https_server_.GetURL(replacement_path)); | 467 https_server_.GetURL(replacement_path)); |
451 | 468 |
452 CheckAuthenticatedState(browser()->GetSelectedTabContents(), true); | 469 CheckAuthenticatedState(browser()->GetSelectedTabContents(), true); |
453 } | 470 } |
454 | 471 |
455 // Visits a page that runs insecure content and tries to suppress the insecure | 472 // Visits a page that runs insecure content and tries to suppress the insecure |
456 // content warnings by randomizing location.hash. | 473 // content warnings by randomizing location.hash. |
457 // Based on http://crbug.com/8706 | 474 // Based on http://crbug.com/8706 |
458 // Disabled, http://crbug.com/85475. | |
459 IN_PROC_BROWSER_TEST_F(SSLUITest, | 475 IN_PROC_BROWSER_TEST_F(SSLUITest, |
460 DISABLED_TestRunsInsecuredContentRandomizeHash) { | 476 TestRunsInsecuredContentRandomizeHash) { |
461 ASSERT_TRUE(test_server()->Start()); | 477 ASSERT_TRUE(test_server()->Start()); |
462 ASSERT_TRUE(https_server_.Start()); | 478 ASSERT_TRUE(https_server_.Start()); |
463 | 479 |
464 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL( | 480 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL( |
465 "files/ssl/page_runs_insecure_content.html")); | 481 "files/ssl/page_runs_insecure_content.html")); |
466 | 482 |
467 CheckAuthenticationBrokenState(browser()->GetSelectedTabContents(), 0, true, | 483 CheckAuthenticationBrokenState(browser()->GetSelectedTabContents(), 0, true, |
468 false); | 484 false); |
469 } | 485 } |
470 | 486 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 // The new tab has insecure content. | 589 // The new tab has insecure content. |
574 CheckAuthenticatedState(tab2->tab_contents(), true); | 590 CheckAuthenticatedState(tab2->tab_contents(), true); |
575 | 591 |
576 // The original tab should not be contaminated. | 592 // The original tab should not be contaminated. |
577 CheckAuthenticatedState(tab1->tab_contents(), false); | 593 CheckAuthenticatedState(tab1->tab_contents(), false); |
578 } | 594 } |
579 | 595 |
580 // Visits two pages from the same origin: one that runs insecure content and one | 596 // Visits two pages from the same origin: one that runs insecure content and one |
581 // that doesn't. The test checks that we propagate the insecure content state | 597 // that doesn't. The test checks that we propagate the insecure content state |
582 // from one to the other. | 598 // from one to the other. |
583 // Disabled, http://crbug.com/85475. | 599 IN_PROC_BROWSER_TEST_F(SSLUITest, TestRunsInsecureContentTwoTabs) { |
584 IN_PROC_BROWSER_TEST_F(SSLUITest, DISABLED_TestRunsInsecureContentTwoTabs) { | |
585 ASSERT_TRUE(test_server()->Start()); | 600 ASSERT_TRUE(test_server()->Start()); |
586 ASSERT_TRUE(https_server_.Start()); | 601 ASSERT_TRUE(https_server_.Start()); |
587 | 602 |
588 ui_test_utils::NavigateToURL(browser(), | 603 ui_test_utils::NavigateToURL(browser(), |
589 https_server_.GetURL("files/ssl/blank_page.html")); | 604 https_server_.GetURL("files/ssl/blank_page.html")); |
590 | 605 |
591 TabContentsWrapper* tab1 = browser()->GetSelectedTabContentsWrapper(); | 606 TabContentsWrapper* tab1 = browser()->GetSelectedTabContentsWrapper(); |
592 | 607 |
593 // This tab should be fine. | 608 // This tab should be fine. |
594 CheckAuthenticatedState(tab1->tab_contents(), false); | 609 CheckAuthenticatedState(tab1->tab_contents(), false); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 const GURL url_https = https_server_.GetURL(replacement_path); | 655 const GURL url_https = https_server_.GetURL(replacement_path); |
641 ui_test_utils::NavigateToURL(browser(), url_https); | 656 ui_test_utils::NavigateToURL(browser(), url_https); |
642 CheckAuthenticatedState(tab, true); | 657 CheckAuthenticatedState(tab, true); |
643 } | 658 } |
644 | 659 |
645 // http://crbug.com/84729 | 660 // http://crbug.com/84729 |
646 #if defined(OS_CHROMEOS) | 661 #if defined(OS_CHROMEOS) |
647 #define MAYBE_TestRunsCachedInsecureContent \ | 662 #define MAYBE_TestRunsCachedInsecureContent \ |
648 DISABLED_TestRunsCachedInsecureContent | 663 DISABLED_TestRunsCachedInsecureContent |
649 #else | 664 #else |
650 // Disabled, http://crbug.com/85475. | 665 #define MAYBE_TestRunsCachedInsecureContent TestRunsCachedInsecureContent |
651 #define MAYBE_TestRunsCachedInsecureContent \ | |
652 DISABLED_TestRunsCachedInsecureContent | |
653 #endif // defined(OS_CHROMEOS) | 666 #endif // defined(OS_CHROMEOS) |
654 | 667 |
655 // Visits a page with script over http. Visits another page over https | 668 // Visits a page with script over http. Visits another page over https |
656 // referencing that same script over http (hoping it is coming from the webcore | 669 // referencing that same script over http (hoping it is coming from the webcore |
657 // memory cache). | 670 // memory cache). |
658 IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestRunsCachedInsecureContent) { | 671 IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestRunsCachedInsecureContent) { |
659 ASSERT_TRUE(test_server()->Start()); | 672 ASSERT_TRUE(test_server()->Start()); |
660 ASSERT_TRUE(https_server_.Start()); | 673 ASSERT_TRUE(https_server_.Start()); |
661 | 674 |
662 std::string replacement_path; | 675 std::string replacement_path; |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 // content. | 1126 // content. |
1114 std::string page_with_unsafe_worker_path; | 1127 std::string page_with_unsafe_worker_path; |
1115 ASSERT_TRUE(GetPageWithUnsafeWorkerPath(https_server_expired_, | 1128 ASSERT_TRUE(GetPageWithUnsafeWorkerPath(https_server_expired_, |
1116 &page_with_unsafe_worker_path)); | 1129 &page_with_unsafe_worker_path)); |
1117 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL( | 1130 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL( |
1118 page_with_unsafe_worker_path)); | 1131 page_with_unsafe_worker_path)); |
1119 CheckWorkerLoadResult(tab, true); // Worker loads insecure content | 1132 CheckWorkerLoadResult(tab, true); // Worker loads insecure content |
1120 CheckAuthenticationBrokenState(tab, 0, true, false); | 1133 CheckAuthenticationBrokenState(tab, 0, true, false); |
1121 } | 1134 } |
1122 | 1135 |
| 1136 // Test that when the browser blocks displaying insecure content, the |
| 1137 // indicator shows a secure page, because the blocking made the otherwise |
| 1138 // unsafe page safe (the notification of this state is handled by other means). |
| 1139 IN_PROC_BROWSER_TEST_F(SSLUITestBlock, TestBlockDisplayingInsecureContent) { |
| 1140 ASSERT_TRUE(test_server()->Start()); |
| 1141 ASSERT_TRUE(https_server_.Start()); |
| 1142 |
| 1143 std::string replacement_path; |
| 1144 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
| 1145 "files/ssl/page_displays_insecure_content.html", |
| 1146 test_server()->host_port_pair(), |
| 1147 &replacement_path)); |
| 1148 |
| 1149 ui_test_utils::NavigateToURL(browser(), |
| 1150 https_server_.GetURL(replacement_path)); |
| 1151 |
| 1152 CheckAuthenticatedState(browser()->GetSelectedTabContents(), false); |
| 1153 } |
| 1154 |
| 1155 // Test that when the browser blocks running insecure content, the |
| 1156 // indicator shows a secure page, because the blocking made the otherwise |
| 1157 // unsafe page safe (the notification of this state is handled by other means). |
| 1158 IN_PROC_BROWSER_TEST_F(SSLUITestBlock, TestBlockRunningInsecureContent) { |
| 1159 ASSERT_TRUE(test_server()->Start()); |
| 1160 ASSERT_TRUE(https_server_.Start()); |
| 1161 |
| 1162 std::string replacement_path; |
| 1163 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( |
| 1164 "files/ssl/page_runs_insecure_content.html", |
| 1165 test_server()->host_port_pair(), |
| 1166 &replacement_path)); |
| 1167 |
| 1168 ui_test_utils::NavigateToURL(browser(), |
| 1169 https_server_.GetURL(replacement_path)); |
| 1170 |
| 1171 CheckAuthenticatedState(browser()->GetSelectedTabContents(), false); |
| 1172 } |
| 1173 |
| 1174 |
1123 // TODO(jcampan): more tests to do below. | 1175 // TODO(jcampan): more tests to do below. |
1124 | 1176 |
1125 // Visit a page over https that contains a frame with a redirect. | 1177 // Visit a page over https that contains a frame with a redirect. |
1126 | 1178 |
1127 // XMLHttpRequest insecure content in synchronous mode. | 1179 // XMLHttpRequest insecure content in synchronous mode. |
1128 | 1180 |
1129 // XMLHttpRequest insecure content in asynchronous mode. | 1181 // XMLHttpRequest insecure content in asynchronous mode. |
1130 | 1182 |
1131 // XMLHttpRequest over bad ssl in synchronous mode. | 1183 // XMLHttpRequest over bad ssl in synchronous mode. |
1132 | 1184 |
1133 // XMLHttpRequest over OK ssl in synchronous mode. | 1185 // XMLHttpRequest over OK ssl in synchronous mode. |
OLD | NEW |