OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/strings/pattern.h" | 10 #include "base/strings/pattern.h" |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 // Tests that a content initiated navigation to a data URL is blocked. | 500 // Tests that a content initiated navigation to a data URL is blocked. |
501 IN_PROC_BROWSER_TEST_F(DataUrlNavigationBrowserTest, HTML_Navigation_Block) { | 501 IN_PROC_BROWSER_TEST_F(DataUrlNavigationBrowserTest, HTML_Navigation_Block) { |
502 NavigateToURL(shell(), | 502 NavigateToURL(shell(), |
503 embedded_test_server()->GetURL("/data_url_navigations.html")); | 503 embedded_test_server()->GetURL("/data_url_navigations.html")); |
504 ExecuteScriptAndCheckNavigation( | 504 ExecuteScriptAndCheckNavigation( |
505 shell()->web_contents()->GetMainFrame(), | 505 shell()->web_contents()->GetMainFrame(), |
506 "document.getElementById('navigate-top-frame-to-html').click()", | 506 "document.getElementById('navigate-top-frame-to-html').click()", |
507 NAVIGATION_BLOCKED); | 507 NAVIGATION_BLOCKED); |
508 } | 508 } |
509 | 509 |
| 510 class DataUrlNavigationAllowedFromContentTest |
| 511 : public DataUrlNavigationBrowserTest { |
| 512 public: |
| 513 DataUrlNavigationAllowedFromContentTest() {} |
| 514 |
| 515 protected: |
| 516 void SetUp() override { |
| 517 scoped_feature_list_.InitAndEnableFeature( |
| 518 features::kAllowContentInitiatedDataUrlNavigations); |
| 519 DataUrlNavigationBrowserTest::SetUp(); |
| 520 } |
| 521 |
| 522 private: |
| 523 base::test::ScopedFeatureList scoped_feature_list_; |
| 524 |
| 525 DISALLOW_COPY_AND_ASSIGN(DataUrlNavigationAllowedFromContentTest); |
| 526 }; |
| 527 |
510 // Tests that a content initiated navigation to a data URL is allowed if | 528 // Tests that a content initiated navigation to a data URL is allowed if |
511 // blocking is disabled with a feature flag. | 529 // blocking is disabled with a feature flag. |
512 IN_PROC_BROWSER_TEST_F(DataUrlNavigationBrowserTest, | 530 IN_PROC_BROWSER_TEST_F(DataUrlNavigationAllowedFromContentTest, |
513 HTML_Navigation_Allow_FeatureFlag) { | 531 HTML_Navigation) { |
514 base::test::ScopedFeatureList feature_list; | |
515 feature_list.InitAndEnableFeature( | |
516 features::kAllowContentInitiatedDataUrlNavigations); | |
517 NavigateToURL(shell(), | 532 NavigateToURL(shell(), |
518 embedded_test_server()->GetURL("/data_url_navigations.html")); | 533 embedded_test_server()->GetURL("/data_url_navigations.html")); |
519 ExecuteScriptAndCheckNavigation( | 534 ExecuteScriptAndCheckNavigation( |
520 shell()->web_contents()->GetMainFrame(), | 535 shell()->web_contents()->GetMainFrame(), |
521 "document.getElementById('navigate-top-frame-to-html').click()", | 536 "document.getElementById('navigate-top-frame-to-html').click()", |
522 NAVIGATION_ALLOWED); | 537 NAVIGATION_ALLOWED); |
523 } | 538 } |
524 | 539 |
525 // Tests that a window.open to a data URL with HTML mime type is blocked. | 540 // Tests that a window.open to a data URL with HTML mime type is blocked. |
526 IN_PROC_BROWSER_TEST_F(DataUrlNavigationBrowserTest, HTML_WindowOpen_Block) { | 541 IN_PROC_BROWSER_TEST_F(DataUrlNavigationBrowserTest, HTML_WindowOpen_Block) { |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 ASSERT_TRUE(child); | 948 ASSERT_TRUE(child); |
934 if (AreAllSitesIsolatedForTesting()) { | 949 if (AreAllSitesIsolatedForTesting()) { |
935 ASSERT_TRUE(child->IsCrossProcessSubframe()); | 950 ASSERT_TRUE(child->IsCrossProcessSubframe()); |
936 } | 951 } |
937 ExecuteScriptAndCheckNavigationDownload( | 952 ExecuteScriptAndCheckNavigationDownload( |
938 child, "document.getElementById('window-open-pdf').click()"); | 953 child, "document.getElementById('window-open-pdf').click()"); |
939 #endif | 954 #endif |
940 } | 955 } |
941 | 956 |
942 } // content | 957 } // content |
OLD | NEW |