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" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
17 #include "base/strings/string_piece.h" | 17 #include "base/strings/string_piece.h" |
18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
20 #include "base/test/histogram_tester.h" | 20 #include "base/test/histogram_tester.h" |
| 21 #include "base/test/simple_test_clock.h" |
21 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
22 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 23 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
23 #include "chrome/browser/metrics/subprocess_metrics_provider.h" | 24 #include "chrome/browser/metrics/subprocess_metrics_provider.h" |
24 #include "chrome/browser/page_load_metrics/observers/subresource_filter_metrics_
observer.h" | 25 #include "chrome/browser/page_load_metrics/observers/subresource_filter_metrics_
observer.h" |
25 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" | 26 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" |
26 #include "chrome/browser/safe_browsing/v4_test_utils.h" | 27 #include "chrome/browser/safe_browsing/v4_test_utils.h" |
27 #include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h" | 28 #include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h" |
28 #include "chrome/browser/subresource_filter/test_ruleset_publisher.h" | 29 #include "chrome/browser/subresource_filter/test_ruleset_publisher.h" |
29 #include "chrome/browser/ui/browser.h" | 30 #include "chrome/browser/ui/browser.h" |
30 #include "chrome/browser/ui/browser_commands.h" | 31 #include "chrome/browser/ui/browser_commands.h" |
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 // page load right after start-up. | 787 // page load right after start-up. |
787 ui_test_utils::NavigateToURL(browser(), url); | 788 ui_test_utils::NavigateToURL(browser(), url); |
788 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); | 789 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); |
789 } | 790 } |
790 | 791 |
791 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, | 792 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, |
792 PromptShownAgainOnNextNavigation) { | 793 PromptShownAgainOnNextNavigation) { |
793 ASSERT_NO_FATAL_FAILURE( | 794 ASSERT_NO_FATAL_FAILURE( |
794 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); | 795 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); |
795 GURL url(GetTestUrl(kTestFrameSetPath)); | 796 GURL url(GetTestUrl(kTestFrameSetPath)); |
| 797 GURL a_url(embedded_test_server()->GetURL( |
| 798 "a.com", "/subresource_filter/frame_with_included_script.html")); |
796 ConfigureAsPhishingURL(url); | 799 ConfigureAsPhishingURL(url); |
797 base::HistogramTester tester; | 800 base::HistogramTester tester; |
798 ui_test_utils::NavigateToURL(browser(), url); | 801 ui_test_utils::NavigateToURL(browser(), url); |
799 tester.ExpectBucketCount(kSubresourceFilterActionsHistogram, kActionUIShown, | 802 tester.ExpectBucketCount(kSubresourceFilterActionsHistogram, kActionUIShown, |
800 1); | 803 1); |
801 // Check that the bubble is not shown again for this navigation. | 804 // Check that the bubble is not shown again for this navigation. |
802 EXPECT_FALSE(IsDynamicScriptElementLoaded(FindFrameByName("five"))); | 805 EXPECT_FALSE(IsDynamicScriptElementLoaded(FindFrameByName("five"))); |
803 tester.ExpectBucketCount(kSubresourceFilterActionsHistogram, kActionUIShown, | 806 tester.ExpectBucketCount(kSubresourceFilterActionsHistogram, kActionUIShown, |
804 1); | 807 1); |
805 // Check that bubble is shown for new navigation. | 808 // Check that bubble is shown for new navigation. Must be cross site to avoid |
806 ui_test_utils::NavigateToURL(browser(), url); | 809 // triggering smart UI on Android. |
| 810 ConfigureAsPhishingURL(a_url); |
| 811 ui_test_utils::NavigateToURL(browser(), a_url); |
| 812 ContentSubresourceFilterDriverFactory* driver_factory = |
| 813 ContentSubresourceFilterDriverFactory::FromWebContents(web_contents()); |
| 814 ChromeSubresourceFilterClient* client = |
| 815 static_cast<ChromeSubresourceFilterClient*>(driver_factory->client()); |
807 tester.ExpectBucketCount(kSubresourceFilterActionsHistogram, kActionUIShown, | 816 tester.ExpectBucketCount(kSubresourceFilterActionsHistogram, kActionUIShown, |
808 2); | 817 client->UsingSmartUI() ? 1 : 2); |
809 } | 818 } |
810 | 819 |
811 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, | 820 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, |
812 CrossSiteSubFrameActivationWithoutWhitelist) { | 821 CrossSiteSubFrameActivationWithoutWhitelist) { |
813 GURL a_url(embedded_test_server()->GetURL( | 822 GURL a_url(embedded_test_server()->GetURL( |
814 "a.com", "/subresource_filter/frame_cross_site_set.html")); | 823 "a.com", "/subresource_filter/frame_cross_site_set.html")); |
815 ConfigureAsPhishingURL(a_url); | 824 ConfigureAsPhishingURL(a_url); |
816 ASSERT_NO_FATAL_FAILURE( | 825 ASSERT_NO_FATAL_FAILURE( |
817 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); | 826 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); |
818 ui_test_utils::NavigateToURL(browser(), a_url); | 827 ui_test_utils::NavigateToURL(browser(), a_url); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
927 EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); | 936 EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); |
928 | 937 |
929 // A cross site blacklisted navigation should stay activated, however. | 938 // A cross site blacklisted navigation should stay activated, however. |
930 GURL a_url(embedded_test_server()->GetURL( | 939 GURL a_url(embedded_test_server()->GetURL( |
931 "a.com", "/subresource_filter/frame_with_included_script.html")); | 940 "a.com", "/subresource_filter/frame_with_included_script.html")); |
932 ConfigureAsPhishingURL(a_url); | 941 ConfigureAsPhishingURL(a_url); |
933 ui_test_utils::NavigateToURL(browser(), a_url); | 942 ui_test_utils::NavigateToURL(browser(), a_url); |
934 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); | 943 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); |
935 } | 944 } |
936 | 945 |
| 946 // Test the "smart" UI, aka the logic to hide the UI on subsequent same-domain |
| 947 // navigations, until a certain time threshold has been reached. This is an |
| 948 // android-only feature. |
| 949 #if defined(OS_ANDROID) |
| 950 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, |
| 951 DoNotShowUIUntilThresholdReached) { |
| 952 ASSERT_NO_FATAL_FAILURE( |
| 953 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); |
| 954 GURL a_url(embedded_test_server()->GetURL( |
| 955 "a.com", "/subresource_filter/frame_with_included_script.html")); |
| 956 GURL b_url(embedded_test_server()->GetURL( |
| 957 "b.com", "/subresource_filter/frame_with_included_script.html")); |
| 958 // Test utils only support one blacklisted site at a time. |
| 959 // TODO(csharrison): Add support for more than one URL. |
| 960 ConfigureAsPhishingURL(a_url); |
| 961 |
| 962 // Cast is safe because this is the only type of client in non-unittest code. |
| 963 ChromeSubresourceFilterClient* client = |
| 964 static_cast<ChromeSubresourceFilterClient*>( |
| 965 ContentSubresourceFilterDriverFactory::FromWebContents(web_contents()) |
| 966 ->client()); |
| 967 auto test_clock = base::MakeUnique<base::SimpleTestClock>(); |
| 968 base::SimpleTestClock* raw_clock = test_clock.get(); |
| 969 client->set_clock_for_testing(std::move(test_clock)); |
| 970 base::Time now = raw_clock->Now(); |
| 971 |
| 972 base::HistogramTester histogram_tester; |
| 973 |
| 974 // First load should trigger the UI. |
| 975 ui_test_utils::NavigateToURL(browser(), a_url); |
| 976 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); |
| 977 EXPECT_TRUE(client->shown_for_navigation()); |
| 978 |
| 979 histogram_tester.ExpectBucketCount(kSubresourceFilterActionsHistogram, |
| 980 kActionUISuppressed, 0); |
| 981 |
| 982 // Second load should not trigger the UI, but should still filter content. |
| 983 ui_test_utils::NavigateToURL(browser(), a_url); |
| 984 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); |
| 985 EXPECT_FALSE(client->shown_for_navigation()); |
| 986 |
| 987 histogram_tester.ExpectBucketCount(kSubresourceFilterActionsHistogram, |
| 988 kActionUISuppressed, 1); |
| 989 |
| 990 ConfigureAsPhishingURL(b_url); |
| 991 |
| 992 // Load to another domain should trigger the UI. |
| 993 ui_test_utils::NavigateToURL(browser(), b_url); |
| 994 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); |
| 995 EXPECT_TRUE(client->shown_for_navigation()); |
| 996 |
| 997 ConfigureAsPhishingURL(a_url); |
| 998 |
| 999 // Fast forward the clock, and a_url should trigger the UI again. |
| 1000 raw_clock->SetNow(now + base::TimeDelta::FromHours(24)); |
| 1001 ui_test_utils::NavigateToURL(browser(), a_url); |
| 1002 EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); |
| 1003 EXPECT_TRUE(client->shown_for_navigation()); |
| 1004 |
| 1005 histogram_tester.ExpectBucketCount(kSubresourceFilterActionsHistogram, |
| 1006 kActionUISuppressed, 1); |
| 1007 } |
| 1008 #endif |
| 1009 |
937 IN_PROC_BROWSER_TEST_P(SubresourceFilterWebSocketBrowserTest, BlockWebSocket) { | 1010 IN_PROC_BROWSER_TEST_P(SubresourceFilterWebSocketBrowserTest, BlockWebSocket) { |
938 GURL url(GetTestUrl( | 1011 GURL url(GetTestUrl( |
939 base::StringPrintf("subresource_filter/page_with_websocket.html?%s", | 1012 base::StringPrintf("subresource_filter/page_with_websocket.html?%s", |
940 GetParam() == IN_WORKER ? "inWorker" : ""))); | 1013 GetParam() == IN_WORKER ? "inWorker" : ""))); |
941 GURL websocket_url(GetWebSocketUrl("echo-with-no-extension")); | 1014 GURL websocket_url(GetWebSocketUrl("echo-with-no-extension")); |
942 ConfigureAsPhishingURL(url); | 1015 ConfigureAsPhishingURL(url); |
943 ASSERT_NO_FATAL_FAILURE( | 1016 ASSERT_NO_FATAL_FAILURE( |
944 SetRulesetToDisallowURLsWithPathSuffix("echo-with-no-extension")); | 1017 SetRulesetToDisallowURLsWithPathSuffix("echo-with-no-extension")); |
945 ui_test_utils::NavigateToURL(browser(), url); | 1018 ui_test_utils::NavigateToURL(browser(), url); |
946 CreateWebSocketAndExpectResult(websocket_url, | 1019 CreateWebSocketAndExpectResult(websocket_url, |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1292 std::string(kSubresourceFilterOnlySuffix)), | 1365 std::string(kSubresourceFilterOnlySuffix)), |
1293 ::testing::IsEmpty()); | 1366 ::testing::IsEmpty()); |
1294 | 1367 |
1295 EXPECT_THAT(tester.GetAllSamples(std::string(kNavigationChainSize) + | 1368 EXPECT_THAT(tester.GetAllSamples(std::string(kNavigationChainSize) + |
1296 std::string(kSubresourceFilterOnlySuffix)), | 1369 std::string(kSubresourceFilterOnlySuffix)), |
1297 ::testing::IsEmpty()); | 1370 ::testing::IsEmpty()); |
1298 } | 1371 } |
1299 #endif | 1372 #endif |
1300 | 1373 |
1301 } // namespace subresource_filter | 1374 } // namespace subresource_filter |
OLD | NEW |