Chromium Code Reviews| Index: chrome/browser/extensions/api/storage/settings_apitest.cc |
| diff --git a/chrome/browser/extensions/api/storage/settings_apitest.cc b/chrome/browser/extensions/api/storage/settings_apitest.cc |
| index c687d6f39c52fedaf0a2c3cdea8587bfcebcb56c..754d047b8f0a1df591a44487304d91949172961a 100644 |
| --- a/chrome/browser/extensions/api/storage/settings_apitest.cc |
| +++ b/chrome/browser/extensions/api/storage/settings_apitest.cc |
| @@ -28,11 +28,14 @@ |
| #include "chrome/browser/policy/browser_policy_connector.h" |
| #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
| #include "chrome/browser/policy/policy_bundle.h" |
| -#include "chrome/browser/policy/policy_domain_descriptor.h" |
| #include "chrome/browser/policy/policy_map.h" |
| #include "chrome/browser/policy/policy_service.h" |
|
bartfab (slow)
2013/11/05 15:53:04
Nit: No longer used.
Joao da Silva
2013/11/07 13:15:00
Done.
|
| #include "chrome/browser/policy/profile_policy_connector.h" |
|
bartfab (slow)
2013/11/05 15:53:04
Nit: No longer used.
Joao da Silva
2013/11/07 13:15:00
Done.
|
| #include "chrome/browser/policy/profile_policy_connector_factory.h" |
|
bartfab (slow)
2013/11/05 15:53:04
Nit: No longer used.
Joao da Silva
2013/11/07 13:15:00
Done.
|
| +#include "chrome/browser/policy/schema_map.h" |
| +#include "chrome/browser/policy/schema_registry_service.h" |
|
bartfab (slow)
2013/11/05 15:53:04
Nit: As commented elsewhere, in line with your usu
Joao da Silva
2013/11/07 13:15:00
Same as before, it needs to see it's derived from
|
| +#include "chrome/browser/policy/schema_registry_service_factory.h" |
| +#include "components/policy/core/common/schema.h" |
| #endif |
| namespace extensions { |
| @@ -44,6 +47,7 @@ using settings_namespace::Namespace; |
| using settings_namespace::SYNC; |
| using settings_namespace::ToString; |
| using testing::AnyNumber; |
|
bartfab (slow)
2013/11/05 15:53:04
Nit: No longer used.
Joao da Silva
2013/11/07 13:15:00
Done.
|
| +using testing::Mock; |
| using testing::Return; |
| using testing::_; |
| @@ -100,6 +104,15 @@ class SyncChangeProcessorDelegate : public syncer::SyncChangeProcessor { |
| DISALLOW_COPY_AND_ASSIGN(SyncChangeProcessorDelegate); |
| }; |
| +class MockSchemaRegistryObserver : public policy::SchemaRegistry::Observer { |
|
bartfab (slow)
2013/11/05 15:53:04
Nit: #include "chrome/browser/policy/schema_regist
Joao da Silva
2013/11/07 13:15:00
Done.
|
| + public: |
| + MockSchemaRegistryObserver() {} |
| + virtual ~MockSchemaRegistryObserver() {} |
| + |
| + MOCK_METHOD2(OnSchemaRegistryUpdated, |
| + void(const scoped_refptr<policy::SchemaMap>&, bool)); |
| +}; |
| + |
| } // namespace |
| class ExtensionSettingsApiTest : public ExtensionApiTest { |
| @@ -110,7 +123,6 @@ class ExtensionSettingsApiTest : public ExtensionApiTest { |
| #if defined(ENABLE_CONFIGURATION_POLICY) |
| EXPECT_CALL(policy_provider_, IsInitializationComplete(_)) |
| .WillRepeatedly(Return(true)); |
| - EXPECT_CALL(policy_provider_, RegisterPolicyDomain(_)).Times(AnyNumber()); |
| policy::BrowserPolicyConnector::SetPolicyProviderForTesting( |
| &policy_provider_); |
| #endif |
| @@ -445,9 +457,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, IsStorageEnabled) { |
| #if defined(ENABLE_CONFIGURATION_POLICY) |
| -IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, PolicyDomainDescriptor) { |
| - // Verifies that the PolicyDomainDescriptor for the extensions domain is |
| - // created on startup. |
| +IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, ExtensionsSchemas) { |
| + // Verifies that the Schemas for the extensions domain are created on startup. |
| Profile* profile = browser()->profile(); |
| ExtensionSystem* extension_system = |
| ExtensionSystemFactory::GetForProfile(profile); |
| @@ -459,12 +470,66 @@ IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, PolicyDomainDescriptor) { |
| ASSERT_TRUE(extension_system->ready().is_signaled()); |
| } |
| - policy::ProfilePolicyConnector* connector = |
| - policy::ProfilePolicyConnectorFactory::GetForProfile(profile); |
| - policy::PolicyService* service = connector->policy_service(); |
| - scoped_refptr<const policy::PolicyDomainDescriptor> descriptor = |
| - service->GetPolicyDomainDescriptor(policy::POLICY_DOMAIN_EXTENSIONS); |
| - EXPECT_TRUE(descriptor.get()); |
| + // This test starts without any test extensions installed. |
| + EXPECT_FALSE(GetSingleLoadedExtension()); |
| + message_.clear(); |
| + |
| + policy::SchemaRegistry* registry = |
| + policy::SchemaRegistryServiceFactory::GetForContext(profile); |
| + ASSERT_TRUE(registry); |
| + const policy::ComponentMap* components = |
| + registry->schema_map()->GetComponents(policy::POLICY_DOMAIN_EXTENSIONS); |
| + EXPECT_FALSE(components); |
| + |
| + MockSchemaRegistryObserver observer; |
| + registry->AddObserver(&observer); |
| + |
| + // Install a managed extension. |
| + EXPECT_CALL(observer, OnSchemaRegistryUpdated(_, true)); |
| + const Extension* extension = |
| + LoadExtension(test_data_dir_.AppendASCII("settings/managed_storage")); |
| + ASSERT_TRUE(extension); |
| + Mock::VerifyAndClearExpectations(&observer); |
| + registry->RemoveObserver(&observer); |
| + |
| + // Verify that its schema has been published, and verify its contents. |
| + const policy::Schema* schema = |
| + registry->schema_map()->GetSchema(policy::PolicyNamespace( |
|
bartfab (slow)
2013/11/05 15:53:04
Nit: #include "components/policy/core/common/polic
Joao da Silva
2013/11/07 13:15:00
Done.
|
| + policy::POLICY_DOMAIN_EXTENSIONS, kManagedStorageExtensionId)); |
| + ASSERT_TRUE(schema); |
| + |
| + ASSERT_TRUE(schema->valid()); |
| + ASSERT_EQ(base::Value::TYPE_DICTIONARY, schema->type()); |
|
bartfab (slow)
2013/11/05 15:53:04
Nit: #include "base/values.h"
Joao da Silva
2013/11/07 13:15:00
Done.
|
| + ASSERT_TRUE(schema->GetKnownProperty("string-policy").valid()); |
| + EXPECT_EQ(base::Value::TYPE_STRING, |
| + schema->GetKnownProperty("string-policy").type()); |
| + ASSERT_TRUE(schema->GetKnownProperty("int-policy").valid()); |
| + EXPECT_EQ(base::Value::TYPE_INTEGER, |
| + schema->GetKnownProperty("int-policy").type()); |
| + ASSERT_TRUE(schema->GetKnownProperty("double-policy").valid()); |
| + EXPECT_EQ(base::Value::TYPE_DOUBLE, |
| + schema->GetKnownProperty("double-policy").type()); |
| + ASSERT_TRUE(schema->GetKnownProperty("boolean-policy").valid()); |
| + EXPECT_EQ(base::Value::TYPE_BOOLEAN, |
| + schema->GetKnownProperty("boolean-policy").type()); |
| + |
| + policy::Schema list = schema->GetKnownProperty("list-policy"); |
| + ASSERT_TRUE(list.valid()); |
| + ASSERT_EQ(base::Value::TYPE_LIST, list.type()); |
| + ASSERT_TRUE(list.GetItems().valid()); |
| + EXPECT_EQ(base::Value::TYPE_STRING, list.GetItems().type()); |
| + |
| + policy::Schema dict = schema->GetKnownProperty("dict-policy"); |
| + ASSERT_TRUE(dict.valid()); |
| + ASSERT_EQ(base::Value::TYPE_DICTIONARY, dict.type()); |
| + list = dict.GetKnownProperty("list"); |
| + ASSERT_TRUE(list.valid()); |
| + ASSERT_EQ(base::Value::TYPE_LIST, list.type()); |
| + dict = list.GetItems(); |
| + ASSERT_TRUE(dict.valid()); |
| + ASSERT_EQ(base::Value::TYPE_DICTIONARY, dict.type()); |
| + ASSERT_TRUE(dict.GetProperty("anything").valid()); |
| + EXPECT_EQ(base::Value::TYPE_INTEGER, dict.GetProperty("anything").type()); |
| } |
| IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, ManagedStorage) { |