| 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/policy/cloud_policy_manager.h" | 5 #include "chrome/browser/policy/cloud_policy_manager.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 const base::ListValue* policy_value) OVERRIDE; | 46 const base::ListValue* policy_value) OVERRIDE; |
| 47 virtual void InstallDictionaryPolicy( | 47 virtual void InstallDictionaryPolicy( |
| 48 const std::string& policy_name, | 48 const std::string& policy_name, |
| 49 const base::DictionaryValue* policy_value) OVERRIDE; | 49 const base::DictionaryValue* policy_value) OVERRIDE; |
| 50 | 50 |
| 51 // Creates harnesses for mandatory and recommended levels, respectively. | 51 // Creates harnesses for mandatory and recommended levels, respectively. |
| 52 static PolicyProviderTestHarness* CreateMandatory(); | 52 static PolicyProviderTestHarness* CreateMandatory(); |
| 53 static PolicyProviderTestHarness* CreateRecommended(); | 53 static PolicyProviderTestHarness* CreateRecommended(); |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 MockCloudPolicyStore* store_; | 56 MockCloudPolicyStore store_; |
| 57 | 57 |
| 58 DISALLOW_COPY_AND_ASSIGN(TestHarness); | 58 DISALLOW_COPY_AND_ASSIGN(TestHarness); |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 TestHarness::TestHarness(PolicyLevel level) | 61 TestHarness::TestHarness(PolicyLevel level) |
| 62 : PolicyProviderTestHarness(level, POLICY_SCOPE_USER) {} | 62 : PolicyProviderTestHarness(level, POLICY_SCOPE_USER) {} |
| 63 | 63 |
| 64 TestHarness::~TestHarness() {} | 64 TestHarness::~TestHarness() {} |
| 65 | 65 |
| 66 void TestHarness::SetUp() {} | 66 void TestHarness::SetUp() {} |
| 67 | 67 |
| 68 ConfigurationPolicyProvider* TestHarness::CreateProvider( | 68 ConfigurationPolicyProvider* TestHarness::CreateProvider( |
| 69 const PolicyDefinitionList* policy_definition_list) { | 69 const PolicyDefinitionList* policy_definition_list) { |
| 70 // Create and initialize the store. | 70 // Create and initialize the store. |
| 71 store_ = new MockCloudPolicyStore(); | 71 store_.NotifyStoreLoaded(); |
| 72 store_->NotifyStoreLoaded(); | 72 ConfigurationPolicyProvider* provider = new CloudPolicyManager(&store_); |
| 73 ConfigurationPolicyProvider* provider = | 73 Mock::VerifyAndClearExpectations(&store_); |
| 74 new CloudPolicyManager(scoped_ptr<CloudPolicyStore>(store_)); | |
| 75 Mock::VerifyAndClearExpectations(store_); | |
| 76 return provider; | 74 return provider; |
| 77 } | 75 } |
| 78 | 76 |
| 79 void TestHarness::InstallEmptyPolicy() {} | 77 void TestHarness::InstallEmptyPolicy() {} |
| 80 | 78 |
| 81 void TestHarness::InstallStringPolicy(const std::string& policy_name, | 79 void TestHarness::InstallStringPolicy(const std::string& policy_name, |
| 82 const std::string& policy_value) { | 80 const std::string& policy_value) { |
| 83 store_->policy_map_.Set(policy_name, policy_level(), policy_scope(), | 81 store_.policy_map_.Set(policy_name, policy_level(), policy_scope(), |
| 84 base::Value::CreateStringValue(policy_value)); | 82 base::Value::CreateStringValue(policy_value)); |
| 85 } | 83 } |
| 86 | 84 |
| 87 void TestHarness::InstallIntegerPolicy(const std::string& policy_name, | 85 void TestHarness::InstallIntegerPolicy(const std::string& policy_name, |
| 88 int policy_value) { | 86 int policy_value) { |
| 89 store_->policy_map_.Set(policy_name, policy_level(), policy_scope(), | 87 store_.policy_map_.Set(policy_name, policy_level(), policy_scope(), |
| 90 base::Value::CreateIntegerValue(policy_value)); | 88 base::Value::CreateIntegerValue(policy_value)); |
| 91 } | 89 } |
| 92 | 90 |
| 93 void TestHarness::InstallBooleanPolicy(const std::string& policy_name, | 91 void TestHarness::InstallBooleanPolicy(const std::string& policy_name, |
| 94 bool policy_value) { | 92 bool policy_value) { |
| 95 store_->policy_map_.Set(policy_name, policy_level(), policy_scope(), | 93 store_.policy_map_.Set(policy_name, policy_level(), policy_scope(), |
| 96 base::Value::CreateBooleanValue(policy_value)); | 94 base::Value::CreateBooleanValue(policy_value)); |
| 97 } | 95 } |
| 98 | 96 |
| 99 void TestHarness::InstallStringListPolicy(const std::string& policy_name, | 97 void TestHarness::InstallStringListPolicy(const std::string& policy_name, |
| 100 const base::ListValue* policy_value) { | 98 const base::ListValue* policy_value) { |
| 101 store_->policy_map_.Set(policy_name, policy_level(), policy_scope(), | 99 store_.policy_map_.Set(policy_name, policy_level(), policy_scope(), |
| 102 policy_value->DeepCopy()); | 100 policy_value->DeepCopy()); |
| 103 } | 101 } |
| 104 | 102 |
| 105 void TestHarness::InstallDictionaryPolicy( | 103 void TestHarness::InstallDictionaryPolicy( |
| 106 const std::string& policy_name, | 104 const std::string& policy_name, |
| 107 const base::DictionaryValue* policy_value) { | 105 const base::DictionaryValue* policy_value) { |
| 108 store_->policy_map_.Set(policy_name, policy_level(), policy_scope(), | 106 store_.policy_map_.Set(policy_name, policy_level(), policy_scope(), |
| 109 policy_value->DeepCopy()); | 107 policy_value->DeepCopy()); |
| 110 } | 108 } |
| 111 | 109 |
| 112 // static | 110 // static |
| 113 PolicyProviderTestHarness* TestHarness::CreateMandatory() { | 111 PolicyProviderTestHarness* TestHarness::CreateMandatory() { |
| 114 return new TestHarness(POLICY_LEVEL_MANDATORY); | 112 return new TestHarness(POLICY_LEVEL_MANDATORY); |
| 115 } | 113 } |
| 116 | 114 |
| 117 // static | 115 // static |
| 118 PolicyProviderTestHarness* TestHarness::CreateRecommended() { | 116 PolicyProviderTestHarness* TestHarness::CreateRecommended() { |
| 119 return new TestHarness(POLICY_LEVEL_RECOMMENDED); | 117 return new TestHarness(POLICY_LEVEL_RECOMMENDED); |
| 120 } | 118 } |
| 121 | 119 |
| 122 // Instantiate abstract test case for basic policy reading tests. | 120 // Instantiate abstract test case for basic policy reading tests. |
| 123 INSTANTIATE_TEST_CASE_P( | 121 INSTANTIATE_TEST_CASE_P( |
| 124 UserCloudPolicyManagerProviderTest, | 122 UserCloudPolicyManagerProviderTest, |
| 125 ConfigurationPolicyProviderTest, | 123 ConfigurationPolicyProviderTest, |
| 126 testing::Values(TestHarness::CreateMandatory, | 124 testing::Values(TestHarness::CreateMandatory, |
| 127 TestHarness::CreateRecommended)); | 125 TestHarness::CreateRecommended)); |
| 128 | 126 |
| 129 class TestCloudPolicyManager : public CloudPolicyManager { | 127 class TestCloudPolicyManager : public CloudPolicyManager { |
| 130 public: | 128 public: |
| 131 explicit TestCloudPolicyManager(scoped_ptr<CloudPolicyStore> store) | 129 explicit TestCloudPolicyManager(CloudPolicyStore* store) |
| 132 : CloudPolicyManager(store.Pass()) {} | 130 : CloudPolicyManager(store) {} |
| 133 virtual ~TestCloudPolicyManager() {} | 131 virtual ~TestCloudPolicyManager() {} |
| 134 | 132 |
| 135 // Publish the protected members for testing. | 133 // Publish the protected members for testing. |
| 136 using CloudPolicyManager::InitializeService; | 134 using CloudPolicyManager::InitializeService; |
| 137 using CloudPolicyManager::ShutdownService; | 135 using CloudPolicyManager::ShutdownService; |
| 138 using CloudPolicyManager::StartRefreshScheduler; | 136 using CloudPolicyManager::StartRefreshScheduler; |
| 139 using CloudPolicyManager::CheckAndPublishPolicy; | 137 using CloudPolicyManager::CheckAndPublishPolicy; |
| 140 | 138 |
| 141 private: | 139 private: |
| 142 DISALLOW_COPY_AND_ASSIGN(TestCloudPolicyManager); | 140 DISALLOW_COPY_AND_ASSIGN(TestCloudPolicyManager); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 154 // Set up a policy map for testing. | 152 // Set up a policy map for testing. |
| 155 policy_map_.Set("key", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 153 policy_map_.Set("key", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 156 base::Value::CreateStringValue("value")); | 154 base::Value::CreateStringValue("value")); |
| 157 expected_bundle_.Get(POLICY_DOMAIN_CHROME, std::string()).CopyFrom( | 155 expected_bundle_.Get(POLICY_DOMAIN_CHROME, std::string()).CopyFrom( |
| 158 policy_map_); | 156 policy_map_); |
| 159 | 157 |
| 160 policy_.payload().mutable_homepagelocation()->set_value( | 158 policy_.payload().mutable_homepagelocation()->set_value( |
| 161 "http://www.example.com"); | 159 "http://www.example.com"); |
| 162 policy_.Build(); | 160 policy_.Build(); |
| 163 | 161 |
| 164 store_ = new MockCloudPolicyStore(); | 162 EXPECT_CALL(store_, Load()); |
| 165 EXPECT_CALL(*store_, Load()); | 163 manager_.reset(new TestCloudPolicyManager(&store_)); |
| 166 manager_.reset( | |
| 167 new TestCloudPolicyManager(scoped_ptr<CloudPolicyStore>(store_))); | |
| 168 manager_->Init(); | 164 manager_->Init(); |
| 169 Mock::VerifyAndClearExpectations(store_); | 165 Mock::VerifyAndClearExpectations(&store_); |
| 170 manager_->AddObserver(&observer_); | 166 manager_->AddObserver(&observer_); |
| 171 } | 167 } |
| 172 | 168 |
| 173 virtual void TearDown() OVERRIDE { | 169 virtual void TearDown() OVERRIDE { |
| 174 manager_->RemoveObserver(&observer_); | 170 manager_->RemoveObserver(&observer_); |
| 175 manager_->Shutdown(); | 171 manager_->Shutdown(); |
| 176 } | 172 } |
| 177 | 173 |
| 178 // Required by the refresh scheduler that's created by the manager. | 174 // Required by the refresh scheduler that's created by the manager. |
| 179 MessageLoop loop_; | 175 MessageLoop loop_; |
| 180 | 176 |
| 181 // Testing policy. | 177 // Testing policy. |
| 182 UserPolicyBuilder policy_; | 178 UserPolicyBuilder policy_; |
| 183 PolicyMap policy_map_; | 179 PolicyMap policy_map_; |
| 184 PolicyBundle expected_bundle_; | 180 PolicyBundle expected_bundle_; |
| 185 | 181 |
| 186 // Policy infrastructure. | 182 // Policy infrastructure. |
| 187 MockConfigurationPolicyObserver observer_; | 183 MockConfigurationPolicyObserver observer_; |
| 188 MockCloudPolicyStore* store_; | 184 MockCloudPolicyStore store_; |
| 189 scoped_ptr<TestCloudPolicyManager> manager_; | 185 scoped_ptr<TestCloudPolicyManager> manager_; |
| 190 | 186 |
| 191 private: | 187 private: |
| 192 DISALLOW_COPY_AND_ASSIGN(CloudPolicyManagerTest); | 188 DISALLOW_COPY_AND_ASSIGN(CloudPolicyManagerTest); |
| 193 }; | 189 }; |
| 194 | 190 |
| 195 TEST_F(CloudPolicyManagerTest, InitAndShutdown) { | 191 TEST_F(CloudPolicyManagerTest, InitAndShutdown) { |
| 196 PolicyBundle empty_bundle; | 192 PolicyBundle empty_bundle; |
| 197 EXPECT_TRUE(empty_bundle.Equals(manager_->policies())); | 193 EXPECT_TRUE(empty_bundle.Equals(manager_->policies())); |
| 198 EXPECT_FALSE(manager_->IsInitializationComplete()); | 194 EXPECT_FALSE(manager_->IsInitializationComplete()); |
| 199 | 195 |
| 200 EXPECT_CALL(observer_, OnUpdatePolicy(_)).Times(0); | 196 EXPECT_CALL(observer_, OnUpdatePolicy(_)).Times(0); |
| 201 manager_->CheckAndPublishPolicy(); | 197 manager_->CheckAndPublishPolicy(); |
| 202 Mock::VerifyAndClearExpectations(&observer_); | 198 Mock::VerifyAndClearExpectations(&observer_); |
| 203 | 199 |
| 204 store_->policy_map_.CopyFrom(policy_map_); | 200 store_.policy_map_.CopyFrom(policy_map_); |
| 205 store_->policy_.reset(new em::PolicyData(policy_.policy_data())); | 201 store_.policy_.reset(new em::PolicyData(policy_.policy_data())); |
| 206 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); | 202 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); |
| 207 store_->NotifyStoreLoaded(); | 203 store_.NotifyStoreLoaded(); |
| 208 Mock::VerifyAndClearExpectations(&observer_); | 204 Mock::VerifyAndClearExpectations(&observer_); |
| 209 EXPECT_TRUE(expected_bundle_.Equals(manager_->policies())); | 205 EXPECT_TRUE(expected_bundle_.Equals(manager_->policies())); |
| 210 EXPECT_TRUE(manager_->IsInitializationComplete()); | 206 EXPECT_TRUE(manager_->IsInitializationComplete()); |
| 211 | 207 |
| 212 MockCloudPolicyClient* client = new MockCloudPolicyClient(); | 208 MockCloudPolicyClient* client = new MockCloudPolicyClient(); |
| 213 EXPECT_CALL(*client, SetupRegistration(_, _)); | 209 EXPECT_CALL(*client, SetupRegistration(_, _)); |
| 214 manager_->InitializeService(scoped_ptr<CloudPolicyClient>(client)); | 210 manager_->InitializeService(scoped_ptr<CloudPolicyClient>(client)); |
| 215 Mock::VerifyAndClearExpectations(client); | 211 Mock::VerifyAndClearExpectations(client); |
| 216 EXPECT_TRUE(manager_->cloud_policy_client()); | 212 EXPECT_TRUE(manager_->cloud_policy_client()); |
| 217 EXPECT_TRUE(manager_->cloud_policy_service()); | 213 EXPECT_TRUE(manager_->cloud_policy_service()); |
| 218 | 214 |
| 219 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); | 215 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); |
| 220 manager_->CheckAndPublishPolicy(); | 216 manager_->CheckAndPublishPolicy(); |
| 221 Mock::VerifyAndClearExpectations(&observer_); | 217 Mock::VerifyAndClearExpectations(&observer_); |
| 222 | 218 |
| 223 manager_->ShutdownService(); | 219 manager_->ShutdownService(); |
| 224 EXPECT_FALSE(manager_->cloud_policy_client()); | 220 EXPECT_FALSE(manager_->cloud_policy_client()); |
| 225 EXPECT_FALSE(manager_->cloud_policy_service()); | 221 EXPECT_FALSE(manager_->cloud_policy_service()); |
| 226 } | 222 } |
| 227 | 223 |
| 228 TEST_F(CloudPolicyManagerTest, RegistrationAndFetch) { | 224 TEST_F(CloudPolicyManagerTest, RegistrationAndFetch) { |
| 229 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); | 225 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); |
| 230 store_->NotifyStoreLoaded(); | 226 store_.NotifyStoreLoaded(); |
| 231 Mock::VerifyAndClearExpectations(&observer_); | 227 Mock::VerifyAndClearExpectations(&observer_); |
| 232 EXPECT_TRUE(manager_->IsInitializationComplete()); | 228 EXPECT_TRUE(manager_->IsInitializationComplete()); |
| 233 | 229 |
| 234 MockCloudPolicyClient* client = new MockCloudPolicyClient(); | 230 MockCloudPolicyClient* client = new MockCloudPolicyClient(); |
| 235 manager_->InitializeService(scoped_ptr<CloudPolicyClient>(client)); | 231 manager_->InitializeService(scoped_ptr<CloudPolicyClient>(client)); |
| 236 | 232 |
| 237 client->SetDMToken(policy_.policy_data().request_token()); | 233 client->SetDMToken(policy_.policy_data().request_token()); |
| 238 client->NotifyRegistrationStateChanged(); | 234 client->NotifyRegistrationStateChanged(); |
| 239 | 235 |
| 240 client->SetPolicy(policy_.policy()); | 236 client->SetPolicy(policy_.policy()); |
| 241 EXPECT_CALL(*store_, Store(ProtoMatches(policy_.policy()))); | 237 EXPECT_CALL(store_, Store(ProtoMatches(policy_.policy()))); |
| 242 client->NotifyPolicyFetched(); | 238 client->NotifyPolicyFetched(); |
| 243 Mock::VerifyAndClearExpectations(store_); | 239 Mock::VerifyAndClearExpectations(&store_); |
| 244 | 240 |
| 245 store_->policy_map_.CopyFrom(policy_map_); | 241 store_.policy_map_.CopyFrom(policy_map_); |
| 246 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); | 242 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); |
| 247 store_->NotifyStoreLoaded(); | 243 store_.NotifyStoreLoaded(); |
| 248 Mock::VerifyAndClearExpectations(&observer_); | 244 Mock::VerifyAndClearExpectations(&observer_); |
| 249 EXPECT_TRUE(expected_bundle_.Equals(manager_->policies())); | 245 EXPECT_TRUE(expected_bundle_.Equals(manager_->policies())); |
| 250 } | 246 } |
| 251 | 247 |
| 252 TEST_F(CloudPolicyManagerTest, Update) { | 248 TEST_F(CloudPolicyManagerTest, Update) { |
| 253 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); | 249 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); |
| 254 store_->NotifyStoreLoaded(); | 250 store_.NotifyStoreLoaded(); |
| 255 Mock::VerifyAndClearExpectations(&observer_); | 251 Mock::VerifyAndClearExpectations(&observer_); |
| 256 EXPECT_TRUE(manager_->IsInitializationComplete()); | 252 EXPECT_TRUE(manager_->IsInitializationComplete()); |
| 257 PolicyBundle empty_bundle; | 253 PolicyBundle empty_bundle; |
| 258 EXPECT_TRUE(empty_bundle.Equals(manager_->policies())); | 254 EXPECT_TRUE(empty_bundle.Equals(manager_->policies())); |
| 259 | 255 |
| 260 store_->policy_map_.CopyFrom(policy_map_); | 256 store_.policy_map_.CopyFrom(policy_map_); |
| 261 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); | 257 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); |
| 262 store_->NotifyStoreLoaded(); | 258 store_.NotifyStoreLoaded(); |
| 263 Mock::VerifyAndClearExpectations(&observer_); | 259 Mock::VerifyAndClearExpectations(&observer_); |
| 264 EXPECT_TRUE(expected_bundle_.Equals(manager_->policies())); | 260 EXPECT_TRUE(expected_bundle_.Equals(manager_->policies())); |
| 265 EXPECT_TRUE(manager_->IsInitializationComplete()); | 261 EXPECT_TRUE(manager_->IsInitializationComplete()); |
| 266 } | 262 } |
| 267 | 263 |
| 268 TEST_F(CloudPolicyManagerTest, RefreshNotRegistered) { | 264 TEST_F(CloudPolicyManagerTest, RefreshNotRegistered) { |
| 269 MockCloudPolicyClient* client = new MockCloudPolicyClient(); | 265 MockCloudPolicyClient* client = new MockCloudPolicyClient(); |
| 270 manager_->InitializeService(scoped_ptr<CloudPolicyClient>(client)); | 266 manager_->InitializeService(scoped_ptr<CloudPolicyClient>(client)); |
| 271 | 267 |
| 272 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); | 268 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); |
| 273 store_->NotifyStoreLoaded(); | 269 store_.NotifyStoreLoaded(); |
| 274 Mock::VerifyAndClearExpectations(&observer_); | 270 Mock::VerifyAndClearExpectations(&observer_); |
| 275 | 271 |
| 276 // A refresh on a non-registered store should not block. | 272 // A refresh on a non-registered store should not block. |
| 277 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); | 273 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); |
| 278 manager_->RefreshPolicies(); | 274 manager_->RefreshPolicies(); |
| 279 Mock::VerifyAndClearExpectations(&observer_); | 275 Mock::VerifyAndClearExpectations(&observer_); |
| 280 } | 276 } |
| 281 | 277 |
| 282 TEST_F(CloudPolicyManagerTest, RefreshSuccessful) { | 278 TEST_F(CloudPolicyManagerTest, RefreshSuccessful) { |
| 283 MockCloudPolicyClient* client = new MockCloudPolicyClient(); | 279 MockCloudPolicyClient* client = new MockCloudPolicyClient(); |
| 284 manager_->InitializeService(scoped_ptr<CloudPolicyClient>(client)); | 280 manager_->InitializeService(scoped_ptr<CloudPolicyClient>(client)); |
| 285 | 281 |
| 286 // Simulate a store load. | 282 // Simulate a store load. |
| 287 store_->policy_.reset(new em::PolicyData(policy_.policy_data())); | 283 store_.policy_.reset(new em::PolicyData(policy_.policy_data())); |
| 288 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); | 284 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); |
| 289 EXPECT_CALL(*client, SetupRegistration(_, _)); | 285 EXPECT_CALL(*client, SetupRegistration(_, _)); |
| 290 store_->NotifyStoreLoaded(); | 286 store_.NotifyStoreLoaded(); |
| 291 Mock::VerifyAndClearExpectations(client); | 287 Mock::VerifyAndClearExpectations(client); |
| 292 Mock::VerifyAndClearExpectations(&observer_); | 288 Mock::VerifyAndClearExpectations(&observer_); |
| 293 | 289 |
| 294 // Acknowledge registration. | 290 // Acknowledge registration. |
| 295 client->SetDMToken(policy_.policy_data().request_token()); | 291 client->SetDMToken(policy_.policy_data().request_token()); |
| 296 | 292 |
| 297 // Start a refresh. | 293 // Start a refresh. |
| 298 EXPECT_CALL(observer_, OnUpdatePolicy(_)).Times(0); | 294 EXPECT_CALL(observer_, OnUpdatePolicy(_)).Times(0); |
| 299 EXPECT_CALL(*client, FetchPolicy()); | 295 EXPECT_CALL(*client, FetchPolicy()); |
| 300 manager_->RefreshPolicies(); | 296 manager_->RefreshPolicies(); |
| 301 Mock::VerifyAndClearExpectations(client); | 297 Mock::VerifyAndClearExpectations(client); |
| 302 Mock::VerifyAndClearExpectations(&observer_); | 298 Mock::VerifyAndClearExpectations(&observer_); |
| 303 store_->policy_map_.CopyFrom(policy_map_); | 299 store_.policy_map_.CopyFrom(policy_map_); |
| 304 | 300 |
| 305 // A stray reload should be suppressed until the refresh completes. | 301 // A stray reload should be suppressed until the refresh completes. |
| 306 EXPECT_CALL(observer_, OnUpdatePolicy(_)).Times(0); | 302 EXPECT_CALL(observer_, OnUpdatePolicy(_)).Times(0); |
| 307 store_->NotifyStoreLoaded(); | 303 store_.NotifyStoreLoaded(); |
| 308 Mock::VerifyAndClearExpectations(&observer_); | 304 Mock::VerifyAndClearExpectations(&observer_); |
| 309 | 305 |
| 310 // Respond to the policy fetch, which should trigger a write to |store_|. | 306 // Respond to the policy fetch, which should trigger a write to |store_|. |
| 311 EXPECT_CALL(observer_, OnUpdatePolicy(_)).Times(0); | 307 EXPECT_CALL(observer_, OnUpdatePolicy(_)).Times(0); |
| 312 EXPECT_CALL(*store_, Store(_)); | 308 EXPECT_CALL(store_, Store(_)); |
| 313 client->SetPolicy(policy_.policy()); | 309 client->SetPolicy(policy_.policy()); |
| 314 client->NotifyPolicyFetched(); | 310 client->NotifyPolicyFetched(); |
| 315 Mock::VerifyAndClearExpectations(&observer_); | 311 Mock::VerifyAndClearExpectations(&observer_); |
| 316 Mock::VerifyAndClearExpectations(store_); | 312 Mock::VerifyAndClearExpectations(&store_); |
| 317 | 313 |
| 318 // The load notification from |store_| should trigger the policy update. | 314 // The load notification from |store_| should trigger the policy update. |
| 319 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); | 315 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); |
| 320 store_->NotifyStoreLoaded(); | 316 store_.NotifyStoreLoaded(); |
| 321 EXPECT_TRUE(expected_bundle_.Equals(manager_->policies())); | 317 EXPECT_TRUE(expected_bundle_.Equals(manager_->policies())); |
| 322 Mock::VerifyAndClearExpectations(&observer_); | 318 Mock::VerifyAndClearExpectations(&observer_); |
| 323 } | 319 } |
| 324 | 320 |
| 325 } // namespace | 321 } // namespace |
| 326 } // namespace policy | 322 } // namespace policy |
| OLD | NEW |