| 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 "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" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 scoped_refptr<SettingsObserverList> observers_; | 117 scoped_refptr<SettingsObserverList> observers_; |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 TEST_F(PolicyValueStoreTest, DontProvideRecommendedPolicies) { | 120 TEST_F(PolicyValueStoreTest, DontProvideRecommendedPolicies) { |
| 121 policy::PolicyMap policies; | 121 policy::PolicyMap policies; |
| 122 base::FundamentalValue expected(123); | 122 base::FundamentalValue expected(123); |
| 123 policies.Set("must", policy::POLICY_LEVEL_MANDATORY, | 123 policies.Set("must", policy::POLICY_LEVEL_MANDATORY, |
| 124 policy::POLICY_SCOPE_USER, expected.DeepCopy(), NULL); | 124 policy::POLICY_SCOPE_USER, expected.DeepCopy(), NULL); |
| 125 policies.Set("may", policy::POLICY_LEVEL_RECOMMENDED, | 125 policies.Set("may", policy::POLICY_LEVEL_RECOMMENDED, |
| 126 policy::POLICY_SCOPE_USER, | 126 policy::POLICY_SCOPE_USER, |
| 127 base::Value::CreateIntegerValue(456), NULL); | 127 new base::FundamentalValue(456), NULL); |
| 128 store_->SetCurrentPolicy(policies, false); | 128 store_->SetCurrentPolicy(policies, false); |
| 129 ValueStore::ReadResult result = store_->Get(); | 129 ValueStore::ReadResult result = store_->Get(); |
| 130 ASSERT_FALSE(result->HasError()); | 130 ASSERT_FALSE(result->HasError()); |
| 131 EXPECT_EQ(1u, result->settings()->size()); | 131 EXPECT_EQ(1u, result->settings()->size()); |
| 132 base::Value* value = NULL; | 132 base::Value* value = NULL; |
| 133 EXPECT_FALSE(result->settings()->Get("may", &value)); | 133 EXPECT_FALSE(result->settings()->Get("may", &value)); |
| 134 EXPECT_TRUE(result->settings()->Get("must", &value)); | 134 EXPECT_TRUE(result->settings()->Get("must", &value)); |
| 135 EXPECT_TRUE(base::Value::Equals(&expected, value)); | 135 EXPECT_TRUE(base::Value::Equals(&expected, value)); |
| 136 } | 136 } |
| 137 | 137 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 148 EXPECT_TRUE(store_->Remove("key")->HasError()); | 148 EXPECT_TRUE(store_->Remove("key")->HasError()); |
| 149 std::vector<std::string> keys; | 149 std::vector<std::string> keys; |
| 150 keys.push_back("key"); | 150 keys.push_back("key"); |
| 151 EXPECT_TRUE(store_->Remove(keys)->HasError()); | 151 EXPECT_TRUE(store_->Remove(keys)->HasError()); |
| 152 EXPECT_TRUE(store_->Clear()->HasError()); | 152 EXPECT_TRUE(store_->Clear()->HasError()); |
| 153 } | 153 } |
| 154 | 154 |
| 155 TEST_F(PolicyValueStoreTest, NotifyOnChanges) { | 155 TEST_F(PolicyValueStoreTest, NotifyOnChanges) { |
| 156 policy::PolicyMap policies; | 156 policy::PolicyMap policies; |
| 157 policies.Set("aaa", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, | 157 policies.Set("aaa", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, |
| 158 base::Value::CreateStringValue("111"), NULL); | 158 new base::StringValue("111"), NULL); |
| 159 EXPECT_CALL(observer_, OnSettingsChanged(_, _, _)).Times(0); | 159 EXPECT_CALL(observer_, OnSettingsChanged(_, _, _)).Times(0); |
| 160 // No notification when setting the initial policy. | 160 // No notification when setting the initial policy. |
| 161 store_->SetCurrentPolicy(policies, false); | 161 store_->SetCurrentPolicy(policies, false); |
| 162 loop_.RunUntilIdle(); | 162 loop_.RunUntilIdle(); |
| 163 Mock::VerifyAndClearExpectations(&observer_); | 163 Mock::VerifyAndClearExpectations(&observer_); |
| 164 | 164 |
| 165 // And no notifications on changes when not asked for. | 165 // And no notifications on changes when not asked for. |
| 166 policies.Set("aaa", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, | 166 policies.Set("aaa", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, |
| 167 base::Value::CreateStringValue("222"), NULL); | 167 new base::StringValue("222"), NULL); |
| 168 policies.Set("bbb", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, | 168 policies.Set("bbb", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, |
| 169 base::Value::CreateStringValue("223"), NULL); | 169 new base::StringValue("223"), NULL); |
| 170 EXPECT_CALL(observer_, OnSettingsChanged(_, _, _)).Times(0); | 170 EXPECT_CALL(observer_, OnSettingsChanged(_, _, _)).Times(0); |
| 171 store_->SetCurrentPolicy(policies, false); | 171 store_->SetCurrentPolicy(policies, false); |
| 172 loop_.RunUntilIdle(); | 172 loop_.RunUntilIdle(); |
| 173 Mock::VerifyAndClearExpectations(&observer_); | 173 Mock::VerifyAndClearExpectations(&observer_); |
| 174 | 174 |
| 175 // Notify when new policies are added. | 175 // Notify when new policies are added. |
| 176 ValueStoreChangeList changes; | 176 ValueStoreChangeList changes; |
| 177 base::StringValue value("333"); | 177 base::StringValue value("333"); |
| 178 changes.push_back(ValueStoreChange("ccc", NULL, value.DeepCopy())); | 178 changes.push_back(ValueStoreChange("ccc", NULL, value.DeepCopy())); |
| 179 policies.Set("ccc", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, | 179 policies.Set("ccc", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 Mock::VerifyAndClearExpectations(&observer_); | 211 Mock::VerifyAndClearExpectations(&observer_); |
| 212 | 212 |
| 213 // Don't notify when there aren't changes. | 213 // Don't notify when there aren't changes. |
| 214 EXPECT_CALL(observer_, OnSettingsChanged(_, _, _)).Times(0); | 214 EXPECT_CALL(observer_, OnSettingsChanged(_, _, _)).Times(0); |
| 215 store_->SetCurrentPolicy(policies, true); | 215 store_->SetCurrentPolicy(policies, true); |
| 216 loop_.RunUntilIdle(); | 216 loop_.RunUntilIdle(); |
| 217 Mock::VerifyAndClearExpectations(&observer_); | 217 Mock::VerifyAndClearExpectations(&observer_); |
| 218 } | 218 } |
| 219 | 219 |
| 220 } // namespace extensions | 220 } // namespace extensions |
| OLD | NEW |