Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(803)

Unified Diff: components/previews/core/previews_black_list_unittest.cc

Issue 2878363004: If users clear history, the previews recency rule should be cleared (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/previews/core/previews_black_list_unittest.cc
diff --git a/components/previews/core/previews_black_list_unittest.cc b/components/previews/core/previews_black_list_unittest.cc
index 2c8a1fc3b80a1dddb25925352f5cf68159fa796b..09e5bdc8213d2398f30fcd90ed3da1b36ab1c4cc 100644
--- a/components/previews/core/previews_black_list_unittest.cc
+++ b/components/previews/core/previews_black_list_unittest.cc
@@ -603,4 +603,59 @@ TEST_F(PreviewsBlackListTest, AddPreviewUMA) {
1);
}
+TEST_F(PreviewsBlackListTest, ClearingBlackListClearsRecentNavigation) {
+ const GURL url("http://www.url.com");
+
+ const size_t host_indifferent_history = 1;
+ const int host_indifferent_threshold = host_indifferent_history + 1;
+ const int duration_in_days = 365;
+ // Disable single opt out by setting duration to 0.
+ const int single_opt_out_duration = 5;
+ base::FieldTrialList field_trial_list(nullptr);
+ std::map<std::string, std::string> params;
bengr 2017/05/15 21:15:14 #include <map>
RyanSturm 2017/05/15 21:58:58 Done.
+ params["per_host_black_list_duration_in_days"] =
+ base::IntToString(duration_in_days);
+ params["host_indifferent_max_stored_history_length"] =
+ base::SizeTToString(host_indifferent_history);
+ params["host_indifferent_opt_out_threshold"] =
+ base::IntToString(host_indifferent_threshold);
+ params["single_opt_out_duration_in_seconds"] =
+ base::IntToString(single_opt_out_duration);
+ ASSERT_TRUE(
+ variations::AssociateVariationParams("ClientSidePreviews", "Enabled",
+ params) &&
+ base::FieldTrialList::CreateFieldTrial("ClientSidePreviews", "Enabled"));
+
+ struct {
+ bool short_history_clear;
+ } tests[] = {{true}, {false}};
bengr 2017/05/15 21:15:14 This is an anti-pattern. Write this as two separat
RyanSturm 2017/05/15 21:58:59 Done.
+
+ base::MessageLoop loop;
+ for (auto test : tests) {
+ base::SimpleTestClock* test_clock = new base::SimpleTestClock();
+ base::Time start = test_clock->Now();
+ if (!test.short_history_clear) {
+ test_clock->Advance(
+ base::TimeDelta::FromSeconds(single_opt_out_duration));
+ }
+
+ TestPreviewsOptOutStore* opt_out_store = new TestPreviewsOptOutStore();
+
+ std::unique_ptr<PreviewsBlackList> black_list(new PreviewsBlackList(
+ base::WrapUnique(opt_out_store), base::WrapUnique(test_clock)));
+
+ black_list->AddPreviewNavigation(url, true /* opt_out */,
+ PreviewsType::OFFLINE);
+ test_clock->Advance(base::TimeDelta::FromSeconds(1));
+ black_list->ClearBlackList(start, test_clock->Now());
+ base::RunLoop().RunUntilIdle();
+
+ EXPECT_EQ(test.short_history_clear
+ ? PreviewsEligibilityReason::USER_RECENTLY_OPTED_OUT
+ : PreviewsEligibilityReason::ALLOWED,
+ black_list->IsLoadedAndAllowed(url, PreviewsType::OFFLINE));
+ }
+ variations::testing::ClearAllVariationParams();
+}
+
} // namespace previews

Powered by Google App Engine
This is Rietveld 408576698