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

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

Issue 1350913006: Revert of Add source column to chrome://policy showing the origins of policies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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 "base/callback.h" 7 #include "base/callback.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "components/policy/core/common/external_data_fetcher.h" 13 #include "components/policy/core/common/external_data_fetcher.h"
14 #include "components/policy/core/common/policy_map.h" 14 #include "components/policy/core/common/policy_map.h"
15 #include "components/policy/core/common/policy_types.h"
16 #include "content/public/test/test_browser_thread.h" 15 #include "content/public/test/test_browser_thread.h"
17 #include "extensions/browser/api/storage/settings_observer.h" 16 #include "extensions/browser/api/storage/settings_observer.h"
18 #include "extensions/browser/value_store/leveldb_value_store.h" 17 #include "extensions/browser/value_store/leveldb_value_store.h"
19 #include "extensions/browser/value_store/value_store_unittest.h" 18 #include "extensions/browser/value_store/value_store_unittest.h"
20 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
22 21
23 using testing::_; 22 using testing::_;
24 using testing::Mock; 23 using testing::Mock;
25 24
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 content::TestBrowserThread file_thread_; 113 content::TestBrowserThread file_thread_;
115 scoped_ptr<PolicyValueStore> store_; 114 scoped_ptr<PolicyValueStore> store_;
116 MockSettingsObserver observer_; 115 MockSettingsObserver observer_;
117 scoped_refptr<SettingsObserverList> observers_; 116 scoped_refptr<SettingsObserverList> observers_;
118 }; 117 };
119 118
120 TEST_F(PolicyValueStoreTest, DontProvideRecommendedPolicies) { 119 TEST_F(PolicyValueStoreTest, DontProvideRecommendedPolicies) {
121 policy::PolicyMap policies; 120 policy::PolicyMap policies;
122 base::FundamentalValue expected(123); 121 base::FundamentalValue expected(123);
123 policies.Set("must", policy::POLICY_LEVEL_MANDATORY, 122 policies.Set("must", policy::POLICY_LEVEL_MANDATORY,
124 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, 123 policy::POLICY_SCOPE_USER, expected.DeepCopy(), NULL);
125 expected.DeepCopy(), nullptr);
126 policies.Set("may", policy::POLICY_LEVEL_RECOMMENDED, 124 policies.Set("may", policy::POLICY_LEVEL_RECOMMENDED,
127 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, 125 policy::POLICY_SCOPE_USER,
128 new base::FundamentalValue(456), NULL); 126 new base::FundamentalValue(456), NULL);
129 store_->SetCurrentPolicy(policies); 127 store_->SetCurrentPolicy(policies);
130 ValueStore::ReadResult result = store_->Get(); 128 ValueStore::ReadResult result = store_->Get();
131 ASSERT_FALSE(result->HasError()); 129 ASSERT_FALSE(result->HasError());
132 EXPECT_EQ(1u, result->settings().size()); 130 EXPECT_EQ(1u, result->settings().size());
133 base::Value* value = NULL; 131 base::Value* value = NULL;
134 EXPECT_FALSE(result->settings().Get("may", &value)); 132 EXPECT_FALSE(result->settings().Get("may", &value));
135 EXPECT_TRUE(result->settings().Get("must", &value)); 133 EXPECT_TRUE(result->settings().Get("must", &value));
136 EXPECT_TRUE(base::Value::Equals(&expected, value)); 134 EXPECT_TRUE(base::Value::Equals(&expected, value));
137 } 135 }
(...skipping 22 matching lines...) Expand all
160 ValueStoreChangeList changes; 158 ValueStoreChangeList changes;
161 changes.push_back(ValueStoreChange("aaa", NULL, value.DeepCopy())); 159 changes.push_back(ValueStoreChange("aaa", NULL, value.DeepCopy()));
162 EXPECT_CALL(observer_, 160 EXPECT_CALL(observer_,
163 OnSettingsChanged(kTestExtensionId, 161 OnSettingsChanged(kTestExtensionId,
164 settings_namespace::MANAGED, 162 settings_namespace::MANAGED,
165 ValueStoreChange::ToJson(changes))); 163 ValueStoreChange::ToJson(changes)));
166 } 164 }
167 165
168 policy::PolicyMap policies; 166 policy::PolicyMap policies;
169 policies.Set("aaa", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, 167 policies.Set("aaa", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER,
170 policy::POLICY_SOURCE_CLOUD, value.DeepCopy(), nullptr); 168 value.DeepCopy(), NULL);
171 store_->SetCurrentPolicy(policies); 169 store_->SetCurrentPolicy(policies);
172 loop_.RunUntilIdle(); 170 loop_.RunUntilIdle();
173 Mock::VerifyAndClearExpectations(&observer_); 171 Mock::VerifyAndClearExpectations(&observer_);
174 172
175 // Notify when new policies are added. 173 // Notify when new policies are added.
176 { 174 {
177 ValueStoreChangeList changes; 175 ValueStoreChangeList changes;
178 changes.push_back(ValueStoreChange("bbb", NULL, value.DeepCopy())); 176 changes.push_back(ValueStoreChange("bbb", NULL, value.DeepCopy()));
179 EXPECT_CALL(observer_, 177 EXPECT_CALL(observer_,
180 OnSettingsChanged(kTestExtensionId, 178 OnSettingsChanged(kTestExtensionId,
181 settings_namespace::MANAGED, 179 settings_namespace::MANAGED,
182 ValueStoreChange::ToJson(changes))); 180 ValueStoreChange::ToJson(changes)));
183 } 181 }
184 182
185 policies.Set("bbb", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, 183 policies.Set("bbb", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER,
186 policy::POLICY_SOURCE_CLOUD, value.DeepCopy(), nullptr); 184 value.DeepCopy(), NULL);
187 store_->SetCurrentPolicy(policies); 185 store_->SetCurrentPolicy(policies);
188 loop_.RunUntilIdle(); 186 loop_.RunUntilIdle();
189 Mock::VerifyAndClearExpectations(&observer_); 187 Mock::VerifyAndClearExpectations(&observer_);
190 188
191 // Notify when policies change. 189 // Notify when policies change.
192 const base::StringValue new_value("222"); 190 const base::StringValue new_value("222");
193 { 191 {
194 ValueStoreChangeList changes; 192 ValueStoreChangeList changes;
195 changes.push_back( 193 changes.push_back(
196 ValueStoreChange("bbb", value.DeepCopy(), new_value.DeepCopy())); 194 ValueStoreChange("bbb", value.DeepCopy(), new_value.DeepCopy()));
197 EXPECT_CALL(observer_, 195 EXPECT_CALL(observer_,
198 OnSettingsChanged(kTestExtensionId, 196 OnSettingsChanged(kTestExtensionId,
199 settings_namespace::MANAGED, 197 settings_namespace::MANAGED,
200 ValueStoreChange::ToJson(changes))); 198 ValueStoreChange::ToJson(changes)));
201 } 199 }
202 200
203 policies.Set("bbb", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, 201 policies.Set("bbb", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER,
204 policy::POLICY_SOURCE_CLOUD, new_value.DeepCopy(), nullptr); 202 new_value.DeepCopy(), NULL);
205 store_->SetCurrentPolicy(policies); 203 store_->SetCurrentPolicy(policies);
206 loop_.RunUntilIdle(); 204 loop_.RunUntilIdle();
207 Mock::VerifyAndClearExpectations(&observer_); 205 Mock::VerifyAndClearExpectations(&observer_);
208 206
209 // Notify when policies are removed. 207 // Notify when policies are removed.
210 { 208 {
211 ValueStoreChangeList changes; 209 ValueStoreChangeList changes;
212 changes.push_back(ValueStoreChange("bbb", new_value.DeepCopy(), NULL)); 210 changes.push_back(ValueStoreChange("bbb", new_value.DeepCopy(), NULL));
213 EXPECT_CALL(observer_, 211 EXPECT_CALL(observer_,
214 OnSettingsChanged(kTestExtensionId, 212 OnSettingsChanged(kTestExtensionId,
215 settings_namespace::MANAGED, 213 settings_namespace::MANAGED,
216 ValueStoreChange::ToJson(changes))); 214 ValueStoreChange::ToJson(changes)));
217 } 215 }
218 216
219 policies.Erase("bbb"); 217 policies.Erase("bbb");
220 store_->SetCurrentPolicy(policies); 218 store_->SetCurrentPolicy(policies);
221 loop_.RunUntilIdle(); 219 loop_.RunUntilIdle();
222 Mock::VerifyAndClearExpectations(&observer_); 220 Mock::VerifyAndClearExpectations(&observer_);
223 221
224 // Don't notify when there aren't any changes. 222 // Don't notify when there aren't any changes.
225 EXPECT_CALL(observer_, OnSettingsChanged(_, _, _)).Times(0); 223 EXPECT_CALL(observer_, OnSettingsChanged(_, _, _)).Times(0);
226 store_->SetCurrentPolicy(policies); 224 store_->SetCurrentPolicy(policies);
227 loop_.RunUntilIdle(); 225 loop_.RunUntilIdle();
228 Mock::VerifyAndClearExpectations(&observer_); 226 Mock::VerifyAndClearExpectations(&observer_);
229 } 227 }
230 228
231 } // namespace extensions 229 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698