Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/json/json_writer.h" | 6 #include "base/json/json_writer.h" |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "chrome/browser/extensions/api/storage/settings_frontend.h" | 9 #include "chrome/browser/extensions/api/storage/settings_frontend.h" |
| 10 #include "chrome/browser/extensions/api/storage/settings_namespace.h" | 10 #include "chrome/browser/extensions/api/storage/settings_namespace.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "sync/api/sync_change.h" | 21 #include "sync/api/sync_change.h" |
| 22 #include "sync/api/sync_change_processor.h" | 22 #include "sync/api/sync_change_processor.h" |
| 23 #include "sync/api/sync_error_factory.h" | 23 #include "sync/api/sync_error_factory.h" |
| 24 #include "sync/api/sync_error_factory_mock.h" | 24 #include "sync/api/sync_error_factory_mock.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 26 | 26 |
| 27 #if defined(ENABLE_CONFIGURATION_POLICY) | 27 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 28 #include "chrome/browser/policy/browser_policy_connector.h" | 28 #include "chrome/browser/policy/browser_policy_connector.h" |
| 29 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 29 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
| 30 #include "chrome/browser/policy/policy_bundle.h" | 30 #include "chrome/browser/policy/policy_bundle.h" |
| 31 #include "chrome/browser/policy/policy_domain_descriptor.h" | |
| 32 #include "chrome/browser/policy/policy_map.h" | 31 #include "chrome/browser/policy/policy_map.h" |
| 33 #include "chrome/browser/policy/policy_service.h" | 32 #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.
| |
| 34 #include "chrome/browser/policy/profile_policy_connector.h" | 33 #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.
| |
| 35 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 34 #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.
| |
| 35 #include "chrome/browser/policy/schema_map.h" | |
| 36 #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
| |
| 37 #include "chrome/browser/policy/schema_registry_service_factory.h" | |
| 38 #include "components/policy/core/common/schema.h" | |
| 36 #endif | 39 #endif |
| 37 | 40 |
| 38 namespace extensions { | 41 namespace extensions { |
| 39 | 42 |
| 40 using settings_namespace::FromString; | 43 using settings_namespace::FromString; |
| 41 using settings_namespace::LOCAL; | 44 using settings_namespace::LOCAL; |
| 42 using settings_namespace::MANAGED; | 45 using settings_namespace::MANAGED; |
| 43 using settings_namespace::Namespace; | 46 using settings_namespace::Namespace; |
| 44 using settings_namespace::SYNC; | 47 using settings_namespace::SYNC; |
| 45 using settings_namespace::ToString; | 48 using settings_namespace::ToString; |
| 46 using testing::AnyNumber; | 49 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.
| |
| 50 using testing::Mock; | |
| 47 using testing::Return; | 51 using testing::Return; |
| 48 using testing::_; | 52 using testing::_; |
| 49 | 53 |
| 50 namespace { | 54 namespace { |
| 51 | 55 |
| 52 // TODO(kalman): test both EXTENSION_SETTINGS and APP_SETTINGS. | 56 // TODO(kalman): test both EXTENSION_SETTINGS and APP_SETTINGS. |
| 53 const syncer::ModelType kModelType = syncer::EXTENSION_SETTINGS; | 57 const syncer::ModelType kModelType = syncer::EXTENSION_SETTINGS; |
| 54 | 58 |
| 55 // The managed_storage extension has a key defined in its manifest, so that | 59 // The managed_storage extension has a key defined in its manifest, so that |
| 56 // its extension ID is well-known and the policy system can push policies for | 60 // its extension ID is well-known and the policy system can push policies for |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 return recipient_->GetAllSyncData(type); | 97 return recipient_->GetAllSyncData(type); |
| 94 } | 98 } |
| 95 | 99 |
| 96 private: | 100 private: |
| 97 // The recipient of all sync changes. | 101 // The recipient of all sync changes. |
| 98 syncer::SyncChangeProcessor* recipient_; | 102 syncer::SyncChangeProcessor* recipient_; |
| 99 | 103 |
| 100 DISALLOW_COPY_AND_ASSIGN(SyncChangeProcessorDelegate); | 104 DISALLOW_COPY_AND_ASSIGN(SyncChangeProcessorDelegate); |
| 101 }; | 105 }; |
| 102 | 106 |
| 107 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.
| |
| 108 public: | |
| 109 MockSchemaRegistryObserver() {} | |
| 110 virtual ~MockSchemaRegistryObserver() {} | |
| 111 | |
| 112 MOCK_METHOD2(OnSchemaRegistryUpdated, | |
| 113 void(const scoped_refptr<policy::SchemaMap>&, bool)); | |
| 114 }; | |
| 115 | |
| 103 } // namespace | 116 } // namespace |
| 104 | 117 |
| 105 class ExtensionSettingsApiTest : public ExtensionApiTest { | 118 class ExtensionSettingsApiTest : public ExtensionApiTest { |
| 106 protected: | 119 protected: |
| 107 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 120 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 108 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | 121 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
| 109 | 122 |
| 110 #if defined(ENABLE_CONFIGURATION_POLICY) | 123 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 111 EXPECT_CALL(policy_provider_, IsInitializationComplete(_)) | 124 EXPECT_CALL(policy_provider_, IsInitializationComplete(_)) |
| 112 .WillRepeatedly(Return(true)); | 125 .WillRepeatedly(Return(true)); |
| 113 EXPECT_CALL(policy_provider_, RegisterPolicyDomain(_)).Times(AnyNumber()); | |
| 114 policy::BrowserPolicyConnector::SetPolicyProviderForTesting( | 126 policy::BrowserPolicyConnector::SetPolicyProviderForTesting( |
| 115 &policy_provider_); | 127 &policy_provider_); |
| 116 #endif | 128 #endif |
| 117 } | 129 } |
| 118 | 130 |
| 119 void ReplyWhenSatisfied( | 131 void ReplyWhenSatisfied( |
| 120 Namespace settings_namespace, | 132 Namespace settings_namespace, |
| 121 const std::string& normal_action, | 133 const std::string& normal_action, |
| 122 const std::string& incognito_action) { | 134 const std::string& incognito_action) { |
| 123 MaybeLoadAndReplyWhenSatisfied( | 135 MaybeLoadAndReplyWhenSatisfied( |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 438 | 450 |
| 439 #if defined(ENABLE_CONFIGURATION_POLICY) | 451 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 440 EXPECT_TRUE(frontend->IsStorageEnabled(MANAGED)); | 452 EXPECT_TRUE(frontend->IsStorageEnabled(MANAGED)); |
| 441 #else | 453 #else |
| 442 EXPECT_FALSE(frontend->IsStorageEnabled(MANAGED)); | 454 EXPECT_FALSE(frontend->IsStorageEnabled(MANAGED)); |
| 443 #endif | 455 #endif |
| 444 } | 456 } |
| 445 | 457 |
| 446 #if defined(ENABLE_CONFIGURATION_POLICY) | 458 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 447 | 459 |
| 448 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, PolicyDomainDescriptor) { | 460 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, ExtensionsSchemas) { |
| 449 // Verifies that the PolicyDomainDescriptor for the extensions domain is | 461 // Verifies that the Schemas for the extensions domain are created on startup. |
| 450 // created on startup. | |
| 451 Profile* profile = browser()->profile(); | 462 Profile* profile = browser()->profile(); |
| 452 ExtensionSystem* extension_system = | 463 ExtensionSystem* extension_system = |
| 453 ExtensionSystemFactory::GetForProfile(profile); | 464 ExtensionSystemFactory::GetForProfile(profile); |
| 454 if (!extension_system->ready().is_signaled()) { | 465 if (!extension_system->ready().is_signaled()) { |
| 455 // Wait until the extension system is ready. | 466 // Wait until the extension system is ready. |
| 456 base::RunLoop run_loop; | 467 base::RunLoop run_loop; |
| 457 extension_system->ready().Post(FROM_HERE, run_loop.QuitClosure()); | 468 extension_system->ready().Post(FROM_HERE, run_loop.QuitClosure()); |
| 458 run_loop.Run(); | 469 run_loop.Run(); |
| 459 ASSERT_TRUE(extension_system->ready().is_signaled()); | 470 ASSERT_TRUE(extension_system->ready().is_signaled()); |
| 460 } | 471 } |
| 461 | 472 |
| 462 policy::ProfilePolicyConnector* connector = | 473 // This test starts without any test extensions installed. |
| 463 policy::ProfilePolicyConnectorFactory::GetForProfile(profile); | 474 EXPECT_FALSE(GetSingleLoadedExtension()); |
| 464 policy::PolicyService* service = connector->policy_service(); | 475 message_.clear(); |
| 465 scoped_refptr<const policy::PolicyDomainDescriptor> descriptor = | 476 |
| 466 service->GetPolicyDomainDescriptor(policy::POLICY_DOMAIN_EXTENSIONS); | 477 policy::SchemaRegistry* registry = |
| 467 EXPECT_TRUE(descriptor.get()); | 478 policy::SchemaRegistryServiceFactory::GetForContext(profile); |
| 479 ASSERT_TRUE(registry); | |
| 480 const policy::ComponentMap* components = | |
| 481 registry->schema_map()->GetComponents(policy::POLICY_DOMAIN_EXTENSIONS); | |
| 482 EXPECT_FALSE(components); | |
| 483 | |
| 484 MockSchemaRegistryObserver observer; | |
| 485 registry->AddObserver(&observer); | |
| 486 | |
| 487 // Install a managed extension. | |
| 488 EXPECT_CALL(observer, OnSchemaRegistryUpdated(_, true)); | |
| 489 const Extension* extension = | |
| 490 LoadExtension(test_data_dir_.AppendASCII("settings/managed_storage")); | |
| 491 ASSERT_TRUE(extension); | |
| 492 Mock::VerifyAndClearExpectations(&observer); | |
| 493 registry->RemoveObserver(&observer); | |
| 494 | |
| 495 // Verify that its schema has been published, and verify its contents. | |
| 496 const policy::Schema* schema = | |
| 497 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.
| |
| 498 policy::POLICY_DOMAIN_EXTENSIONS, kManagedStorageExtensionId)); | |
| 499 ASSERT_TRUE(schema); | |
| 500 | |
| 501 ASSERT_TRUE(schema->valid()); | |
| 502 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.
| |
| 503 ASSERT_TRUE(schema->GetKnownProperty("string-policy").valid()); | |
| 504 EXPECT_EQ(base::Value::TYPE_STRING, | |
| 505 schema->GetKnownProperty("string-policy").type()); | |
| 506 ASSERT_TRUE(schema->GetKnownProperty("int-policy").valid()); | |
| 507 EXPECT_EQ(base::Value::TYPE_INTEGER, | |
| 508 schema->GetKnownProperty("int-policy").type()); | |
| 509 ASSERT_TRUE(schema->GetKnownProperty("double-policy").valid()); | |
| 510 EXPECT_EQ(base::Value::TYPE_DOUBLE, | |
| 511 schema->GetKnownProperty("double-policy").type()); | |
| 512 ASSERT_TRUE(schema->GetKnownProperty("boolean-policy").valid()); | |
| 513 EXPECT_EQ(base::Value::TYPE_BOOLEAN, | |
| 514 schema->GetKnownProperty("boolean-policy").type()); | |
| 515 | |
| 516 policy::Schema list = schema->GetKnownProperty("list-policy"); | |
| 517 ASSERT_TRUE(list.valid()); | |
| 518 ASSERT_EQ(base::Value::TYPE_LIST, list.type()); | |
| 519 ASSERT_TRUE(list.GetItems().valid()); | |
| 520 EXPECT_EQ(base::Value::TYPE_STRING, list.GetItems().type()); | |
| 521 | |
| 522 policy::Schema dict = schema->GetKnownProperty("dict-policy"); | |
| 523 ASSERT_TRUE(dict.valid()); | |
| 524 ASSERT_EQ(base::Value::TYPE_DICTIONARY, dict.type()); | |
| 525 list = dict.GetKnownProperty("list"); | |
| 526 ASSERT_TRUE(list.valid()); | |
| 527 ASSERT_EQ(base::Value::TYPE_LIST, list.type()); | |
| 528 dict = list.GetItems(); | |
| 529 ASSERT_TRUE(dict.valid()); | |
| 530 ASSERT_EQ(base::Value::TYPE_DICTIONARY, dict.type()); | |
| 531 ASSERT_TRUE(dict.GetProperty("anything").valid()); | |
| 532 EXPECT_EQ(base::Value::TYPE_INTEGER, dict.GetProperty("anything").type()); | |
| 468 } | 533 } |
| 469 | 534 |
| 470 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, ManagedStorage) { | 535 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, ManagedStorage) { |
| 471 // Set policies for the test extension. | 536 // Set policies for the test extension. |
| 472 scoped_ptr<base::DictionaryValue> policy = extensions::DictionaryBuilder() | 537 scoped_ptr<base::DictionaryValue> policy = extensions::DictionaryBuilder() |
| 473 .Set("string-policy", "value") | 538 .Set("string-policy", "value") |
| 474 .Set("int-policy", -123) | 539 .Set("int-policy", -123) |
| 475 .Set("double-policy", 456e7) | 540 .Set("double-policy", 456e7) |
| 476 .SetBoolean("boolean-policy", true) | 541 .SetBoolean("boolean-policy", true) |
| 477 .Set("list-policy", extensions::ListBuilder() | 542 .Set("list-policy", extensions::ListBuilder() |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 558 SettingsFrontend* frontend = | 623 SettingsFrontend* frontend = |
| 559 browser()->profile()->GetExtensionService()->settings_frontend(); | 624 browser()->profile()->GetExtensionService()->settings_frontend(); |
| 560 frontend->DisableStorageForTesting(MANAGED); | 625 frontend->DisableStorageForTesting(MANAGED); |
| 561 EXPECT_FALSE(frontend->IsStorageEnabled(MANAGED)); | 626 EXPECT_FALSE(frontend->IsStorageEnabled(MANAGED)); |
| 562 // Now run the extension. | 627 // Now run the extension. |
| 563 ASSERT_TRUE(RunExtensionTest("settings/managed_storage_disabled")) | 628 ASSERT_TRUE(RunExtensionTest("settings/managed_storage_disabled")) |
| 564 << message_; | 629 << message_; |
| 565 } | 630 } |
| 566 | 631 |
| 567 } // namespace extensions | 632 } // namespace extensions |
| OLD | NEW |