Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: chrome/browser/ssl/security_state_tab_helper_browser_tests.cc

Issue 2917873004: Implement 'Not secure' warning for non-secure pages in Incognito mode (Closed)
Patch Set: Fix Guest mode test Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/ssl/security_state_tab_helper.h" 5 #include "chrome/browser/ssl/security_state_tab_helper.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/test/scoped_command_line.h"
12 #include "base/threading/sequenced_worker_pool.h" 13 #include "base/threading/sequenced_worker_pool.h"
14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/profiles/profile_window.h"
17 #include "chrome/browser/search_engines/template_url_service_factory.h"
13 #include "chrome/browser/ssl/cert_verifier_browser_test.h" 18 #include "chrome/browser/ssl/cert_verifier_browser_test.h"
14 #include "chrome/browser/ssl/ssl_blocking_page.h" 19 #include "chrome/browser/ssl/ssl_blocking_page.h"
15 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_commands.h" 21 #include "chrome/browser/ui/browser_commands.h"
22 #include "chrome/browser/ui/browser_finder.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" 23 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/common/chrome_paths.h" 24 #include "chrome/common/chrome_paths.h"
19 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
21 #include "chrome/test/base/in_process_browser_test.h" 27 #include "chrome/test/base/in_process_browser_test.h"
22 #include "chrome/test/base/ui_test_utils.h" 28 #include "chrome/test/base/ui_test_utils.h"
23 #include "components/prefs/pref_service.h" 29 #include "components/prefs/pref_service.h"
24 #include "components/security_state/core/security_state.h" 30 #include "components/security_state/core/security_state.h"
25 #include "components/security_state/core/switches.h" 31 #include "components/security_state/core/switches.h"
26 #include "components/strings/grit/components_strings.h" 32 #include "components/strings/grit/components_strings.h"
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); 371 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
366 } 372 }
367 } 373 }
368 374
369 net::EmbeddedTestServer https_server_; 375 net::EmbeddedTestServer https_server_;
370 376
371 private: 377 private:
372 DISALLOW_COPY_AND_ASSIGN(SecurityStateTabHelperTest); 378 DISALLOW_COPY_AND_ASSIGN(SecurityStateTabHelperTest);
373 }; 379 };
374 380
381 // Same as SecurityStateTabHelperTest, but with Incognito enabled.
382 class SecurityStateTabHelperIncognitoTest : public SecurityStateTabHelperTest {
383 public:
384 SecurityStateTabHelperIncognitoTest() : SecurityStateTabHelperTest() {}
385
386 void SetUpCommandLine(base::CommandLine* command_line) override {
387 SecurityStateTabHelperTest::SetUpCommandLine(command_line);
388 // Test should run Incognito.
389 command_line->AppendSwitch(switches::kIncognito);
390 }
391
392 private:
393 DISALLOW_COPY_AND_ASSIGN(SecurityStateTabHelperIncognitoTest);
394 };
395
375 class DidChangeVisibleSecurityStateTest : public InProcessBrowserTest { 396 class DidChangeVisibleSecurityStateTest : public InProcessBrowserTest {
376 public: 397 public:
377 DidChangeVisibleSecurityStateTest() 398 DidChangeVisibleSecurityStateTest()
378 : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) { 399 : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {
379 https_server_.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot)); 400 https_server_.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot));
380 } 401 }
381 402
382 void SetUpCommandLine(base::CommandLine* command_line) override { 403 void SetUpCommandLine(base::CommandLine* command_line) override {
383 // Browser will both run and display insecure content. 404 // Browser will both run and display insecure content.
384 command_line->AppendSwitch(switches::kAllowRunningInsecureContent); 405 command_line->AppendSwitch(switches::kAllowRunningInsecureContent);
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 protected: 947 protected:
927 void SetUpOnMainThread() override { 948 void SetUpOnMainThread() override {
928 ASSERT_TRUE(embedded_test_server()->Start()); 949 ASSERT_TRUE(embedded_test_server()->Start());
929 950
930 content::BrowserThread::PostTask( 951 content::BrowserThread::PostTask(
931 content::BrowserThread::IO, FROM_HERE, 952 content::BrowserThread::IO, FROM_HERE,
932 base::Bind(&InstallLoadingInterceptor, 953 base::Bind(&InstallLoadingInterceptor,
933 embedded_test_server()->GetURL("/title1.html").host())); 954 embedded_test_server()->GetURL("/title1.html").host()));
934 } 955 }
935 956
957 private:
936 DISALLOW_COPY_AND_ASSIGN(SecurityStateLoadingTest); 958 DISALLOW_COPY_AND_ASSIGN(SecurityStateLoadingTest);
937 }; 959 };
938 960
939 // Tests that navigation state changes cause the security state to be 961 // Tests that navigation state changes cause the security state to be
940 // updated. 962 // updated.
941 IN_PROC_BROWSER_TEST_F(SecurityStateLoadingTest, NavigationStateChanges) { 963 IN_PROC_BROWSER_TEST_F(SecurityStateLoadingTest, NavigationStateChanges) {
942 ASSERT_TRUE(https_server_.Start()); 964 ASSERT_TRUE(https_server_.Start());
943 SetUpMockCertVerifierForHttpsServer(0, net::OK); 965 SetUpMockCertVerifierForHttpsServer(0, net::OK);
944 966
945 // Navigate to an HTTPS page. 967 // Navigate to an HTTPS page.
(...skipping 30 matching lines...) Expand all
976 "/password/simple_password.html")); 998 "/password/simple_password.html"));
977 InjectScript(contents); 999 InjectScript(contents);
978 security_state::SecurityInfo security_info; 1000 security_state::SecurityInfo security_info;
979 helper->GetSecurityInfo(&security_info); 1001 helper->GetSecurityInfo(&security_info);
980 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level); 1002 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level);
981 1003
982 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry(); 1004 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry();
983 ASSERT_TRUE(entry); 1005 ASSERT_TRUE(entry);
984 EXPECT_TRUE(entry->GetSSL().content_status & 1006 EXPECT_TRUE(entry->GetSSL().content_status &
985 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); 1007 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
1008
1009 {
1010 // Ensure the warning is still present when HTTPBad Phase 2 flag is enabled.
1011 base::test::ScopedCommandLine scoped_command_line;
1012 scoped_command_line.GetProcessCommandLine()->AppendSwitchASCII(
1013 security_state::switches::kMarkHttpAs,
1014 security_state::switches::kMarkHttpAsNonSecureWhileIncognito);
1015
1016 helper->GetSecurityInfo(&security_info);
1017 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level);
1018 }
986 } 1019 }
987 1020
988 // Tests that when a visible password field is detected on a blob URL, the 1021 // Tests that when a visible password field is detected on a blob URL, the
989 // security level is downgraded to HTTP_SHOW_WARNING. 1022 // security level is downgraded to HTTP_SHOW_WARNING.
990 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, 1023 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
991 PasswordSecurityLevelDowngradedOnBlobUrl) { 1024 PasswordSecurityLevelDowngradedOnBlobUrl) {
992 TestPasswordFieldOnBlobOrFilesystemURL( 1025 TestPasswordFieldOnBlobOrFilesystemURL(
993 "blob", 1026 "blob",
994 "var blob = new Blob(['<html><form><input type=password></form></html>']," 1027 "var blob = new Blob(['<html><form><input type=password></form></html>'],"
995 " {type: 'text/html'});" 1028 " {type: 'text/html'});"
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 // already a console message logged for the current main-frame 1378 // already a console message logged for the current main-frame
1346 // navigation. 1379 // navigation.
1347 content::WindowedNotificationObserver subframe_observer( 1380 content::WindowedNotificationObserver subframe_observer(
1348 content::NOTIFICATION_LOAD_STOP, 1381 content::NOTIFICATION_LOAD_STOP,
1349 content::Source<content::NavigationController>( 1382 content::Source<content::NavigationController>(
1350 &contents->GetController())); 1383 &contents->GetController()));
1351 EXPECT_TRUE(content::ExecuteScript( 1384 EXPECT_TRUE(content::ExecuteScript(
1352 contents, "document.getElementById('navFrame').src = '/title2.html';")); 1385 contents, "document.getElementById('navFrame').src = '/title2.html';"));
1353 subframe_observer.Wait(); 1386 subframe_observer.Wait();
1354 contents->OnCreditCardInputShownOnHttp(); 1387 contents->OnCreditCardInputShownOnHttp();
1388 helper->GetSecurityInfo(&security_info);
1355 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level); 1389 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level);
1356 1390
1357 // Do a main frame navigation and then trigger HTTP_SHOW_WARNING 1391 // Do a main frame navigation and then trigger HTTP_SHOW_WARNING
1358 // again. From the above subframe navigation and this main-frame 1392 // again. From the above subframe navigation and this main-frame
1359 // navigation, exactly one console message is expected. 1393 // navigation, exactly one console message is expected.
1360 GURL second_http_url = 1394 GURL second_http_url =
1361 GetURLWithNonLocalHostname(embedded_test_server(), "/title2.html"); 1395 GetURLWithNonLocalHostname(embedded_test_server(), "/title2.html");
1362 ui_test_utils::NavigateToURL(delegate, second_http_url); 1396 ui_test_utils::NavigateToURL(delegate, second_http_url);
1363 entry = contents->GetController().GetVisibleEntry(); 1397 entry = contents->GetController().GetVisibleEntry();
1364 ASSERT_TRUE(entry); 1398 ASSERT_TRUE(entry);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 delegate->ClearConsoleMessages(); 1455 delegate->ClearConsoleMessages();
1422 1456
1423 // Navigate with pushState and trigger VisibleSecurityStateChanged 1457 // Navigate with pushState and trigger VisibleSecurityStateChanged
1424 // again. While the security level is still HTTP_SHOW_WARNING, an 1458 // again. While the security level is still HTTP_SHOW_WARNING, an
1425 // additional console message should not be logged because there was 1459 // additional console message should not be logged because there was
1426 // already a console message logged for the current main-frame 1460 // already a console message logged for the current main-frame
1427 // navigation. 1461 // navigation.
1428 EXPECT_TRUE(content::ExecuteScript( 1462 EXPECT_TRUE(content::ExecuteScript(
1429 contents, "history.pushState({ foo: 'bar' }, 'foo', 'bar');")); 1463 contents, "history.pushState({ foo: 'bar' }, 'foo', 'bar');"));
1430 contents->OnCreditCardInputShownOnHttp(); 1464 contents->OnCreditCardInputShownOnHttp();
1465 helper->GetSecurityInfo(&security_info);
1431 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level); 1466 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level);
1432 1467
1433 // Do a main frame navigation and then trigger HTTP_SHOW_WARNING 1468 // Do a main frame navigation and then trigger HTTP_SHOW_WARNING
1434 // again. From the above pushState navigation and this main-frame 1469 // again. From the above pushState navigation and this main-frame
1435 // navigation, exactly one console message is expected. 1470 // navigation, exactly one console message is expected.
1436 GURL second_http_url = 1471 GURL second_http_url =
1437 GetURLWithNonLocalHostname(embedded_test_server(), "/title2.html"); 1472 GetURLWithNonLocalHostname(embedded_test_server(), "/title2.html");
1438 ui_test_utils::NavigateToURL(delegate, second_http_url); 1473 ui_test_utils::NavigateToURL(delegate, second_http_url);
1439 entry = contents->GetController().GetVisibleEntry(); 1474 entry = contents->GetController().GetVisibleEntry();
1440 ASSERT_TRUE(entry); 1475 ASSERT_TRUE(entry);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
1607 INVALID_CERTIFICATE, browser(), 1642 INVALID_CERTIFICATE, browser(),
1608 https_test_server_expired.GetCertificate().get()); 1643 https_test_server_expired.GetCertificate().get());
1609 EXPECT_TRUE(observer.latest_explanations().scheme_is_cryptographic); 1644 EXPECT_TRUE(observer.latest_explanations().scheme_is_cryptographic);
1610 EXPECT_FALSE(observer.latest_explanations().pkp_bypassed); 1645 EXPECT_FALSE(observer.latest_explanations().pkp_bypassed);
1611 EXPECT_TRUE(observer.latest_explanations().info_explanations.empty()); 1646 EXPECT_TRUE(observer.latest_explanations().info_explanations.empty());
1612 EXPECT_FALSE(observer.latest_explanations().displayed_mixed_content); 1647 EXPECT_FALSE(observer.latest_explanations().displayed_mixed_content);
1613 EXPECT_FALSE(observer.latest_explanations().ran_mixed_content); 1648 EXPECT_FALSE(observer.latest_explanations().ran_mixed_content);
1614 EXPECT_TRUE(observer.latest_explanations().summary.empty()); 1649 EXPECT_TRUE(observer.latest_explanations().summary.empty());
1615 } 1650 }
1616 1651
1652 // Tests that the security level of a HTTP page in Incognito mode is downgraded
1653 // to HTTP_SHOW_WARNING when MarkHttpAsNonSecureWhileIncognito is enabled.
1654 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperIncognitoTest,
1655 SecurityLevelDowngradedForHTTPInIncognito) {
1656 // Set the mode using the command line flag rather than the field trial to
1657 // ensure that fieldtrial_testing_config.json does not interfere.
1658 base::test::ScopedCommandLine scoped_command_line;
1659 scoped_command_line.GetProcessCommandLine()->AppendSwitchASCII(
1660 security_state::switches::kMarkHttpAs,
1661 security_state::switches::kMarkHttpAsNonSecureWhileIncognito);
1662
1663 ConsoleWebContentsDelegate* delegate = new ConsoleWebContentsDelegate(
1664 Browser::CreateParams(browser()->profile(), true));
1665 content::WebContents* original_contents =
1666 browser()->tab_strip_model()->GetActiveWebContents();
1667 content::WebContents* contents =
1668 content::WebContents::Create(content::WebContents::CreateParams(
1669 original_contents->GetBrowserContext()));
1670 ASSERT_TRUE(contents);
1671 ASSERT_TRUE(contents->GetBrowserContext()->IsOffTheRecord());
1672 contents->SetDelegate(delegate);
1673 delegate->tab_strip_model()->AppendWebContents(contents, true);
1674 int index = delegate->tab_strip_model()->GetIndexOfWebContents(contents);
1675 delegate->tab_strip_model()->ActivateTabAt(index, true);
1676 ASSERT_EQ(contents, delegate->tab_strip_model()->GetActiveWebContents());
1677
1678 SecurityStyleTestObserver observer(contents);
1679
1680 SecurityStateTabHelper* helper =
1681 SecurityStateTabHelper::FromWebContents(contents);
1682 ASSERT_TRUE(helper);
1683
1684 // Navigate to an HTTP page. Use a non-local hostname so that is it
1685 // not considered secure.
1686 GURL http_url =
1687 GetURLWithNonLocalHostname(embedded_test_server(), "/title1.html");
1688 ui_test_utils::NavigateToURL(delegate, http_url);
1689 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry();
1690 ASSERT_TRUE(entry);
1691 EXPECT_EQ(http_url, entry->GetURL());
1692
1693 security_state::SecurityInfo security_info;
1694 helper->GetSecurityInfo(&security_info);
1695 EXPECT_TRUE(security_info.is_incognito);
1696 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level);
1697 EXPECT_EQ(1u, observer.latest_explanations().neutral_explanations.size());
1698 EXPECT_EQ(blink::kWebSecurityStyleNeutral, observer.latest_security_style());
1699
1700 // Check that the expected console message is present.
1701 ASSERT_NO_FATAL_FAILURE(CheckForOneHttpWarningConsoleMessage(delegate));
1702
1703 // Ensure that same-page pushstate does not add another notice.
1704 EXPECT_TRUE(content::ExecuteScript(
1705 contents, "history.pushState({ foo: 'bar' }, 'foo', 'bar');"));
1706 EXPECT_EQ(1u, observer.latest_explanations().neutral_explanations.size());
1707 EXPECT_EQ(blink::kWebSecurityStyleNeutral, observer.latest_security_style());
1708 // Check that the expected console message is present.
estark 2017/06/13 22:47:11 nit: "Check that no additional console message is
elawrence 2017/06/14 17:01:39 Done.
1709 ASSERT_NO_FATAL_FAILURE(CheckForOneHttpWarningConsoleMessage(delegate));
1710 }
1711
1712 // Tests that additional HTTP_SHOW_WARNING console messages are not
1713 // printed after aborted navigations.
1714 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperIncognitoTest,
1715 ConsoleMessageNotPrintedForAbortedNavigation) {
1716 // Set the mode using the command line flag rather than the field trial to
1717 // ensure that fieldtrial_testing_config.json does not interfere.
1718 base::test::ScopedCommandLine scoped_command_line;
1719 scoped_command_line.GetProcessCommandLine()->AppendSwitchASCII(
1720 security_state::switches::kMarkHttpAs,
1721 security_state::switches::kMarkHttpAsNonSecureWhileIncognito);
1722
1723 ConsoleWebContentsDelegate* delegate = new ConsoleWebContentsDelegate(
1724 Browser::CreateParams(browser()->profile(), true));
1725 content::WebContents* original_contents =
1726 browser()->tab_strip_model()->GetActiveWebContents();
1727 content::WebContents* contents =
1728 content::WebContents::Create(content::WebContents::CreateParams(
1729 original_contents->GetBrowserContext()));
1730 ASSERT_TRUE(contents);
1731 ASSERT_TRUE(contents->GetBrowserContext()->IsOffTheRecord());
1732 contents->SetDelegate(delegate);
1733 delegate->tab_strip_model()->AppendWebContents(contents, true);
1734 int index = delegate->tab_strip_model()->GetIndexOfWebContents(contents);
1735 delegate->tab_strip_model()->ActivateTabAt(index, true);
1736 ASSERT_EQ(contents, delegate->tab_strip_model()->GetActiveWebContents());
1737
1738 SecurityStyleTestObserver observer(contents);
1739
1740 SecurityStateTabHelper* helper =
1741 SecurityStateTabHelper::FromWebContents(contents);
1742 ASSERT_TRUE(helper);
1743
1744 // Navigate to an HTTP page. Use a non-local hostname so that is it
1745 // not considered secure.
1746 GURL http_url =
1747 GetURLWithNonLocalHostname(embedded_test_server(), "/title1.html");
1748 ui_test_utils::NavigateToURL(delegate, http_url);
1749
1750 security_state::SecurityInfo security_info;
1751 helper->GetSecurityInfo(&security_info);
1752 EXPECT_TRUE(security_info.is_incognito);
1753 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level);
1754 EXPECT_EQ(blink::kWebSecurityStyleNeutral, observer.latest_security_style());
1755 EXPECT_EQ(1u, observer.latest_explanations().neutral_explanations.size());
1756
1757 // Check that the expected console message is present.
1758 ASSERT_NO_FATAL_FAILURE(CheckForOneHttpWarningConsoleMessage(delegate));
1759 delegate->ClearConsoleMessages();
1760
1761 // Perform a navigation that does not commit.
1762 // The embedded test server returns a HTTP/204 only for local URLs, so
1763 // we cannot use GetURLWithNonLocalHostname() here.
1764 GURL http204_url = embedded_test_server()->GetURL("/nocontent");
1765 ui_test_utils::NavigateToURL(delegate, http204_url);
1766
1767 // No change is expected in the security state.
1768 EXPECT_TRUE(security_info.is_incognito);
1769 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level);
1770 EXPECT_EQ(blink::kWebSecurityStyleNeutral, observer.latest_security_style());
1771 EXPECT_EQ(1u, observer.latest_explanations().neutral_explanations.size());
1772
1773 // No additional console logging should occur.
1774 EXPECT_TRUE(delegate->console_messages().empty());
1775 }
1776
1777 // Tests that the security level of a HTTP page in Guest mode is not downgraded
1778 // to HTTP_SHOW_WARNING when MarkHttpAsNonSecureWhileIncognito is enabled.
1779 #if defined(OS_CHROMEOS)
1780 // Guest mode cannot be readily browser-tested on ChromeOS.
estark 2017/06/13 22:47:11 Optional nit: Is there a bug or some other kind of
elawrence 2017/06/14 17:01:38 I'll try to find something better than https://www
1781 #define MAYBE_SecurityLevelNotDowngradedForHTTPInGuestMode \
1782 DISABLED_SecurityLevelNotDowngradedForHTTPInGuestMode
1783 #else
1784 #define MAYBE_SecurityLevelNotDowngradedForHTTPInGuestMode \
1785 SecurityLevelNotDowngradedForHTTPInGuestMode
1786 #endif
1787 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
1788 MAYBE_SecurityLevelNotDowngradedForHTTPInGuestMode) {
1789 base::test::ScopedCommandLine scoped_command_line;
1790 scoped_command_line.GetProcessCommandLine()->AppendSwitchASCII(
1791 security_state::switches::kMarkHttpAs,
1792 security_state::switches::kMarkHttpAsNonSecureWhileIncognito);
1793
1794 // Create a new browser in Guest Mode.
1795 EXPECT_EQ(1U, BrowserList::GetInstance()->size());
1796 content::WindowedNotificationObserver browser_creation_observer(
1797 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
1798 content::NotificationService::AllSources());
1799 profiles::SwitchToGuestProfile(ProfileManager::CreateCallback());
1800 base::RunLoop().RunUntilIdle();
estark 2017/06/13 22:47:11 Is this necessary? ProfileWindowBrowserTest::OpenG
elawrence 2017/06/14 17:01:39 Removed. It doesn't appear to be necessary, althou
1801 browser_creation_observer.Wait();
1802 EXPECT_EQ(2U, BrowserList::GetInstance()->size());
1803 Profile* guest = g_browser_process->profile_manager()->GetProfileByPath(
1804 ProfileManager::GetGuestProfilePath());
1805 Browser* guest_browser = chrome::FindAnyBrowser(guest, true);
1806 EXPECT_TRUE(guest_browser);
estark 2017/06/13 22:47:11 nit: ASSERT_TRUE to abort the test if false (other
elawrence 2017/06/14 17:01:38 Gah, fixed. That'll teach me to copy/paste out of
1807
1808 ConsoleWebContentsDelegate* delegate = new ConsoleWebContentsDelegate(
1809 Browser::CreateParams(guest_browser->profile(), true));
1810 content::WebContents* original_contents =
1811 guest_browser->tab_strip_model()->GetActiveWebContents();
1812 content::WebContents* contents =
1813 content::WebContents::Create(content::WebContents::CreateParams(
1814 original_contents->GetBrowserContext()));
1815 ASSERT_TRUE(contents);
1816 ASSERT_TRUE(contents->GetBrowserContext()->IsOffTheRecord());
1817 contents->SetDelegate(delegate);
1818 delegate->tab_strip_model()->AppendWebContents(contents, true);
1819 int index = delegate->tab_strip_model()->GetIndexOfWebContents(contents);
1820 delegate->tab_strip_model()->ActivateTabAt(index, true);
1821 ASSERT_EQ(contents, delegate->tab_strip_model()->GetActiveWebContents());
1822
1823 SecurityStyleTestObserver observer(contents);
1824
1825 SecurityStateTabHelper* helper =
1826 SecurityStateTabHelper::FromWebContents(contents);
1827 ASSERT_TRUE(helper);
1828
1829 // Navigate to an HTTP page. Use a non-local hostname so that is it
estark 2017/06/13 22:47:11 nit: is it => it is
elawrence 2017/06/14 17:01:39 Fxied.
1830 // not considered secure.
1831 GURL http_url =
1832 GetURLWithNonLocalHostname(embedded_test_server(), "/title1.html");
1833 ui_test_utils::NavigateToURL(delegate, http_url);
1834
1835 security_state::SecurityInfo security_info;
1836 helper->GetSecurityInfo(&security_info);
1837 EXPECT_FALSE(security_info.is_incognito);
1838 EXPECT_EQ(security_state::NONE, security_info.security_level);
1839 EXPECT_EQ(0u, observer.latest_explanations().neutral_explanations.size());
1840 EXPECT_EQ(blink::kWebSecurityStyleNeutral, observer.latest_security_style());
1841
1842 // Ensure that same-page pushstate does not add a notice.
1843 EXPECT_TRUE(content::ExecuteScript(
estark 2017/06/13 22:47:11 I think you could probably cut out this part of th
elawrence 2017/06/14 17:01:38 Done.
1844 contents, "history.pushState({ foo: 'bar' }, 'foo', 'bar');"));
1845 helper->GetSecurityInfo(&security_info);
1846 EXPECT_FALSE(security_info.is_incognito);
1847 EXPECT_EQ(security_state::NONE, security_info.security_level);
1848 EXPECT_EQ(0u, observer.latest_explanations().neutral_explanations.size());
1849 EXPECT_EQ(blink::kWebSecurityStyleNeutral, observer.latest_security_style());
1850
1851 // No console notification should occur.
1852 EXPECT_TRUE(delegate->console_messages().empty());
1853 }
1854
1855 // Tests that the security level of a HTTP page is NEUTRAL when MarkHttpAs is
1856 // not set.
1857 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperIncognitoTest,
1858 SecurityLevelNeutralByDefaultForHTTP) {
1859 content::WebContents* contents =
1860 browser()->tab_strip_model()->GetActiveWebContents();
1861 ASSERT_TRUE(contents);
1862
1863 ASSERT_TRUE(contents->GetBrowserContext()->IsOffTheRecord());
1864
1865 SecurityStyleTestObserver observer(contents);
1866
1867 SecurityStateTabHelper* helper =
1868 SecurityStateTabHelper::FromWebContents(contents);
1869 ASSERT_TRUE(helper);
1870
1871 // Navigate to an HTTP page. Use a non-local hostname so that is it
1872 // not considered secure.
1873 GURL http_url =
1874 GetURLWithNonLocalHostname(embedded_test_server(), "/title1.html");
1875 ui_test_utils::NavigateToURL(browser(), http_url);
1876
1877 security_state::SecurityInfo security_info;
1878 helper->GetSecurityInfo(&security_info);
1879 EXPECT_TRUE(security_info.is_incognito);
1880 EXPECT_EQ(security_state::NONE, security_info.security_level);
1881 EXPECT_EQ(0u, observer.latest_explanations().neutral_explanations.size());
1882 EXPECT_EQ(blink::kWebSecurityStyleNeutral, observer.latest_security_style());
1883 }
1884
1885 // Tests that the security level of a HTTP page is downgraded to DANGEROUS when
1886 // MarkHttpAsDangerous is enabled.
1887 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperIncognitoTest,
1888 SecurityLevelDangerousWhenMarkHttpAsDangerous) {
1889 base::test::ScopedCommandLine scoped_command_line;
1890 scoped_command_line.GetProcessCommandLine()->AppendSwitchASCII(
1891 security_state::switches::kMarkHttpAs,
1892 security_state::switches::kMarkHttpAsDangerous);
1893
1894 content::WebContents* contents =
1895 browser()->tab_strip_model()->GetActiveWebContents();
1896 ASSERT_TRUE(contents);
1897 ASSERT_TRUE(contents->GetBrowserContext()->IsOffTheRecord());
1898
1899 SecurityStyleTestObserver observer(contents);
1900
1901 SecurityStateTabHelper* helper =
1902 SecurityStateTabHelper::FromWebContents(contents);
1903 ASSERT_TRUE(helper);
1904
1905 // Navigate to an HTTP page. Use a non-local hostname so that is it
1906 // not considered secure.
1907 GURL http_url =
1908 GetURLWithNonLocalHostname(embedded_test_server(), "/title1.html");
1909 ui_test_utils::NavigateToURL(browser(), http_url);
1910
1911 security_state::SecurityInfo security_info;
1912 helper->GetSecurityInfo(&security_info);
1913 EXPECT_TRUE(security_info.is_incognito);
1914 EXPECT_EQ(security_state::DANGEROUS, security_info.security_level);
1915 EXPECT_EQ(blink::kWebSecurityStyleInsecure, observer.latest_security_style());
1916 }
1917
1617 // Visit a valid HTTPS page, then a broken HTTPS page, and then go back, 1918 // Visit a valid HTTPS page, then a broken HTTPS page, and then go back,
1618 // and test that the observed security style matches. 1919 // and test that the observed security style matches.
1619 #if defined(OS_CHROMEOS) 1920 #if defined(OS_CHROMEOS)
1620 // Flaky on Chrome OS. See https://crbug.com/638576. 1921 // Flaky on Chrome OS. See https://crbug.com/638576.
1621 #define MAYBE_DidChangeVisibleSecurityStateObserverGoBack \ 1922 #define MAYBE_DidChangeVisibleSecurityStateObserverGoBack \
1622 DISABLED_DidChangeVisibleSecurityStateObserverGoBack 1923 DISABLED_DidChangeVisibleSecurityStateObserverGoBack
1623 #else 1924 #else
1624 #define MAYBE_DidChangeVisibleSecurityStateObserverGoBack \ 1925 #define MAYBE_DidChangeVisibleSecurityStateObserverGoBack \
1625 DidChangeVisibleSecurityStateObserverGoBack 1926 DidChangeVisibleSecurityStateObserverGoBack
1626 #endif 1927 #endif
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1857 base::string16 obsolete_description = l10n_util::GetStringFUTF16( 2158 base::string16 obsolete_description = l10n_util::GetStringFUTF16(
1858 IDS_OBSOLETE_SSL_DESCRIPTION, description_replacements, nullptr); 2159 IDS_OBSOLETE_SSL_DESCRIPTION, description_replacements, nullptr);
1859 2160
1860 EXPECT_EQ( 2161 EXPECT_EQ(
1861 obsolete_description, 2162 obsolete_description,
1862 base::ASCIIToUTF16( 2163 base::ASCIIToUTF16(
1863 observer.latest_explanations().info_explanations[0].description)); 2164 observer.latest_explanations().info_explanations[0].description));
1864 } 2165 }
1865 2166
1866 } // namespace 2167 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698