OLD | NEW |
---|---|
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 Loading... | |
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 | |
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 underlay_->SetValue(mapped_underlay_key, | |
327 base::WrapUnique(new FundamentalValue(42)), | |
328 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | |
329 overlay_->SetValue(mapped_overlay_key, | |
330 base::WrapUnique(new FundamentalValue(43)), | |
331 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | |
332 | |
333 auto values = overlay_->GetValues(); | |
334 const Value* value = nullptr; | |
335 // Check that an overlay preference is returned. | |
336 ASSERT_TRUE(values->Get(overlay_key, &value)); | |
337 EXPECT_TRUE(base::FundamentalValue(43).Equals(value)); | |
338 | |
339 // Check that an underlay preference is returned. | |
340 ASSERT_TRUE(values->Get(regular_key, &value)); | |
341 EXPECT_TRUE(base::FundamentalValue(42).Equals(value)); | |
342 | |
343 // Check that the overlay is preferred. | |
344 ASSERT_TRUE(values->Get(shared_key, &value)); | |
345 EXPECT_TRUE(base::FundamentalValue(43).Equals(value)); | |
346 | |
347 // Check that mapping works. | |
348 ASSERT_TRUE(values->Get(mapped_overlay_key, &value)); | |
349 EXPECT_TRUE(base::FundamentalValue(43).Equals(value)); | |
350 ASSERT_FALSE(values->Get(mapped_underlay_key, &value)); | |
Sam McNally
2017/02/21 02:12:13
This one can be EXPECT_FALSE.
tibell
2017/02/21 02:18:22
Done.
| |
351 } | |
352 | |
312 } // namespace base | 353 } // namespace base |
OLD | NEW |