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

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

Issue 2387823002: Adding ClearBlackList to the PreviewsBlackList and plumbing to UI (Closed)
Patch Set: tbansal comments 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_io_data.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 d9fd376183c263b64f159a2df011c60cb69283f5..507491da841627e7cd3cfc950e1d0e6b0ab411f4 100644
--- a/components/previews/core/previews_black_list_unittest.cc
+++ b/components/previews/core/previews_black_list_unittest.cc
@@ -33,37 +33,45 @@ namespace previews {
namespace {
void RunLoadCallback(LoadBlackListCallback callback,
std::unique_ptr<BlackListItemMap> black_list_item_map) {
callback.Run(std::move(black_list_item_map));
}
class TestPreviewsOptOutStore : public PreviewsOptOutStore {
public:
- TestPreviewsOptOutStore() {}
+ 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());
base::MessageLoop::current()->task_runner()->PostTask(
FROM_HERE, base::Bind(&RunLoadCallback, callback,
base::Passed(&black_list_item_map)));
}
+
+ void ClearBlackList(base::Time begin_time, base::Time end_time) override {
+ ++clear_blacklist_count_;
+ }
+
+ int clear_blacklist_count_;
};
} // 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;
@@ -71,21 +79,23 @@ TEST_F(PreviewsBlackListTest, BlackListNoStore) {
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);
ASSERT_TRUE(
variations::AssociateVariationParams("ClientSidePreviews", "Enabled",
params) &&
base::FieldTrialList::CreateFieldTrial("ClientSidePreviews", "Enabled"));
- base::Clock* test_clock = new base::SimpleTestClock();
+ 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);
black_list->AddPreviewNavigation(url_a, true, PreviewsType::OFFLINE);
@@ -98,20 +108,26 @@ TEST_F(PreviewsBlackListTest, BlackListNoStore) {
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);
black_list->AddPreviewNavigation(url_b, false, PreviewsType::OFFLINE);
black_list->AddPreviewNavigation(url_b, false, PreviewsType::OFFLINE);
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) {
// 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;
@@ -121,25 +137,28 @@ TEST_F(PreviewsBlackListTest, BlackListWithStore) {
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);
ASSERT_TRUE(
variations::AssociateVariationParams("ClientSidePreviews", "Enabled",
params) &&
base::FieldTrialList::CreateFieldTrial("ClientSidePreviews", "Enabled"));
base::MessageLoop loop;
- base::Clock* test_clock = new base::SimpleTestClock();
+ base::SimpleTestClock* test_clock = new base::SimpleTestClock();
+ base::Time start = test_clock->Now();
+ test_clock->Advance(base::TimeDelta::FromSeconds(1));
+
+ TestPreviewsOptOutStore* opt_out_store = new TestPreviewsOptOutStore();
- std::unique_ptr<PreviewsBlackList> black_list(
- new PreviewsBlackList(base::MakeUnique<TestPreviewsOptOutStore>(),
- base::WrapUnique(test_clock)));
+ std::unique_ptr<PreviewsBlackList> black_list(new PreviewsBlackList(
+ base::WrapUnique(opt_out_store), base::WrapUnique(test_clock)));
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_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));
@@ -159,54 +178,90 @@ TEST_F(PreviewsBlackListTest, BlackListWithStore) {
EXPECT_FALSE(black_list->IsLoadedAndAllowed(url_b, PreviewsType::OFFLINE));
black_list->AddPreviewNavigation(url_b, false, PreviewsType::OFFLINE);
black_list->AddPreviewNavigation(url_b, false, PreviewsType::OFFLINE);
black_list->AddPreviewNavigation(url_b, false, PreviewsType::OFFLINE);
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, 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;
base::FieldTrialList field_trial_list(nullptr);
std::map<std::string, std::string> params;
params["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;
std::vector<bool> test_opt_out{true, false};
for (auto opt_out : test_opt_out) {
- base::Clock* test_clock = new base::SimpleTestClock();
+ base::SimpleTestClock* test_clock = new base::SimpleTestClock();
+
+ TestPreviewsOptOutStore* opt_out_store = new TestPreviewsOptOutStore();
- std::unique_ptr<PreviewsBlackList> black_list(
- new PreviewsBlackList(base::MakeUnique<TestPreviewsOptOutStore>(),
- base::WrapUnique(test_clock)));
+ 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);
black_list->AddPreviewNavigation(url, opt_out, PreviewsType::OFFLINE);
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);
+ 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);
+ black_list->AddPreviewNavigation(url2, opt_out, PreviewsType::OFFLINE);
+ 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();
}
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");
« no previous file with comments | « components/previews/core/previews_black_list.cc ('k') | components/previews/core/previews_io_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698