| Index: chrome/browser/ssl/security_state_tab_helper_browser_tests.cc
|
| diff --git a/chrome/browser/ssl/security_state_tab_helper_browser_tests.cc b/chrome/browser/ssl/security_state_tab_helper_browser_tests.cc
|
| index 07981b7b02046b2f4d0f4438fc712f38982224fb..cf5a8ac987580deb90ae0ddbd3da7812dcf55e97 100644
|
| --- a/chrome/browser/ssl/security_state_tab_helper_browser_tests.cc
|
| +++ b/chrome/browser/ssl/security_state_tab_helper_browser_tests.cc
|
| @@ -9,11 +9,16 @@
|
| #include "base/macros.h"
|
| #include "base/strings/string_split.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| +#include "base/test/scoped_command_line.h"
|
| #include "base/threading/sequenced_worker_pool.h"
|
| +#include "chrome/browser/browser_process.h"
|
| +#include "chrome/browser/chrome_notification_types.h"
|
| +#include "chrome/browser/profiles/profile_window.h"
|
| #include "chrome/browser/ssl/cert_verifier_browser_test.h"
|
| #include "chrome/browser/ssl/ssl_blocking_page.h"
|
| #include "chrome/browser/ui/browser.h"
|
| #include "chrome/browser/ui/browser_commands.h"
|
| +#include "chrome/browser/ui/browser_finder.h"
|
| #include "chrome/browser/ui/tabs/tab_strip_model.h"
|
| #include "chrome/common/chrome_paths.h"
|
| #include "chrome/common/chrome_switches.h"
|
| @@ -372,6 +377,21 @@ class SecurityStateTabHelperTest : public CertVerifierBrowserTest {
|
| DISALLOW_COPY_AND_ASSIGN(SecurityStateTabHelperTest);
|
| };
|
|
|
| +// Same as SecurityStateTabHelperTest, but with Incognito enabled.
|
| +class SecurityStateTabHelperIncognitoTest : public SecurityStateTabHelperTest {
|
| + public:
|
| + SecurityStateTabHelperIncognitoTest() : SecurityStateTabHelperTest() {}
|
| +
|
| + void SetUpCommandLine(base::CommandLine* command_line) override {
|
| + SecurityStateTabHelperTest::SetUpCommandLine(command_line);
|
| + // Test should run Incognito.
|
| + command_line->AppendSwitch(switches::kIncognito);
|
| + }
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(SecurityStateTabHelperIncognitoTest);
|
| +};
|
| +
|
| class DidChangeVisibleSecurityStateTest : public InProcessBrowserTest {
|
| public:
|
| DidChangeVisibleSecurityStateTest()
|
| @@ -933,6 +953,7 @@ class SecurityStateLoadingTest : public SecurityStateTabHelperTest {
|
| embedded_test_server()->GetURL("/title1.html").host()));
|
| }
|
|
|
| + private:
|
| DISALLOW_COPY_AND_ASSIGN(SecurityStateLoadingTest);
|
| };
|
|
|
| @@ -983,6 +1004,17 @@ IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
|
| ASSERT_TRUE(entry);
|
| EXPECT_TRUE(entry->GetSSL().content_status &
|
| content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
|
| +
|
| + {
|
| + // Ensure the warning is still present when HTTPBad Phase 2 flag is enabled.
|
| + base::test::ScopedCommandLine scoped_command_line;
|
| + scoped_command_line.GetProcessCommandLine()->AppendSwitchASCII(
|
| + security_state::switches::kMarkHttpAs,
|
| + security_state::switches::kMarkHttpAsNonSecureWhileIncognito);
|
| +
|
| + helper->GetSecurityInfo(&security_info);
|
| + EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level);
|
| + }
|
| }
|
|
|
| // Tests that when a visible password field is detected on a blob URL, the
|
| @@ -1243,7 +1275,7 @@ IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, ConsoleMessage) {
|
| delegate->tab_strip_model()->ActivateTabAt(index, true);
|
| ASSERT_EQ(contents, delegate->tab_strip_model()->GetActiveWebContents());
|
|
|
| - // Navigate to an HTTP page. Use a non-local hostname so that is it
|
| + // Navigate to an HTTP page. Use a non-local hostname so that it is
|
| // not considered secure.
|
| GURL http_url =
|
| GetURLWithNonLocalHostname(embedded_test_server(), "/title1.html");
|
| @@ -1311,7 +1343,7 @@ IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
|
| delegate->tab_strip_model()->ActivateTabAt(index, true);
|
| ASSERT_EQ(contents, delegate->tab_strip_model()->GetActiveWebContents());
|
|
|
| - // Navigate to an HTTP page. Use a non-local hostname so that is it
|
| + // Navigate to an HTTP page. Use a non-local hostname so that it is
|
| // not considered secure.
|
| GURL http_url = GetURLWithNonLocalHostname(embedded_test_server(),
|
| "/ssl/page_with_frame.html");
|
| @@ -1352,6 +1384,7 @@ IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
|
| contents, "document.getElementById('navFrame').src = '/title2.html';"));
|
| subframe_observer.Wait();
|
| contents->OnCreditCardInputShownOnHttp();
|
| + helper->GetSecurityInfo(&security_info);
|
| EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level);
|
|
|
| // Do a main frame navigation and then trigger HTTP_SHOW_WARNING
|
| @@ -1392,7 +1425,7 @@ IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
|
| delegate->tab_strip_model()->ActivateTabAt(index, true);
|
| ASSERT_EQ(contents, delegate->tab_strip_model()->GetActiveWebContents());
|
|
|
| - // Navigate to an HTTP page. Use a non-local hostname so that is it
|
| + // Navigate to an HTTP page. Use a non-local hostname so that it is
|
| // not considered secure.
|
| GURL http_url =
|
| GetURLWithNonLocalHostname(embedded_test_server(), "/title1.html");
|
| @@ -1428,6 +1461,7 @@ IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
|
| EXPECT_TRUE(content::ExecuteScript(
|
| contents, "history.pushState({ foo: 'bar' }, 'foo', 'bar');"));
|
| contents->OnCreditCardInputShownOnHttp();
|
| + helper->GetSecurityInfo(&security_info);
|
| EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level);
|
|
|
| // Do a main frame navigation and then trigger HTTP_SHOW_WARNING
|
| @@ -1614,6 +1648,262 @@ IN_PROC_BROWSER_TEST_F(DidChangeVisibleSecurityStateTest,
|
| EXPECT_TRUE(observer.latest_explanations().summary.empty());
|
| }
|
|
|
| +// Tests that the security level of a HTTP page in Incognito mode is downgraded
|
| +// to HTTP_SHOW_WARNING when MarkHttpAsNonSecureWhileIncognito is enabled.
|
| +IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperIncognitoTest,
|
| + SecurityLevelDowngradedForHTTPInIncognito) {
|
| + // Set the mode using the command line flag rather than the field trial to
|
| + // ensure that fieldtrial_testing_config.json does not interfere.
|
| + base::test::ScopedCommandLine scoped_command_line;
|
| + scoped_command_line.GetProcessCommandLine()->AppendSwitchASCII(
|
| + security_state::switches::kMarkHttpAs,
|
| + security_state::switches::kMarkHttpAsNonSecureWhileIncognito);
|
| +
|
| + ConsoleWebContentsDelegate* delegate = new ConsoleWebContentsDelegate(
|
| + Browser::CreateParams(browser()->profile(), true));
|
| + content::WebContents* original_contents =
|
| + browser()->tab_strip_model()->GetActiveWebContents();
|
| + content::WebContents* contents =
|
| + content::WebContents::Create(content::WebContents::CreateParams(
|
| + original_contents->GetBrowserContext()));
|
| + ASSERT_TRUE(contents);
|
| + ASSERT_TRUE(contents->GetBrowserContext()->IsOffTheRecord());
|
| + contents->SetDelegate(delegate);
|
| + delegate->tab_strip_model()->AppendWebContents(contents, true);
|
| + int index = delegate->tab_strip_model()->GetIndexOfWebContents(contents);
|
| + delegate->tab_strip_model()->ActivateTabAt(index, true);
|
| + ASSERT_EQ(contents, delegate->tab_strip_model()->GetActiveWebContents());
|
| +
|
| + SecurityStyleTestObserver observer(contents);
|
| +
|
| + SecurityStateTabHelper* helper =
|
| + SecurityStateTabHelper::FromWebContents(contents);
|
| + ASSERT_TRUE(helper);
|
| +
|
| + // Navigate to an HTTP page. Use a non-local hostname so that it is
|
| + // not considered secure.
|
| + GURL http_url =
|
| + GetURLWithNonLocalHostname(embedded_test_server(), "/title1.html");
|
| + ui_test_utils::NavigateToURL(delegate, http_url);
|
| + content::NavigationEntry* entry = contents->GetController().GetVisibleEntry();
|
| + ASSERT_TRUE(entry);
|
| + EXPECT_EQ(http_url, entry->GetURL());
|
| +
|
| + security_state::SecurityInfo security_info;
|
| + helper->GetSecurityInfo(&security_info);
|
| + EXPECT_TRUE(security_info.incognito_downgraded_security_level);
|
| + EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level);
|
| + EXPECT_EQ(1u, observer.latest_explanations().neutral_explanations.size());
|
| + EXPECT_EQ(blink::kWebSecurityStyleNeutral, observer.latest_security_style());
|
| +
|
| + // Check that the expected console message is present.
|
| + ASSERT_NO_FATAL_FAILURE(CheckForOneHttpWarningConsoleMessage(delegate));
|
| +
|
| + // Ensure that same-page pushstate does not add another notice.
|
| + EXPECT_TRUE(content::ExecuteScript(
|
| + contents, "history.pushState({ foo: 'bar' }, 'foo', 'bar');"));
|
| + EXPECT_EQ(1u, observer.latest_explanations().neutral_explanations.size());
|
| + EXPECT_EQ(blink::kWebSecurityStyleNeutral, observer.latest_security_style());
|
| + // Check that no additional console message is present.
|
| + ASSERT_NO_FATAL_FAILURE(CheckForOneHttpWarningConsoleMessage(delegate));
|
| +}
|
| +
|
| +// Tests that additional HTTP_SHOW_WARNING console messages are not
|
| +// printed after aborted navigations.
|
| +IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperIncognitoTest,
|
| + ConsoleMessageNotPrintedForAbortedNavigation) {
|
| + // Set the mode using the command line flag rather than the field trial to
|
| + // ensure that fieldtrial_testing_config.json does not interfere.
|
| + base::test::ScopedCommandLine scoped_command_line;
|
| + scoped_command_line.GetProcessCommandLine()->AppendSwitchASCII(
|
| + security_state::switches::kMarkHttpAs,
|
| + security_state::switches::kMarkHttpAsNonSecureWhileIncognito);
|
| +
|
| + ConsoleWebContentsDelegate* delegate = new ConsoleWebContentsDelegate(
|
| + Browser::CreateParams(browser()->profile(), true));
|
| + content::WebContents* original_contents =
|
| + browser()->tab_strip_model()->GetActiveWebContents();
|
| + content::WebContents* contents =
|
| + content::WebContents::Create(content::WebContents::CreateParams(
|
| + original_contents->GetBrowserContext()));
|
| + ASSERT_TRUE(contents);
|
| + ASSERT_TRUE(contents->GetBrowserContext()->IsOffTheRecord());
|
| + contents->SetDelegate(delegate);
|
| + delegate->tab_strip_model()->AppendWebContents(contents, true);
|
| + int index = delegate->tab_strip_model()->GetIndexOfWebContents(contents);
|
| + delegate->tab_strip_model()->ActivateTabAt(index, true);
|
| + ASSERT_EQ(contents, delegate->tab_strip_model()->GetActiveWebContents());
|
| +
|
| + SecurityStyleTestObserver observer(contents);
|
| +
|
| + SecurityStateTabHelper* helper =
|
| + SecurityStateTabHelper::FromWebContents(contents);
|
| + ASSERT_TRUE(helper);
|
| +
|
| + // Navigate to an HTTP page. Use a non-local hostname so that it is
|
| + // not considered secure.
|
| + GURL http_url =
|
| + GetURLWithNonLocalHostname(embedded_test_server(), "/title1.html");
|
| + ui_test_utils::NavigateToURL(delegate, http_url);
|
| +
|
| + security_state::SecurityInfo security_info;
|
| + helper->GetSecurityInfo(&security_info);
|
| + EXPECT_TRUE(security_info.incognito_downgraded_security_level);
|
| + EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level);
|
| + EXPECT_EQ(blink::kWebSecurityStyleNeutral, observer.latest_security_style());
|
| + EXPECT_EQ(1u, observer.latest_explanations().neutral_explanations.size());
|
| +
|
| + // Check that the expected console message is present.
|
| + ASSERT_NO_FATAL_FAILURE(CheckForOneHttpWarningConsoleMessage(delegate));
|
| + delegate->ClearConsoleMessages();
|
| +
|
| + // Perform a navigation that does not commit.
|
| + // The embedded test server returns a HTTP/204 only for local URLs, so
|
| + // we cannot use GetURLWithNonLocalHostname() here.
|
| + GURL http204_url = embedded_test_server()->GetURL("/nocontent");
|
| + ui_test_utils::NavigateToURL(delegate, http204_url);
|
| +
|
| + // No change is expected in the security state.
|
| + EXPECT_TRUE(security_info.incognito_downgraded_security_level);
|
| + EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level);
|
| + EXPECT_EQ(blink::kWebSecurityStyleNeutral, observer.latest_security_style());
|
| + EXPECT_EQ(1u, observer.latest_explanations().neutral_explanations.size());
|
| +
|
| + // No additional console logging should occur.
|
| + EXPECT_TRUE(delegate->console_messages().empty());
|
| +}
|
| +
|
| +// Tests that the security level of a HTTP page in Guest mode is not downgraded
|
| +// to HTTP_SHOW_WARNING when MarkHttpAsNonSecureWhileIncognito is enabled.
|
| +#if defined(OS_CHROMEOS)
|
| +// Guest mode cannot be readily browser-tested on ChromeOS.
|
| +#define MAYBE_SecurityLevelNotDowngradedForHTTPInGuestMode \
|
| + DISABLED_SecurityLevelNotDowngradedForHTTPInGuestMode
|
| +#else
|
| +#define MAYBE_SecurityLevelNotDowngradedForHTTPInGuestMode \
|
| + SecurityLevelNotDowngradedForHTTPInGuestMode
|
| +#endif
|
| +IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
|
| + MAYBE_SecurityLevelNotDowngradedForHTTPInGuestMode) {
|
| + base::test::ScopedCommandLine scoped_command_line;
|
| + scoped_command_line.GetProcessCommandLine()->AppendSwitchASCII(
|
| + security_state::switches::kMarkHttpAs,
|
| + security_state::switches::kMarkHttpAsNonSecureWhileIncognito);
|
| +
|
| + // Create a new browser in Guest Mode.
|
| + EXPECT_EQ(1U, BrowserList::GetInstance()->size());
|
| + content::WindowedNotificationObserver browser_creation_observer(
|
| + chrome::NOTIFICATION_BROWSER_WINDOW_READY,
|
| + content::NotificationService::AllSources());
|
| + profiles::SwitchToGuestProfile(ProfileManager::CreateCallback());
|
| + browser_creation_observer.Wait();
|
| + EXPECT_EQ(2U, BrowserList::GetInstance()->size());
|
| + Profile* guest = g_browser_process->profile_manager()->GetProfileByPath(
|
| + ProfileManager::GetGuestProfilePath());
|
| + Browser* guest_browser = chrome::FindAnyBrowser(guest, true);
|
| + ASSERT_TRUE(guest_browser);
|
| +
|
| + ConsoleWebContentsDelegate* delegate = new ConsoleWebContentsDelegate(
|
| + Browser::CreateParams(guest_browser->profile(), true));
|
| + content::WebContents* original_contents =
|
| + guest_browser->tab_strip_model()->GetActiveWebContents();
|
| + content::WebContents* contents =
|
| + content::WebContents::Create(content::WebContents::CreateParams(
|
| + original_contents->GetBrowserContext()));
|
| + ASSERT_TRUE(contents);
|
| + ASSERT_TRUE(contents->GetBrowserContext()->IsOffTheRecord());
|
| + contents->SetDelegate(delegate);
|
| + delegate->tab_strip_model()->AppendWebContents(contents, true);
|
| + int index = delegate->tab_strip_model()->GetIndexOfWebContents(contents);
|
| + delegate->tab_strip_model()->ActivateTabAt(index, true);
|
| + ASSERT_EQ(contents, delegate->tab_strip_model()->GetActiveWebContents());
|
| +
|
| + SecurityStyleTestObserver observer(contents);
|
| +
|
| + SecurityStateTabHelper* helper =
|
| + SecurityStateTabHelper::FromWebContents(contents);
|
| + ASSERT_TRUE(helper);
|
| +
|
| + // Navigate to an HTTP page. Use a non-local hostname so that it is
|
| + // not considered secure.
|
| + GURL http_url =
|
| + GetURLWithNonLocalHostname(embedded_test_server(), "/title1.html");
|
| + ui_test_utils::NavigateToURL(delegate, http_url);
|
| +
|
| + security_state::SecurityInfo security_info;
|
| + helper->GetSecurityInfo(&security_info);
|
| + EXPECT_FALSE(security_info.incognito_downgraded_security_level);
|
| + EXPECT_EQ(security_state::NONE, security_info.security_level);
|
| + EXPECT_EQ(0u, observer.latest_explanations().neutral_explanations.size());
|
| + EXPECT_EQ(blink::kWebSecurityStyleNeutral, observer.latest_security_style());
|
| +
|
| + // No console notification should occur.
|
| + EXPECT_TRUE(delegate->console_messages().empty());
|
| +}
|
| +
|
| +// Tests that the security level of a HTTP page is NEUTRAL when MarkHttpAs is
|
| +// not set.
|
| +IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperIncognitoTest,
|
| + SecurityLevelNeutralByDefaultForHTTP) {
|
| + content::WebContents* contents =
|
| + browser()->tab_strip_model()->GetActiveWebContents();
|
| + ASSERT_TRUE(contents);
|
| +
|
| + ASSERT_TRUE(contents->GetBrowserContext()->IsOffTheRecord());
|
| +
|
| + SecurityStyleTestObserver observer(contents);
|
| +
|
| + SecurityStateTabHelper* helper =
|
| + SecurityStateTabHelper::FromWebContents(contents);
|
| + ASSERT_TRUE(helper);
|
| +
|
| + // Navigate to an HTTP page. Use a non-local hostname so that it is
|
| + // not considered secure.
|
| + GURL http_url =
|
| + GetURLWithNonLocalHostname(embedded_test_server(), "/title1.html");
|
| + ui_test_utils::NavigateToURL(browser(), http_url);
|
| +
|
| + security_state::SecurityInfo security_info;
|
| + helper->GetSecurityInfo(&security_info);
|
| + EXPECT_FALSE(security_info.incognito_downgraded_security_level);
|
| + EXPECT_EQ(security_state::NONE, security_info.security_level);
|
| + EXPECT_EQ(0u, observer.latest_explanations().neutral_explanations.size());
|
| + EXPECT_EQ(blink::kWebSecurityStyleNeutral, observer.latest_security_style());
|
| +}
|
| +
|
| +// Tests that the security level of a HTTP page is downgraded to DANGEROUS when
|
| +// MarkHttpAsDangerous is enabled.
|
| +IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperIncognitoTest,
|
| + SecurityLevelDangerousWhenMarkHttpAsDangerous) {
|
| + base::test::ScopedCommandLine scoped_command_line;
|
| + scoped_command_line.GetProcessCommandLine()->AppendSwitchASCII(
|
| + security_state::switches::kMarkHttpAs,
|
| + security_state::switches::kMarkHttpAsDangerous);
|
| +
|
| + content::WebContents* contents =
|
| + browser()->tab_strip_model()->GetActiveWebContents();
|
| + ASSERT_TRUE(contents);
|
| + ASSERT_TRUE(contents->GetBrowserContext()->IsOffTheRecord());
|
| +
|
| + SecurityStyleTestObserver observer(contents);
|
| +
|
| + SecurityStateTabHelper* helper =
|
| + SecurityStateTabHelper::FromWebContents(contents);
|
| + ASSERT_TRUE(helper);
|
| +
|
| + // Navigate to an HTTP page. Use a non-local hostname so that it is
|
| + // not considered secure.
|
| + GURL http_url =
|
| + GetURLWithNonLocalHostname(embedded_test_server(), "/title1.html");
|
| + ui_test_utils::NavigateToURL(browser(), http_url);
|
| +
|
| + security_state::SecurityInfo security_info;
|
| + helper->GetSecurityInfo(&security_info);
|
| + EXPECT_FALSE(security_info.incognito_downgraded_security_level);
|
| + EXPECT_EQ(security_state::DANGEROUS, security_info.security_level);
|
| + EXPECT_EQ(blink::kWebSecurityStyleInsecure, observer.latest_security_style());
|
| +}
|
| +
|
| // Visit a valid HTTPS page, then a broken HTTPS page, and then go back,
|
| // and test that the observed security style matches.
|
| #if defined(OS_CHROMEOS)
|
|
|