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

Side by Side Diff: chrome/browser/extensions/api/storage/policy_value_store_unittest.cc

Issue 2664753002: Remove base::StringValue (Closed)
Patch Set: Rebase Created 3 years, 9 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 "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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
143 TEST_F(PolicyValueStoreTest, ReadOnly) { 143 TEST_F(PolicyValueStoreTest, ReadOnly) {
144 ValueStore::WriteOptions options = ValueStore::DEFAULTS; 144 ValueStore::WriteOptions options = ValueStore::DEFAULTS;
145 145
146 base::StringValue string_value("value"); 146 base::Value string_value("value");
147 EXPECT_FALSE(store_->Set(options, "key", string_value)->status().ok()); 147 EXPECT_FALSE(store_->Set(options, "key", string_value)->status().ok());
148 148
149 base::DictionaryValue dict; 149 base::DictionaryValue dict;
150 dict.SetString("key", "value"); 150 dict.SetString("key", "value");
151 EXPECT_FALSE(store_->Set(options, dict)->status().ok()); 151 EXPECT_FALSE(store_->Set(options, dict)->status().ok());
152 152
153 EXPECT_FALSE(store_->Remove("key")->status().ok()); 153 EXPECT_FALSE(store_->Remove("key")->status().ok());
154 std::vector<std::string> keys; 154 std::vector<std::string> keys;
155 keys.push_back("key"); 155 keys.push_back("key");
156 EXPECT_FALSE(store_->Remove(keys)->status().ok()); 156 EXPECT_FALSE(store_->Remove(keys)->status().ok());
157 EXPECT_FALSE(store_->Clear()->status().ok()); 157 EXPECT_FALSE(store_->Clear()->status().ok());
158 } 158 }
159 159
160 TEST_F(PolicyValueStoreTest, NotifyOnChanges) { 160 TEST_F(PolicyValueStoreTest, NotifyOnChanges) {
161 // Notify when setting the initial policy. 161 // Notify when setting the initial policy.
162 const base::StringValue value("111"); 162 const base::Value value("111");
163 { 163 {
164 ValueStoreChangeList changes; 164 ValueStoreChangeList changes;
165 changes.push_back(ValueStoreChange("aaa", nullptr, value.CreateDeepCopy())); 165 changes.push_back(ValueStoreChange("aaa", nullptr, value.CreateDeepCopy()));
166 EXPECT_CALL(observer_, 166 EXPECT_CALL(observer_,
167 OnSettingsChanged(kTestExtensionId, 167 OnSettingsChanged(kTestExtensionId,
168 settings_namespace::MANAGED, 168 settings_namespace::MANAGED,
169 ValueStoreChange::ToJson(changes))); 169 ValueStoreChange::ToJson(changes)));
170 } 170 }
171 171
172 policy::PolicyMap policies; 172 policy::PolicyMap policies;
(...skipping 13 matching lines...) Expand all
186 ValueStoreChange::ToJson(changes))); 186 ValueStoreChange::ToJson(changes)));
187 } 187 }
188 188
189 policies.Set("bbb", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, 189 policies.Set("bbb", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER,
190 policy::POLICY_SOURCE_CLOUD, value.CreateDeepCopy(), nullptr); 190 policy::POLICY_SOURCE_CLOUD, value.CreateDeepCopy(), nullptr);
191 store_->SetCurrentPolicy(policies); 191 store_->SetCurrentPolicy(policies);
192 base::RunLoop().RunUntilIdle(); 192 base::RunLoop().RunUntilIdle();
193 Mock::VerifyAndClearExpectations(&observer_); 193 Mock::VerifyAndClearExpectations(&observer_);
194 194
195 // Notify when policies change. 195 // Notify when policies change.
196 const base::StringValue new_value("222"); 196 const base::Value new_value("222");
197 { 197 {
198 ValueStoreChangeList changes; 198 ValueStoreChangeList changes;
199 changes.push_back(ValueStoreChange("bbb", value.CreateDeepCopy(), 199 changes.push_back(ValueStoreChange("bbb", value.CreateDeepCopy(),
200 new_value.CreateDeepCopy())); 200 new_value.CreateDeepCopy()));
201 EXPECT_CALL(observer_, 201 EXPECT_CALL(observer_,
202 OnSettingsChanged(kTestExtensionId, 202 OnSettingsChanged(kTestExtensionId,
203 settings_namespace::MANAGED, 203 settings_namespace::MANAGED,
204 ValueStoreChange::ToJson(changes))); 204 ValueStoreChange::ToJson(changes)));
205 } 205 }
206 206
(...skipping 21 matching lines...) Expand all
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698