This source file includes following definitions.
- seen_
- Wait
- DidFailProvisionalLoad
- Check
- Check
- Check
- CheckSecurityState
- wss_server_expired_
- SetUpCommandLine
- CheckAuthenticatedState
- CheckUnauthenticatedState
- CheckAuthenticationBrokenState
- CheckWorkerLoadResult
- ProceedThroughInterstitial
- IsShowingWebContentsModalDialog
- GetFilePathWithHostAndPortReplacement
- GetTopFramePath
- GetPageWithUnsafeWorkerPath
- SetUpCommandLine
- SetUpCommandLine
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "base/command_line.h"
#include "base/path_service.h"
#include "base/prefs/pref_service.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/interstitial_page.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/security_style.h"
#include "content/public/common/ssl_status.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/download_test_observer.h"
#include "content/public/test/test_renderer_host.h"
#include "crypto/nss_util.h"
#include "net/base/crypto_module.h"
#include "net/base/net_errors.h"
#include "net/base/test_data_directory.h"
#include "net/cert/cert_status_flags.h"
#include "net/test/spawned_test_server/spawned_test_server.h"
#if defined(USE_NSS)
#include "net/cert/nss_cert_database.h"
#endif
using base::ASCIIToUTF16;
using content::InterstitialPage;
using content::NavigationController;
using content::NavigationEntry;
using content::SSLStatus;
using content::WebContents;
using web_modal::WebContentsModalDialogManager;
const base::FilePath::CharType kDocRoot[] =
FILE_PATH_LITERAL("chrome/test/data");
namespace {
class ProvisionalLoadWaiter : public content::WebContentsObserver {
public:
explicit ProvisionalLoadWaiter(WebContents* tab)
: WebContentsObserver(tab), waiting_(false), seen_(false) {}
void Wait() {
if (seen_)
return;
waiting_ = true;
content::RunMessageLoop();
}
virtual void DidFailProvisionalLoad(
int64 frame_id,
const base::string16& frame_unique_name,
bool is_main_frame,
const GURL& validated_url,
int error_code,
const base::string16& error_description,
content::RenderViewHost* render_view_host) OVERRIDE {
seen_ = true;
if (waiting_)
base::MessageLoopForUI::current()->Quit();
}
private:
bool waiting_;
bool seen_;
};
namespace AuthState {
enum AuthStateFlags {
NONE = 0,
DISPLAYED_INSECURE_CONTENT = 1 << 0,
RAN_INSECURE_CONTENT = 1 << 1,
SHOWING_INTERSTITIAL = 1 << 2
};
void Check(const NavigationEntry& entry, int expected_authentication_state) {
EXPECT_EQ(!!(expected_authentication_state & AuthState::SHOWING_INTERSTITIAL)
? content::PAGE_TYPE_INTERSTITIAL
: content::PAGE_TYPE_NORMAL,
entry.GetPageType());
bool displayed_insecure_content =
!!(entry.GetSSL().content_status & SSLStatus::DISPLAYED_INSECURE_CONTENT);
EXPECT_EQ(
!!(expected_authentication_state & AuthState::DISPLAYED_INSECURE_CONTENT),
displayed_insecure_content);
bool ran_insecure_content =
!!(entry.GetSSL().content_status & SSLStatus::RAN_INSECURE_CONTENT);
EXPECT_EQ(!!(expected_authentication_state & AuthState::RAN_INSECURE_CONTENT),
ran_insecure_content);
}
}
namespace SecurityStyle {
void Check(const NavigationEntry& entry,
content::SecurityStyle expected_security_style) {
EXPECT_EQ(expected_security_style, entry.GetSSL().security_style);
}
}
namespace CertError {
enum CertErrorFlags {
NONE = 0
};
void Check(const NavigationEntry& entry, net::CertStatus error) {
if (error) {
EXPECT_EQ(error, entry.GetSSL().cert_status & error);
net::CertStatus extra_cert_errors =
error ^ (entry.GetSSL().cert_status & net::CERT_STATUS_ALL_ERRORS);
if (extra_cert_errors)
LOG(WARNING) << "Got unexpected cert error: " << extra_cert_errors;
} else {
EXPECT_EQ(0U, entry.GetSSL().cert_status & net::CERT_STATUS_ALL_ERRORS);
}
}
}
void CheckSecurityState(WebContents* tab,
net::CertStatus error,
content::SecurityStyle expected_security_style,
int expected_authentication_state) {
ASSERT_FALSE(tab->IsCrashed());
NavigationEntry* entry = tab->GetController().GetActiveEntry();
ASSERT_TRUE(entry);
CertError::Check(*entry, error);
SecurityStyle::Check(*entry, expected_security_style);
AuthState::Check(*entry, expected_authentication_state);
}
}
class SSLUITest : public InProcessBrowserTest {
public:
SSLUITest()
: https_server_(net::SpawnedTestServer::TYPE_HTTPS,
SSLOptions(SSLOptions::CERT_OK),
base::FilePath(kDocRoot)),
https_server_expired_(net::SpawnedTestServer::TYPE_HTTPS,
SSLOptions(SSLOptions::CERT_EXPIRED),
base::FilePath(kDocRoot)),
https_server_mismatched_(net::SpawnedTestServer::TYPE_HTTPS,
SSLOptions(SSLOptions::CERT_MISMATCHED_NAME),
base::FilePath(kDocRoot)),
wss_server_expired_(net::SpawnedTestServer::TYPE_WSS,
SSLOptions(SSLOptions::CERT_EXPIRED),
net::GetWebSocketTestDataDirectory()) {}
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
command_line->AppendSwitch(switches::kAllowRunningInsecureContent);
command_line->AppendSwitch(switches::kProcessPerSite);
}
void CheckAuthenticatedState(WebContents* tab,
int expected_authentication_state) {
CheckSecurityState(tab,
CertError::NONE,
content::SECURITY_STYLE_AUTHENTICATED,
expected_authentication_state);
}
void CheckUnauthenticatedState(WebContents* tab) {
CheckSecurityState(tab,
CertError::NONE,
content::SECURITY_STYLE_UNAUTHENTICATED,
AuthState::NONE);
}
void CheckAuthenticationBrokenState(WebContents* tab,
net::CertStatus error,
int expected_authentication_state) {
CheckSecurityState(tab,
error,
content::SECURITY_STYLE_AUTHENTICATION_BROKEN,
expected_authentication_state);
ASSERT_NE(net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION, error);
}
void CheckWorkerLoadResult(WebContents* tab, bool expected_load) {
const int kTimeoutMS = 200;
base::Time time_to_quit = base::Time::Now() +
base::TimeDelta::FromMilliseconds(30000);
while (base::Time::Now() < time_to_quit) {
bool worker_finished = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"window.domAutomationController.send(IsWorkerFinished());",
&worker_finished));
if (worker_finished)
break;
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::MessageLoop::QuitClosure(),
base::TimeDelta::FromMilliseconds(kTimeoutMS));
content::RunMessageLoop();
}
bool actually_loaded_content = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"window.domAutomationController.send(IsContentLoaded());",
&actually_loaded_content));
EXPECT_EQ(expected_load, actually_loaded_content);
}
void ProceedThroughInterstitial(WebContents* tab) {
InterstitialPage* interstitial_page = tab->GetInterstitialPage();
ASSERT_TRUE(interstitial_page);
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(&tab->GetController()));
interstitial_page->Proceed();
observer.Wait();
}
bool IsShowingWebContentsModalDialog() const {
return WebContentsModalDialogManager::FromWebContents(
browser()->tab_strip_model()->GetActiveWebContents())->
IsDialogActive();
}
static bool GetFilePathWithHostAndPortReplacement(
const std::string& original_file_path,
const net::HostPortPair& host_port_pair,
std::string* replacement_path) {
std::vector<net::SpawnedTestServer::StringPair> replacement_text;
replacement_text.push_back(
make_pair("REPLACE_WITH_HOST_AND_PORT", host_port_pair.ToString()));
return net::SpawnedTestServer::GetFilePathWithReplacements(
original_file_path, replacement_text, replacement_path);
}
static bool GetTopFramePath(const net::SpawnedTestServer& http_server,
const net::SpawnedTestServer& good_https_server,
const net::SpawnedTestServer& bad_https_server,
std::string* top_frame_path) {
GURL http_url = http_server.GetURL("files/ssl/google.html");
GURL good_https_url = good_https_server.GetURL("files/ssl/google.html");
GURL bad_https_url = bad_https_server.GetURL(
"files/ssl/bad_iframe.html");
std::vector<net::SpawnedTestServer::StringPair> replacement_text_frame_left;
replacement_text_frame_left.push_back(
make_pair("REPLACE_WITH_HTTP_PAGE", http_url.spec()));
replacement_text_frame_left.push_back(
make_pair("REPLACE_WITH_GOOD_HTTPS_PAGE", good_https_url.spec()));
replacement_text_frame_left.push_back(
make_pair("REPLACE_WITH_BAD_HTTPS_PAGE", bad_https_url.spec()));
std::string frame_left_path;
if (!net::SpawnedTestServer::GetFilePathWithReplacements(
"frame_left.html",
replacement_text_frame_left,
&frame_left_path))
return false;
std::vector<net::SpawnedTestServer::StringPair> replacement_text_top_frame;
replacement_text_top_frame.push_back(
make_pair("REPLACE_WITH_FRAME_LEFT_PATH", frame_left_path));
return net::SpawnedTestServer::GetFilePathWithReplacements(
"files/ssl/top_frame.html",
replacement_text_top_frame,
top_frame_path);
}
static bool GetPageWithUnsafeWorkerPath(
const net::SpawnedTestServer& expired_https_server,
std::string* page_with_unsafe_worker_path) {
GURL imported_js_url = expired_https_server.GetURL("files/ssl/imported.js");
std::vector<net::SpawnedTestServer::StringPair>
replacement_text_for_unsafe_worker;
replacement_text_for_unsafe_worker.push_back(
make_pair("REPLACE_WITH_IMPORTED_JS_URL", imported_js_url.spec()));
std::string unsafe_worker_path;
if (!net::SpawnedTestServer::GetFilePathWithReplacements(
"unsafe_worker.js",
replacement_text_for_unsafe_worker,
&unsafe_worker_path))
return false;
std::vector<net::SpawnedTestServer::StringPair>
replacement_text_for_page_with_unsafe_worker;
replacement_text_for_page_with_unsafe_worker.push_back(
make_pair("REPLACE_WITH_UNSAFE_WORKER_PATH", unsafe_worker_path));
return net::SpawnedTestServer::GetFilePathWithReplacements(
"files/ssl/page_with_unsafe_worker.html",
replacement_text_for_page_with_unsafe_worker,
page_with_unsafe_worker_path);
}
net::SpawnedTestServer https_server_;
net::SpawnedTestServer https_server_expired_;
net::SpawnedTestServer https_server_mismatched_;
net::SpawnedTestServer wss_server_expired_;
private:
typedef net::SpawnedTestServer::SSLOptions SSLOptions;
DISALLOW_COPY_AND_ASSIGN(SSLUITest);
};
class SSLUITestBlock : public SSLUITest {
public:
SSLUITestBlock() : SSLUITest() {}
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
command_line->AppendSwitch(switches::kNoDisplayingInsecureContent);
}
};
class SSLUITestIgnoreCertErrors : public SSLUITest {
public:
SSLUITestIgnoreCertErrors() : SSLUITest() {}
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
command_line->AppendSwitch(switches::kIgnoreCertificateErrors);
}
};
IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTP) {
ASSERT_TRUE(test_server()->Start());
ui_test_utils::NavigateToURL(browser(),
test_server()->GetURL("files/ssl/google.html"));
CheckUnauthenticatedState(
browser()->tab_strip_model()->GetActiveWebContents());
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTPWithBrokenHTTPSResource) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_expired_.Start());
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_with_unsafe_contents.html",
https_server_expired_.host_port_pair(),
&replacement_path));
ui_test_utils::NavigateToURL(
browser(), test_server()->GetURL(replacement_path));
CheckUnauthenticatedState(
browser()->tab_strip_model()->GetActiveWebContents());
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestBrokenHTTPSWithInsecureContent) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_expired_.Start());
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_displays_insecure_content.html",
test_server()->host_port_pair(),
&replacement_path));
ui_test_utils::NavigateToURL(browser(),
https_server_expired_.GetURL(replacement_path));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
ProceedThroughInterstitial(tab);
CheckAuthenticationBrokenState(tab,
net::CERT_STATUS_DATE_INVALID,
AuthState::DISPLAYED_INSECURE_CONTENT);
}
#if defined(OS_CHROMEOS)
#define MAYBE_TestOKHTTPS DISABLED_TestOKHTTPS
#else
#define MAYBE_TestOKHTTPS TestOKHTTPS
#endif
IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestOKHTTPS) {
ASSERT_TRUE(https_server_.Start());
ui_test_utils::NavigateToURL(browser(),
https_server_.GetURL("files/ssl/google.html"));
CheckAuthenticatedState(browser()->tab_strip_model()->GetActiveWebContents(),
AuthState::NONE);
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTPSExpiredCertAndProceed) {
ASSERT_TRUE(https_server_expired_.Start());
ui_test_utils::NavigateToURL(browser(),
https_server_expired_.GetURL("files/ssl/google.html"));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
ProceedThroughInterstitial(tab);
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::NONE);
}
#ifndef NEDBUG
#define MAYBE_TestHTTPSExpiredCertAndDontProceed \
DISABLED_TestHTTPSExpiredCertAndDontProceed
#else
#define MAYBE_TestHTTPSExpiredCertAndDontProceed \
TestHTTPSExpiredCertAndDontProceed
#endif
IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestHTTPSExpiredCertAndDontProceed) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
ASSERT_TRUE(https_server_expired_.Start());
ui_test_utils::NavigateToURL(browser(),
https_server_.GetURL("files/ssl/google.html"));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
NavigationEntry* entry = tab->GetController().GetActiveEntry();
ASSERT_TRUE(entry);
GURL cross_site_url =
https_server_expired_.GetURL("files/ssl/google.html");
ASSERT_EQ("127.0.0.1", cross_site_url.host());
GURL::Replacements replacements;
std::string new_host("localhost");
replacements.SetHostStr(new_host);
cross_site_url = cross_site_url.ReplaceComponents(replacements);
ui_test_utils::NavigateToURL(browser(), cross_site_url);
CheckAuthenticationBrokenState(tab,
net::CERT_STATUS_COMMON_NAME_INVALID,
AuthState::SHOWING_INTERSTITIAL);
InterstitialPage* interstitial_page = tab->GetInterstitialPage();
ASSERT_TRUE(interstitial_page);
interstitial_page->DontProceed();
CheckAuthenticatedState(tab, AuthState::NONE);
ui_test_utils::NavigateToURL(browser(),
test_server()->GetURL("files/ssl/google.html"));
CheckUnauthenticatedState(tab);
}
IN_PROC_BROWSER_TEST_F(SSLUITest,
TestHTTPSExpiredCertAndGoBackViaButton) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_expired_.Start());
ui_test_utils::NavigateToURL(browser(),
test_server()->GetURL("files/ssl/google.html"));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
NavigationEntry* entry = tab->GetController().GetActiveEntry();
ASSERT_TRUE(entry);
ui_test_utils::NavigateToURL(browser(),
https_server_expired_.GetURL("files/ssl/google.html"));
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
ProvisionalLoadWaiter load_failed_observer(tab);
chrome::GoBack(browser(), CURRENT_TAB);
load_failed_observer.Wait();
EXPECT_FALSE(content::RenderViewHostTester::IsRenderViewHostSwappedOut(
tab->GetRenderViewHost()));
EXPECT_FALSE(browser()->tab_strip_model()->GetActiveWebContents()->
GetInterstitialPage());
CheckUnauthenticatedState(tab);
}
IN_PROC_BROWSER_TEST_F(SSLUITest,
TestHTTPSExpiredCertAndGoBackViaMenu) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_expired_.Start());
ui_test_utils::NavigateToURL(browser(),
test_server()->GetURL("files/ssl/google.html"));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
NavigationEntry* entry = tab->GetController().GetActiveEntry();
ASSERT_TRUE(entry);
ui_test_utils::NavigateToURL(browser(),
https_server_expired_.GetURL("files/ssl/google.html"));
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
tab->GetController().GoToOffset(-1);
EXPECT_FALSE(browser()->tab_strip_model()->GetActiveWebContents()->
GetInterstitialPage());
CheckUnauthenticatedState(tab);
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTPSExpiredCertAndGoForward) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_expired_.Start());
ui_test_utils::NavigateToURL(browser(),
test_server()->GetURL("files/ssl/google.html"));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
NavigationEntry* entry1 = tab->GetController().GetActiveEntry();
ASSERT_TRUE(entry1);
ui_test_utils::NavigateToURL(browser(),
test_server()->GetURL("files/ssl/blank_page.html"));
NavigationEntry* entry2 = tab->GetController().GetActiveEntry();
ASSERT_TRUE(entry2);
{
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(&tab->GetController()));
tab->GetController().GoBack();
observer.Wait();
}
ASSERT_TRUE(tab->GetController().CanGoForward());
NavigationEntry* entry3 = tab->GetController().GetActiveEntry();
ASSERT_TRUE(entry1 == entry3);
ui_test_utils::NavigateToURL(browser(),
https_server_expired_.GetURL("files/ssl/google.html"));
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
{
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(&tab->GetController()));
tab->GetController().GoToOffset(1);
observer.Wait();
}
EXPECT_FALSE(browser()->tab_strip_model()->GetActiveWebContents()->
GetInterstitialPage());
CheckUnauthenticatedState(tab);
EXPECT_FALSE(tab->GetController().CanGoForward());
NavigationEntry* entry4 = tab->GetController().GetActiveEntry();
EXPECT_TRUE(entry2 == entry4);
}
#if defined(OS_WIN) || defined(LEAK_SANITIZER)
#define MAYBE_TestWSSInvalidCertAndClose DISABLED_TestWSSInvalidCertAndClose
#else
#define MAYBE_TestWSSInvalidCertAndClose TestWSSInvalidCertAndClose
#endif
IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestWSSInvalidCertAndClose) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(wss_server_expired_.Start());
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS"));
watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
std::string master_url_path = base::StringPrintf("%s?%d",
test_server()->GetURL("files/ssl/wss_close.html").spec().c_str(),
wss_server_expired_.host_port_pair().port());
GURL master_url(master_url_path);
std::string slave_url_path = base::StringPrintf("%s?%d",
test_server()->GetURL("files/ssl/wss_close_slave.html").spec().c_str(),
wss_server_expired_.host_port_pair().port());
GURL slave_url(slave_url_path);
WebContents* tabs[16];
for (int i = 0; i < 16; ++i) {
tabs[i] = chrome::AddSelectedTabWithURL(browser(), slave_url,
content::PAGE_TRANSITION_LINK);
}
chrome::SelectNextTab(browser());
ui_test_utils::NavigateToURL(browser(), master_url);
const base::string16 result = watcher.WaitAndGetTitle();
EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass"));
for (int i = 0; i < 16; ++i)
chrome::CloseWebContents(browser(), tabs[i], false);
chrome::CloseWebContents(browser(), tab, false);
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestWSSInvalidCertAndGoForward) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(wss_server_expired_.Start());
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS"));
watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
std::string scheme("https");
GURL::Replacements replacements;
replacements.SetSchemeStr(scheme);
ui_test_utils::NavigateToURL(
browser(),
wss_server_expired_.GetURL(
"connect_check.html").ReplaceComponents(replacements));
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
ProceedThroughInterstitial(tab);
const base::string16 result = watcher.WaitAndGetTitle();
EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass"));
}
#if defined(USE_NSS)
IN_PROC_BROWSER_TEST_F(SSLUITest, DISABLED_TestWSSClientCert) {
crypto::ScopedTestNSSDB test_nssdb;
ASSERT_TRUE(test_nssdb.is_open());
net::NSSCertDatabase* cert_db = net::NSSCertDatabase::GetInstance();
scoped_refptr<net::CryptoModule> crypt_module = cert_db->GetPublicModule();
std::string pkcs12_data;
base::FilePath cert_path = net::GetTestCertsDirectory().Append(
FILE_PATH_LITERAL("websocket_client_cert.p12"));
EXPECT_TRUE(base::ReadFileToString(cert_path, &pkcs12_data));
EXPECT_EQ(net::OK,
cert_db->ImportFromPKCS12(
crypt_module.get(), pkcs12_data, base::string16(), true, NULL));
net::SpawnedTestServer::SSLOptions options(
net::SpawnedTestServer::SSLOptions::CERT_OK);
options.request_client_certificate = true;
base::FilePath ca_path = net::GetTestCertsDirectory().Append(
FILE_PATH_LITERAL("websocket_cacert.pem"));
options.client_authorities.push_back(ca_path);
net::SpawnedTestServer wss_server(net::SpawnedTestServer::TYPE_WSS,
options,
net::GetWebSocketTestDataDirectory());
ASSERT_TRUE(wss_server.Start());
std::string scheme("https");
GURL::Replacements replacements;
replacements.SetSchemeStr(scheme);
GURL url = wss_server.GetURL("connect_check.html").ReplaceComponents(
replacements);
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS"));
watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
DCHECK(profile);
scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
dict->SetString("ISSUER.CN", "pywebsocket");
profile->GetHostContentSettingsMap()->SetWebsiteSetting(
ContentSettingsPattern::FromURL(url),
ContentSettingsPattern::FromURL(url),
CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
std::string(),
dict.release());
ui_test_utils::NavigateToURL(browser(), url);
CheckAuthenticatedState(tab, AuthState::NONE);
const base::string16 result = watcher.WaitAndGetTitle();
EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass"));
}
#endif
#if defined(OS_CHROMEOS)
#define MAYBE_TestHTTPSErrorWithNoNavEntry \
DISABLED_TestHTTPSErrorWithNoNavEntry
#else
#define MAYBE_TestHTTPSErrorWithNoNavEntry TestHTTPSErrorWithNoNavEntry
#endif
IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestHTTPSErrorWithNoNavEntry) {
ASSERT_TRUE(https_server_expired_.Start());
GURL url = https_server_expired_.GetURL("files/ssl/google.htm");
WebContents* tab2 = chrome::AddSelectedTabWithURL(
browser(), url, content::PAGE_TRANSITION_TYPED);
content::WaitForLoadStop(tab2);
EXPECT_FALSE(chrome::CanGoBack(browser()));
ASSERT_TRUE(tab2->GetInterstitialPage());
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestBadHTTPSDownload) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_expired_.Start());
GURL url_non_dangerous = test_server()->GetURL(std::string());
GURL url_dangerous =
https_server_expired_.GetURL("files/downloads/dangerous/dangerous.exe");
base::ScopedTempDir downloads_directory_;
ASSERT_TRUE(downloads_directory_.CreateUniqueTempDir());
browser()->profile()->GetPrefs()->SetFilePath(
prefs::kDownloadDefaultDirectory,
downloads_directory_.path());
ui_test_utils::NavigateToURL(browser(), url_non_dangerous);
{
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
chrome::NavigateParams navigate_params(browser(), url_dangerous,
content::PAGE_TRANSITION_TYPED);
chrome::Navigate(&navigate_params);
observer.Wait();
}
content::DownloadTestObserverTerminal dangerous_download_observer(
content::BrowserContext::GetDownloadManager(browser()->profile()),
1,
content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT);
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(tab != NULL);
ASSERT_TRUE(tab->GetInterstitialPage() != NULL);
{
content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_DOWNLOAD_INITIATED,
content::NotificationService::AllSources());
tab->GetInterstitialPage()->Proceed();
observer.Wait();
}
ASSERT_TRUE(tab->GetInterstitialPage() != NULL);
EXPECT_TRUE(chrome::CanGoBack(browser()));
chrome::GoBack(browser(), CURRENT_TAB);
dangerous_download_observer.WaitForFinished();
}
#if defined(OS_WIN)
#define MAYBE_TestDisplaysInsecureContent DISABLED_TestDisplaysInsecureContent
#else
#define MAYBE_TestDisplaysInsecureContent TestDisplaysInsecureContent
#endif
IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestDisplaysInsecureContent) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_displays_insecure_content.html",
test_server()->host_port_pair(),
&replacement_path));
ui_test_utils::NavigateToURL(browser(),
https_server_.GetURL(replacement_path));
CheckAuthenticatedState(browser()->tab_strip_model()->GetActiveWebContents(),
AuthState::DISPLAYED_INSECURE_CONTENT);
}
IN_PROC_BROWSER_TEST_F(SSLUITest,
TestRunsInsecuredContentRandomizeHash) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
ui_test_utils::NavigateToURL(browser(), https_server_.GetURL(
"files/ssl/page_runs_insecure_content.html"));
CheckAuthenticationBrokenState(
browser()->tab_strip_model()->GetActiveWebContents(),
CertError::NONE,
AuthState::DISPLAYED_INSECURE_CONTENT | AuthState::RAN_INSECURE_CONTENT);
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeContents) {
ASSERT_TRUE(https_server_.Start());
ASSERT_TRUE(https_server_expired_.Start());
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_with_unsafe_contents.html",
https_server_expired_.host_port_pair(),
&replacement_path));
ui_test_utils::NavigateToURL(browser(),
https_server_.GetURL(replacement_path));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
CheckAuthenticatedState(tab, AuthState::NONE);
EXPECT_FALSE(IsShowingWebContentsModalDialog());
int img_width;
EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
tab,
"window.domAutomationController.send(ImageWidth());",
&img_width));
EXPECT_LT(img_width, 100);
bool js_result = false;
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"window.domAutomationController.send(IsFooSet());",
&js_result));
EXPECT_FALSE(js_result);
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestDisplaysInsecureContentLoadedFromJS) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_with_dynamic_insecure_content.html",
test_server()->host_port_pair(),
&replacement_path));
ui_test_utils::NavigateToURL(browser(), https_server_.GetURL(
replacement_path));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
CheckAuthenticatedState(tab, AuthState::NONE);
bool js_result = false;
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"loadBadImage();",
&js_result));
EXPECT_TRUE(js_result);
CheckAuthenticatedState(tab, AuthState::DISPLAYED_INSECURE_CONTENT);
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestDisplaysInsecureContentTwoTabs) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
ui_test_utils::NavigateToURL(browser(),
https_server_.GetURL("files/ssl/blank_page.html"));
WebContents* tab1 = browser()->tab_strip_model()->GetActiveWebContents();
CheckAuthenticatedState(tab1, AuthState::NONE);
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_displays_insecure_content.html",
test_server()->host_port_pair(),
&replacement_path));
GURL url = https_server_.GetURL(replacement_path);
chrome::NavigateParams params(browser(), url, content::PAGE_TRANSITION_TYPED);
params.disposition = NEW_FOREGROUND_TAB;
params.tabstrip_index = 0;
params.source_contents = tab1;
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
chrome::Navigate(¶ms);
WebContents* tab2 = params.target_contents;
observer.Wait();
CheckAuthenticatedState(tab2, AuthState::DISPLAYED_INSECURE_CONTENT);
CheckAuthenticatedState(tab1, AuthState::NONE);
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestRunsInsecureContentTwoTabs) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
ui_test_utils::NavigateToURL(browser(),
https_server_.GetURL("files/ssl/blank_page.html"));
WebContents* tab1 = browser()->tab_strip_model()->GetActiveWebContents();
CheckAuthenticatedState(tab1, AuthState::NONE);
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_runs_insecure_content.html",
test_server()->host_port_pair(),
&replacement_path));
GURL url = https_server_.GetURL(replacement_path);
chrome::NavigateParams params(browser(), url, content::PAGE_TRANSITION_TYPED);
params.disposition = NEW_FOREGROUND_TAB;
params.source_contents = tab1;
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
chrome::Navigate(¶ms);
WebContents* tab2 = params.target_contents;
observer.Wait();
EXPECT_EQ(tab1->GetRenderProcessHost(), tab2->GetRenderProcessHost());
CheckAuthenticationBrokenState(
tab2,
CertError::NONE,
AuthState::DISPLAYED_INSECURE_CONTENT | AuthState::RAN_INSECURE_CONTENT);
CheckAuthenticationBrokenState(
tab1, CertError::NONE, AuthState::RAN_INSECURE_CONTENT);
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestDisplaysCachedInsecureContent) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_displays_insecure_content.html",
test_server()->host_port_pair(),
&replacement_path));
const GURL url_http = test_server()->GetURL(replacement_path);
ui_test_utils::NavigateToURL(browser(), url_http);
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
CheckUnauthenticatedState(tab);
const GURL url_https = https_server_.GetURL(replacement_path);
ui_test_utils::NavigateToURL(browser(), url_https);
CheckAuthenticatedState(tab, AuthState::DISPLAYED_INSECURE_CONTENT);
}
#if defined(OS_CHROMEOS)
#define MAYBE_TestRunsCachedInsecureContent \
DISABLED_TestRunsCachedInsecureContent
#else
#define MAYBE_TestRunsCachedInsecureContent TestRunsCachedInsecureContent
#endif
IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestRunsCachedInsecureContent) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_runs_insecure_content.html",
test_server()->host_port_pair(),
&replacement_path));
const GURL url_http = test_server()->GetURL(replacement_path);
ui_test_utils::NavigateToURL(browser(), url_http);
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
CheckUnauthenticatedState(tab);
const GURL url_https = https_server_.GetURL(replacement_path);
ui_test_utils::NavigateToURL(browser(), url_https);
CheckAuthenticationBrokenState(
tab,
CertError::NONE,
AuthState::DISPLAYED_INSECURE_CONTENT | AuthState::RAN_INSECURE_CONTENT);
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestCNInvalidStickiness) {
ASSERT_TRUE(https_server_.Start());
ASSERT_TRUE(https_server_mismatched_.Start());
ui_test_utils::NavigateToURL(browser(),
https_server_mismatched_.GetURL("files/ssl/google.html"));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
CheckAuthenticationBrokenState(tab,
net::CERT_STATUS_COMMON_NAME_INVALID,
AuthState::SHOWING_INTERSTITIAL);
ProceedThroughInterstitial(tab);
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_COMMON_NAME_INVALID, AuthState::NONE);
GURL url(https_server_.GetURL("files/ssl/google.html"));
ui_test_utils::NavigateToURL(browser(), url);
CheckAuthenticatedState(tab, AuthState::NONE);
ui_test_utils::NavigateToURL(browser(),
https_server_mismatched_.GetURL("files/ssl/google.html"));
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_COMMON_NAME_INVALID, AuthState::NONE);
}
#if defined(OS_CHROMEOS)
#define MAYBE_TestRefNavigation DISABLED_TestRefNavigation
#else
#define MAYBE_TestRefNavigation TestRefNavigation
#endif
IN_PROC_BROWSER_TEST_F(SSLUITest, TestRefNavigation) {
ASSERT_TRUE(https_server_expired_.Start());
ui_test_utils::NavigateToURL(browser(),
https_server_expired_.GetURL("files/ssl/page_with_refs.html"));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
ProceedThroughInterstitial(tab);
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::NONE);
ui_test_utils::NavigateToURL(browser(),
https_server_expired_.GetURL("files/ssl/page_with_refs.html#jp"));
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::NONE);
}
IN_PROC_BROWSER_TEST_F(SSLUITest, DISABLED_TestCloseTabWithUnsafePopup) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_expired_.Start());
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_with_unsafe_popup.html",
https_server_expired_.host_port_pair(),
&replacement_path));
ui_test_utils::NavigateToURL(browser(),
test_server()->GetURL(replacement_path));
WebContents* tab1 = browser()->tab_strip_model()->GetActiveWebContents();
for (int i = 0; i < 10; i++) {
if (IsShowingWebContentsModalDialog())
break;
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::MessageLoop::QuitClosure(),
base::TimeDelta::FromSeconds(1));
content::RunMessageLoop();
}
ASSERT_TRUE(IsShowingWebContentsModalDialog());
GURL url = test_server()->GetURL("files/ssl/google.html");
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
chrome::AddSelectedTabWithURL(browser(), url, content::PAGE_TRANSITION_TYPED);
observer.Wait();
chrome::CloseWebContents(browser(), tab1, false);
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestRedirectBadToGoodHTTPS) {
ASSERT_TRUE(https_server_.Start());
ASSERT_TRUE(https_server_expired_.Start());
GURL url1 = https_server_expired_.GetURL("server-redirect?");
GURL url2 = https_server_.GetURL("files/ssl/google.html");
ui_test_utils::NavigateToURL(browser(), GURL(url1.spec() + url2.spec()));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
ProceedThroughInterstitial(tab);
CheckAuthenticatedState(tab, AuthState::NONE);
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestRedirectGoodToBadHTTPS) {
ASSERT_TRUE(https_server_.Start());
ASSERT_TRUE(https_server_expired_.Start());
GURL url1 = https_server_.GetURL("server-redirect?");
GURL url2 = https_server_expired_.GetURL("files/ssl/google.html");
ui_test_utils::NavigateToURL(browser(), GURL(url1.spec() + url2.spec()));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
ProceedThroughInterstitial(tab);
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::NONE);
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestRedirectHTTPToGoodHTTPS) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
GURL http_url = test_server()->GetURL("server-redirect?");
GURL good_https_url =
https_server_.GetURL("files/ssl/google.html");
ui_test_utils::NavigateToURL(browser(),
GURL(http_url.spec() + good_https_url.spec()));
CheckAuthenticatedState(tab, AuthState::NONE);
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestRedirectHTTPToBadHTTPS) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_expired_.Start());
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
GURL http_url = test_server()->GetURL("server-redirect?");
GURL bad_https_url =
https_server_expired_.GetURL("files/ssl/google.html");
ui_test_utils::NavigateToURL(browser(),
GURL(http_url.spec() + bad_https_url.spec()));
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
ProceedThroughInterstitial(tab);
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::NONE);
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestRedirectHTTPSToHTTP) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
GURL https_url = https_server_.GetURL("server-redirect?");
GURL http_url = test_server()->GetURL("files/ssl/google.html");
ui_test_utils::NavigateToURL(browser(),
GURL(https_url.spec() + http_url.spec()));
CheckUnauthenticatedState(
browser()->tab_strip_model()->GetActiveWebContents());
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestConnectToBadPort) {
ui_test_utils::NavigateToURL(browser(), GURL("http://localhost:17"));
CheckUnauthenticatedState(
browser()->tab_strip_model()->GetActiveWebContents());
ui_test_utils::NavigateToURL(browser(), GURL("https://localhost:17"));
CheckUnauthenticatedState(
browser()->tab_strip_model()->GetActiveWebContents());
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestGoodFrameNavigation) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
ASSERT_TRUE(https_server_expired_.Start());
std::string top_frame_path;
ASSERT_TRUE(GetTopFramePath(*test_server(),
https_server_,
https_server_expired_,
&top_frame_path));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
ui_test_utils::NavigateToURL(browser(),
https_server_.GetURL(top_frame_path));
CheckAuthenticatedState(tab, AuthState::NONE);
bool success = false;
{
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(&tab->GetController()));
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"window.domAutomationController.send(clickLink('goodHTTPSLink'));",
&success));
ASSERT_TRUE(success);
observer.Wait();
}
CheckAuthenticatedState(tab, AuthState::NONE);
{
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(&tab->GetController()));
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"window.domAutomationController.send(clickLink('badHTTPSLink'));",
&success));
ASSERT_TRUE(success);
observer.Wait();
}
CheckAuthenticatedState(tab, AuthState::NONE);
bool is_content_evil = true;
content::RenderFrameHost* content_frame = content::FrameMatchingPredicate(
tab, base::Bind(&content::FrameMatchesName, "contentFrame"));
std::string is_evil_js("window.domAutomationController.send("
"document.getElementById('evilDiv') != null);");
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(content_frame,
is_evil_js,
&is_content_evil));
EXPECT_FALSE(is_content_evil);
{
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(&tab->GetController()));
tab->GetController().GoBack();
observer.Wait();
}
CheckAuthenticatedState(tab, AuthState::NONE);
{
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(&tab->GetController()));
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"window.domAutomationController.send(clickLink('HTTPLink'));",
&success));
ASSERT_TRUE(success);
observer.Wait();
}
CheckAuthenticationBrokenState(
tab,
CertError::NONE,
AuthState::DISPLAYED_INSECURE_CONTENT | AuthState::RAN_INSECURE_CONTENT);
{
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(&tab->GetController()));
tab->GetController().GoBack();
observer.Wait();
}
CheckAuthenticationBrokenState(
tab,
CertError::NONE,
AuthState::DISPLAYED_INSECURE_CONTENT | AuthState::RAN_INSECURE_CONTENT);
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestBadFrameNavigation) {
ASSERT_TRUE(https_server_.Start());
ASSERT_TRUE(https_server_expired_.Start());
std::string top_frame_path;
ASSERT_TRUE(GetTopFramePath(*test_server(),
https_server_,
https_server_expired_,
&top_frame_path));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
ui_test_utils::NavigateToURL(browser(),
https_server_expired_.GetURL(top_frame_path));
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
ProceedThroughInterstitial(tab);
bool success = false;
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(&tab->GetController()));
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"window.domAutomationController.send(clickLink('goodHTTPSLink'));",
&success));
ASSERT_TRUE(success);
observer.Wait();
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::NONE);
}
IN_PROC_BROWSER_TEST_F(SSLUITest, DISABLED_TestUnauthenticatedFrameNavigation) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
ASSERT_TRUE(https_server_expired_.Start());
std::string top_frame_path;
ASSERT_TRUE(GetTopFramePath(*test_server(),
https_server_,
https_server_expired_,
&top_frame_path));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
ui_test_utils::NavigateToURL(browser(),
test_server()->GetURL(top_frame_path));
CheckUnauthenticatedState(tab);
{
bool success = false;
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(&tab->GetController()));
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"window.domAutomationController.send(clickLink('goodHTTPSLink'));",
&success));
ASSERT_TRUE(success);
observer.Wait();
}
CheckUnauthenticatedState(tab);
{
bool success = false;
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(&tab->GetController()));
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"window.domAutomationController.send(clickLink('badHTTPSLink'));",
&success));
ASSERT_TRUE(success);
observer.Wait();
}
CheckUnauthenticatedState(tab);
bool is_content_evil = true;
content::RenderFrameHost* content_frame = content::FrameMatchingPredicate(
tab, base::Bind(&content::FrameMatchesName, "contentFrame"));
std::string is_evil_js("window.domAutomationController.send("
"document.getElementById('evilDiv') != null);");
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(content_frame,
is_evil_js,
&is_content_evil));
EXPECT_FALSE(is_content_evil);
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeContentsInWorkerFiltered) {
ASSERT_TRUE(https_server_.Start());
ASSERT_TRUE(https_server_expired_.Start());
std::string page_with_unsafe_worker_path;
ASSERT_TRUE(GetPageWithUnsafeWorkerPath(https_server_expired_,
&page_with_unsafe_worker_path));
ui_test_utils::NavigateToURL(browser(), https_server_.GetURL(
page_with_unsafe_worker_path));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
CheckWorkerLoadResult(tab, false);
CheckAuthenticatedState(tab, AuthState::NONE);
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeContentsInWorker) {
ASSERT_TRUE(https_server_.Start());
ASSERT_TRUE(https_server_expired_.Start());
ui_test_utils::NavigateToURL(browser(),
https_server_expired_.GetURL("files/ssl/blank_page.html"));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
ProceedThroughInterstitial(tab);
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::NONE);
std::string page_with_unsafe_worker_path;
ASSERT_TRUE(GetPageWithUnsafeWorkerPath(https_server_expired_,
&page_with_unsafe_worker_path));
ui_test_utils::NavigateToURL(browser(), https_server_.GetURL(
page_with_unsafe_worker_path));
CheckWorkerLoadResult(tab, true);
CheckAuthenticationBrokenState(
tab, CertError::NONE, AuthState::RAN_INSECURE_CONTENT);
}
IN_PROC_BROWSER_TEST_F(SSLUITestBlock, TestBlockDisplayingInsecureImage) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_displays_insecure_content.html",
test_server()->host_port_pair(),
&replacement_path));
ui_test_utils::NavigateToURL(browser(),
https_server_.GetURL(replacement_path));
CheckAuthenticatedState(browser()->tab_strip_model()->GetActiveWebContents(),
AuthState::NONE);
}
IN_PROC_BROWSER_TEST_F(SSLUITestBlock, TestBlockDisplayingInsecureIframe) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_displays_insecure_iframe.html",
test_server()->host_port_pair(),
&replacement_path));
ui_test_utils::NavigateToURL(browser(),
https_server_.GetURL(replacement_path));
CheckAuthenticatedState(browser()->tab_strip_model()->GetActiveWebContents(),
AuthState::NONE);
}
IN_PROC_BROWSER_TEST_F(SSLUITestBlock, TestBlockRunningInsecureContent) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_runs_insecure_content.html",
test_server()->host_port_pair(),
&replacement_path));
ui_test_utils::NavigateToURL(browser(),
https_server_.GetURL(replacement_path));
CheckAuthenticatedState(browser()->tab_strip_model()->GetActiveWebContents(),
AuthState::NONE);
}
IN_PROC_BROWSER_TEST_F(SSLUITestIgnoreCertErrors, TestWSS) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(wss_server_expired_.Start());
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS"));
watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
std::string scheme("https");
GURL::Replacements replacements;
replacements.SetSchemeStr(scheme);
ui_test_utils::NavigateToURL(
browser(),
wss_server_expired_.GetURL(
"connect_check.html").ReplaceComponents(replacements));
const base::string16 result = watcher.WaitAndGetTitle();
EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass"));
}
IN_PROC_BROWSER_TEST_F(SSLUITest, InterstitialNotAffectedByContentSettings) {
browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
ASSERT_TRUE(https_server_expired_.Start());
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
ui_test_utils::NavigateToURL(browser(),
https_server_expired_.GetURL("files/ssl/google.html"));
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
InterstitialPage* interstitial_page = tab->GetInterstitialPage();
content::RenderViewHost* interstitial_rvh =
interstitial_page->GetRenderViewHostForTesting();
bool result = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
interstitial_rvh,
"window.domAutomationController.send(true);",
&result));
ASSERT_TRUE(result);
}