Index: components/previews/core/previews_opt_out_store_sql_unittest.cc |
diff --git a/components/previews/core/previews_opt_out_store_sql_unittest.cc b/components/previews/core/previews_opt_out_store_sql_unittest.cc |
index de9d07309b6604383ada4f7da0cc887c9432c9c1..c210045028e9b0586db16068fc87e6ff23ce4709 100644 |
--- a/components/previews/core/previews_opt_out_store_sql_unittest.cc |
+++ b/components/previews/core/previews_opt_out_store_sql_unittest.cc |
@@ -33,22 +33,24 @@ namespace { |
const base::FilePath::CharType kOptOutFilename[] = FILE_PATH_LITERAL("OptOut"); |
} // namespace |
class PreviewsOptOutStoreSQLTest : public testing::Test { |
public: |
PreviewsOptOutStoreSQLTest() {} |
~PreviewsOptOutStoreSQLTest() override {} |
// Called when |store_| is done loading. |
- void OnLoaded(std::unique_ptr<BlackListItemMap> black_list_map) { |
+ void OnLoaded(std::unique_ptr<BlackListItemMap> black_list_map, |
+ std::unique_ptr<PreviewsBlackListItem> host_indifferent_item) { |
black_list_map_ = std::move(black_list_map); |
+ host_indifferent_item_ = std::move(host_indifferent_item); |
} |
// Initializes the store and get the data from it. |
void Load() { |
store_->LoadBlackList(base::Bind(&PreviewsOptOutStoreSQLTest::OnLoaded, |
base::Unretained(this))); |
base::RunLoop().RunUntilIdle(); |
} |
// Destroys the database connection and |store_|. |
@@ -81,20 +83,23 @@ class PreviewsOptOutStoreSQLTest : public testing::Test { |
base::HistogramTester histogram_tester_; |
base::MessageLoop message_loop_; |
// The backing SQL store. |
std::unique_ptr<PreviewsOptOutStoreSQL> store_; |
// The map returned from |store_|. |
std::unique_ptr<BlackListItemMap> black_list_map_; |
+ // The host indifferent item from |store_| |
+ std::unique_ptr<PreviewsBlackListItem> host_indifferent_item_; |
+ |
// The directory for the database. |
base::ScopedTempDir temp_dir_; |
}; |
TEST_F(PreviewsOptOutStoreSQLTest, TestErrorRecovery) { |
// Creates the database and corrupt to test the recovery method. |
std::string test_host = "host.com"; |
CreateAndLoad(); |
store_->AddPreviewNavigation(true, test_host, PreviewsType::OFFLINE, |
base::Time::Now()); |
@@ -129,20 +134,22 @@ TEST_F(PreviewsOptOutStoreSQLTest, TestPersistance) { |
DestroyStore(); |
// Reload and test for persistence |
CreateAndLoad(); |
EXPECT_EQ(1U, black_list_map_->size()); |
auto iter = black_list_map_->find(test_host); |
EXPECT_NE(black_list_map_->end(), iter); |
EXPECT_EQ(1U, iter->second->OptOutRecordsSizeForTesting()); |
EXPECT_EQ(now, iter->second->most_recent_opt_out_time().value()); |
+ EXPECT_EQ(1U, host_indifferent_item_->OptOutRecordsSizeForTesting()); |
+ EXPECT_EQ(now, host_indifferent_item_->most_recent_opt_out_time().value()); |
histogram_tester_.ExpectBucketCount("Previews.OptOut.DBRowCount", 1, 1); |
histogram_tester_.ExpectTotalCount("Previews.OptOut.DBRowCount", 2); |
} |
TEST_F(PreviewsOptOutStoreSQLTest, TestMaxRows) { |
// Tests that the number of rows are culled down to the row limit at each |
// load. |
std::string test_host_a = "host_a.com"; |
std::string test_host_b = "host_b.com"; |
std::string test_host_c = "host_c.com"; |
@@ -172,36 +179,41 @@ TEST_F(PreviewsOptOutStoreSQLTest, TestMaxRows) { |
// to write its data to disk. |
DestroyStore(); |
// Reload and test for persistence |
CreateAndLoad(); |
histogram_tester_.ExpectBucketCount("Previews.OptOut.DBRowCount", |
static_cast<int>(row_limit) + 1, 1); |
// The delete happens after the load, so it is possible to load more than |
// |row_limit| into the in memory map. |
EXPECT_EQ(row_limit + 1, black_list_map_->size()); |
+ EXPECT_EQ(row_limit + 1, |
+ host_indifferent_item_->OptOutRecordsSizeForTesting()); |
DestroyStore(); |
CreateAndLoad(); |
histogram_tester_.ExpectBucketCount("Previews.OptOut.DBRowCount", |
static_cast<int>(row_limit), 1); |
EXPECT_EQ(row_limit, black_list_map_->size()); |
auto iter_host_b = black_list_map_->find(test_host_b); |
auto iter_host_c = black_list_map_->find(test_host_c); |
EXPECT_EQ(black_list_map_->end(), black_list_map_->find(test_host_a)); |
EXPECT_NE(black_list_map_->end(), iter_host_b); |
EXPECT_NE(black_list_map_->end(), iter_host_c); |
EXPECT_EQ(host_b_time, |
iter_host_b->second->most_recent_opt_out_time().value()); |
EXPECT_EQ(1U, iter_host_b->second->OptOutRecordsSizeForTesting()); |
+ EXPECT_EQ(host_b_time, |
+ host_indifferent_item_->most_recent_opt_out_time().value()); |
+ EXPECT_EQ(row_limit, host_indifferent_item_->OptOutRecordsSizeForTesting()); |
histogram_tester_.ExpectTotalCount("Previews.OptOut.DBRowCount", 3); |
} |
TEST_F(PreviewsOptOutStoreSQLTest, TestMaxRowsPerHost) { |
// Tests that each host is limited to |row_limit| rows. |
std::string test_host = "host.com"; |
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
size_t row_limit = 2; |
std::string row_limit_string = base::SizeTToString(row_limit); |
command_line->AppendSwitchASCII("previews-max-opt-out-rows-per-host", |
@@ -232,18 +244,19 @@ TEST_F(PreviewsOptOutStoreSQLTest, TestMaxRowsPerHost) { |
histogram_tester_.ExpectBucketCount("Previews.OptOut.DBRowCount", |
static_cast<int>(row_limit), 1); |
EXPECT_EQ(1U, black_list_map_->size()); |
auto iter = black_list_map_->find(test_host); |
EXPECT_NE(black_list_map_->end(), iter); |
EXPECT_EQ(last_opt_out_time, |
iter->second->most_recent_opt_out_time().value()); |
EXPECT_EQ(row_limit, iter->second->OptOutRecordsSizeForTesting()); |
+ EXPECT_EQ(row_limit, host_indifferent_item_->OptOutRecordsSizeForTesting()); |
clock.Advance(base::TimeDelta::FromSeconds(1)); |
// If both entries' opt out states are stored correctly, then this should not |
// be black listed. |
EXPECT_FALSE(iter->second->IsBlackListed(clock.Now())); |
histogram_tester_.ExpectTotalCount("Previews.OptOut.DBRowCount", 2); |
} |
} // namespace net |