Chromium Code Reviews| Index: chrome/browser/policy/cloud/component_cloud_policy_service_unittest.cc |
| diff --git a/chrome/browser/policy/cloud/component_cloud_policy_service_unittest.cc b/chrome/browser/policy/cloud/component_cloud_policy_service_unittest.cc |
| index b5403b6613f0a097db5c05966e63a5c8fac5150e..0de9db13f49db2f0aa6ff63d4351eeb6b0a8c8fb 100644 |
| --- a/chrome/browser/policy/cloud/component_cloud_policy_service_unittest.cc |
| +++ b/chrome/browser/policy/cloud/component_cloud_policy_service_unittest.cc |
| @@ -5,6 +5,7 @@ |
| #include "chrome/browser/policy/cloud/component_cloud_policy_service.h" |
| #include "base/files/scoped_temp_dir.h" |
| +#include "base/memory/ref_counted.h" |
|
bartfab (slow)
2013/05/21 12:10:56
Nit: Already included by component_cloud_policy_se
Joao da Silva
2013/05/21 17:50:14
Done.
|
| #include "base/message_loop.h" |
| #include "base/pickle.h" |
| #include "base/run_loop.h" |
| @@ -17,7 +18,9 @@ |
| #include "chrome/browser/policy/cloud/mock_cloud_policy_store.h" |
| #include "chrome/browser/policy/cloud/policy_builder.h" |
| #include "chrome/browser/policy/cloud/resource_cache.h" |
| +#include "chrome/browser/policy/policy_domain_descriptor.h" |
| #include "chrome/browser/policy/policy_map.h" |
| +#include "chrome/browser/policy/policy_schema.h" |
| #include "chrome/browser/policy/policy_types.h" |
| #include "chrome/browser/policy/proto/cloud/chrome_extension_policy.pb.h" |
| #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" |
| @@ -43,6 +46,7 @@ const char kTestExtension2[] = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; |
| const char kTestExtension3[] = "cccccccccccccccccccccccccccccccc"; |
| const char kTestDownload[] = "http://example.com/getpolicy?id=123"; |
| const char kTestDownload2[] = "http://example.com/getpolicy?id=456"; |
| + |
| const char kTestPolicy[] = |
| "{" |
| " \"Name\": {" |
| @@ -54,6 +58,16 @@ const char kTestPolicy[] = |
| " }" |
| "}"; |
| +const char kTestSchema[] = |
| + "{" |
| + " \"$schema\": \"http://json-schema.org/draft-03/schema#\"," |
| + " \"type\": \"object\"," |
| + " \"properties\": {" |
| + " \"Name\": { \"type\": \"string\" }," |
| + " \"Second\": { \"type\": \"string\" }" |
| + " }" |
| + "}"; |
| + |
| class MockComponentCloudPolicyDelegate |
| : public ComponentCloudPolicyService::Delegate { |
| public: |
| @@ -176,6 +190,13 @@ class ComponentCloudPolicyServiceTest : public testing::Test { |
| return builder_.GetBlob(); |
| } |
| + scoped_ptr<PolicySchema> CreateTestSchema() { |
| + std::string error; |
| + scoped_ptr<PolicySchema> schema = PolicySchema::Parse(kTestSchema, &error); |
| + EXPECT_TRUE(schema) << error; |
| + return schema.Pass(); |
| + } |
| + |
| MessageLoop loop_; |
| content::TestBrowserThread ui_thread_; |
| content::TestBrowserThread file_thread_; |
| @@ -250,10 +271,11 @@ TEST_F(ComponentCloudPolicyServiceTest, InitializationWithCachedComponents) { |
| TEST_F(ComponentCloudPolicyServiceTest, ConnectAfterRegister) { |
| // Add some components. |
| - std::set<std::string> components; |
| - components.insert(kTestExtension); |
| - components.insert(kTestExtension2); |
| - service_->RegisterPolicyDomain(POLICY_DOMAIN_EXTENSIONS, components); |
| + scoped_refptr<PolicyDomainDescriptor> descriptor = new PolicyDomainDescriptor( |
| + POLICY_DOMAIN_EXTENSIONS); |
| + descriptor->SetComponent(kTestExtension, CreateTestSchema()); |
| + descriptor->SetComponent(kTestExtension2, CreateTestSchema()); |
| + service_->RegisterPolicyDomain(descriptor); |
| // Now connect the client. |
| EXPECT_TRUE(client_.namespaces_to_fetch_.empty()); |
| @@ -288,7 +310,12 @@ TEST_F(ComponentCloudPolicyServiceTest, ConnectAfterRegister) { |
| std::set<std::string> unpickled; |
| unpickled.insert(value0); |
| unpickled.insert(value1); |
| - EXPECT_EQ(components, unpickled); |
| + |
| + std::set<std::string> expected_components; |
| + expected_components.insert(kTestExtension); |
| + expected_components.insert(kTestExtension2); |
| + |
| + EXPECT_EQ(expected_components, unpickled); |
| } |
| TEST_F(ComponentCloudPolicyServiceTest, StoreReadyAfterConnectAndRegister) { |
| @@ -296,9 +323,10 @@ TEST_F(ComponentCloudPolicyServiceTest, StoreReadyAfterConnectAndRegister) { |
| PopulateCache(); |
| // Add some components. |
| - std::set<std::string> components; |
| - components.insert(kTestExtension); |
| - service_->RegisterPolicyDomain(POLICY_DOMAIN_EXTENSIONS, components); |
| + scoped_refptr<PolicyDomainDescriptor> descriptor = new PolicyDomainDescriptor( |
| + POLICY_DOMAIN_EXTENSIONS); |
| + descriptor->SetComponent(kTestExtension, CreateTestSchema()); |
| + service_->RegisterPolicyDomain(descriptor); |
| // And connect the client. Make the client have some policies, with a new |
| // download_url. |
| @@ -334,9 +362,10 @@ TEST_F(ComponentCloudPolicyServiceTest, ConnectThenRegisterThenStoreReady) { |
| // Now register the current components, before the backend has been |
| // initialized. |
| EXPECT_TRUE(client_.namespaces_to_fetch_.empty()); |
| - std::set<std::string> components; |
| - components.insert(kTestExtension); |
| - service_->RegisterPolicyDomain(POLICY_DOMAIN_EXTENSIONS, components); |
| + scoped_refptr<PolicyDomainDescriptor> descriptor = new PolicyDomainDescriptor( |
| + POLICY_DOMAIN_EXTENSIONS); |
| + descriptor->SetComponent(kTestExtension, CreateTestSchema()); |
| + service_->RegisterPolicyDomain(descriptor); |
| EXPECT_TRUE(client_.namespaces_to_fetch_.empty()); |
| // Now load the store. The client gets the namespaces. |
| @@ -356,10 +385,11 @@ TEST_F(ComponentCloudPolicyServiceTest, FetchPolicy) { |
| Mock::VerifyAndClearExpectations(&delegate_); |
| // Register the components to fetch. |
| - std::set<std::string> components; |
| - components.insert(kTestExtension); |
| + scoped_refptr<PolicyDomainDescriptor> descriptor = new PolicyDomainDescriptor( |
| + POLICY_DOMAIN_EXTENSIONS); |
| + descriptor->SetComponent(kTestExtension, CreateTestSchema()); |
| EXPECT_CALL(delegate_, OnComponentCloudPolicyRefreshNeeded()); |
| - service_->RegisterPolicyDomain(POLICY_DOMAIN_EXTENSIONS, components); |
| + service_->RegisterPolicyDomain(descriptor); |
| Mock::VerifyAndClearExpectations(&delegate_); |
| // Send back a fake policy fetch response. |
| @@ -410,9 +440,10 @@ TEST_F(ComponentCloudPolicyServiceTest, LoadAndPurgeCache) { |
| EXPECT_CALL(delegate_, OnComponentCloudPolicyUpdated()); |
| // The service will start updating the components that are registered, which |
| // starts by fetching policy for them. |
| - std::set<std::string> keep; |
| - keep.insert(kTestExtension2); |
| - service_->RegisterPolicyDomain(POLICY_DOMAIN_EXTENSIONS, keep); |
| + scoped_refptr<PolicyDomainDescriptor> descriptor = new PolicyDomainDescriptor( |
| + POLICY_DOMAIN_EXTENSIONS); |
| + descriptor->SetComponent(kTestExtension2, CreateTestSchema()); |
| + service_->RegisterPolicyDomain(descriptor); |
| RunUntilIdle(); |
| Mock::VerifyAndClearExpectations(&delegate_); |
| @@ -443,9 +474,10 @@ TEST_F(ComponentCloudPolicyServiceTest, UpdateCredentials) { |
| // Connect the client and register an extension. |
| service_->Connect(&client_, request_context_); |
| EXPECT_CALL(delegate_, OnComponentCloudPolicyRefreshNeeded()); |
| - std::set<std::string> components; |
| - components.insert(kTestExtension); |
| - service_->RegisterPolicyDomain(POLICY_DOMAIN_EXTENSIONS, components); |
| + scoped_refptr<PolicyDomainDescriptor> descriptor = new PolicyDomainDescriptor( |
| + POLICY_DOMAIN_EXTENSIONS); |
| + descriptor->SetComponent(kTestExtension, CreateTestSchema()); |
| + service_->RegisterPolicyDomain(descriptor); |
| Mock::VerifyAndClearExpectations(&delegate_); |
| // Send the response to the service. The response data will be rejected, |