Index: chrome/browser/subresource_filter/subresource_filter_browsertest.cc |
diff --git a/chrome/browser/subresource_filter/subresource_filter_browsertest.cc b/chrome/browser/subresource_filter/subresource_filter_browsertest.cc |
index 718ac828c89d5f6793888ab06b77444429b41be1..a15fe40f14994485cfde9a72c2e234a8c0376c17 100644 |
--- a/chrome/browser/subresource_filter/subresource_filter_browsertest.cc |
+++ b/chrome/browser/subresource_filter/subresource_filter_browsertest.cc |
@@ -18,6 +18,7 @@ |
#include "base/strings/string_util.h" |
#include "base/strings/stringprintf.h" |
#include "base/test/histogram_tester.h" |
+#include "base/test/simple_test_clock.h" |
#include "chrome/browser/browser_process.h" |
#include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
#include "chrome/browser/metrics/subprocess_metrics_provider.h" |
@@ -793,6 +794,8 @@ IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, |
ASSERT_NO_FATAL_FAILURE( |
SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); |
GURL url(GetTestUrl(kTestFrameSetPath)); |
+ GURL a_url(embedded_test_server()->GetURL( |
+ "a.com", "/subresource_filter/frame_with_included_script.html")); |
ConfigureAsPhishingURL(url); |
base::HistogramTester tester; |
ui_test_utils::NavigateToURL(browser(), url); |
@@ -802,10 +805,16 @@ IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, |
EXPECT_FALSE(IsDynamicScriptElementLoaded(FindFrameByName("five"))); |
tester.ExpectBucketCount(kSubresourceFilterActionsHistogram, kActionUIShown, |
1); |
- // Check that bubble is shown for new navigation. |
- ui_test_utils::NavigateToURL(browser(), url); |
+ // Check that bubble is shown for new navigation. Must be cross site to avoid |
+ // triggering smart UI on Android. |
+ ConfigureAsPhishingURL(a_url); |
+ ui_test_utils::NavigateToURL(browser(), a_url); |
+ ContentSubresourceFilterDriverFactory* driver_factory = |
+ ContentSubresourceFilterDriverFactory::FromWebContents(web_contents()); |
+ ChromeSubresourceFilterClient* client = |
+ static_cast<ChromeSubresourceFilterClient*>(driver_factory->client()); |
tester.ExpectBucketCount(kSubresourceFilterActionsHistogram, kActionUIShown, |
- 2); |
+ client->UsingSmartUI() ? 1 : 2); |
} |
IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, |
@@ -934,6 +943,70 @@ IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, |
EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); |
} |
+// Test the "smart" UI, aka the logic to hide the UI on subsequent same-domain |
+// navigations, until a certain time threshold has been reached. This is an |
+// android-only feature. |
+#if defined(OS_ANDROID) |
+IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, |
+ DoNotShowUIUntilThresholdReached) { |
+ ASSERT_NO_FATAL_FAILURE( |
+ SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); |
+ GURL a_url(embedded_test_server()->GetURL( |
+ "a.com", "/subresource_filter/frame_with_included_script.html")); |
+ GURL b_url(embedded_test_server()->GetURL( |
+ "b.com", "/subresource_filter/frame_with_included_script.html")); |
+ // Test utils only support one blacklisted site at a time. |
+ // TODO(csharrison): Add support for more than one URL. |
+ ConfigureAsPhishingURL(a_url); |
+ |
+ // Cast is safe because this is the only type of client in non-unittest code. |
+ ChromeSubresourceFilterClient* client = |
+ static_cast<ChromeSubresourceFilterClient*>( |
+ ContentSubresourceFilterDriverFactory::FromWebContents(web_contents()) |
+ ->client()); |
+ auto test_clock = base::MakeUnique<base::SimpleTestClock>(); |
+ base::SimpleTestClock* raw_clock = test_clock.get(); |
+ client->set_clock_for_testing(std::move(test_clock)); |
+ base::Time now = raw_clock->Now(); |
+ |
+ base::HistogramTester histogram_tester; |
+ |
+ // First load should trigger the UI. |
+ ui_test_utils::NavigateToURL(browser(), a_url); |
+ EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); |
+ EXPECT_TRUE(client->shown_for_navigation()); |
+ |
+ histogram_tester.ExpectBucketCount(kSubresourceFilterActionsHistogram, |
+ kActionUISuppressed, 0); |
+ |
+ // Second load should not trigger the UI, but should still filter content. |
+ ui_test_utils::NavigateToURL(browser(), a_url); |
+ EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); |
+ EXPECT_FALSE(client->shown_for_navigation()); |
+ |
+ histogram_tester.ExpectBucketCount(kSubresourceFilterActionsHistogram, |
+ kActionUISuppressed, 1); |
+ |
+ ConfigureAsPhishingURL(b_url); |
+ |
+ // Load to another domain should trigger the UI. |
+ ui_test_utils::NavigateToURL(browser(), b_url); |
+ EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); |
+ EXPECT_TRUE(client->shown_for_navigation()); |
+ |
+ ConfigureAsPhishingURL(a_url); |
+ |
+ // Fast forward the clock, and a_url should trigger the UI again. |
+ raw_clock->SetNow(now + base::TimeDelta::FromHours(24)); |
+ ui_test_utils::NavigateToURL(browser(), a_url); |
+ EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents()->GetMainFrame())); |
+ EXPECT_TRUE(client->shown_for_navigation()); |
+ |
+ histogram_tester.ExpectBucketCount(kSubresourceFilterActionsHistogram, |
+ kActionUISuppressed, 1); |
+} |
+#endif |
+ |
IN_PROC_BROWSER_TEST_P(SubresourceFilterWebSocketBrowserTest, BlockWebSocket) { |
GURL url(GetTestUrl( |
base::StringPrintf("subresource_filter/page_with_websocket.html?%s", |