Index: chrome/browser/subresource_filter/subresource_filter_content_settings_manager_factory_unittest.cc |
diff --git a/chrome/browser/subresource_filter/subresource_filter_content_settings_manager_factory_unittest.cc b/chrome/browser/subresource_filter/subresource_filter_content_settings_manager_factory_unittest.cc |
index 39f683b327f88c13b7b23449010f08aa543914e8..788703dade5e1f514ba33e1c58f869430d814257 100644 |
--- a/chrome/browser/subresource_filter/subresource_filter_content_settings_manager_factory_unittest.cc |
+++ b/chrome/browser/subresource_filter/subresource_filter_content_settings_manager_factory_unittest.cc |
@@ -6,8 +6,10 @@ |
#include "base/macros.h" |
#include "base/test/histogram_tester.h" |
+#include "base/test/simple_test_clock.h" |
#include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
#include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h" |
+#include "chrome/browser/subresource_filter/subresource_filter_content_settings_manager.h" |
#include "chrome/test/base/testing_profile.h" |
#include "components/content_settings/core/browser/host_content_settings_map.h" |
#include "content/public/test/test_browser_thread_bundle.h" |
@@ -23,8 +25,12 @@ class SubresourceFilterContentSettingsManagerFactoryTest |
SubresourceFilterContentSettingsManagerFactoryTest() {} |
void SetUp() override { |
- SubresourceFilterContentSettingsManagerFactory::EnsureForProfile( |
- &testing_profile_); |
+ settings_manager_ = |
+ SubresourceFilterContentSettingsManagerFactory::EnsureForProfile( |
+ &testing_profile_); |
+ auto test_clock = base::MakeUnique<base::SimpleTestClock>(); |
engedy
2017/04/12 14:02:51
#include "base/memory/ptr_util.h"
Charlie Harrison
2017/04/12 17:53:45
Done.
|
+ test_clock_ = test_clock.get(); |
+ settings_manager_->set_clock_for_testing(std::move(test_clock)); |
engedy
2017/04/12 14:02:51
#include <utility>
Charlie Harrison
2017/04/12 17:53:45
Done.
|
histogram_tester().ExpectTotalCount(kActionsHistogram, 0); |
} |
@@ -34,11 +40,23 @@ class SubresourceFilterContentSettingsManagerFactoryTest |
const base::HistogramTester& histogram_tester() { return histogram_tester_; } |
+ SubresourceFilterContentSettingsManager* settings_manager() { |
+ return settings_manager_; |
+ } |
+ |
+ base::SimpleTestClock* test_clock() { return test_clock_; } |
+ |
private: |
content::TestBrowserThreadBundle thread_bundle_; |
TestingProfile testing_profile_; |
base::HistogramTester histogram_tester_; |
+ // Owned by the testing_profile_. |
+ SubresourceFilterContentSettingsManager* settings_manager_ = nullptr; |
+ |
+ // Owned by the settings_manager_. |
+ base::SimpleTestClock* test_clock_ = nullptr; |
+ |
DISALLOW_COPY_AND_ASSIGN(SubresourceFilterContentSettingsManagerFactoryTest); |
}; |
@@ -99,4 +117,61 @@ TEST_F(SubresourceFilterContentSettingsManagerFactoryTest, WildcardUpdate) { |
kActionContentSettingsWildcardUpdate, 2); |
} |
+TEST_F(SubresourceFilterContentSettingsManagerFactoryTest, SmartUI) { |
+ if (!settings_manager()->should_use_smart_ui()) |
+ return; |
+ |
+ GURL url("https://example.test/"); |
+ GURL url2("https://example.test/path"); |
+ EXPECT_TRUE(settings_manager()->ShouldShowUIForSite(url)); |
+ EXPECT_TRUE(settings_manager()->ShouldShowUIForSite(url2)); |
+ |
+ settings_manager()->OnDidShowUI(url); |
+ |
+ // Subsequent navigations to same-domains should not show UI. |
+ EXPECT_FALSE(settings_manager()->ShouldShowUIForSite(url)); |
+ EXPECT_FALSE(settings_manager()->ShouldShowUIForSite(url2)); |
+ |
+ // Showing the UI should trigger a forced content setting update, but no |
engedy
2017/04/12 14:02:51
nit: Let's enforce the first part of this sentence
Charlie Harrison
2017/04/12 17:53:45
Done.
|
+ // metrics should be recorded. |
+ histogram_tester().ExpectBucketCount(kActionsHistogram, |
+ kActionContentSettingsAllowed, 0); |
+ |
+ // Fast forward the clock. |
+ test_clock()->Advance( |
+ SubresourceFilterContentSettingsManager::kUIShowThresholdTime); |
+ EXPECT_TRUE(settings_manager()->ShouldShowUIForSite(url)); |
+ EXPECT_TRUE(settings_manager()->ShouldShowUIForSite(url2)); |
+} |
+ |
+// If the user manually sets a content setting to block the feature, the smart |
+// UI should be reset. |
+TEST_F(SubresourceFilterContentSettingsManagerFactoryTest, |
+ SmartUIWithOverride_Resets) { |
+ if (!settings_manager()->should_use_smart_ui()) |
+ return; |
+ |
+ GURL url("https://example.test/"); |
+ EXPECT_TRUE(settings_manager()->ShouldShowUIForSite(url)); |
+ |
+ settings_manager()->OnDidShowUI(url); |
+ |
+ // Subsequent navigations to same-domains should not show UI. |
+ EXPECT_FALSE(settings_manager()->ShouldShowUIForSite(url)); |
+ |
+ // The user changed their mind, make sure the feature is showing up in the |
+ // settings UI. i.e. the setting should be non-default. |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, settings_manager()->GetContentSetting(url)); |
+ settings_manager()->SetContentSetting(url, CONTENT_SETTING_BLOCK, |
+ true /* log_metrics */); |
+ |
+ histogram_tester().ExpectBucketCount(kActionsHistogram, |
+ kActionContentSettingsBlocked, 1); |
+ histogram_tester().ExpectBucketCount( |
+ kActionsHistogram, kActionContentSettingsBlockedWhileUISuppressed, 1); |
+ |
+ // Smart UI should be reset. |
+ EXPECT_TRUE(settings_manager()->ShouldShowUIForSite(url)); |
+} |
+ |
} // namespace |