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

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: Remove obsolete includes 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"
13 #include "chrome/browser/ssl/cert_verifier_browser_test.h" 17 #include "chrome/browser/ssl/cert_verifier_browser_test.h"
14 #include "chrome/browser/ssl/ssl_blocking_page.h" 18 #include "chrome/browser/ssl/ssl_blocking_page.h"
15 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_commands.h" 20 #include "chrome/browser/ui/browser_commands.h"
21 #include "chrome/browser/ui/browser_finder.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" 22 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/common/chrome_paths.h" 23 #include "chrome/common/chrome_paths.h"
19 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
21 #include "chrome/test/base/in_process_browser_test.h" 26 #include "chrome/test/base/in_process_browser_test.h"
22 #include "chrome/test/base/ui_test_utils.h" 27 #include "chrome/test/base/ui_test_utils.h"
23 #include "components/prefs/pref_service.h" 28 #include "components/prefs/pref_service.h"
24 #include "components/security_state/core/security_state.h" 29 #include "components/security_state/core/security_state.h"
25 #include "components/security_state/core/switches.h" 30 #include "components/security_state/core/switches.h"
26 #include "components/strings/grit/components_strings.h" 31 #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); 370 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
366 } 371 }
367 } 372 }
368 373
369 net::EmbeddedTestServer https_server_; 374 net::EmbeddedTestServer https_server_;
370 375
371 private: 376 private:
372 DISALLOW_COPY_AND_ASSIGN(SecurityStateTabHelperTest); 377 DISALLOW_COPY_AND_ASSIGN(SecurityStateTabHelperTest);
373 }; 378 };
374 379
380 // Same as SecurityStateTabHelperTest, but with Incognito enabled.
381 class SecurityStateTabHelperIncognitoTest : public SecurityStateTabHelperTest {
382 public:
383 SecurityStateTabHelperIncognitoTest() : SecurityStateTabHelperTest() {}
384
385 void SetUpCommandLine(base::CommandLine* command_line) override {
386 SecurityStateTabHelperTest::SetUpCommandLine(command_line);
387 // Test should run Incognito.
388 command_line->AppendSwitch(switches::kIncognito);
389 }
390
391 private:
392 DISALLOW_COPY_AND_ASSIGN(SecurityStateTabHelperIncognitoTest);
393 };
394
375 class DidChangeVisibleSecurityStateTest : public InProcessBrowserTest { 395 class DidChangeVisibleSecurityStateTest : public InProcessBrowserTest {
376 public: 396 public:
377 DidChangeVisibleSecurityStateTest() 397 DidChangeVisibleSecurityStateTest()
378 : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) { 398 : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {
379 https_server_.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot)); 399 https_server_.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot));
380 } 400 }
381 401
382 void SetUpCommandLine(base::CommandLine* command_line) override { 402 void SetUpCommandLine(base::CommandLine* command_line) override {
383 // Browser will both run and display insecure content. 403 // Browser will both run and display insecure content.
384 command_line->AppendSwitch(switches::kAllowRunningInsecureContent); 404 command_line->AppendSwitch(switches::kAllowRunningInsecureContent);
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 protected: 946 protected:
927 void SetUpOnMainThread() override { 947 void SetUpOnMainThread() override {
928 ASSERT_TRUE(embedded_test_server()->Start()); 948 ASSERT_TRUE(embedded_test_server()->Start());
929 949
930 content::BrowserThread::PostTask( 950 content::BrowserThread::PostTask(
931 content::BrowserThread::IO, FROM_HERE, 951 content::BrowserThread::IO, FROM_HERE,
932 base::Bind(&InstallLoadingInterceptor, 952 base::Bind(&InstallLoadingInterceptor,
933 embedded_test_server()->GetURL("/title1.html").host())); 953 embedded_test_server()->GetURL("/title1.html").host()));
934 } 954 }
935 955
956 private:
936 DISALLOW_COPY_AND_ASSIGN(SecurityStateLoadingTest); 957 DISALLOW_COPY_AND_ASSIGN(SecurityStateLoadingTest);
937 }; 958 };
938 959
939 // Tests that navigation state changes cause the security state to be 960 // Tests that navigation state changes cause the security state to be
940 // updated. 961 // updated.
941 IN_PROC_BROWSER_TEST_F(SecurityStateLoadingTest, NavigationStateChanges) { 962 IN_PROC_BROWSER_TEST_F(SecurityStateLoadingTest, NavigationStateChanges) {
942 ASSERT_TRUE(https_server_.Start()); 963 ASSERT_TRUE(https_server_.Start());
943 SetUpMockCertVerifierForHttpsServer(0, net::OK); 964 SetUpMockCertVerifierForHttpsServer(0, net::OK);
944 965
945 // Navigate to an HTTPS page. 966 // Navigate to an HTTPS page.
(...skipping 30 matching lines...) Expand all
976 "/password/simple_password.html")); 997 "/password/simple_password.html"));
977 InjectScript(contents); 998 InjectScript(contents);
978 security_state::SecurityInfo security_info; 999 security_state::SecurityInfo security_info;
979 helper->GetSecurityInfo(&security_info); 1000 helper->GetSecurityInfo(&security_info);
980 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level); 1001 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level);
981 1002
982 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry(); 1003 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry();
983 ASSERT_TRUE(entry); 1004 ASSERT_TRUE(entry);
984 EXPECT_TRUE(entry->GetSSL().content_status & 1005 EXPECT_TRUE(entry->GetSSL().content_status &
985 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); 1006 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
1007
1008 {
1009 // Ensure the warning is still present when HTTPBad Phase 2 flag is enabled.
1010 base::test::ScopedCommandLine scoped_command_line;
1011 scoped_command_line.GetProcessCommandLine()->AppendSwitchASCII(
1012 security_state::switches::kMarkHttpAs,
1013 security_state::switches::kMarkHttpAsNonSecureWhileIncognito);
1014
1015 helper->GetSecurityInfo(&security_info);
1016 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level);
1017 }
986 } 1018 }
987 1019
988 // Tests that when a visible password field is detected on a blob URL, the 1020 // Tests that when a visible password field is detected on a blob URL, the
989 // security level is downgraded to HTTP_SHOW_WARNING. 1021 // security level is downgraded to HTTP_SHOW_WARNING.
990 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest, 1022 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
991 PasswordSecurityLevelDowngradedOnBlobUrl) { 1023 PasswordSecurityLevelDowngradedOnBlobUrl) {
992 TestPasswordFieldOnBlobOrFilesystemURL( 1024 TestPasswordFieldOnBlobOrFilesystemURL(
993 "blob", 1025 "blob",
994 "var blob = new Blob(['<html><form><input type=password></form></html>']," 1026 "var blob = new Blob(['<html><form><input type=password></form></html>'],"
995 " {type: 'text/html'});" 1027 " {type: 'text/html'});"
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 content::WebContents* contents = 1268 content::WebContents* contents =
1237 content::WebContents::Create(content::WebContents::CreateParams( 1269 content::WebContents::Create(content::WebContents::CreateParams(
1238 original_contents->GetBrowserContext())); 1270 original_contents->GetBrowserContext()));
1239 ASSERT_TRUE(contents); 1271 ASSERT_TRUE(contents);
1240 contents->SetDelegate(delegate); 1272 contents->SetDelegate(delegate);
1241 delegate->tab_strip_model()->AppendWebContents(contents, true); 1273 delegate->tab_strip_model()->AppendWebContents(contents, true);
1242 int index = delegate->tab_strip_model()->GetIndexOfWebContents(contents); 1274 int index = delegate->tab_strip_model()->GetIndexOfWebContents(contents);
1243 delegate->tab_strip_model()->ActivateTabAt(index, true); 1275 delegate->tab_strip_model()->ActivateTabAt(index, true);
1244 ASSERT_EQ(contents, delegate->tab_strip_model()->GetActiveWebContents()); 1276 ASSERT_EQ(contents, delegate->tab_strip_model()->GetActiveWebContents());
1245 1277
1246 // Navigate to an HTTP page. Use a non-local hostname so that is it 1278 // Navigate to an HTTP page. Use a non-local hostname so that it is
1247 // not considered secure. 1279 // not considered secure.
1248 GURL http_url = 1280 GURL http_url =
1249 GetURLWithNonLocalHostname(embedded_test_server(), "/title1.html"); 1281 GetURLWithNonLocalHostname(embedded_test_server(), "/title1.html");
1250 ui_test_utils::NavigateToURL(delegate, http_url); 1282 ui_test_utils::NavigateToURL(delegate, http_url);
1251 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry(); 1283 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry();
1252 ASSERT_TRUE(entry); 1284 ASSERT_TRUE(entry);
1253 EXPECT_EQ(http_url, entry->GetURL()); 1285 EXPECT_EQ(http_url, entry->GetURL());
1254 EXPECT_TRUE(delegate->console_messages().empty()); 1286 EXPECT_TRUE(delegate->console_messages().empty());
1255 1287
1256 // Trigger the HTTP_SHOW_WARNING state. 1288 // Trigger the HTTP_SHOW_WARNING state.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 content::WebContents* contents = 1336 content::WebContents* contents =
1305 content::WebContents::Create(content::WebContents::CreateParams( 1337 content::WebContents::Create(content::WebContents::CreateParams(
1306 original_contents->GetBrowserContext())); 1338 original_contents->GetBrowserContext()));
1307 ASSERT_TRUE(contents); 1339 ASSERT_TRUE(contents);
1308 contents->SetDelegate(delegate); 1340 contents->SetDelegate(delegate);
1309 delegate->tab_strip_model()->AppendWebContents(contents, true); 1341 delegate->tab_strip_model()->AppendWebContents(contents, true);
1310 int index = delegate->tab_strip_model()->GetIndexOfWebContents(contents); 1342 int index = delegate->tab_strip_model()->GetIndexOfWebContents(contents);
1311 delegate->tab_strip_model()->ActivateTabAt(index, true); 1343 delegate->tab_strip_model()->ActivateTabAt(index, true);
1312 ASSERT_EQ(contents, delegate->tab_strip_model()->GetActiveWebContents()); 1344 ASSERT_EQ(contents, delegate->tab_strip_model()->GetActiveWebContents());
1313 1345
1314 // Navigate to an HTTP page. Use a non-local hostname so that is it 1346 // Navigate to an HTTP page. Use a non-local hostname so that it is
1315 // not considered secure. 1347 // not considered secure.
1316 GURL http_url = GetURLWithNonLocalHostname(embedded_test_server(), 1348 GURL http_url = GetURLWithNonLocalHostname(embedded_test_server(),
1317 "/ssl/page_with_frame.html"); 1349 "/ssl/page_with_frame.html");
1318 ui_test_utils::NavigateToURL(delegate, http_url); 1350 ui_test_utils::NavigateToURL(delegate, http_url);
1319 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry(); 1351 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry();
1320 ASSERT_TRUE(entry); 1352 ASSERT_TRUE(entry);
1321 EXPECT_EQ(http_url, entry->GetURL()); 1353 EXPECT_EQ(http_url, entry->GetURL());
1322 EXPECT_TRUE(delegate->console_messages().empty()); 1354 EXPECT_TRUE(delegate->console_messages().empty());
1323 1355
1324 // Trigger the HTTP_SHOW_WARNING state. 1356 // Trigger the HTTP_SHOW_WARNING state.
(...skipping 20 matching lines...) Expand all
1345 // already a console message logged for the current main-frame 1377 // already a console message logged for the current main-frame
1346 // navigation. 1378 // navigation.
1347 content::WindowedNotificationObserver subframe_observer( 1379 content::WindowedNotificationObserver subframe_observer(
1348 content::NOTIFICATION_LOAD_STOP, 1380 content::NOTIFICATION_LOAD_STOP,
1349 content::Source<content::NavigationController>( 1381 content::Source<content::NavigationController>(
1350 &contents->GetController())); 1382 &contents->GetController()));
1351 EXPECT_TRUE(content::ExecuteScript( 1383 EXPECT_TRUE(content::ExecuteScript(
1352 contents, "document.getElementById('navFrame').src = '/title2.html';")); 1384 contents, "document.getElementById('navFrame').src = '/title2.html';"));
1353 subframe_observer.Wait(); 1385 subframe_observer.Wait();
1354 contents->OnCreditCardInputShownOnHttp(); 1386 contents->OnCreditCardInputShownOnHttp();
1387 helper->GetSecurityInfo(&security_info);
1355 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level); 1388 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level);
1356 1389
1357 // Do a main frame navigation and then trigger HTTP_SHOW_WARNING 1390 // Do a main frame navigation and then trigger HTTP_SHOW_WARNING
1358 // again. From the above subframe navigation and this main-frame 1391 // again. From the above subframe navigation and this main-frame
1359 // navigation, exactly one console message is expected. 1392 // navigation, exactly one console message is expected.
1360 GURL second_http_url = 1393 GURL second_http_url =
1361 GetURLWithNonLocalHostname(embedded_test_server(), "/title2.html"); 1394 GetURLWithNonLocalHostname(embedded_test_server(), "/title2.html");
1362 ui_test_utils::NavigateToURL(delegate, second_http_url); 1395 ui_test_utils::NavigateToURL(delegate, second_http_url);
1363 entry = contents->GetController().GetVisibleEntry(); 1396 entry = contents->GetController().GetVisibleEntry();
1364 ASSERT_TRUE(entry); 1397 ASSERT_TRUE(entry);
(...skipping 20 matching lines...) Expand all
1385 content::WebContents* contents = 1418 content::WebContents* contents =
1386 content::WebContents::Create(content::WebContents::CreateParams( 1419 content::WebContents::Create(content::WebContents::CreateParams(
1387 original_contents->GetBrowserContext())); 1420 original_contents->GetBrowserContext()));
1388 ASSERT_TRUE(contents); 1421 ASSERT_TRUE(contents);
1389 contents->SetDelegate(delegate); 1422 contents->SetDelegate(delegate);
1390 delegate->tab_strip_model()->AppendWebContents(contents, true); 1423 delegate->tab_strip_model()->AppendWebContents(contents, true);
1391 int index = delegate->tab_strip_model()->GetIndexOfWebContents(contents); 1424 int index = delegate->tab_strip_model()->GetIndexOfWebContents(contents);
1392 delegate->tab_strip_model()->ActivateTabAt(index, true); 1425 delegate->tab_strip_model()->ActivateTabAt(index, true);
1393 ASSERT_EQ(contents, delegate->tab_strip_model()->GetActiveWebContents()); 1426 ASSERT_EQ(contents, delegate->tab_strip_model()->GetActiveWebContents());
1394 1427
1395 // Navigate to an HTTP page. Use a non-local hostname so that is it 1428 // Navigate to an HTTP page. Use a non-local hostname so that it is
1396 // not considered secure. 1429 // not considered secure.
1397 GURL http_url = 1430 GURL http_url =
1398 GetURLWithNonLocalHostname(embedded_test_server(), "/title1.html"); 1431 GetURLWithNonLocalHostname(embedded_test_server(), "/title1.html");
1399 ui_test_utils::NavigateToURL(delegate, http_url); 1432 ui_test_utils::NavigateToURL(delegate, http_url);
1400 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry(); 1433 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry();
1401 ASSERT_TRUE(entry); 1434 ASSERT_TRUE(entry);
1402 EXPECT_EQ(http_url, entry->GetURL()); 1435 EXPECT_EQ(http_url, entry->GetURL());
1403 EXPECT_TRUE(delegate->console_messages().empty()); 1436 EXPECT_TRUE(delegate->console_messages().empty());
1404 1437
1405 // Trigger the HTTP_SHOW_WARNING state. 1438 // Trigger the HTTP_SHOW_WARNING state.
(...skipping 15 matching lines...) Expand all
1421 delegate->ClearConsoleMessages(); 1454 delegate->ClearConsoleMessages();
1422 1455
1423 // Navigate with pushState and trigger VisibleSecurityStateChanged 1456 // Navigate with pushState and trigger VisibleSecurityStateChanged
1424 // again. While the security level is still HTTP_SHOW_WARNING, an 1457 // again. While the security level is still HTTP_SHOW_WARNING, an
1425 // additional console message should not be logged because there was 1458 // additional console message should not be logged because there was
1426 // already a console message logged for the current main-frame 1459 // already a console message logged for the current main-frame
1427 // navigation. 1460 // navigation.
1428 EXPECT_TRUE(content::ExecuteScript( 1461 EXPECT_TRUE(content::ExecuteScript(
1429 contents, "history.pushState({ foo: 'bar' }, 'foo', 'bar');")); 1462 contents, "history.pushState({ foo: 'bar' }, 'foo', 'bar');"));
1430 contents->OnCreditCardInputShownOnHttp(); 1463 contents->OnCreditCardInputShownOnHttp();
1464 helper->GetSecurityInfo(&security_info);
1431 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level); 1465 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level);
1432 1466
1433 // Do a main frame navigation and then trigger HTTP_SHOW_WARNING 1467 // Do a main frame navigation and then trigger HTTP_SHOW_WARNING
1434 // again. From the above pushState navigation and this main-frame 1468 // again. From the above pushState navigation and this main-frame
1435 // navigation, exactly one console message is expected. 1469 // navigation, exactly one console message is expected.
1436 GURL second_http_url = 1470 GURL second_http_url =
1437 GetURLWithNonLocalHostname(embedded_test_server(), "/title2.html"); 1471 GetURLWithNonLocalHostname(embedded_test_server(), "/title2.html");
1438 ui_test_utils::NavigateToURL(delegate, second_http_url); 1472 ui_test_utils::NavigateToURL(delegate, second_http_url);
1439 entry = contents->GetController().GetVisibleEntry(); 1473 entry = contents->GetController().GetVisibleEntry();
1440 ASSERT_TRUE(entry); 1474 ASSERT_TRUE(entry);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
1607 INVALID_CERTIFICATE, browser(), 1641 INVALID_CERTIFICATE, browser(),
1608 https_test_server_expired.GetCertificate().get()); 1642 https_test_server_expired.GetCertificate().get());
1609 EXPECT_TRUE(observer.latest_explanations().scheme_is_cryptographic); 1643 EXPECT_TRUE(observer.latest_explanations().scheme_is_cryptographic);
1610 EXPECT_FALSE(observer.latest_explanations().pkp_bypassed); 1644 EXPECT_FALSE(observer.latest_explanations().pkp_bypassed);
1611 EXPECT_TRUE(observer.latest_explanations().info_explanations.empty()); 1645 EXPECT_TRUE(observer.latest_explanations().info_explanations.empty());
1612 EXPECT_FALSE(observer.latest_explanations().displayed_mixed_content); 1646 EXPECT_FALSE(observer.latest_explanations().displayed_mixed_content);
1613 EXPECT_FALSE(observer.latest_explanations().ran_mixed_content); 1647 EXPECT_FALSE(observer.latest_explanations().ran_mixed_content);
1614 EXPECT_TRUE(observer.latest_explanations().summary.empty()); 1648 EXPECT_TRUE(observer.latest_explanations().summary.empty());
1615 } 1649 }
1616 1650
1651 // Tests that the security level of a HTTP page in Incognito mode is downgraded
1652 // to HTTP_SHOW_WARNING when MarkHttpAsNonSecureWhileIncognito is enabled.
1653 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperIncognitoTest,
1654 SecurityLevelDowngradedForHTTPInIncognito) {
1655 // Set the mode using the command line flag rather than the field trial to
1656 // ensure that fieldtrial_testing_config.json does not interfere.
1657 base::test::ScopedCommandLine scoped_command_line;
1658 scoped_command_line.GetProcessCommandLine()->AppendSwitchASCII(
1659 security_state::switches::kMarkHttpAs,
1660 security_state::switches::kMarkHttpAsNonSecureWhileIncognito);
1661
1662 ConsoleWebContentsDelegate* delegate = new ConsoleWebContentsDelegate(
1663 Browser::CreateParams(browser()->profile(), true));
1664 content::WebContents* original_contents =
1665 browser()->tab_strip_model()->GetActiveWebContents();
1666 content::WebContents* contents =
1667 content::WebContents::Create(content::WebContents::CreateParams(
1668 original_contents->GetBrowserContext()));
1669 ASSERT_TRUE(contents);
1670 ASSERT_TRUE(contents->GetBrowserContext()->IsOffTheRecord());
1671 contents->SetDelegate(delegate);
1672 delegate->tab_strip_model()->AppendWebContents(contents, true);
1673 int index = delegate->tab_strip_model()->GetIndexOfWebContents(contents);
1674 delegate->tab_strip_model()->ActivateTabAt(index, true);
1675 ASSERT_EQ(contents, delegate->tab_strip_model()->GetActiveWebContents());
1676
1677 SecurityStyleTestObserver observer(contents);
1678
1679 SecurityStateTabHelper* helper =
1680 SecurityStateTabHelper::FromWebContents(contents);
1681 ASSERT_TRUE(helper);
1682
1683 // Navigate to an HTTP page. Use a non-local hostname so that it is
1684 // not considered secure.
1685 GURL http_url =
1686 GetURLWithNonLocalHostname(embedded_test_server(), "/title1.html");
1687 ui_test_utils::NavigateToURL(delegate, http_url);
1688 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry();
1689 ASSERT_TRUE(entry);
1690 EXPECT_EQ(http_url, entry->GetURL());
1691
1692 security_state::SecurityInfo security_info;
1693 helper->GetSecurityInfo(&security_info);
1694 EXPECT_TRUE(security_info.incognito_downgraded_security_level);
1695 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level);
1696 EXPECT_EQ(1u, observer.latest_explanations().neutral_explanations.size());
1697 EXPECT_EQ(blink::kWebSecurityStyleNeutral, observer.latest_security_style());
1698
1699 // Check that the expected console message is present.
1700 ASSERT_NO_FATAL_FAILURE(CheckForOneHttpWarningConsoleMessage(delegate));
1701
1702 // Ensure that same-page pushstate does not add another notice.
1703 EXPECT_TRUE(content::ExecuteScript(
1704 contents, "history.pushState({ foo: 'bar' }, 'foo', 'bar');"));
1705 EXPECT_EQ(1u, observer.latest_explanations().neutral_explanations.size());
1706 EXPECT_EQ(blink::kWebSecurityStyleNeutral, observer.latest_security_style());
1707 // Check that no additional console message is present.
1708 ASSERT_NO_FATAL_FAILURE(CheckForOneHttpWarningConsoleMessage(delegate));
1709 }
1710
1711 // Tests that additional HTTP_SHOW_WARNING console messages are not
1712 // printed after aborted navigations.
1713 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperIncognitoTest,
1714 ConsoleMessageNotPrintedForAbortedNavigation) {
1715 // Set the mode using the command line flag rather than the field trial to
1716 // ensure that fieldtrial_testing_config.json does not interfere.
1717 base::test::ScopedCommandLine scoped_command_line;
1718 scoped_command_line.GetProcessCommandLine()->AppendSwitchASCII(
1719 security_state::switches::kMarkHttpAs,
1720 security_state::switches::kMarkHttpAsNonSecureWhileIncognito);
1721
1722 ConsoleWebContentsDelegate* delegate = new ConsoleWebContentsDelegate(
1723 Browser::CreateParams(browser()->profile(), true));
1724 content::WebContents* original_contents =
1725 browser()->tab_strip_model()->GetActiveWebContents();
1726 content::WebContents* contents =
1727 content::WebContents::Create(content::WebContents::CreateParams(
1728 original_contents->GetBrowserContext()));
1729 ASSERT_TRUE(contents);
1730 ASSERT_TRUE(contents->GetBrowserContext()->IsOffTheRecord());
1731 contents->SetDelegate(delegate);
1732 delegate->tab_strip_model()->AppendWebContents(contents, true);
1733 int index = delegate->tab_strip_model()->GetIndexOfWebContents(contents);
1734 delegate->tab_strip_model()->ActivateTabAt(index, true);
1735 ASSERT_EQ(contents, delegate->tab_strip_model()->GetActiveWebContents());
1736
1737 SecurityStyleTestObserver observer(contents);
1738
1739 SecurityStateTabHelper* helper =
1740 SecurityStateTabHelper::FromWebContents(contents);
1741 ASSERT_TRUE(helper);
1742
1743 // Navigate to an HTTP page. Use a non-local hostname so that it is
1744 // not considered secure.
1745 GURL http_url =
1746 GetURLWithNonLocalHostname(embedded_test_server(), "/title1.html");
1747 ui_test_utils::NavigateToURL(delegate, http_url);
1748
1749 security_state::SecurityInfo security_info;
1750 helper->GetSecurityInfo(&security_info);
1751 EXPECT_TRUE(security_info.incognito_downgraded_security_level);
1752 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level);
1753 EXPECT_EQ(blink::kWebSecurityStyleNeutral, observer.latest_security_style());
1754 EXPECT_EQ(1u, observer.latest_explanations().neutral_explanations.size());
1755
1756 // Check that the expected console message is present.
1757 ASSERT_NO_FATAL_FAILURE(CheckForOneHttpWarningConsoleMessage(delegate));
1758 delegate->ClearConsoleMessages();
1759
1760 // Perform a navigation that does not commit.
1761 // The embedded test server returns a HTTP/204 only for local URLs, so
1762 // we cannot use GetURLWithNonLocalHostname() here.
1763 GURL http204_url = embedded_test_server()->GetURL("/nocontent");
1764 ui_test_utils::NavigateToURL(delegate, http204_url);
1765
1766 // No change is expected in the security state.
1767 EXPECT_TRUE(security_info.incognito_downgraded_security_level);
1768 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level);
1769 EXPECT_EQ(blink::kWebSecurityStyleNeutral, observer.latest_security_style());
1770 EXPECT_EQ(1u, observer.latest_explanations().neutral_explanations.size());
1771
1772 // No additional console logging should occur.
1773 EXPECT_TRUE(delegate->console_messages().empty());
1774 }
1775
1776 // Tests that the security level of a HTTP page in Guest mode is not downgraded
1777 // to HTTP_SHOW_WARNING when MarkHttpAsNonSecureWhileIncognito is enabled.
1778 #if defined(OS_CHROMEOS)
1779 // Guest mode cannot be readily browser-tested on ChromeOS.
1780 #define MAYBE_SecurityLevelNotDowngradedForHTTPInGuestMode \
1781 DISABLED_SecurityLevelNotDowngradedForHTTPInGuestMode
1782 #else
1783 #define MAYBE_SecurityLevelNotDowngradedForHTTPInGuestMode \
1784 SecurityLevelNotDowngradedForHTTPInGuestMode
1785 #endif
1786 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTest,
1787 MAYBE_SecurityLevelNotDowngradedForHTTPInGuestMode) {
1788 base::test::ScopedCommandLine scoped_command_line;
1789 scoped_command_line.GetProcessCommandLine()->AppendSwitchASCII(
1790 security_state::switches::kMarkHttpAs,
1791 security_state::switches::kMarkHttpAsNonSecureWhileIncognito);
1792
1793 // Create a new browser in Guest Mode.
1794 EXPECT_EQ(1U, BrowserList::GetInstance()->size());
1795 content::WindowedNotificationObserver browser_creation_observer(
1796 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
1797 content::NotificationService::AllSources());
1798 profiles::SwitchToGuestProfile(ProfileManager::CreateCallback());
1799 browser_creation_observer.Wait();
1800 EXPECT_EQ(2U, BrowserList::GetInstance()->size());
1801 Profile* guest = g_browser_process->profile_manager()->GetProfileByPath(
1802 ProfileManager::GetGuestProfilePath());
1803 Browser* guest_browser = chrome::FindAnyBrowser(guest, true);
1804 ASSERT_TRUE(guest_browser);
1805
1806 ConsoleWebContentsDelegate* delegate = new ConsoleWebContentsDelegate(
1807 Browser::CreateParams(guest_browser->profile(), true));
1808 content::WebContents* original_contents =
1809 guest_browser->tab_strip_model()->GetActiveWebContents();
1810 content::WebContents* contents =
1811 content::WebContents::Create(content::WebContents::CreateParams(
1812 original_contents->GetBrowserContext()));
1813 ASSERT_TRUE(contents);
1814 ASSERT_TRUE(contents->GetBrowserContext()->IsOffTheRecord());
1815 contents->SetDelegate(delegate);
1816 delegate->tab_strip_model()->AppendWebContents(contents, true);
1817 int index = delegate->tab_strip_model()->GetIndexOfWebContents(contents);
1818 delegate->tab_strip_model()->ActivateTabAt(index, true);
1819 ASSERT_EQ(contents, delegate->tab_strip_model()->GetActiveWebContents());
1820
1821 SecurityStyleTestObserver observer(contents);
1822
1823 SecurityStateTabHelper* helper =
1824 SecurityStateTabHelper::FromWebContents(contents);
1825 ASSERT_TRUE(helper);
1826
1827 // Navigate to an HTTP page. Use a non-local hostname so that it is
1828 // not considered secure.
1829 GURL http_url =
1830 GetURLWithNonLocalHostname(embedded_test_server(), "/title1.html");
1831 ui_test_utils::NavigateToURL(delegate, http_url);
1832
1833 security_state::SecurityInfo security_info;
1834 helper->GetSecurityInfo(&security_info);
1835 EXPECT_FALSE(security_info.incognito_downgraded_security_level);
1836 EXPECT_EQ(security_state::NONE, security_info.security_level);
1837 EXPECT_EQ(0u, observer.latest_explanations().neutral_explanations.size());
1838 EXPECT_EQ(blink::kWebSecurityStyleNeutral, observer.latest_security_style());
1839
1840 // No console notification should occur.
1841 EXPECT_TRUE(delegate->console_messages().empty());
1842 }
1843
1844 // Tests that the security level of a HTTP page is NEUTRAL when MarkHttpAs is
1845 // not set.
1846 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperIncognitoTest,
1847 SecurityLevelNeutralByDefaultForHTTP) {
1848 content::WebContents* contents =
1849 browser()->tab_strip_model()->GetActiveWebContents();
1850 ASSERT_TRUE(contents);
1851
1852 ASSERT_TRUE(contents->GetBrowserContext()->IsOffTheRecord());
1853
1854 SecurityStyleTestObserver observer(contents);
1855
1856 SecurityStateTabHelper* helper =
1857 SecurityStateTabHelper::FromWebContents(contents);
1858 ASSERT_TRUE(helper);
1859
1860 // Navigate to an HTTP page. Use a non-local hostname so that it is
1861 // not considered secure.
1862 GURL http_url =
1863 GetURLWithNonLocalHostname(embedded_test_server(), "/title1.html");
1864 ui_test_utils::NavigateToURL(browser(), http_url);
1865
1866 security_state::SecurityInfo security_info;
1867 helper->GetSecurityInfo(&security_info);
1868 EXPECT_FALSE(security_info.incognito_downgraded_security_level);
1869 EXPECT_EQ(security_state::NONE, security_info.security_level);
1870 EXPECT_EQ(0u, observer.latest_explanations().neutral_explanations.size());
1871 EXPECT_EQ(blink::kWebSecurityStyleNeutral, observer.latest_security_style());
1872 }
1873
1874 // Tests that the security level of a HTTP page is downgraded to DANGEROUS when
1875 // MarkHttpAsDangerous is enabled.
1876 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperIncognitoTest,
1877 SecurityLevelDangerousWhenMarkHttpAsDangerous) {
1878 base::test::ScopedCommandLine scoped_command_line;
1879 scoped_command_line.GetProcessCommandLine()->AppendSwitchASCII(
1880 security_state::switches::kMarkHttpAs,
1881 security_state::switches::kMarkHttpAsDangerous);
1882
1883 content::WebContents* contents =
1884 browser()->tab_strip_model()->GetActiveWebContents();
1885 ASSERT_TRUE(contents);
1886 ASSERT_TRUE(contents->GetBrowserContext()->IsOffTheRecord());
1887
1888 SecurityStyleTestObserver observer(contents);
1889
1890 SecurityStateTabHelper* helper =
1891 SecurityStateTabHelper::FromWebContents(contents);
1892 ASSERT_TRUE(helper);
1893
1894 // Navigate to an HTTP page. Use a non-local hostname so that it is
1895 // not considered secure.
1896 GURL http_url =
1897 GetURLWithNonLocalHostname(embedded_test_server(), "/title1.html");
1898 ui_test_utils::NavigateToURL(browser(), http_url);
1899
1900 security_state::SecurityInfo security_info;
1901 helper->GetSecurityInfo(&security_info);
1902 EXPECT_FALSE(security_info.incognito_downgraded_security_level);
1903 EXPECT_EQ(security_state::DANGEROUS, security_info.security_level);
1904 EXPECT_EQ(blink::kWebSecurityStyleInsecure, observer.latest_security_style());
1905 }
1906
1617 // Visit a valid HTTPS page, then a broken HTTPS page, and then go back, 1907 // Visit a valid HTTPS page, then a broken HTTPS page, and then go back,
1618 // and test that the observed security style matches. 1908 // and test that the observed security style matches.
1619 #if defined(OS_CHROMEOS) 1909 #if defined(OS_CHROMEOS)
1620 // Flaky on Chrome OS. See https://crbug.com/638576. 1910 // Flaky on Chrome OS. See https://crbug.com/638576.
1621 #define MAYBE_DidChangeVisibleSecurityStateObserverGoBack \ 1911 #define MAYBE_DidChangeVisibleSecurityStateObserverGoBack \
1622 DISABLED_DidChangeVisibleSecurityStateObserverGoBack 1912 DISABLED_DidChangeVisibleSecurityStateObserverGoBack
1623 #else 1913 #else
1624 #define MAYBE_DidChangeVisibleSecurityStateObserverGoBack \ 1914 #define MAYBE_DidChangeVisibleSecurityStateObserverGoBack \
1625 DidChangeVisibleSecurityStateObserverGoBack 1915 DidChangeVisibleSecurityStateObserverGoBack
1626 #endif 1916 #endif
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1857 base::string16 obsolete_description = l10n_util::GetStringFUTF16( 2147 base::string16 obsolete_description = l10n_util::GetStringFUTF16(
1858 IDS_OBSOLETE_SSL_DESCRIPTION, description_replacements, nullptr); 2148 IDS_OBSOLETE_SSL_DESCRIPTION, description_replacements, nullptr);
1859 2149
1860 EXPECT_EQ( 2150 EXPECT_EQ(
1861 obsolete_description, 2151 obsolete_description,
1862 base::ASCIIToUTF16( 2152 base::ASCIIToUTF16(
1863 observer.latest_explanations().info_explanations[0].description)); 2153 observer.latest_explanations().info_explanations[0].description));
1864 } 2154 }
1865 2155
1866 } // namespace 2156 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ssl/security_state_tab_helper.cc ('k') | components/security_state/content/content_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698