| 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 <utility> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/extensions/api/storage/settings_sync_util.h" | 12 #include "chrome/browser/extensions/api/storage/settings_sync_util.h" |
| 13 #include "chrome/browser/extensions/extension_apitest.h" | 13 #include "chrome/browser/extensions/extension_apitest.h" |
| 14 #include "chrome/browser/extensions/extension_system_factory.h" | 14 #include "chrome/browser/extensions/extension_system_factory.h" |
| 15 #include "chrome/browser/policy/schema_registry_service.h" |
| 16 #include "chrome/browser/policy/schema_registry_service_factory.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 19 #include "components/policy/core/browser/browser_policy_connector.h" |
| 20 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
| 21 #include "components/policy/core/common/policy_bundle.h" |
| 22 #include "components/policy/core/common/policy_map.h" |
| 23 #include "components/policy/core/common/policy_namespace.h" |
| 24 #include "components/policy/core/common/policy_types.h" |
| 25 #include "components/policy/core/common/schema.h" |
| 26 #include "components/policy/core/common/schema_map.h" |
| 27 #include "components/policy/core/common/schema_registry.h" |
| 17 #include "extensions/browser/api/storage/settings_namespace.h" | 28 #include "extensions/browser/api/storage/settings_namespace.h" |
| 18 #include "extensions/browser/api/storage/storage_frontend.h" | 29 #include "extensions/browser/api/storage/storage_frontend.h" |
| 19 #include "extensions/browser/extension_system.h" | 30 #include "extensions/browser/extension_system.h" |
| 20 #include "extensions/common/value_builder.h" | 31 #include "extensions/common/value_builder.h" |
| 21 #include "extensions/test/extension_test_message_listener.h" | 32 #include "extensions/test/extension_test_message_listener.h" |
| 22 #include "extensions/test/result_catcher.h" | 33 #include "extensions/test/result_catcher.h" |
| 23 #include "sync/api/fake_sync_change_processor.h" | 34 #include "sync/api/fake_sync_change_processor.h" |
| 24 #include "sync/api/sync_change.h" | 35 #include "sync/api/sync_change.h" |
| 25 #include "sync/api/sync_change_processor.h" | 36 #include "sync/api/sync_change_processor.h" |
| 26 #include "sync/api/sync_change_processor_wrapper_for_test.h" | 37 #include "sync/api/sync_change_processor_wrapper_for_test.h" |
| 27 #include "sync/api/sync_error_factory.h" | 38 #include "sync/api/sync_error_factory.h" |
| 28 #include "sync/api/sync_error_factory_mock.h" | 39 #include "sync/api/sync_error_factory_mock.h" |
| 29 #include "sync/api/syncable_service.h" | 40 #include "sync/api/syncable_service.h" |
| 30 #include "testing/gmock/include/gmock/gmock.h" | 41 #include "testing/gmock/include/gmock/gmock.h" |
| 31 | 42 |
| 32 #if defined(ENABLE_CONFIGURATION_POLICY) | |
| 33 #include "chrome/browser/policy/schema_registry_service.h" | |
| 34 #include "chrome/browser/policy/schema_registry_service_factory.h" | |
| 35 #include "components/policy/core/browser/browser_policy_connector.h" | |
| 36 #include "components/policy/core/common/mock_configuration_policy_provider.h" | |
| 37 #include "components/policy/core/common/policy_bundle.h" | |
| 38 #include "components/policy/core/common/policy_map.h" | |
| 39 #include "components/policy/core/common/policy_namespace.h" | |
| 40 #include "components/policy/core/common/policy_types.h" | |
| 41 #include "components/policy/core/common/schema.h" | |
| 42 #include "components/policy/core/common/schema_map.h" | |
| 43 #include "components/policy/core/common/schema_registry.h" | |
| 44 #endif | |
| 45 | |
| 46 namespace extensions { | 43 namespace extensions { |
| 47 | 44 |
| 48 using settings_namespace::LOCAL; | 45 using settings_namespace::LOCAL; |
| 49 using settings_namespace::MANAGED; | 46 using settings_namespace::MANAGED; |
| 50 using settings_namespace::Namespace; | 47 using settings_namespace::Namespace; |
| 51 using settings_namespace::SYNC; | 48 using settings_namespace::SYNC; |
| 52 using settings_namespace::ToString; | 49 using settings_namespace::ToString; |
| 53 using testing::Mock; | 50 using testing::Mock; |
| 54 using testing::Return; | 51 using testing::Return; |
| 55 using testing::_; | 52 using testing::_; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 72 MOCK_METHOD1(OnSchemaRegistryUpdated, void(bool)); | 69 MOCK_METHOD1(OnSchemaRegistryUpdated, void(bool)); |
| 73 }; | 70 }; |
| 74 | 71 |
| 75 } // namespace | 72 } // namespace |
| 76 | 73 |
| 77 class ExtensionSettingsApiTest : public ExtensionApiTest { | 74 class ExtensionSettingsApiTest : public ExtensionApiTest { |
| 78 protected: | 75 protected: |
| 79 void SetUpInProcessBrowserTestFixture() override { | 76 void SetUpInProcessBrowserTestFixture() override { |
| 80 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | 77 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
| 81 | 78 |
| 82 #if defined(ENABLE_CONFIGURATION_POLICY) | |
| 83 EXPECT_CALL(policy_provider_, IsInitializationComplete(_)) | 79 EXPECT_CALL(policy_provider_, IsInitializationComplete(_)) |
| 84 .WillRepeatedly(Return(true)); | 80 .WillRepeatedly(Return(true)); |
| 85 policy_provider_.SetAutoRefresh(); | 81 policy_provider_.SetAutoRefresh(); |
| 86 policy::BrowserPolicyConnector::SetPolicyProviderForTesting( | 82 policy::BrowserPolicyConnector::SetPolicyProviderForTesting( |
| 87 &policy_provider_); | 83 &policy_provider_); |
| 88 #endif | |
| 89 } | 84 } |
| 90 | 85 |
| 91 void ReplyWhenSatisfied( | 86 void ReplyWhenSatisfied( |
| 92 Namespace settings_namespace, | 87 Namespace settings_namespace, |
| 93 const std::string& normal_action, | 88 const std::string& normal_action, |
| 94 const std::string& incognito_action) { | 89 const std::string& incognito_action) { |
| 95 MaybeLoadAndReplyWhenSatisfied( | 90 MaybeLoadAndReplyWhenSatisfied( |
| 96 settings_namespace, normal_action, incognito_action, NULL, false); | 91 settings_namespace, normal_action, incognito_action, NULL, false); |
| 97 } | 92 } |
| 98 | 93 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 125 void InitSync(syncer::SyncChangeProcessor* sync_processor) { | 120 void InitSync(syncer::SyncChangeProcessor* sync_processor) { |
| 126 base::MessageLoop::current()->RunUntilIdle(); | 121 base::MessageLoop::current()->RunUntilIdle(); |
| 127 InitSyncWithSyncableService(sync_processor, GetSyncableService()); | 122 InitSyncWithSyncableService(sync_processor, GetSyncableService()); |
| 128 } | 123 } |
| 129 | 124 |
| 130 void SendChanges(const syncer::SyncChangeList& change_list) { | 125 void SendChanges(const syncer::SyncChangeList& change_list) { |
| 131 base::MessageLoop::current()->RunUntilIdle(); | 126 base::MessageLoop::current()->RunUntilIdle(); |
| 132 SendChangesToSyncableService(change_list, GetSyncableService()); | 127 SendChangesToSyncableService(change_list, GetSyncableService()); |
| 133 } | 128 } |
| 134 | 129 |
| 135 #if defined(ENABLE_CONFIGURATION_POLICY) | |
| 136 void SetPolicies(const base::DictionaryValue& policies) { | 130 void SetPolicies(const base::DictionaryValue& policies) { |
| 137 scoped_ptr<policy::PolicyBundle> bundle(new policy::PolicyBundle()); | 131 scoped_ptr<policy::PolicyBundle> bundle(new policy::PolicyBundle()); |
| 138 policy::PolicyMap& policy_map = bundle->Get(policy::PolicyNamespace( | 132 policy::PolicyMap& policy_map = bundle->Get(policy::PolicyNamespace( |
| 139 policy::POLICY_DOMAIN_EXTENSIONS, kManagedStorageExtensionId)); | 133 policy::POLICY_DOMAIN_EXTENSIONS, kManagedStorageExtensionId)); |
| 140 policy_map.LoadFrom(&policies, policy::POLICY_LEVEL_MANDATORY, | 134 policy_map.LoadFrom(&policies, policy::POLICY_LEVEL_MANDATORY, |
| 141 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD); | 135 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD); |
| 142 policy_provider_.UpdatePolicy(std::move(bundle)); | 136 policy_provider_.UpdatePolicy(std::move(bundle)); |
| 143 } | 137 } |
| 144 #endif | |
| 145 | 138 |
| 146 private: | 139 private: |
| 147 const Extension* MaybeLoadAndReplyWhenSatisfied( | 140 const Extension* MaybeLoadAndReplyWhenSatisfied( |
| 148 Namespace settings_namespace, | 141 Namespace settings_namespace, |
| 149 const std::string& normal_action, | 142 const std::string& normal_action, |
| 150 const std::string& incognito_action, | 143 const std::string& incognito_action, |
| 151 // May be NULL to imply not loading the extension. | 144 // May be NULL to imply not loading the extension. |
| 152 const std::string* extension_dir, | 145 const std::string* extension_dir, |
| 153 bool is_final_action) { | 146 bool is_final_action) { |
| 154 ExtensionTestMessageListener listener("waiting", true); | 147 ExtensionTestMessageListener listener("waiting", true); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 } | 196 } |
| 204 | 197 |
| 205 void SendChangesToSyncableService( | 198 void SendChangesToSyncableService( |
| 206 const syncer::SyncChangeList& change_list, | 199 const syncer::SyncChangeList& change_list, |
| 207 syncer::SyncableService* settings_service) { | 200 syncer::SyncableService* settings_service) { |
| 208 EXPECT_FALSE( | 201 EXPECT_FALSE( |
| 209 settings_service->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); | 202 settings_service->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); |
| 210 } | 203 } |
| 211 | 204 |
| 212 protected: | 205 protected: |
| 213 #if defined(ENABLE_CONFIGURATION_POLICY) | |
| 214 policy::MockConfigurationPolicyProvider policy_provider_; | 206 policy::MockConfigurationPolicyProvider policy_provider_; |
| 215 #endif | |
| 216 }; | 207 }; |
| 217 | 208 |
| 218 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, SimpleTest) { | 209 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, SimpleTest) { |
| 219 ASSERT_TRUE(RunExtensionTest("settings/simple_test")) << message_; | 210 ASSERT_TRUE(RunExtensionTest("settings/simple_test")) << message_; |
| 220 } | 211 } |
| 221 | 212 |
| 222 // Structure of this test taken from IncognitoSplitMode. | 213 // Structure of this test taken from IncognitoSplitMode. |
| 223 // Note that only split-mode incognito is tested, because spanning mode | 214 // Note that only split-mode incognito is tested, because spanning mode |
| 224 // incognito looks the same as normal mode when the only API activity comes | 215 // incognito looks the same as normal mode when the only API activity comes |
| 225 // from background pages. | 216 // from background pages. |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 | 393 |
| 403 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 394 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 404 EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message(); | 395 EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message(); |
| 405 } | 396 } |
| 406 | 397 |
| 407 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, IsStorageEnabled) { | 398 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, IsStorageEnabled) { |
| 408 StorageFrontend* frontend = StorageFrontend::Get(browser()->profile()); | 399 StorageFrontend* frontend = StorageFrontend::Get(browser()->profile()); |
| 409 EXPECT_TRUE(frontend->IsStorageEnabled(LOCAL)); | 400 EXPECT_TRUE(frontend->IsStorageEnabled(LOCAL)); |
| 410 EXPECT_TRUE(frontend->IsStorageEnabled(SYNC)); | 401 EXPECT_TRUE(frontend->IsStorageEnabled(SYNC)); |
| 411 | 402 |
| 412 #if defined(ENABLE_CONFIGURATION_POLICY) | |
| 413 EXPECT_TRUE(frontend->IsStorageEnabled(MANAGED)); | 403 EXPECT_TRUE(frontend->IsStorageEnabled(MANAGED)); |
| 414 #else | |
| 415 EXPECT_FALSE(frontend->IsStorageEnabled(MANAGED)); | |
| 416 #endif | |
| 417 } | 404 } |
| 418 | 405 |
| 419 #if defined(ENABLE_CONFIGURATION_POLICY) | |
| 420 | |
| 421 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, ExtensionsSchemas) { | 406 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, ExtensionsSchemas) { |
| 422 // Verifies that the Schemas for the extensions domain are created on startup. | 407 // Verifies that the Schemas for the extensions domain are created on startup. |
| 423 Profile* profile = browser()->profile(); | 408 Profile* profile = browser()->profile(); |
| 424 ExtensionSystem* extension_system = ExtensionSystem::Get(profile); | 409 ExtensionSystem* extension_system = ExtensionSystem::Get(profile); |
| 425 if (!extension_system->ready().is_signaled()) { | 410 if (!extension_system->ready().is_signaled()) { |
| 426 // Wait until the extension system is ready. | 411 // Wait until the extension system is ready. |
| 427 base::RunLoop run_loop; | 412 base::RunLoop run_loop; |
| 428 extension_system->ready().Post(FROM_HERE, run_loop.QuitClosure()); | 413 extension_system->ready().Post(FROM_HERE, run_loop.QuitClosure()); |
| 429 run_loop.Run(); | 414 run_loop.Run(); |
| 430 ASSERT_TRUE(extension_system->ready().is_signaled()); | 415 ASSERT_TRUE(extension_system->ready().is_signaled()); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 // Verify that the test extension is still installed. | 553 // Verify that the test extension is still installed. |
| 569 const Extension* extension = GetSingleLoadedExtension(); | 554 const Extension* extension = GetSingleLoadedExtension(); |
| 570 ASSERT_TRUE(extension); | 555 ASSERT_TRUE(extension); |
| 571 EXPECT_EQ(kManagedStorageExtensionId, extension->id()); | 556 EXPECT_EQ(kManagedStorageExtensionId, extension->id()); |
| 572 | 557 |
| 573 // Running the test again skips the onInstalled callback, and just triggers | 558 // Running the test again skips the onInstalled callback, and just triggers |
| 574 // the onChanged notification. | 559 // the onChanged notification. |
| 575 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 560 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 576 } | 561 } |
| 577 | 562 |
| 578 #endif // defined(ENABLE_CONFIGURATION_POLICY) | |
| 579 | |
| 580 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, ManagedStorageDisabled) { | 563 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, ManagedStorageDisabled) { |
| 581 // Disable the 'managed' namespace. This is redundant when | 564 // Disable the 'managed' namespace. |
| 582 // ENABLE_CONFIGURATION_POLICY is not defined. | |
| 583 StorageFrontend* frontend = StorageFrontend::Get(browser()->profile()); | 565 StorageFrontend* frontend = StorageFrontend::Get(browser()->profile()); |
| 584 frontend->DisableStorageForTesting(MANAGED); | 566 frontend->DisableStorageForTesting(MANAGED); |
| 585 EXPECT_FALSE(frontend->IsStorageEnabled(MANAGED)); | 567 EXPECT_FALSE(frontend->IsStorageEnabled(MANAGED)); |
| 586 // Now run the extension. | 568 // Now run the extension. |
| 587 ASSERT_TRUE(RunExtensionTest("settings/managed_storage_disabled")) | 569 ASSERT_TRUE(RunExtensionTest("settings/managed_storage_disabled")) |
| 588 << message_; | 570 << message_; |
| 589 } | 571 } |
| 590 | 572 |
| 591 } // namespace extensions | 573 } // namespace extensions |
| OLD | NEW |