Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #import "ios/chrome/browser/ui/settings/utils/pref_backed_boolean.h" | 5 #import "ios/chrome/browser/ui/settings/utils/pref_backed_boolean.h" |
| 6 | 6 |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/memory/ptr_util.h" | |
| 7 #include "base/values.h" | 10 #include "base/values.h" |
| 8 #include "components/prefs/pref_registry_simple.h" | 11 #include "components/prefs/pref_registry_simple.h" |
| 9 #include "components/prefs/testing_pref_service.h" | 12 #include "components/prefs/testing_pref_service.h" |
| 10 #import "ios/chrome/browser/ui/settings/utils/fake_observable_boolean.h" | 13 #import "ios/chrome/browser/ui/settings/utils/fake_observable_boolean.h" |
| 11 #include "ios/web/public/test/test_web_thread_bundle.h" | 14 #include "ios/web/public/test/test_web_thread_bundle.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "testing/platform_test.h" | 16 #include "testing/platform_test.h" |
| 14 | 17 |
| 15 #if !defined(__has_feature) || !__has_feature(objc_arc) | 18 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 16 #error "This file requires ARC support." | 19 #error "This file requires ARC support." |
| 17 #endif | 20 #endif |
| 18 | 21 |
| 19 namespace { | 22 namespace { |
| 20 | 23 |
| 21 const char kTestSwitchPref[] = "test-pref"; | 24 const char kTestSwitchPref[] = "test-pref"; |
| 22 | 25 |
| 23 class PrefBackedBooleanTest : public PlatformTest { | 26 class PrefBackedBooleanTest : public PlatformTest { |
| 24 public: | 27 public: |
| 25 void SetUp() override { | 28 void SetUp() override { |
| 26 pref_service_.registry()->RegisterBooleanPref(kTestSwitchPref, false); | 29 pref_service_.registry()->RegisterBooleanPref(kTestSwitchPref, false); |
| 27 observable_boolean_ = | 30 observable_boolean_ = |
| 28 [[PrefBackedBoolean alloc] initWithPrefService:&pref_service_ | 31 [[PrefBackedBoolean alloc] initWithPrefService:&pref_service_ |
| 29 prefName:kTestSwitchPref]; | 32 prefName:kTestSwitchPref]; |
| 30 } | 33 } |
| 31 | 34 |
| 32 protected: | 35 protected: |
| 33 bool GetPref() { return pref_service_.GetBoolean(kTestSwitchPref); } | 36 bool GetPref() { return pref_service_.GetBoolean(kTestSwitchPref); } |
| 34 | 37 |
| 35 void SetPref(bool value) { | 38 void SetPref(bool value) { |
| 36 base::Value* booleanValue = new base::Value(value); | 39 std::unique_ptr<base::Value> booleanValue = |
|
jdoerrie
2017/03/29 09:28:00
Nit: auto
vabr (Chromium)
2017/03/29 09:43:56
Done.
| |
| 37 pref_service_.SetUserPref(kTestSwitchPref, booleanValue); | 40 base::MakeUnique<base::Value>(value); |
| 41 pref_service_.SetUserPref(kTestSwitchPref, std::move(booleanValue)); | |
| 38 } | 42 } |
| 39 | 43 |
| 40 PrefBackedBoolean* GetObservableBoolean() { return observable_boolean_; } | 44 PrefBackedBoolean* GetObservableBoolean() { return observable_boolean_; } |
| 41 | 45 |
| 42 web::TestWebThreadBundle thread_bundle_; | 46 web::TestWebThreadBundle thread_bundle_; |
| 43 TestingPrefServiceSimple pref_service_; | 47 TestingPrefServiceSimple pref_service_; |
| 44 PrefBackedBoolean* observable_boolean_; | 48 PrefBackedBoolean* observable_boolean_; |
| 45 }; | 49 }; |
| 46 | 50 |
| 47 TEST_F(PrefBackedBooleanTest, ReadFromPrefs) { | 51 TEST_F(PrefBackedBooleanTest, ReadFromPrefs) { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 68 | 72 |
| 69 SetPref(true); | 73 SetPref(true); |
| 70 EXPECT_EQ(1, observer.updateCount) << "Changing value should update observer"; | 74 EXPECT_EQ(1, observer.updateCount) << "Changing value should update observer"; |
| 71 | 75 |
| 72 SetPref(true); | 76 SetPref(true); |
| 73 EXPECT_EQ(1, observer.updateCount) | 77 EXPECT_EQ(1, observer.updateCount) |
| 74 << "Setting the same value should not update observer"; | 78 << "Setting the same value should not update observer"; |
| 75 } | 79 } |
| 76 | 80 |
| 77 } // namespace | 81 } // namespace |
| OLD | NEW |