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

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

Issue 2640023007: Adds PreviewsType version mechanism for clearing blacklist entries. (Closed)
Patch Set: Cleaned up commented include Created 3 years, 10 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_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 c210045028e9b0586db16068fc87e6ff23ce4709..71582f95e550fe770057dba544148d29b6f164da 100644
--- a/components/previews/core/previews_opt_out_store_sql_unittest.cc
+++ b/components/previews/core/previews_opt_out_store_sql_unittest.cc
@@ -23,6 +23,7 @@
#include "base/time/time.h"
#include "components/previews/core/previews_black_list_item.h"
#include "components/previews/core/previews_opt_out_store.h"
+#include "components/variations/variations_associated_data.h"
#include "sql/test/test_helpers.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -36,7 +37,8 @@ const base::FilePath::CharType kOptOutFilename[] = FILE_PATH_LITERAL("OptOut");
class PreviewsOptOutStoreSQLTest : public testing::Test {
public:
- PreviewsOptOutStoreSQLTest() {}
+ PreviewsOptOutStoreSQLTest()
+ : field_trials_(new base::FieldTrialList(nullptr)) {}
~PreviewsOptOutStoreSQLTest() override {}
// Called when |store_| is done loading.
@@ -80,6 +82,13 @@ class PreviewsOptOutStoreSQLTest : public testing::Test {
void TearDown() override { DestroyStore(); }
protected:
+ void ResetFieldTrials() {
+ field_trials_.reset();
+ field_trials_.reset(new base::FieldTrialList(nullptr));
+ variations::testing::ClearAllVariationIDs();
+ variations::testing::ClearAllVariationParams();
+ }
+
base::HistogramTester histogram_tester_;
base::MessageLoop message_loop_;
@@ -95,6 +104,9 @@ class PreviewsOptOutStoreSQLTest : public testing::Test {
// The directory for the database.
base::ScopedTempDir temp_dir_;
+
+ private:
+ std::unique_ptr<base::FieldTrialList> field_trials_;
};
TEST_F(PreviewsOptOutStoreSQLTest, TestErrorRecovery) {
@@ -259,4 +271,43 @@ TEST_F(PreviewsOptOutStoreSQLTest, TestMaxRowsPerHost) {
histogram_tester_.ExpectTotalCount("Previews.OptOut.DBRowCount", 2);
}
+TEST_F(PreviewsOptOutStoreSQLTest, TestPreviewsVersionUpdate) {
+ // Tests if data is cleared for new version of previews type.
+ // Enable offline previews and add black list entry for it.
+ std::map<std::string, std::string> params;
+ params["show_offline_pages"] = "true";
+ params["show_offline_pages.version"] = "1";
+ EXPECT_TRUE(variations::AssociateVariationParams("ClientSidePreviews",
RyanSturm 2017/02/08 23:51:00 This method is deprecated and moved to base/. Can
dougarnett 2017/02/09 17:46:59 Done.
+ "Enabled", params));
+ EXPECT_TRUE(
+ base::FieldTrialList::CreateFieldTrial("ClientSidePreviews", "Enabled"));
+ std::string test_host = "host.com";
+ CreateAndLoad();
+ histogram_tester_.ExpectUniqueSample("Previews.OptOut.DBRowCount", 0, 1);
+ base::Time now = base::Time::Now();
+ store_->AddPreviewNavigation(true, test_host, PreviewsType::OFFLINE, now);
+ base::RunLoop().RunUntilIdle();
+
+ // Force data write to database then reload it and verify black list entry
+ // is present.
+ DestroyStore();
+ CreateAndLoad();
+ auto iter = black_list_map_->find(test_host);
+ EXPECT_NE(black_list_map_->end(), iter);
+ EXPECT_EQ(1U, iter->second->OptOutRecordsSizeForTesting());
+
+ // Now reload with incremented previews version and verify black list
+ // entry dropped.
+ ResetFieldTrials();
+ params["show_offline_pages.version"] = "2";
+ EXPECT_TRUE(variations::AssociateVariationParams("ClientSidePreviews",
+ "Enabled", params));
+ EXPECT_TRUE(
+ base::FieldTrialList::CreateFieldTrial("ClientSidePreviews", "Enabled"));
+ DestroyStore();
+ CreateAndLoad();
+ iter = black_list_map_->find(test_host);
+ EXPECT_EQ(black_list_map_->end(), iter);
RyanSturm 2017/02/08 23:51:00 Call ResetFieldTrials at the end of this as well.
dougarnett 2017/02/09 17:46:59 Done.
+}
+
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698