| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <map> | 5 #include <map> |
| 6 #include <memory> | 6 #include <memory> |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 956 ContentSettingsWhitelistViaReload_DoNotActivate) { | 956 ContentSettingsWhitelistViaReload_DoNotActivate) { |
| 957 ASSERT_NO_FATAL_FAILURE( | 957 ASSERT_NO_FATAL_FAILURE( |
| 958 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); | 958 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); |
| 959 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html")); | 959 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html")); |
| 960 ConfigureAsPhishingURL(url); | 960 ConfigureAsPhishingURL(url); |
| 961 | 961 |
| 962 ui_test_utils::NavigateToURL(browser(), url); | 962 ui_test_utils::NavigateToURL(browser(), url); |
| 963 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); | 963 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); |
| 964 | 964 |
| 965 // Whitelist via a reload. | 965 // Whitelist via a reload. |
| 966 ContentSubresourceFilterDriverFactory* driver_factory = | |
| 967 ContentSubresourceFilterDriverFactory::FromWebContents(web_contents()); | |
| 968 ASSERT_TRUE(driver_factory); | |
| 969 | |
| 970 content::TestNavigationObserver navigation_observer(web_contents(), 1); | 966 content::TestNavigationObserver navigation_observer(web_contents(), 1); |
| 971 driver_factory->OnReloadRequested(); | 967 ChromeSubresourceFilterClient::FromWebContents(web_contents()) |
| 968 ->OnReloadRequested(); |
| 972 navigation_observer.Wait(); | 969 navigation_observer.Wait(); |
| 973 | 970 |
| 974 EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); | 971 EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); |
| 975 } | 972 } |
| 976 | 973 |
| 977 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, | 974 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, |
| 978 ContentSettingsWhitelistViaReload_WhitelistIsByDomain) { | 975 ContentSettingsWhitelistViaReload_WhitelistIsByDomain) { |
| 979 ASSERT_NO_FATAL_FAILURE( | 976 ASSERT_NO_FATAL_FAILURE( |
| 980 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); | 977 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); |
| 981 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html")); | 978 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html")); |
| 982 ConfigureAsPhishingURL(url); | 979 ConfigureAsPhishingURL(url); |
| 983 | 980 |
| 984 ui_test_utils::NavigateToURL(browser(), url); | 981 ui_test_utils::NavigateToURL(browser(), url); |
| 985 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); | 982 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); |
| 986 | 983 |
| 987 // Whitelist via a reload. | 984 // Whitelist via a reload. |
| 988 ContentSubresourceFilterDriverFactory* driver_factory = | |
| 989 ContentSubresourceFilterDriverFactory::FromWebContents(web_contents()); | |
| 990 ASSERT_TRUE(driver_factory); | |
| 991 | |
| 992 content::TestNavigationObserver navigation_observer(web_contents(), 1); | 985 content::TestNavigationObserver navigation_observer(web_contents(), 1); |
| 993 driver_factory->OnReloadRequested(); | 986 ChromeSubresourceFilterClient::FromWebContents(web_contents()) |
| 987 ->OnReloadRequested(); |
| 994 navigation_observer.Wait(); | 988 navigation_observer.Wait(); |
| 995 | 989 |
| 996 EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); | 990 EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); |
| 997 | 991 |
| 998 // Another navigation to the same domain should be whitelisted too. | 992 // Another navigation to the same domain should be whitelisted too. |
| 999 ui_test_utils::NavigateToURL( | 993 ui_test_utils::NavigateToURL( |
| 1000 browser(), | 994 browser(), |
| 1001 GetTestUrl("subresource_filter/frame_with_included_script.html?query")); | 995 GetTestUrl("subresource_filter/frame_with_included_script.html?query")); |
| 1002 EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); | 996 EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); |
| 1003 | 997 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1017 ASSERT_NO_FATAL_FAILURE( | 1011 ASSERT_NO_FATAL_FAILURE( |
| 1018 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); | 1012 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); |
| 1019 GURL a_url(embedded_test_server()->GetURL( | 1013 GURL a_url(embedded_test_server()->GetURL( |
| 1020 "a.com", "/subresource_filter/frame_with_included_script.html")); | 1014 "a.com", "/subresource_filter/frame_with_included_script.html")); |
| 1021 GURL b_url(embedded_test_server()->GetURL( | 1015 GURL b_url(embedded_test_server()->GetURL( |
| 1022 "b.com", "/subresource_filter/frame_with_included_script.html")); | 1016 "b.com", "/subresource_filter/frame_with_included_script.html")); |
| 1023 // Test utils only support one blacklisted site at a time. | 1017 // Test utils only support one blacklisted site at a time. |
| 1024 // TODO(csharrison): Add support for more than one URL. | 1018 // TODO(csharrison): Add support for more than one URL. |
| 1025 ConfigureAsPhishingURL(a_url); | 1019 ConfigureAsPhishingURL(a_url); |
| 1026 | 1020 |
| 1027 // Cast is safe because this is the only type of client in non-unittest code. | |
| 1028 ChromeSubresourceFilterClient* client = | 1021 ChromeSubresourceFilterClient* client = |
| 1029 static_cast<ChromeSubresourceFilterClient*>( | 1022 ChromeSubresourceFilterClient::FromWebContents(web_contents()); |
| 1030 ContentSubresourceFilterDriverFactory::FromWebContents(web_contents()) | |
| 1031 ->client()); | |
| 1032 auto test_clock = base::MakeUnique<base::SimpleTestClock>(); | 1023 auto test_clock = base::MakeUnique<base::SimpleTestClock>(); |
| 1033 base::SimpleTestClock* raw_clock = test_clock.get(); | 1024 base::SimpleTestClock* raw_clock = test_clock.get(); |
| 1034 settings_manager()->set_clock_for_testing(std::move(test_clock)); | 1025 settings_manager()->set_clock_for_testing(std::move(test_clock)); |
| 1035 | 1026 |
| 1036 base::HistogramTester histogram_tester; | 1027 base::HistogramTester histogram_tester; |
| 1037 | 1028 |
| 1038 // First load should trigger the UI. | 1029 // First load should trigger the UI. |
| 1039 ui_test_utils::NavigateToURL(browser(), a_url); | 1030 ui_test_utils::NavigateToURL(browser(), a_url); |
| 1040 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); | 1031 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); |
| 1041 EXPECT_TRUE(client->did_show_ui_for_navigation()); | 1032 EXPECT_TRUE(client->did_show_ui_for_navigation()); |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1454 std::string(kSubresourceFilterOnlySuffix), | 1445 std::string(kSubresourceFilterOnlySuffix), |
| 1455 false, 1); | 1446 false, 1); |
| 1456 | 1447 |
| 1457 tester.ExpectUniqueSample(std::string(kMatchesPatternHistogramName) + | 1448 tester.ExpectUniqueSample(std::string(kMatchesPatternHistogramName) + |
| 1458 std::string(kPhishingInterstitialSuffix), | 1449 std::string(kPhishingInterstitialSuffix), |
| 1459 false, 1); | 1450 false, 1); |
| 1460 } | 1451 } |
| 1461 #endif | 1452 #endif |
| 1462 | 1453 |
| 1463 } // namespace subresource_filter | 1454 } // namespace subresource_filter |
| OLD | NEW |