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

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

Issue 2439203002: Adding a short blacklist period after every previews opt out (Closed)
Patch Set: tbansal commetns Created 4 years, 2 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
« no previous file with comments | « components/previews/core/previews_black_list.cc ('k') | components/previews/core/previews_experiments.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6f98c122b016f94e8f3651566c760aa418e0961d..489986058d6521904c59339e67ea6acf78c2c1a2 100644
--- a/components/previews/core/previews_black_list_unittest.cc
+++ b/components/previews/core/previews_black_list_unittest.cc
@@ -70,25 +70,29 @@ class TestPreviewsOptOutStore : public PreviewsOptOutStore {
} // namespace
TEST_F(PreviewsBlackListTest, BlackListNoStore) {
// Tests the black list behavior when a null OptOutSture is passed in.
const GURL url_a("http://www.url_a.com");
const GURL url_b("http://www.url_b.com");
const size_t history = 4;
const int threshold = 2;
const int duration_in_days = 365;
+ // Disable single opt out by setting duration to 0.
+ const int single_opt_out_duration = 0;
base::FieldTrialList field_trial_list(nullptr);
std::map<std::string, std::string> params;
params["stored_history_length"] = base::SizeTToString(history);
params["opt_out_threshold"] = base::IntToString(threshold);
params["black_list_duration_in_days"] = base::IntToString(duration_in_days);
+ 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"));
base::SimpleTestClock* test_clock = new base::SimpleTestClock();
base::Time start = test_clock->Now();
test_clock->Advance(base::TimeDelta::FromSeconds(1));
std::unique_ptr<PreviewsBlackList> black_list(
@@ -126,25 +130,29 @@ TEST_F(PreviewsBlackListTest, BlackListNoStore) {
}
TEST_F(PreviewsBlackListTest, BlackListWithStore) {
// Tests the black list behavior when a non-null OptOutSture is passed in.
const GURL url_a1("http://www.url_a.com/a1");
const GURL url_a2("http://www.url_a.com/a2");
const GURL url_b("http://www.url_b.com");
const size_t history = 4;
const int threshold = 2;
const int duration_in_days = 365;
+ // Disable single opt out by setting duration to 0.
+ const int single_opt_out_duration = 0;
base::FieldTrialList field_trial_list(nullptr);
std::map<std::string, std::string> params;
params["stored_history_length"] = base::SizeTToString(history);
params["opt_out_threshold"] = base::IntToString(threshold);
params["black_list_duration_in_days"] = base::IntToString(duration_in_days);
+ 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"));
base::MessageLoop loop;
base::SimpleTestClock* test_clock = new base::SimpleTestClock();
base::Time start = test_clock->Now();
test_clock->Advance(base::TimeDelta::FromSeconds(1));
@@ -204,23 +212,27 @@ TEST_F(PreviewsBlackListTest, BlackListWithStore) {
variations::testing::ClearAllVariationParams();
}
TEST_F(PreviewsBlackListTest, QueueBehavior) {
// Tests the black list asynchronous queue behavior. Methods called while
// loading are queued and should run in the order they were queued.
const GURL url("http://www.url.com");
const GURL url2("http://www.url2.com");
const int duration_in_days = 365;
+ // Disable single opt out by setting duration to 0.
+ const int single_opt_out_duration = 0;
base::FieldTrialList field_trial_list(nullptr);
std::map<std::string, std::string> params;
params["black_list_duration_in_days"] = base::IntToString(duration_in_days);
+ 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"));
base::MessageLoop loop;
std::vector<bool> test_opt_out{true, false};
for (auto opt_out : test_opt_out) {
@@ -265,29 +277,33 @@ TEST_F(PreviewsBlackListTest, MaxHosts) {
// Test that the black list only stores n hosts, and it stores the correct n
// hosts.
const GURL url_a("http://www.url_a.com");
const GURL url_b("http://www.url_b.com");
const GURL url_c("http://www.url_c.com");
const GURL url_d("http://www.url_d.com");
const GURL url_e("http://www.url_e.com");
const size_t stored_history_length = 1;
const int opt_out_threshold = 1;
const int black_list_duration_in_days = 365;
+ // Disable single opt out by setting duration to 0.
+ const int single_opt_out_duration = 0;
const size_t max_hosts_in_blacklist = 2;
base::FieldTrialList field_trial_list(nullptr);
std::map<std::string, std::string> params;
params["stored_history_length"] = base::SizeTToString(stored_history_length);
params["opt_out_threshold"] = base::IntToString(opt_out_threshold);
params["black_list_duration_in_days"] =
base::IntToString(black_list_duration_in_days);
params["max_hosts_in_blacklist"] =
base::SizeTToString(max_hosts_in_blacklist);
+ 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"));
base::MessageLoop loop;
base::SimpleTestClock* test_clock = new base::SimpleTestClock();
std::unique_ptr<PreviewsBlackList> black_list(
@@ -308,11 +324,68 @@ TEST_F(PreviewsBlackListTest, MaxHosts) {
test_clock->Advance(base::TimeDelta::FromSeconds(1));
black_list->AddPreviewNavigation(url_e, true, PreviewsType::OFFLINE);
// url_d and url_e should remain in the map, but url_a should be evicted.
EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE));
EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_d, PreviewsType::OFFLINE));
EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_e, PreviewsType::OFFLINE));
variations::testing::ClearAllVariationParams();
}
+TEST_F(PreviewsBlackListTest, SingleOptOut) {
+ // Test that when a user opts out of a preview, previews won't be shown until
+ // |single_opt_out_duration| has elapsed.
+ const GURL url_a("http://www.url_a.com");
+ const GURL url_b("http://www.url_b.com");
+ const GURL url_c("http://www.url_c.com");
+ const size_t stored_history_length = 1;
+ const int opt_out_threshold = 2;
+ const int black_list_duration_in_days = 365;
+ const int single_opt_out_duration = 5;
+ const size_t max_hosts_in_blacklist = 10;
+ base::FieldTrialList field_trial_list(nullptr);
+ std::map<std::string, std::string> params;
+ params["stored_history_length"] = base::SizeTToString(stored_history_length);
+ params["opt_out_threshold"] = base::IntToString(opt_out_threshold);
+ params["black_list_duration_in_days"] =
+ base::IntToString(black_list_duration_in_days);
+ params["max_hosts_in_blacklist"] =
+ base::SizeTToString(max_hosts_in_blacklist);
+ 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"));
+
+ base::SimpleTestClock* test_clock = new base::SimpleTestClock();
+
+ std::unique_ptr<PreviewsBlackList> black_list(
+ new PreviewsBlackList(nullptr, base::WrapUnique(test_clock)));
+
+ black_list->AddPreviewNavigation(url_a, false, PreviewsType::OFFLINE);
+ EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE));
+ EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_c, PreviewsType::OFFLINE));
+
+ test_clock->Advance(
+ base::TimeDelta::FromSeconds(single_opt_out_duration + 1));
+
+ black_list->AddPreviewNavigation(url_b, true, PreviewsType::OFFLINE);
+ EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE));
+ EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_c, PreviewsType::OFFLINE));
+
+ test_clock->Advance(
+ base::TimeDelta::FromSeconds(single_opt_out_duration - 1));
+
+ EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE));
+ EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_c, PreviewsType::OFFLINE));
+
+ test_clock->Advance(
+ base::TimeDelta::FromSeconds(single_opt_out_duration + 1));
+
+ EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE));
+ EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_c, PreviewsType::OFFLINE));
+
+ variations::testing::ClearAllVariationParams();
+}
+
} // namespace previews
« no previous file with comments | « components/previews/core/previews_black_list.cc ('k') | components/previews/core/previews_experiments.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698