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