| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/component_cloud_policy_service.h" | 5 #include "chrome/browser/policy/cloud/component_cloud_policy_service.h" |
| 6 | 6 |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/sha1.h" | 11 #include "base/sha1.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" | 15 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" |
| 16 #include "chrome/browser/policy/cloud/mock_cloud_policy_client.h" | 16 #include "chrome/browser/policy/cloud/mock_cloud_policy_client.h" |
| 17 #include "chrome/browser/policy/cloud/mock_cloud_policy_store.h" | 17 #include "chrome/browser/policy/cloud/mock_cloud_policy_store.h" |
| 18 #include "chrome/browser/policy/cloud/policy_builder.h" | 18 #include "chrome/browser/policy/cloud/policy_builder.h" |
| 19 #include "chrome/browser/policy/cloud/resource_cache.h" | 19 #include "chrome/browser/policy/cloud/resource_cache.h" |
| 20 #include "chrome/browser/policy/policy_domain_descriptor.h" |
| 20 #include "chrome/browser/policy/policy_map.h" | 21 #include "chrome/browser/policy/policy_map.h" |
| 22 #include "chrome/browser/policy/policy_schema.h" |
| 21 #include "chrome/browser/policy/policy_types.h" | 23 #include "chrome/browser/policy/policy_types.h" |
| 22 #include "chrome/browser/policy/proto/cloud/chrome_extension_policy.pb.h" | 24 #include "chrome/browser/policy/proto/cloud/chrome_extension_policy.pb.h" |
| 23 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" | 25 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" |
| 24 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/test/test_browser_thread.h" | 27 #include "content/public/test/test_browser_thread.h" |
| 26 #include "net/url_request/test_url_fetcher_factory.h" | 28 #include "net/url_request/test_url_fetcher_factory.h" |
| 27 #include "net/url_request/url_fetcher_delegate.h" | 29 #include "net/url_request/url_fetcher_delegate.h" |
| 28 #include "net/url_request/url_request_context.h" | 30 #include "net/url_request/url_request_context.h" |
| 29 #include "net/url_request/url_request_context_getter.h" | 31 #include "net/url_request/url_request_context_getter.h" |
| 30 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 32 | 34 |
| 33 namespace em = enterprise_management; | 35 namespace em = enterprise_management; |
| 34 | 36 |
| 35 using testing::Mock; | 37 using testing::Mock; |
| 36 | 38 |
| 37 namespace policy { | 39 namespace policy { |
| 38 | 40 |
| 39 namespace { | 41 namespace { |
| 40 | 42 |
| 41 const char kTestExtension[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 43 const char kTestExtension[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 42 const char kTestExtension2[] = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; | 44 const char kTestExtension2[] = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; |
| 43 const char kTestExtension3[] = "cccccccccccccccccccccccccccccccc"; | 45 const char kTestExtension3[] = "cccccccccccccccccccccccccccccccc"; |
| 44 const char kTestDownload[] = "http://example.com/getpolicy?id=123"; | 46 const char kTestDownload[] = "http://example.com/getpolicy?id=123"; |
| 45 const char kTestDownload2[] = "http://example.com/getpolicy?id=456"; | 47 const char kTestDownload2[] = "http://example.com/getpolicy?id=456"; |
| 48 |
| 46 const char kTestPolicy[] = | 49 const char kTestPolicy[] = |
| 47 "{" | 50 "{" |
| 48 " \"Name\": {" | 51 " \"Name\": {" |
| 49 " \"Value\": \"disabled\"" | 52 " \"Value\": \"disabled\"" |
| 50 " }," | 53 " }," |
| 51 " \"Second\": {" | 54 " \"Second\": {" |
| 52 " \"Value\": \"maybe\"," | 55 " \"Value\": \"maybe\"," |
| 53 " \"Level\": \"Recommended\"" | 56 " \"Level\": \"Recommended\"" |
| 54 " }" | 57 " }" |
| 55 "}"; | 58 "}"; |
| 56 | 59 |
| 60 const char kTestSchema[] = |
| 61 "{" |
| 62 " \"$schema\": \"http://json-schema.org/draft-03/schema#\"," |
| 63 " \"type\": \"object\"," |
| 64 " \"properties\": {" |
| 65 " \"Name\": { \"type\": \"string\" }," |
| 66 " \"Second\": { \"type\": \"string\" }" |
| 67 " }" |
| 68 "}"; |
| 69 |
| 57 class MockComponentCloudPolicyDelegate | 70 class MockComponentCloudPolicyDelegate |
| 58 : public ComponentCloudPolicyService::Delegate { | 71 : public ComponentCloudPolicyService::Delegate { |
| 59 public: | 72 public: |
| 60 virtual ~MockComponentCloudPolicyDelegate() {} | 73 virtual ~MockComponentCloudPolicyDelegate() {} |
| 61 | 74 |
| 62 MOCK_METHOD0(OnComponentCloudPolicyRefreshNeeded, void()); | 75 MOCK_METHOD0(OnComponentCloudPolicyRefreshNeeded, void()); |
| 63 MOCK_METHOD0(OnComponentCloudPolicyUpdated, void()); | 76 MOCK_METHOD0(OnComponentCloudPolicyUpdated, void()); |
| 64 }; | 77 }; |
| 65 | 78 |
| 66 class TestURLRequestContextGetter : public net::URLRequestContextGetter { | 79 class TestURLRequestContextGetter : public net::URLRequestContextGetter { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 scoped_ptr<em::PolicyFetchResponse> CreateResponse() { | 182 scoped_ptr<em::PolicyFetchResponse> CreateResponse() { |
| 170 builder_.Build(); | 183 builder_.Build(); |
| 171 return make_scoped_ptr(new em::PolicyFetchResponse(builder_.policy())); | 184 return make_scoped_ptr(new em::PolicyFetchResponse(builder_.policy())); |
| 172 } | 185 } |
| 173 | 186 |
| 174 std::string CreateSerializedResponse() { | 187 std::string CreateSerializedResponse() { |
| 175 builder_.Build(); | 188 builder_.Build(); |
| 176 return builder_.GetBlob(); | 189 return builder_.GetBlob(); |
| 177 } | 190 } |
| 178 | 191 |
| 192 scoped_ptr<PolicySchema> CreateTestSchema() { |
| 193 std::string error; |
| 194 scoped_ptr<PolicySchema> schema = PolicySchema::Parse(kTestSchema, &error); |
| 195 EXPECT_TRUE(schema) << error; |
| 196 return schema.Pass(); |
| 197 } |
| 198 |
| 179 MessageLoop loop_; | 199 MessageLoop loop_; |
| 180 content::TestBrowserThread ui_thread_; | 200 content::TestBrowserThread ui_thread_; |
| 181 content::TestBrowserThread file_thread_; | 201 content::TestBrowserThread file_thread_; |
| 182 base::ScopedTempDir temp_dir_; | 202 base::ScopedTempDir temp_dir_; |
| 183 scoped_refptr<TestURLRequestContextGetter> request_context_; | 203 scoped_refptr<TestURLRequestContextGetter> request_context_; |
| 184 net::TestURLFetcherFactory fetcher_factory_; | 204 net::TestURLFetcherFactory fetcher_factory_; |
| 185 MockComponentCloudPolicyDelegate delegate_; | 205 MockComponentCloudPolicyDelegate delegate_; |
| 186 // |cache_| is owned by the |service_| and is invalid once the |service_| | 206 // |cache_| is owned by the |service_| and is invalid once the |service_| |
| 187 // is destroyed. | 207 // is destroyed. |
| 188 ResourceCache* cache_; | 208 ResourceCache* cache_; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 std::map<std::string, std::string> contents; | 263 std::map<std::string, std::string> contents; |
| 244 cache_->LoadAllSubkeys(ComponentCloudPolicyService::kComponentNamespaceCache, | 264 cache_->LoadAllSubkeys(ComponentCloudPolicyService::kComponentNamespaceCache, |
| 245 &contents); | 265 &contents); |
| 246 ASSERT_EQ(1u, contents.size()); | 266 ASSERT_EQ(1u, contents.size()); |
| 247 EXPECT_EQ(std::string(dm_protocol::kChromeExtensionPolicyType), | 267 EXPECT_EQ(std::string(dm_protocol::kChromeExtensionPolicyType), |
| 248 contents.begin()->first); | 268 contents.begin()->first); |
| 249 } | 269 } |
| 250 | 270 |
| 251 TEST_F(ComponentCloudPolicyServiceTest, ConnectAfterRegister) { | 271 TEST_F(ComponentCloudPolicyServiceTest, ConnectAfterRegister) { |
| 252 // Add some components. | 272 // Add some components. |
| 253 std::set<std::string> components; | 273 scoped_refptr<PolicyDomainDescriptor> descriptor = new PolicyDomainDescriptor( |
| 254 components.insert(kTestExtension); | 274 POLICY_DOMAIN_EXTENSIONS); |
| 255 components.insert(kTestExtension2); | 275 descriptor->RegisterComponent(kTestExtension, CreateTestSchema()); |
| 256 service_->RegisterPolicyDomain(POLICY_DOMAIN_EXTENSIONS, components); | 276 descriptor->RegisterComponent(kTestExtension2, CreateTestSchema()); |
| 277 service_->RegisterPolicyDomain(descriptor); |
| 257 | 278 |
| 258 // Now connect the client. | 279 // Now connect the client. |
| 259 EXPECT_TRUE(client_.namespaces_to_fetch_.empty()); | 280 EXPECT_TRUE(client_.namespaces_to_fetch_.empty()); |
| 260 service_->Connect(&client_, request_context_); | 281 service_->Connect(&client_, request_context_); |
| 261 EXPECT_TRUE(client_.namespaces_to_fetch_.empty()); | 282 EXPECT_TRUE(client_.namespaces_to_fetch_.empty()); |
| 262 | 283 |
| 263 // It receives the namespaces once the backend is initialized. | 284 // It receives the namespaces once the backend is initialized. |
| 264 LoadStore(); | 285 LoadStore(); |
| 265 std::set<PolicyNamespaceKey> set; | 286 std::set<PolicyNamespaceKey> set; |
| 266 set.insert(PolicyNamespaceKey(dm_protocol::kChromeExtensionPolicyType, | 287 set.insert(PolicyNamespaceKey(dm_protocol::kChromeExtensionPolicyType, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 281 PickleIterator pickit(pickle); | 302 PickleIterator pickit(pickle); |
| 282 std::string value0; | 303 std::string value0; |
| 283 std::string value1; | 304 std::string value1; |
| 284 std::string tmp; | 305 std::string tmp; |
| 285 ASSERT_TRUE(pickit.ReadString(&value0)); | 306 ASSERT_TRUE(pickit.ReadString(&value0)); |
| 286 ASSERT_TRUE(pickit.ReadString(&value1)); | 307 ASSERT_TRUE(pickit.ReadString(&value1)); |
| 287 EXPECT_FALSE(pickit.ReadString(&tmp)); | 308 EXPECT_FALSE(pickit.ReadString(&tmp)); |
| 288 std::set<std::string> unpickled; | 309 std::set<std::string> unpickled; |
| 289 unpickled.insert(value0); | 310 unpickled.insert(value0); |
| 290 unpickled.insert(value1); | 311 unpickled.insert(value1); |
| 291 EXPECT_EQ(components, unpickled); | 312 |
| 313 std::set<std::string> expected_components; |
| 314 expected_components.insert(kTestExtension); |
| 315 expected_components.insert(kTestExtension2); |
| 316 |
| 317 EXPECT_EQ(expected_components, unpickled); |
| 292 } | 318 } |
| 293 | 319 |
| 294 TEST_F(ComponentCloudPolicyServiceTest, StoreReadyAfterConnectAndRegister) { | 320 TEST_F(ComponentCloudPolicyServiceTest, StoreReadyAfterConnectAndRegister) { |
| 295 // Add some previous data to the cache. | 321 // Add some previous data to the cache. |
| 296 PopulateCache(); | 322 PopulateCache(); |
| 297 | 323 |
| 298 // Add some components. | 324 // Add some components. |
| 299 std::set<std::string> components; | 325 scoped_refptr<PolicyDomainDescriptor> descriptor = new PolicyDomainDescriptor( |
| 300 components.insert(kTestExtension); | 326 POLICY_DOMAIN_EXTENSIONS); |
| 301 service_->RegisterPolicyDomain(POLICY_DOMAIN_EXTENSIONS, components); | 327 descriptor->RegisterComponent(kTestExtension, CreateTestSchema()); |
| 328 service_->RegisterPolicyDomain(descriptor); |
| 302 | 329 |
| 303 // And connect the client. Make the client have some policies, with a new | 330 // And connect the client. Make the client have some policies, with a new |
| 304 // download_url. | 331 // download_url. |
| 305 builder_.payload().set_download_url(kTestDownload2); | 332 builder_.payload().set_download_url(kTestDownload2); |
| 306 client_.SetPolicy(PolicyNamespaceKey(dm_protocol::kChromeExtensionPolicyType, | 333 client_.SetPolicy(PolicyNamespaceKey(dm_protocol::kChromeExtensionPolicyType, |
| 307 kTestExtension), | 334 kTestExtension), |
| 308 *CreateResponse()); | 335 *CreateResponse()); |
| 309 service_->Connect(&client_, request_context_); | 336 service_->Connect(&client_, request_context_); |
| 310 | 337 |
| 311 // Now make the store ready. | 338 // Now make the store ready. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 327 EXPECT_EQ(GURL(kTestDownload2), fetcher->GetOriginalURL()); | 354 EXPECT_EQ(GURL(kTestDownload2), fetcher->GetOriginalURL()); |
| 328 } | 355 } |
| 329 | 356 |
| 330 TEST_F(ComponentCloudPolicyServiceTest, ConnectThenRegisterThenStoreReady) { | 357 TEST_F(ComponentCloudPolicyServiceTest, ConnectThenRegisterThenStoreReady) { |
| 331 // Connect right after creating the service. | 358 // Connect right after creating the service. |
| 332 service_->Connect(&client_, request_context_); | 359 service_->Connect(&client_, request_context_); |
| 333 | 360 |
| 334 // Now register the current components, before the backend has been | 361 // Now register the current components, before the backend has been |
| 335 // initialized. | 362 // initialized. |
| 336 EXPECT_TRUE(client_.namespaces_to_fetch_.empty()); | 363 EXPECT_TRUE(client_.namespaces_to_fetch_.empty()); |
| 337 std::set<std::string> components; | 364 scoped_refptr<PolicyDomainDescriptor> descriptor = new PolicyDomainDescriptor( |
| 338 components.insert(kTestExtension); | 365 POLICY_DOMAIN_EXTENSIONS); |
| 339 service_->RegisterPolicyDomain(POLICY_DOMAIN_EXTENSIONS, components); | 366 descriptor->RegisterComponent(kTestExtension, CreateTestSchema()); |
| 367 service_->RegisterPolicyDomain(descriptor); |
| 340 EXPECT_TRUE(client_.namespaces_to_fetch_.empty()); | 368 EXPECT_TRUE(client_.namespaces_to_fetch_.empty()); |
| 341 | 369 |
| 342 // Now load the store. The client gets the namespaces. | 370 // Now load the store. The client gets the namespaces. |
| 343 LoadStore(); | 371 LoadStore(); |
| 344 std::set<PolicyNamespaceKey> set; | 372 std::set<PolicyNamespaceKey> set; |
| 345 set.insert(PolicyNamespaceKey(dm_protocol::kChromeExtensionPolicyType, | 373 set.insert(PolicyNamespaceKey(dm_protocol::kChromeExtensionPolicyType, |
| 346 kTestExtension)); | 374 kTestExtension)); |
| 347 EXPECT_EQ(set, client_.namespaces_to_fetch_); | 375 EXPECT_EQ(set, client_.namespaces_to_fetch_); |
| 348 } | 376 } |
| 349 | 377 |
| 350 TEST_F(ComponentCloudPolicyServiceTest, FetchPolicy) { | 378 TEST_F(ComponentCloudPolicyServiceTest, FetchPolicy) { |
| 351 // Initialize the store and create the backend, and connect the client. | 379 // Initialize the store and create the backend, and connect the client. |
| 352 LoadStore(); | 380 LoadStore(); |
| 353 // A refresh is not needed, because no components were found. | 381 // A refresh is not needed, because no components were found. |
| 354 EXPECT_CALL(delegate_, OnComponentCloudPolicyRefreshNeeded()).Times(0); | 382 EXPECT_CALL(delegate_, OnComponentCloudPolicyRefreshNeeded()).Times(0); |
| 355 service_->Connect(&client_, request_context_); | 383 service_->Connect(&client_, request_context_); |
| 356 Mock::VerifyAndClearExpectations(&delegate_); | 384 Mock::VerifyAndClearExpectations(&delegate_); |
| 357 | 385 |
| 358 // Register the components to fetch. | 386 // Register the components to fetch. |
| 359 std::set<std::string> components; | 387 scoped_refptr<PolicyDomainDescriptor> descriptor = new PolicyDomainDescriptor( |
| 360 components.insert(kTestExtension); | 388 POLICY_DOMAIN_EXTENSIONS); |
| 389 descriptor->RegisterComponent(kTestExtension, CreateTestSchema()); |
| 361 EXPECT_CALL(delegate_, OnComponentCloudPolicyRefreshNeeded()); | 390 EXPECT_CALL(delegate_, OnComponentCloudPolicyRefreshNeeded()); |
| 362 service_->RegisterPolicyDomain(POLICY_DOMAIN_EXTENSIONS, components); | 391 service_->RegisterPolicyDomain(descriptor); |
| 363 Mock::VerifyAndClearExpectations(&delegate_); | 392 Mock::VerifyAndClearExpectations(&delegate_); |
| 364 | 393 |
| 365 // Send back a fake policy fetch response. | 394 // Send back a fake policy fetch response. |
| 366 client_.SetPolicy(PolicyNamespaceKey(dm_protocol::kChromeExtensionPolicyType, | 395 client_.SetPolicy(PolicyNamespaceKey(dm_protocol::kChromeExtensionPolicyType, |
| 367 kTestExtension), | 396 kTestExtension), |
| 368 *CreateResponse()); | 397 *CreateResponse()); |
| 369 service_->OnPolicyFetched(&client_); | 398 service_->OnPolicyFetched(&client_); |
| 370 RunUntilIdle(); | 399 RunUntilIdle(); |
| 371 | 400 |
| 372 // That should have triggered the download fetch. | 401 // That should have triggered the download fetch. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 403 PolicyNamespace ns(POLICY_DOMAIN_EXTENSIONS, kTestExtension); | 432 PolicyNamespace ns(POLICY_DOMAIN_EXTENSIONS, kTestExtension); |
| 404 expected_bundle.Get(ns).CopyFrom(expected_policy_); | 433 expected_bundle.Get(ns).CopyFrom(expected_policy_); |
| 405 ns.component_id = kTestExtension2; | 434 ns.component_id = kTestExtension2; |
| 406 expected_bundle.Get(ns).CopyFrom(expected_policy_); | 435 expected_bundle.Get(ns).CopyFrom(expected_policy_); |
| 407 EXPECT_TRUE(service_->policy().Equals(expected_bundle)); | 436 EXPECT_TRUE(service_->policy().Equals(expected_bundle)); |
| 408 | 437 |
| 409 // Now purge one of the extensions. | 438 // Now purge one of the extensions. |
| 410 EXPECT_CALL(delegate_, OnComponentCloudPolicyUpdated()); | 439 EXPECT_CALL(delegate_, OnComponentCloudPolicyUpdated()); |
| 411 // The service will start updating the components that are registered, which | 440 // The service will start updating the components that are registered, which |
| 412 // starts by fetching policy for them. | 441 // starts by fetching policy for them. |
| 413 std::set<std::string> keep; | 442 scoped_refptr<PolicyDomainDescriptor> descriptor = new PolicyDomainDescriptor( |
| 414 keep.insert(kTestExtension2); | 443 POLICY_DOMAIN_EXTENSIONS); |
| 415 service_->RegisterPolicyDomain(POLICY_DOMAIN_EXTENSIONS, keep); | 444 descriptor->RegisterComponent(kTestExtension2, CreateTestSchema()); |
| 445 service_->RegisterPolicyDomain(descriptor); |
| 416 RunUntilIdle(); | 446 RunUntilIdle(); |
| 417 Mock::VerifyAndClearExpectations(&delegate_); | 447 Mock::VerifyAndClearExpectations(&delegate_); |
| 418 | 448 |
| 419 ns.component_id = kTestExtension; | 449 ns.component_id = kTestExtension; |
| 420 expected_bundle.Get(ns).Clear(); | 450 expected_bundle.Get(ns).Clear(); |
| 421 EXPECT_TRUE(service_->policy().Equals(expected_bundle)); | 451 EXPECT_TRUE(service_->policy().Equals(expected_bundle)); |
| 422 | 452 |
| 423 std::map<std::string, std::string> contents; | 453 std::map<std::string, std::string> contents; |
| 424 cache_->LoadAllSubkeys("extension-policy", &contents); | 454 cache_->LoadAllSubkeys("extension-policy", &contents); |
| 425 EXPECT_EQ(1u, contents.size()); | 455 EXPECT_EQ(1u, contents.size()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 436 store_.policy_.reset(new em::PolicyData()); // No credentials. | 466 store_.policy_.reset(new em::PolicyData()); // No credentials. |
| 437 EXPECT_CALL(delegate_, OnComponentCloudPolicyUpdated()); | 467 EXPECT_CALL(delegate_, OnComponentCloudPolicyUpdated()); |
| 438 store_.NotifyStoreLoaded(); | 468 store_.NotifyStoreLoaded(); |
| 439 RunUntilIdle(); | 469 RunUntilIdle(); |
| 440 Mock::VerifyAndClearExpectations(&delegate_); | 470 Mock::VerifyAndClearExpectations(&delegate_); |
| 441 EXPECT_TRUE(service_->is_initialized()); | 471 EXPECT_TRUE(service_->is_initialized()); |
| 442 | 472 |
| 443 // Connect the client and register an extension. | 473 // Connect the client and register an extension. |
| 444 service_->Connect(&client_, request_context_); | 474 service_->Connect(&client_, request_context_); |
| 445 EXPECT_CALL(delegate_, OnComponentCloudPolicyRefreshNeeded()); | 475 EXPECT_CALL(delegate_, OnComponentCloudPolicyRefreshNeeded()); |
| 446 std::set<std::string> components; | 476 scoped_refptr<PolicyDomainDescriptor> descriptor = new PolicyDomainDescriptor( |
| 447 components.insert(kTestExtension); | 477 POLICY_DOMAIN_EXTENSIONS); |
| 448 service_->RegisterPolicyDomain(POLICY_DOMAIN_EXTENSIONS, components); | 478 descriptor->RegisterComponent(kTestExtension, CreateTestSchema()); |
| 479 service_->RegisterPolicyDomain(descriptor); |
| 449 Mock::VerifyAndClearExpectations(&delegate_); | 480 Mock::VerifyAndClearExpectations(&delegate_); |
| 450 | 481 |
| 451 // Send the response to the service. The response data will be rejected, | 482 // Send the response to the service. The response data will be rejected, |
| 452 // because the store doesn't have the updated credentials yet. | 483 // because the store doesn't have the updated credentials yet. |
| 453 client_.SetPolicy(PolicyNamespaceKey(dm_protocol::kChromeExtensionPolicyType, | 484 client_.SetPolicy(PolicyNamespaceKey(dm_protocol::kChromeExtensionPolicyType, |
| 454 kTestExtension), | 485 kTestExtension), |
| 455 *CreateResponse()); | 486 *CreateResponse()); |
| 456 service_->OnPolicyFetched(&client_); | 487 service_->OnPolicyFetched(&client_); |
| 457 RunUntilIdle(); | 488 RunUntilIdle(); |
| 458 | 489 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 482 Mock::VerifyAndClearExpectations(&delegate_); | 513 Mock::VerifyAndClearExpectations(&delegate_); |
| 483 | 514 |
| 484 // The policy is now being served. | 515 // The policy is now being served. |
| 485 PolicyNamespace ns(POLICY_DOMAIN_EXTENSIONS, kTestExtension); | 516 PolicyNamespace ns(POLICY_DOMAIN_EXTENSIONS, kTestExtension); |
| 486 PolicyBundle expected_bundle; | 517 PolicyBundle expected_bundle; |
| 487 expected_bundle.Get(ns).CopyFrom(expected_policy_); | 518 expected_bundle.Get(ns).CopyFrom(expected_policy_); |
| 488 EXPECT_TRUE(service_->policy().Equals(expected_bundle)); | 519 EXPECT_TRUE(service_->policy().Equals(expected_bundle)); |
| 489 } | 520 } |
| 490 | 521 |
| 491 } // namespace policy | 522 } // namespace policy |
| OLD | NEW |