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 "chrome/browser/extensions/api/storage/policy_value_store.h" | 5 #include "chrome/browser/extensions/api/storage/policy_value_store.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 | 44 |
45 // Extends PolicyValueStore by overriding the mutating methods, so that the | 45 // Extends PolicyValueStore by overriding the mutating methods, so that the |
46 // Get() base implementation can be tested with the ValueStoreTest parameterized | 46 // Get() base implementation can be tested with the ValueStoreTest parameterized |
47 // tests. | 47 // tests. |
48 class MutablePolicyValueStore : public PolicyValueStore { | 48 class MutablePolicyValueStore : public PolicyValueStore { |
49 public: | 49 public: |
50 explicit MutablePolicyValueStore(const base::FilePath& path) | 50 explicit MutablePolicyValueStore(const base::FilePath& path) |
51 : PolicyValueStore( | 51 : PolicyValueStore( |
52 kTestExtensionId, | 52 kTestExtensionId, |
53 make_scoped_refptr(new SettingsObserverList()), | 53 make_scoped_refptr(new SettingsObserverList()), |
54 base::WrapUnique( | 54 base::MakeUnique<LeveldbValueStore>(kDatabaseUMAClientName, path)) { |
Devlin
2016/08/29 15:10:01
I thought git cl format preferred empty methods to
Adam Rice
2016/08/30 07:03:00
I think it wrapped like this because '{' is the 80
| |
55 new LeveldbValueStore(kDatabaseUMAClientName, path))) {} | 55 } |
56 ~MutablePolicyValueStore() override {} | 56 ~MutablePolicyValueStore() override {} |
57 | 57 |
58 WriteResult Set(WriteOptions options, | 58 WriteResult Set(WriteOptions options, |
59 const std::string& key, | 59 const std::string& key, |
60 const base::Value& value) override { | 60 const base::Value& value) override { |
61 return delegate()->Set(options, key, value); | 61 return delegate()->Set(options, key, value); |
62 } | 62 } |
63 | 63 |
64 WriteResult Set(WriteOptions options, | 64 WriteResult Set(WriteOptions options, |
65 const base::DictionaryValue& values) override { | 65 const base::DictionaryValue& values) override { |
(...skipping 30 matching lines...) Expand all Loading... | |
96 PolicyValueStoreTest() | 96 PolicyValueStoreTest() |
97 : file_thread_(content::BrowserThread::FILE, &loop_) {} | 97 : file_thread_(content::BrowserThread::FILE, &loop_) {} |
98 ~PolicyValueStoreTest() override {} | 98 ~PolicyValueStoreTest() override {} |
99 | 99 |
100 void SetUp() override { | 100 void SetUp() override { |
101 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); | 101 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); |
102 observers_ = new SettingsObserverList(); | 102 observers_ = new SettingsObserverList(); |
103 observers_->AddObserver(&observer_); | 103 observers_->AddObserver(&observer_); |
104 store_.reset(new PolicyValueStore( | 104 store_.reset(new PolicyValueStore( |
105 kTestExtensionId, observers_, | 105 kTestExtensionId, observers_, |
106 base::WrapUnique(new LeveldbValueStore(kDatabaseUMAClientName, | 106 base::MakeUnique<LeveldbValueStore>(kDatabaseUMAClientName, |
107 scoped_temp_dir_.path())))); | 107 scoped_temp_dir_.path()))); |
108 } | 108 } |
109 | 109 |
110 void TearDown() override { | 110 void TearDown() override { |
111 observers_->RemoveObserver(&observer_); | 111 observers_->RemoveObserver(&observer_); |
112 store_.reset(); | 112 store_.reset(); |
113 } | 113 } |
114 | 114 |
115 protected: | 115 protected: |
116 base::ScopedTempDir scoped_temp_dir_; | 116 base::ScopedTempDir scoped_temp_dir_; |
117 base::MessageLoop loop_; | 117 base::MessageLoop loop_; |
118 content::TestBrowserThread file_thread_; | 118 content::TestBrowserThread file_thread_; |
119 std::unique_ptr<PolicyValueStore> store_; | 119 std::unique_ptr<PolicyValueStore> store_; |
120 MockSettingsObserver observer_; | 120 MockSettingsObserver observer_; |
121 scoped_refptr<SettingsObserverList> observers_; | 121 scoped_refptr<SettingsObserverList> observers_; |
122 }; | 122 }; |
123 | 123 |
124 TEST_F(PolicyValueStoreTest, DontProvideRecommendedPolicies) { | 124 TEST_F(PolicyValueStoreTest, DontProvideRecommendedPolicies) { |
125 policy::PolicyMap policies; | 125 policy::PolicyMap policies; |
126 base::FundamentalValue expected(123); | 126 base::FundamentalValue expected(123); |
127 policies.Set("must", policy::POLICY_LEVEL_MANDATORY, | 127 policies.Set("must", policy::POLICY_LEVEL_MANDATORY, |
128 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, | 128 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, |
129 expected.CreateDeepCopy(), nullptr); | 129 expected.CreateDeepCopy(), nullptr); |
130 policies.Set("may", policy::POLICY_LEVEL_RECOMMENDED, | 130 policies.Set("may", policy::POLICY_LEVEL_RECOMMENDED, |
131 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, | 131 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, |
132 base::WrapUnique(new base::FundamentalValue(456)), nullptr); | 132 base::MakeUnique<base::FundamentalValue>(456), nullptr); |
133 store_->SetCurrentPolicy(policies); | 133 store_->SetCurrentPolicy(policies); |
134 ValueStore::ReadResult result = store_->Get(); | 134 ValueStore::ReadResult result = store_->Get(); |
135 ASSERT_TRUE(result->status().ok()); | 135 ASSERT_TRUE(result->status().ok()); |
136 EXPECT_EQ(1u, result->settings().size()); | 136 EXPECT_EQ(1u, result->settings().size()); |
137 base::Value* value = NULL; | 137 base::Value* value = NULL; |
138 EXPECT_FALSE(result->settings().Get("may", &value)); | 138 EXPECT_FALSE(result->settings().Get("may", &value)); |
139 EXPECT_TRUE(result->settings().Get("must", &value)); | 139 EXPECT_TRUE(result->settings().Get("must", &value)); |
140 EXPECT_TRUE(base::Value::Equals(&expected, value)); | 140 EXPECT_TRUE(base::Value::Equals(&expected, value)); |
141 } | 141 } |
142 | 142 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 Mock::VerifyAndClearExpectations(&observer_); | 228 Mock::VerifyAndClearExpectations(&observer_); |
229 | 229 |
230 // Don't notify when there aren't any changes. | 230 // Don't notify when there aren't any changes. |
231 EXPECT_CALL(observer_, OnSettingsChanged(_, _, _)).Times(0); | 231 EXPECT_CALL(observer_, OnSettingsChanged(_, _, _)).Times(0); |
232 store_->SetCurrentPolicy(policies); | 232 store_->SetCurrentPolicy(policies); |
233 base::RunLoop().RunUntilIdle(); | 233 base::RunLoop().RunUntilIdle(); |
234 Mock::VerifyAndClearExpectations(&observer_); | 234 Mock::VerifyAndClearExpectations(&observer_); |
235 } | 235 } |
236 | 236 |
237 } // namespace extensions | 237 } // namespace extensions |
OLD | NEW |