Chromium Code Reviews| 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" |
| 11 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
| 12 #include "chrome/browser/content_settings/host_content_settings_map.h" | |
| 12 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_commands.h" | 16 #include "chrome/browser/ui/browser_commands.h" |
| 16 #include "chrome/browser/ui/browser_navigator.h" | 17 #include "chrome/browser/ui/browser_navigator.h" |
| 17 #include "chrome/browser/ui/browser_tabstrip.h" | 18 #include "chrome/browser/ui/browser_tabstrip.h" |
| 18 #include "chrome/browser/ui/constrained_window_tab_helper.h" | 19 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
| 19 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 20 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 21 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
| 22 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
| 23 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 25 #include "chrome/test/base/in_process_browser_test.h" | 26 #include "chrome/test/base/in_process_browser_test.h" |
| 26 #include "chrome/test/base/ui_test_utils.h" | 27 #include "chrome/test/base/ui_test_utils.h" |
| 27 #include "content/public/browser/browser_context.h" | 28 #include "content/public/browser/browser_context.h" |
| 28 #include "content/public/browser/interstitial_page.h" | 29 #include "content/public/browser/interstitial_page.h" |
| 29 #include "content/public/browser/navigation_controller.h" | 30 #include "content/public/browser/navigation_controller.h" |
| 30 #include "content/public/browser/navigation_entry.h" | 31 #include "content/public/browser/navigation_entry.h" |
| 31 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
| 32 #include "content/public/browser/render_view_host.h" | 33 #include "content/public/browser/render_view_host.h" |
| 33 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
| 34 #include "content/public/browser/web_contents_observer.h" | 35 #include "content/public/browser/web_contents_observer.h" |
| 35 #include "content/public/common/security_style.h" | 36 #include "content/public/common/security_style.h" |
| 36 #include "content/public/common/ssl_status.h" | 37 #include "content/public/common/ssl_status.h" |
| 37 #include "content/public/test/browser_test_utils.h" | 38 #include "content/public/test/browser_test_utils.h" |
| 38 #include "content/public/test/download_test_observer.h" | 39 #include "content/public/test/download_test_observer.h" |
| 39 #include "content/public/test/test_renderer_host.h" | 40 #include "content/public/test/test_renderer_host.h" |
| 41 #include "crypto/nss_util.h" | |
| 40 #include "net/base/cert_status_flags.h" | 42 #include "net/base/cert_status_flags.h" |
| 43 #include "net/base/crypto_module.h" | |
| 44 #include "net/base/net_errors.h" | |
| 45 #if defined(USE_NSS) | |
| 46 #include "net/base/nss_cert_database.h" | |
| 47 #endif // defined(USE_NSS) | |
|
Ryan Sleevi
2012/10/15 17:04:52
Please follow Chromium style for platform specific
Takashi Toyoshima
2012/10/16 11:20:46
Done.
| |
| 41 #include "net/test/test_server.h" | 48 #include "net/test/test_server.h" |
| 42 | 49 |
| 43 using content::InterstitialPage; | 50 using content::InterstitialPage; |
| 44 using content::NavigationController; | 51 using content::NavigationController; |
| 45 using content::NavigationEntry; | 52 using content::NavigationEntry; |
| 46 using content::SSLStatus; | 53 using content::SSLStatus; |
| 47 using content::WebContents; | 54 using content::WebContents; |
| 48 | 55 |
| 49 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); | 56 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); |
| 50 | 57 |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 608 | 615 |
| 609 // Proceed anyway. | 616 // Proceed anyway. |
| 610 ProceedThroughInterstitial(tab); | 617 ProceedThroughInterstitial(tab); |
| 611 | 618 |
| 612 // Test page run a WebSocket wss connection test. The result will be shown | 619 // Test page run a WebSocket wss connection test. The result will be shown |
| 613 // as page title. | 620 // as page title. |
| 614 const string16 result = watcher.WaitAndGetTitle(); | 621 const string16 result = watcher.WaitAndGetTitle(); |
| 615 EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass")); | 622 EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass")); |
| 616 } | 623 } |
| 617 | 624 |
| 625 #if defined(USE_NSS) | |
| 626 // SSL client certificate tests are only enabled when using NSS for private key | |
| 627 // storage, as only NSS can avoid modifying global machine state when testing. | |
| 628 // See http://crbug.com/51132 | |
| 629 | |
| 630 // Visit a HTTPS page which requires client cert authentication. The client | |
| 631 // cert will be selected automatically, then a test which uses WebSocket runs. | |
| 632 IN_PROC_BROWSER_TEST_F(SSLUITest, TestWSSClientCert) { | |
| 633 // Open a temporary NSS DB for testing. | |
| 634 // TODO(toyoshim): This currently intentionally leaks the test database due | |
| 635 // to bugs within NSS. Once fixed, this should be a scoped test database. | |
| 636 // See http://crbug.com/136950#c5 for more details. | |
| 637 ASSERT_TRUE(crypto::OpenTestNSSDB()); | |
|
Ryan Sleevi
2012/10/15 17:04:52
Aside: Wondering if this should be a scoped RAII-l
Takashi Toyoshima
2012/10/16 11:20:46
OK, I try it in another CL firstly.
| |
| 638 | |
| 639 // Import client cert for test. These interfaces require NSS. | |
| 640 net::NSSCertDatabase* cert_db = net::NSSCertDatabase::GetInstance(); | |
| 641 scoped_refptr<net::CryptoModule> crypt_module = cert_db->GetPublicModule(); | |
| 642 std::string pkcs12_data; | |
| 643 FilePath cert_path; | |
| 644 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &cert_path)); | |
| 645 cert_path = cert_path.Append( | |
| 646 FILE_PATH_LITERAL("net/data/websocket/client_cert.p12")); | |
| 647 EXPECT_TRUE(file_util::ReadFileToString(cert_path, &pkcs12_data)); | |
| 648 EXPECT_EQ(net::OK, cert_db->ImportFromPKCS12(crypt_module, | |
| 649 pkcs12_data, | |
| 650 string16(), | |
| 651 true, | |
| 652 NULL)); | |
| 653 | |
| 654 // Start WebSocket test server with TLS and client cert authentication. | |
| 655 net::TestServer::SSLOptions options(net::TestServer::SSLOptions::CERT_OK); | |
| 656 options.request_client_certificate = true; | |
| 657 FilePath ca_path; | |
| 658 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &ca_path)); | |
| 659 ca_path = ca_path.Append(FILE_PATH_LITERAL("net/data/websocket/cacert.pem")); | |
| 660 options.client_authorities.push_back(ca_path); | |
| 661 net::TestServer wss_server(net::TestServer::TYPE_WSS, | |
| 662 options, | |
| 663 FilePath(FILE_PATH_LITERAL( | |
| 664 "net/data/websocket"))); | |
| 665 ASSERT_TRUE(wss_server.Start()); | |
| 666 std::string scheme("https"); | |
| 667 GURL::Replacements replacements; | |
| 668 replacements.SetSchemeStr(scheme); | |
| 669 GURL url = | |
| 670 wss_server.GetURL("connect_check.html").ReplaceComponents(replacements); | |
| 671 | |
| 672 // Setup page title observer. | |
| 673 WebContents* tab = chrome::GetActiveWebContents(browser()); | |
| 674 content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS")); | |
| 675 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); | |
| 676 | |
| 677 // Add an entry into AutoSelectCertificateForUrls policy for automatic client | |
| 678 // cert selection. | |
| 679 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); | |
| 680 DCHECK(profile); | |
| 681 scoped_ptr<DictionaryValue> dict(new DictionaryValue()); | |
| 682 dict->SetString("ISSUER.CN", "pywebsocket"); | |
| 683 profile->GetHostContentSettingsMap()->SetWebsiteSetting( | |
| 684 ContentSettingsPattern::FromURL(url), | |
| 685 ContentSettingsPattern::FromURL(url), | |
| 686 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, | |
| 687 std::string(), | |
| 688 dict.release()); | |
| 689 | |
| 690 // Visit a HTTPS page which requires client certs. | |
| 691 ui_test_utils::NavigateToURL(browser(), url); | |
| 692 CheckAuthenticatedState(tab, false); | |
| 693 | |
| 694 // Test page runs a WebSocket wss connection test. The result will be shown | |
| 695 // as page title. | |
| 696 const string16 result = watcher.WaitAndGetTitle(); | |
| 697 EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass")); | |
| 698 } | |
| 699 #endif // defined(USE_NSS) | |
| 700 | |
| 618 // Flaky on CrOS http://crbug.com/92292 | 701 // Flaky on CrOS http://crbug.com/92292 |
| 619 #if defined(OS_CHROMEOS) | 702 #if defined(OS_CHROMEOS) |
| 620 #define MAYBE_TestHTTPSErrorWithNoNavEntry \ | 703 #define MAYBE_TestHTTPSErrorWithNoNavEntry \ |
| 621 DISABLED_TestHTTPSErrorWithNoNavEntry | 704 DISABLED_TestHTTPSErrorWithNoNavEntry |
| 622 #else | 705 #else |
| 623 #define MAYBE_TestHTTPSErrorWithNoNavEntry TestHTTPSErrorWithNoNavEntry | 706 #define MAYBE_TestHTTPSErrorWithNoNavEntry TestHTTPSErrorWithNoNavEntry |
| 624 #endif // defined(OS_CHROMEOS) | 707 #endif // defined(OS_CHROMEOS) |
| 625 | 708 |
| 626 // Open a page with a HTTPS error in a tab with no prior navigation (through a | 709 // Open a page with a HTTPS error in a tab with no prior navigation (through a |
| 627 // link with a blank target). This is to test that the lack of navigation entry | 710 // link with a blank target). This is to test that the lack of navigation entry |
| (...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1526 | 1609 |
| 1527 // Visit a page over https that contains a frame with a redirect. | 1610 // Visit a page over https that contains a frame with a redirect. |
| 1528 | 1611 |
| 1529 // XMLHttpRequest insecure content in synchronous mode. | 1612 // XMLHttpRequest insecure content in synchronous mode. |
| 1530 | 1613 |
| 1531 // XMLHttpRequest insecure content in asynchronous mode. | 1614 // XMLHttpRequest insecure content in asynchronous mode. |
| 1532 | 1615 |
| 1533 // XMLHttpRequest over bad ssl in synchronous mode. | 1616 // XMLHttpRequest over bad ssl in synchronous mode. |
| 1534 | 1617 |
| 1535 // XMLHttpRequest over OK ssl in synchronous mode. | 1618 // XMLHttpRequest over OK ssl in synchronous mode. |
| OLD | NEW |