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

Unified Diff: components/prefs/overlay_user_pref_store_unittest.cc

Issue 2692203007: Add PrefStore::GetValues (Closed)
Patch Set: Add GetValues to FilesystemJsonPrefStore 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
« no previous file with comments | « components/prefs/overlay_user_pref_store.cc ('k') | components/prefs/pref_store.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/prefs/overlay_user_pref_store_unittest.cc
diff --git a/components/prefs/overlay_user_pref_store_unittest.cc b/components/prefs/overlay_user_pref_store_unittest.cc
index d722aeab6e01002dd4276c81c96c0db751a833c5..20cdb1730fb3fdd74143d4442f54bdb75ef09577 100644
--- a/components/prefs/overlay_user_pref_store_unittest.cc
+++ b/components/prefs/overlay_user_pref_store_unittest.cc
@@ -19,9 +19,11 @@ namespace {
const char kBrowserWindowPlacement[] = "browser.window_placement";
const char kShowBookmarkBar[] = "bookmark_bar.show_on_all_tabs";
+const char kSharedKey[] = "sync_promo.show_on_first_run_allowed";
const char* const overlay_key = kBrowserWindowPlacement;
const char* const regular_key = kShowBookmarkBar;
+const char* const shared_key = kSharedKey;
// With the removal of the kWebKitGlobalXXX prefs, we'll no longer have real
// prefs using the overlay pref store, so make up keys here.
const char mapped_overlay_key[] = "test.per_tab.javascript_enabled";
@@ -35,6 +37,7 @@ class OverlayUserPrefStoreTest : public testing::Test {
: underlay_(new TestingPrefStore()),
overlay_(new OverlayUserPrefStore(underlay_.get())) {
overlay_->RegisterOverlayPref(overlay_key);
+ overlay_->RegisterOverlayPref(shared_key);
overlay_->RegisterOverlayPref(mapped_overlay_key, mapped_underlay_key);
}
@@ -309,4 +312,42 @@ TEST_F(OverlayUserPrefStoreTest, ClearMutableValues) {
EXPECT_TRUE(base::FundamentalValue(42).Equals(value));
}
+TEST_F(OverlayUserPrefStoreTest, GetValues) {
+ // To check merge behavior, create underlay and overlay so each has a key the
+ // other doesn't have and they have one key in common.
+ underlay_->SetValue(regular_key, base::WrapUnique(new FundamentalValue(42)),
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ overlay_->SetValue(overlay_key, base::WrapUnique(new FundamentalValue(43)),
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ underlay_->SetValue(shared_key, base::WrapUnique(new FundamentalValue(42)),
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ overlay_->SetValue(shared_key, base::WrapUnique(new FundamentalValue(43)),
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ underlay_->SetValue(mapped_underlay_key,
+ base::WrapUnique(new FundamentalValue(42)),
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ overlay_->SetValue(mapped_overlay_key,
+ base::WrapUnique(new FundamentalValue(43)),
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+
+ auto values = overlay_->GetValues();
+ const Value* value = nullptr;
+ // Check that an overlay preference is returned.
+ ASSERT_TRUE(values->Get(overlay_key, &value));
+ EXPECT_TRUE(base::FundamentalValue(43).Equals(value));
+
+ // Check that an underlay preference is returned.
+ ASSERT_TRUE(values->Get(regular_key, &value));
+ EXPECT_TRUE(base::FundamentalValue(42).Equals(value));
+
+ // Check that the overlay is preferred.
+ ASSERT_TRUE(values->Get(shared_key, &value));
+ EXPECT_TRUE(base::FundamentalValue(43).Equals(value));
+
+ // Check that mapping works.
+ ASSERT_TRUE(values->Get(mapped_overlay_key, &value));
+ EXPECT_TRUE(base::FundamentalValue(43).Equals(value));
+ EXPECT_FALSE(values->Get(mapped_underlay_key, &value));
+}
+
} // namespace base
« no previous file with comments | « components/prefs/overlay_user_pref_store.cc ('k') | components/prefs/pref_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698