Chromium Code Reviews| 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..243bf5ab5284c6a6324a6a30b31a3f015a4c8eac 100644 |
| --- a/components/previews/core/previews_black_list_unittest.cc |
| +++ b/components/previews/core/previews_black_list_unittest.cc |
| @@ -27,124 +27,156 @@ |
| namespace { |
| using PreviewsBlackListTest = testing::Test; |
| } // namespace |
| namespace previews { |
| namespace { |
| -void RunLoadCallback(LoadBlackListCallback callback, |
| - std::unique_ptr<BlackListItemMap> black_list_item_map) { |
| - callback.Run(std::move(black_list_item_map)); |
| +void RunLoadCallback( |
| + LoadBlackListCallback callback, |
| + std::unique_ptr<BlackListItemMap> black_list_item_map, |
| + std::unique_ptr<PreviewsBlackListItem> host_indifferent_black_list_item) { |
| + callback.Run(std::move(black_list_item_map), |
| + std::move(host_indifferent_black_list_item)); |
| } |
| class TestPreviewsOptOutStore : public PreviewsOptOutStore { |
| public: |
| TestPreviewsOptOutStore() : clear_blacklist_count_(0) {} |
| ~TestPreviewsOptOutStore() override {} |
| int clear_blacklist_count() { return clear_blacklist_count_; } |
| private: |
| // PreviewsOptOutStore implementation: |
| void AddPreviewNavigation(bool opt_out, |
| const std::string& host_name, |
| PreviewsType type, |
| base::Time now) override {} |
| void LoadBlackList(LoadBlackListCallback callback) override { |
| std::unique_ptr<BlackListItemMap> black_list_item_map( |
| new BlackListItemMap()); |
| + std::unique_ptr<PreviewsBlackListItem> host_indifferent_black_list_item = |
| + PreviewsBlackList::CreateHostIndifferentBlackListItem(); |
| base::ThreadTaskRunnerHandle::Get()->PostTask( |
| FROM_HERE, base::Bind(&RunLoadCallback, callback, |
| - base::Passed(&black_list_item_map))); |
| + base::Passed(&black_list_item_map), |
| + base::Passed(&host_indifferent_black_list_item))); |
| } |
| void ClearBlackList(base::Time begin_time, base::Time end_time) override { |
| ++clear_blacklist_count_; |
| } |
| int clear_blacklist_count_; |
| }; |
| } // namespace |
| -TEST_F(PreviewsBlackListTest, BlackListNoStore) { |
| +TEST_F(PreviewsBlackListTest, PerHostBlackListNoStore) { |
| // 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 size_t per_host_history = 4; |
| + const int per_host_threshold = 2; |
| + // Host indifferent blacklisting should have no effect with the following |
| + // params. |
| + const size_t host_indifferent_history = 1; |
| + const int host_indifferent_threshold = 2; |
| const int duration_in_days = 365; |
| 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["per_host_max_stored_history_length"] = |
| + base::SizeTToString(per_host_history); |
| + params["host_indifferent_max_stored_history_length"] = |
| + base::SizeTToString(host_indifferent_history); |
| + params["per_host_opt_out_threshold"] = base::IntToString(per_host_threshold); |
| + params["host_indifferent_opt_out_threshold"] = |
| + base::IntToString(host_indifferent_threshold); |
| + params["per_host_black_list_duration_in_days"] = |
| + base::IntToString(duration_in_days); |
| 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( |
| new PreviewsBlackList(nullptr, base::WrapUnique(test_clock))); |
| EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| black_list->AddPreviewNavigation(url_a, true, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| black_list->AddPreviewNavigation(url_a, true, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| black_list->AddPreviewNavigation(url_b, true, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| black_list->AddPreviewNavigation(url_b, true, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| black_list->AddPreviewNavigation(url_b, false, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| black_list->AddPreviewNavigation(url_b, false, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| black_list->AddPreviewNavigation(url_b, false, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| - test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| black_list->ClearBlackList(start, test_clock->Now()); |
| EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| variations::testing::ClearAllVariationParams(); |
| } |
| -TEST_F(PreviewsBlackListTest, BlackListWithStore) { |
| +TEST_F(PreviewsBlackListTest, PerHostBlackListWithStore) { |
| // 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 size_t per_host_history = 4; |
| + const int per_host_threshold = 2; |
| + // Host indifferent blacklisting should have no effect with the following |
| + // params. |
| + const size_t host_indifferent_history = 1; |
| + const int host_indifferent_threshold = 2; |
| const int duration_in_days = 365; |
| 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["per_host_max_stored_history_length"] = |
| + base::SizeTToString(per_host_history); |
| + params["host_indifferent_max_stored_history_length"] = |
| + base::SizeTToString(host_indifferent_history); |
| + params["per_host_opt_out_threshold"] = base::IntToString(per_host_threshold); |
| + params["host_indifferent_opt_out_threshold"] = |
| + base::IntToString(host_indifferent_threshold); |
| + params["per_host_black_list_duration_in_days"] = |
| + base::IntToString(duration_in_days); |
| 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)); |
| @@ -158,105 +190,272 @@ TEST_F(PreviewsBlackListTest, BlackListWithStore) { |
| EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_a2, PreviewsType::OFFLINE)); |
| EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| base::RunLoop().RunUntilIdle(); |
| EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a1, PreviewsType::OFFLINE)); |
| EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a2, PreviewsType::OFFLINE)); |
| EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| black_list->AddPreviewNavigation(url_a1, true, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| black_list->AddPreviewNavigation(url_a1, true, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_a1, PreviewsType::OFFLINE)); |
| EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_a2, PreviewsType::OFFLINE)); |
| EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| black_list->AddPreviewNavigation(url_b, true, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| black_list->AddPreviewNavigation(url_b, true, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_a1, PreviewsType::OFFLINE)); |
| EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_a2, PreviewsType::OFFLINE)); |
| EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| black_list->AddPreviewNavigation(url_b, false, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| black_list->AddPreviewNavigation(url_b, false, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| black_list->AddPreviewNavigation(url_b, false, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_a1, PreviewsType::OFFLINE)); |
| EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_a2, PreviewsType::OFFLINE)); |
| EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| - test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| EXPECT_EQ(0, opt_out_store->clear_blacklist_count()); |
| black_list->ClearBlackList(start, base::Time::Now()); |
| EXPECT_EQ(1, opt_out_store->clear_blacklist_count()); |
| EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_a1, PreviewsType::OFFLINE)); |
| EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_a2, PreviewsType::OFFLINE)); |
| EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| base::RunLoop().RunUntilIdle(); |
| EXPECT_EQ(1, opt_out_store->clear_blacklist_count()); |
| EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a1, PreviewsType::OFFLINE)); |
| EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a1, PreviewsType::OFFLINE)); |
| EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| variations::testing::ClearAllVariationParams(); |
| } |
| +TEST_F(PreviewsBlackListTest, HostIndifferentBlackListNoStore) { |
| + // 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 GURL url_c("http://www.url_c.com"); |
| + const GURL url_d("http://www.url_d.com"); |
| + // Per host blacklisting should have no effect with the following params. |
| + const size_t per_host_history = 1; |
| + const int per_host_threshold = 2; |
| + const size_t host_indifferent_history = 4; |
| + const int host_indifferent_threshold = 4; |
| + const int duration_in_days = 365; |
| + base::FieldTrialList field_trial_list(nullptr); |
| + std::map<std::string, std::string> params; |
| + params["per_host_max_stored_history_length"] = |
| + base::SizeTToString(per_host_history); |
| + params["host_indifferent_max_stored_history_length"] = |
| + base::SizeTToString(host_indifferent_history); |
| + params["per_host_opt_out_threshold"] = base::IntToString(per_host_threshold); |
| + params["host_indifferent_opt_out_threshold"] = |
| + base::IntToString(host_indifferent_threshold); |
| + params["per_host_black_list_duration_in_days"] = |
| + base::IntToString(duration_in_days); |
| + ASSERT_TRUE( |
| + variations::AssociateVariationParams("ClientSidePreviews", "Enabled", |
| + params) && |
| + base::FieldTrialList::CreateFieldTrial("ClientSidePreviews", "Enabled")); |
| + |
| + base::SimpleTestClock* test_clock = new base::SimpleTestClock(); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| + |
| + std::unique_ptr<PreviewsBlackList> black_list( |
| + new PreviewsBlackList(nullptr, base::WrapUnique(test_clock))); |
| + |
| + EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| + EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| + EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_c, PreviewsType::OFFLINE)); |
| + EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_d, PreviewsType::OFFLINE)); |
| + |
| + black_list->AddPreviewNavigation(url_a, true, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| + EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| + |
| + black_list->AddPreviewNavigation(url_b, true, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| + EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| + |
| + black_list->AddPreviewNavigation(url_c, true, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| + EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| + |
| + black_list->AddPreviewNavigation(url_d, true, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| + EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| + EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| + EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_c, PreviewsType::OFFLINE)); |
| + EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_d, PreviewsType::OFFLINE)); |
| + |
| + black_list->AddPreviewNavigation(url_d, false, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| + |
| + EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
|
tbansal1
2016/10/25 16:15:48
Why did these become true?
RyanSturm
2016/10/25 18:15:44
Added comment.
|
| + EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| + EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_c, PreviewsType::OFFLINE)); |
| + EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_d, PreviewsType::OFFLINE)); |
| + |
| + variations::testing::ClearAllVariationParams(); |
| +} |
| + |
| +TEST_F(PreviewsBlackListTest, HostIndifferentBlackListWithStore) { |
|
tbansal1
2016/10/25 16:15:48
IIUC, this test is not really much different from
RyanSturm
2016/10/25 18:15:44
Adding that seems like overkill. When I add the op
tbansal1
2016/10/28 21:59:33
May be. What I am suggesting is testing the integr
|
| + // Tests the black list behavior when a non-null OptOutSture is passed in. |
| + 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"); |
| + // Per host blacklisting should have no effect with the following params. |
| + const size_t per_host_history = 1; |
| + const int per_host_threshold = 2; |
| + const size_t host_indifferent_history = 4; |
| + const int host_indifferent_threshold = 4; |
| + const int duration_in_days = 365; |
| + base::FieldTrialList field_trial_list(nullptr); |
| + std::map<std::string, std::string> params; |
| + params["per_host_max_stored_history_length"] = |
| + base::SizeTToString(per_host_history); |
| + params["host_indifferent_max_stored_history_length"] = |
| + base::SizeTToString(host_indifferent_history); |
| + params["per_host_opt_out_threshold"] = base::IntToString(per_host_threshold); |
| + params["host_indifferent_opt_out_threshold"] = |
| + base::IntToString(host_indifferent_threshold); |
| + params["per_host_black_list_duration_in_days"] = |
| + base::IntToString(duration_in_days); |
| + ASSERT_TRUE( |
| + variations::AssociateVariationParams("ClientSidePreviews", "Enabled", |
| + params) && |
| + base::FieldTrialList::CreateFieldTrial("ClientSidePreviews", "Enabled")); |
| + |
| + base::MessageLoop loop; |
| + |
| + base::SimpleTestClock* test_clock = new base::SimpleTestClock(); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| + |
| + TestPreviewsOptOutStore* opt_out_store = new TestPreviewsOptOutStore(); |
| + |
| + std::unique_ptr<PreviewsBlackList> black_list(new PreviewsBlackList( |
| + base::WrapUnique(opt_out_store), base::WrapUnique(test_clock))); |
| + |
| + EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| + EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| + EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_c, PreviewsType::OFFLINE)); |
| + EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_d, PreviewsType::OFFLINE)); |
| + |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| + EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| + EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_c, PreviewsType::OFFLINE)); |
| + EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_d, PreviewsType::OFFLINE)); |
| + |
| + black_list->AddPreviewNavigation(url_a, true, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| + EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| + |
| + black_list->AddPreviewNavigation(url_b, true, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| + EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| + |
| + black_list->AddPreviewNavigation(url_c, true, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| + EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| + |
| + black_list->AddPreviewNavigation(url_d, true, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| + EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| + EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| + EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_c, PreviewsType::OFFLINE)); |
| + EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_d, PreviewsType::OFFLINE)); |
| + |
| + black_list->AddPreviewNavigation(url_d, false, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| + |
| + EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_a, PreviewsType::OFFLINE)); |
| + EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE)); |
| + EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_c, PreviewsType::OFFLINE)); |
| + EXPECT_TRUE(black_list->IsLoadedAndAllowed(url_d, PreviewsType::OFFLINE)); |
| + |
| + 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"); |
| + // Host indifferent blacklisting should have no effect with the following |
| + // params. |
| + const size_t host_indifferent_history = 1; |
| + const int host_indifferent_threshold = 2; |
| const int duration_in_days = 365; |
| 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["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); |
| 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) { |
| base::SimpleTestClock* test_clock = new base::SimpleTestClock(); |
| + base::Time start = test_clock->Now(); |
| TestPreviewsOptOutStore* opt_out_store = new TestPreviewsOptOutStore(); |
| std::unique_ptr<PreviewsBlackList> black_list(new PreviewsBlackList( |
| base::WrapUnique(opt_out_store), base::WrapUnique(test_clock))); |
| EXPECT_FALSE(black_list->IsLoadedAndAllowed(url, PreviewsType::OFFLINE)); |
| black_list->AddPreviewNavigation(url, opt_out, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| black_list->AddPreviewNavigation(url, opt_out, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| EXPECT_FALSE(black_list->IsLoadedAndAllowed(url, PreviewsType::OFFLINE)); |
| base::RunLoop().RunUntilIdle(); |
| EXPECT_EQ(!opt_out, |
| black_list->IsLoadedAndAllowed(url, PreviewsType::OFFLINE)); |
| - |
| - base::Time start = test_clock->Now(); |
| - test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| black_list->AddPreviewNavigation(url, opt_out, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| black_list->AddPreviewNavigation(url, opt_out, PreviewsType::OFFLINE); |
| test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| EXPECT_EQ(0, opt_out_store->clear_blacklist_count()); |
| black_list->ClearBlackList( |
| start, test_clock->Now() + base::TimeDelta::FromSeconds(1)); |
| EXPECT_EQ(1, opt_out_store->clear_blacklist_count()); |
| black_list->AddPreviewNavigation(url2, opt_out, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| black_list->AddPreviewNavigation(url2, opt_out, PreviewsType::OFFLINE); |
| + test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| base::RunLoop().RunUntilIdle(); |
| EXPECT_EQ(1, opt_out_store->clear_blacklist_count()); |
| EXPECT_TRUE(black_list->IsLoadedAndAllowed(url, PreviewsType::OFFLINE)); |
| EXPECT_EQ(!opt_out, |
| black_list->IsLoadedAndAllowed(url2, PreviewsType::OFFLINE)); |
| } |
| variations::testing::ClearAllVariationParams(); |
| } |
| @@ -266,28 +465,37 @@ TEST_F(PreviewsBlackListTest, MaxHosts) { |
| // 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; |
| const size_t max_hosts_in_blacklist = 2; |
| + // Host indifferent blacklisting should have no effect with the following |
| + // params. |
| + const size_t host_indifferent_history = 1; |
| + const int host_indifferent_threshold = 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"] = |
| + params["per_host_stored_history_length"] = |
| + base::SizeTToString(stored_history_length); |
| + params["per_host_opt_out_threshold"] = base::IntToString(opt_out_threshold); |
| + params["per_host_black_list_duration_in_days"] = |
| base::IntToString(black_list_duration_in_days); |
| params["max_hosts_in_blacklist"] = |
| base::SizeTToString(max_hosts_in_blacklist); |
| + params["host_indifferent_max_stored_history_length"] = |
| + base::SizeTToString(host_indifferent_history); |
| + params["host_indifferent_opt_out_threshold"] = |
| + base::IntToString(host_indifferent_threshold); |
| 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( |