Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Unified Diff: chrome/browser/extensions/api/storage/settings_apitest.cc

Issue 56623005: Policy providers all get a SchemaRegistry to work with. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@chrome-policy-schema-9-purge-with-callback
Patch Set: rebase Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 00778a85cba34f63b616afabd92ef582d25ff93f..a8645f027717e125d75c47ae9733ece106ea5d5a 100644
--- a/chrome/browser/extensions/api/storage/settings_apitest.cc
+++ b/chrome/browser/extensions/api/storage/settings_apitest.cc
@@ -6,6 +6,7 @@
#include "base/json/json_writer.h"
#include "base/memory/ref_counted.h"
#include "base/run_loop.h"
+#include "base/values.h"
#include "chrome/browser/extensions/api/storage/settings_frontend.h"
#include "chrome/browser/extensions/api/storage/settings_namespace.h"
#include "chrome/browser/extensions/api/storage/settings_sync_util.h"
@@ -28,22 +29,23 @@
#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"
-#include "chrome/browser/policy/profile_policy_connector.h"
-#include "chrome/browser/policy/profile_policy_connector_factory.h"
+#include "chrome/browser/policy/schema_map.h"
+#include "chrome/browser/policy/schema_registry.h"
+#include "chrome/browser/policy/schema_registry_service.h"
+#include "chrome/browser/policy/schema_registry_service_factory.h"
+#include "components/policy/core/common/policy_namespace.h"
+#include "components/policy/core/common/schema.h"
#endif
namespace extensions {
-using settings_namespace::FromString;
using settings_namespace::LOCAL;
using settings_namespace::MANAGED;
using settings_namespace::Namespace;
using settings_namespace::SYNC;
using settings_namespace::ToString;
-using testing::AnyNumber;
+using testing::Mock;
using testing::Return;
using testing::_;
@@ -100,6 +102,14 @@ class SyncChangeProcessorDelegate : public syncer::SyncChangeProcessor {
DISALLOW_COPY_AND_ASSIGN(SyncChangeProcessorDelegate);
};
+class MockSchemaRegistryObserver : public policy::SchemaRegistry::Observer {
+ public:
+ MockSchemaRegistryObserver() {}
+ virtual ~MockSchemaRegistryObserver() {}
+
+ MOCK_METHOD1(OnSchemaRegistryUpdated, void(bool));
+};
+
} // namespace
class ExtensionSettingsApiTest : public ExtensionApiTest {
@@ -110,7 +120,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 +454,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 +467,65 @@ 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);
+ EXPECT_FALSE(registry->schema_map()->GetSchema(policy::PolicyNamespace(
+ policy::POLICY_DOMAIN_EXTENSIONS, kManagedStorageExtensionId)));
+
+ 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(
+ policy::POLICY_DOMAIN_EXTENSIONS, kManagedStorageExtensionId));
+ ASSERT_TRUE(schema);
+
+ ASSERT_TRUE(schema->valid());
+ ASSERT_EQ(base::Value::TYPE_DICTIONARY, schema->type());
+ 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) {
« no previous file with comments | « chrome/browser/extensions/api/storage/managed_value_store_cache.cc ('k') | chrome/browser/policy/async_policy_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698