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

Side by Side Diff: components/prefs/overlay_user_pref_store_unittest.cc

Issue 2692203007: Add PrefStore::GetValues (Closed)
Patch Set: Deal correctly with expanded keys 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/prefs/overlay_user_pref_store.h" 5 #include "components/prefs/overlay_user_pref_store.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "components/prefs/pref_store_observer_mock.h" 9 #include "components/prefs/pref_store_observer_mock.h"
10 #include "components/prefs/testing_pref_store.h" 10 #include "components/prefs/testing_pref_store.h"
11 #include "testing/gmock/include/gmock/gmock.h" 11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 using ::testing::Mock; 14 using ::testing::Mock;
15 using ::testing::StrEq; 15 using ::testing::StrEq;
16 16
17 namespace base { 17 namespace base {
18 namespace { 18 namespace {
19 19
20 const char kBrowserWindowPlacement[] = "browser.window_placement"; 20 const char kBrowserWindowPlacement[] = "browser.window_placement";
21 const char kShowBookmarkBar[] = "bookmark_bar.show_on_all_tabs"; 21 const char kShowBookmarkBar[] = "bookmark_bar.show_on_all_tabs";
22 const char kSharedKey[] = "sync_promo.show_on_first_run_allowed";
22 23
23 const char* const overlay_key = kBrowserWindowPlacement; 24 const char* const overlay_key = kBrowserWindowPlacement;
24 const char* const regular_key = kShowBookmarkBar; 25 const char* const regular_key = kShowBookmarkBar;
26 const char* const shared_key = kSharedKey;
25 // With the removal of the kWebKitGlobalXXX prefs, we'll no longer have real 27 // With the removal of the kWebKitGlobalXXX prefs, we'll no longer have real
26 // prefs using the overlay pref store, so make up keys here. 28 // prefs using the overlay pref store, so make up keys here.
27 const char mapped_overlay_key[] = "test.per_tab.javascript_enabled"; 29 const char mapped_overlay_key[] = "test.per_tab.javascript_enabled";
28 const char mapped_underlay_key[] = "test.per_profile.javascript_enabled"; 30 const char mapped_underlay_key[] = "test.per_profile.javascript_enabled";
29 31
30 } // namespace 32 } // namespace
31 33
32 class OverlayUserPrefStoreTest : public testing::Test { 34 class OverlayUserPrefStoreTest : public testing::Test {
33 protected: 35 protected:
34 OverlayUserPrefStoreTest() 36 OverlayUserPrefStoreTest()
35 : underlay_(new TestingPrefStore()), 37 : underlay_(new TestingPrefStore()),
36 overlay_(new OverlayUserPrefStore(underlay_.get())) { 38 overlay_(new OverlayUserPrefStore(underlay_.get())) {
37 overlay_->RegisterOverlayPref(overlay_key); 39 overlay_->RegisterOverlayPref(overlay_key);
40 overlay_->RegisterOverlayPref(shared_key);
38 overlay_->RegisterOverlayPref(mapped_overlay_key, mapped_underlay_key); 41 overlay_->RegisterOverlayPref(mapped_overlay_key, mapped_underlay_key);
39 } 42 }
40 43
41 ~OverlayUserPrefStoreTest() override {} 44 ~OverlayUserPrefStoreTest() override {}
42 45
43 scoped_refptr<TestingPrefStore> underlay_; 46 scoped_refptr<TestingPrefStore> underlay_;
44 scoped_refptr<OverlayUserPrefStore> overlay_; 47 scoped_refptr<OverlayUserPrefStore> overlay_;
45 }; 48 };
46 49
47 TEST_F(OverlayUserPrefStoreTest, Observer) { 50 TEST_F(OverlayUserPrefStoreTest, Observer) {
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 // Check that an overlay preference is returned. 305 // Check that an overlay preference is returned.
303 EXPECT_TRUE(overlay_->GetValue(overlay_key, &value)); 306 EXPECT_TRUE(overlay_->GetValue(overlay_key, &value));
304 EXPECT_TRUE(base::FundamentalValue(43).Equals(value)); 307 EXPECT_TRUE(base::FundamentalValue(43).Equals(value));
305 overlay_->ClearMutableValues(); 308 overlay_->ClearMutableValues();
306 309
307 // Check that an underlay preference is returned. 310 // Check that an underlay preference is returned.
308 EXPECT_TRUE(overlay_->GetValue(overlay_key, &value)); 311 EXPECT_TRUE(overlay_->GetValue(overlay_key, &value));
309 EXPECT_TRUE(base::FundamentalValue(42).Equals(value)); 312 EXPECT_TRUE(base::FundamentalValue(42).Equals(value));
310 } 313 }
311 314
315 TEST_F(OverlayUserPrefStoreTest, GetValues) {
316 // To check merge behavior, create underlay and overlay so each has a key the
Sam McNally 2017/02/21 01:58:25 Can you test with mapped_overlay_key and mapped_un
tibell 2017/02/21 02:11:07 Done.
317 // other doesn't have and they have one key in common.
318 underlay_->SetValue(regular_key, base::WrapUnique(new FundamentalValue(42)),
319 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
320 overlay_->SetValue(overlay_key, base::WrapUnique(new FundamentalValue(43)),
321 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
322 underlay_->SetValue(shared_key, base::WrapUnique(new FundamentalValue(42)),
323 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
324 overlay_->SetValue(shared_key, base::WrapUnique(new FundamentalValue(43)),
325 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
326
327 auto values = overlay_->GetValues();
328 const Value* value = nullptr;
329 // Check that an overlay preference is returned.
330 ASSERT_TRUE(values->Get(overlay_key, &value));
331 EXPECT_TRUE(base::FundamentalValue(43).Equals(value));
332
333 // Check that an underlay preference is returned.
334 ASSERT_TRUE(values->Get(regular_key, &value));
335 EXPECT_TRUE(base::FundamentalValue(42).Equals(value));
336
337 // Check that the overlay is preferred.
338 ASSERT_TRUE(values->Get(shared_key, &value));
339 EXPECT_TRUE(base::FundamentalValue(43).Equals(value));
340 }
341
312 } // namespace base 342 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698