| 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" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 base::MessageLoop::current()->RunUntilIdle(); | 121 base::MessageLoop::current()->RunUntilIdle(); |
| 122 InitSyncWithSyncableService(sync_processor, GetSyncableService()); | 122 InitSyncWithSyncableService(sync_processor, GetSyncableService()); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void SendChanges(const syncer::SyncChangeList& change_list) { | 125 void SendChanges(const syncer::SyncChangeList& change_list) { |
| 126 base::MessageLoop::current()->RunUntilIdle(); | 126 base::MessageLoop::current()->RunUntilIdle(); |
| 127 SendChangesToSyncableService(change_list, GetSyncableService()); | 127 SendChangesToSyncableService(change_list, GetSyncableService()); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void SetPolicies(const base::DictionaryValue& policies) { | 130 void SetPolicies(const base::DictionaryValue& policies) { |
| 131 scoped_ptr<policy::PolicyBundle> bundle(new policy::PolicyBundle()); | 131 std::unique_ptr<policy::PolicyBundle> bundle(new policy::PolicyBundle()); |
| 132 policy::PolicyMap& policy_map = bundle->Get(policy::PolicyNamespace( | 132 policy::PolicyMap& policy_map = bundle->Get(policy::PolicyNamespace( |
| 133 policy::POLICY_DOMAIN_EXTENSIONS, kManagedStorageExtensionId)); | 133 policy::POLICY_DOMAIN_EXTENSIONS, kManagedStorageExtensionId)); |
| 134 policy_map.LoadFrom(&policies, policy::POLICY_LEVEL_MANDATORY, | 134 policy_map.LoadFrom(&policies, policy::POLICY_LEVEL_MANDATORY, |
| 135 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD); | 135 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD); |
| 136 policy_provider_.UpdatePolicy(std::move(bundle)); | 136 policy_provider_.UpdatePolicy(std::move(bundle)); |
| 137 } | 137 } |
| 138 | 138 |
| 139 private: | 139 private: |
| 140 const Extension* MaybeLoadAndReplyWhenSatisfied( | 140 const Extension* MaybeLoadAndReplyWhenSatisfied( |
| 141 Namespace settings_namespace, | 141 Namespace settings_namespace, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 message.SetString("action", action); | 175 message.SetString("action", action); |
| 176 message.SetBoolean("isFinalAction", is_final_action); | 176 message.SetBoolean("isFinalAction", is_final_action); |
| 177 std::string message_json; | 177 std::string message_json; |
| 178 base::JSONWriter::Write(message, &message_json); | 178 base::JSONWriter::Write(message, &message_json); |
| 179 return message_json; | 179 return message_json; |
| 180 } | 180 } |
| 181 | 181 |
| 182 void InitSyncWithSyncableService( | 182 void InitSyncWithSyncableService( |
| 183 syncer::SyncChangeProcessor* sync_processor, | 183 syncer::SyncChangeProcessor* sync_processor, |
| 184 syncer::SyncableService* settings_service) { | 184 syncer::SyncableService* settings_service) { |
| 185 EXPECT_FALSE( | 185 EXPECT_FALSE(settings_service |
| 186 settings_service->MergeDataAndStartSyncing( | 186 ->MergeDataAndStartSyncing( |
| 187 kModelType, | 187 kModelType, syncer::SyncDataList(), |
| 188 syncer::SyncDataList(), | 188 std::unique_ptr<syncer::SyncChangeProcessor>( |
| 189 scoped_ptr<syncer::SyncChangeProcessor>( | 189 new syncer::SyncChangeProcessorWrapperForTest( |
| 190 new syncer::SyncChangeProcessorWrapperForTest( | 190 sync_processor)), |
| 191 sync_processor)), | 191 std::unique_ptr<syncer::SyncErrorFactory>( |
| 192 scoped_ptr<syncer::SyncErrorFactory>( | 192 new syncer::SyncErrorFactoryMock())) |
| 193 new syncer::SyncErrorFactoryMock())) | 193 .error() |
| 194 .error() | 194 .IsSet()); |
| 195 .IsSet()); | |
| 196 } | 195 } |
| 197 | 196 |
| 198 void SendChangesToSyncableService( | 197 void SendChangesToSyncableService( |
| 199 const syncer::SyncChangeList& change_list, | 198 const syncer::SyncChangeList& change_list, |
| 200 syncer::SyncableService* settings_service) { | 199 syncer::SyncableService* settings_service) { |
| 201 EXPECT_FALSE( | 200 EXPECT_FALSE( |
| 202 settings_service->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); | 201 settings_service->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); |
| 203 } | 202 } |
| 204 | 203 |
| 205 protected: | 204 protected: |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 ASSERT_EQ(base::Value::TYPE_LIST, list.type()); | 470 ASSERT_EQ(base::Value::TYPE_LIST, list.type()); |
| 472 dict = list.GetItems(); | 471 dict = list.GetItems(); |
| 473 ASSERT_TRUE(dict.valid()); | 472 ASSERT_TRUE(dict.valid()); |
| 474 ASSERT_EQ(base::Value::TYPE_DICTIONARY, dict.type()); | 473 ASSERT_EQ(base::Value::TYPE_DICTIONARY, dict.type()); |
| 475 ASSERT_TRUE(dict.GetProperty("anything").valid()); | 474 ASSERT_TRUE(dict.GetProperty("anything").valid()); |
| 476 EXPECT_EQ(base::Value::TYPE_INTEGER, dict.GetProperty("anything").type()); | 475 EXPECT_EQ(base::Value::TYPE_INTEGER, dict.GetProperty("anything").type()); |
| 477 } | 476 } |
| 478 | 477 |
| 479 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, ManagedStorage) { | 478 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, ManagedStorage) { |
| 480 // Set policies for the test extension. | 479 // Set policies for the test extension. |
| 481 scoped_ptr<base::DictionaryValue> policy = | 480 std::unique_ptr<base::DictionaryValue> policy = |
| 482 extensions::DictionaryBuilder() | 481 extensions::DictionaryBuilder() |
| 483 .Set("string-policy", "value") | 482 .Set("string-policy", "value") |
| 484 .Set("int-policy", -123) | 483 .Set("int-policy", -123) |
| 485 .Set("double-policy", 456e7) | 484 .Set("double-policy", 456e7) |
| 486 .SetBoolean("boolean-policy", true) | 485 .SetBoolean("boolean-policy", true) |
| 487 .Set("list-policy", extensions::ListBuilder() | 486 .Set("list-policy", extensions::ListBuilder() |
| 488 .Append("one") | 487 .Append("one") |
| 489 .Append("two") | 488 .Append("two") |
| 490 .Append("three") | 489 .Append("three") |
| 491 .Build()) | 490 .Build()) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 509 | 508 |
| 510 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, | 509 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, |
| 511 DISABLED_PRE_ManagedStorageEvents) { | 510 DISABLED_PRE_ManagedStorageEvents) { |
| 512 ResultCatcher catcher; | 511 ResultCatcher catcher; |
| 513 | 512 |
| 514 // This test starts without any test extensions installed. | 513 // This test starts without any test extensions installed. |
| 515 EXPECT_FALSE(GetSingleLoadedExtension()); | 514 EXPECT_FALSE(GetSingleLoadedExtension()); |
| 516 message_.clear(); | 515 message_.clear(); |
| 517 | 516 |
| 518 // Set policies for the test extension. | 517 // Set policies for the test extension. |
| 519 scoped_ptr<base::DictionaryValue> policy = extensions::DictionaryBuilder() | 518 std::unique_ptr<base::DictionaryValue> policy = |
| 520 .Set("constant-policy", "aaa") | 519 extensions::DictionaryBuilder() |
| 521 .Set("changes-policy", "bbb") | 520 .Set("constant-policy", "aaa") |
| 522 .Set("deleted-policy", "ccc") | 521 .Set("changes-policy", "bbb") |
| 523 .Build(); | 522 .Set("deleted-policy", "ccc") |
| 523 .Build(); |
| 524 SetPolicies(*policy); | 524 SetPolicies(*policy); |
| 525 | 525 |
| 526 ExtensionTestMessageListener ready_listener("ready", false); | 526 ExtensionTestMessageListener ready_listener("ready", false); |
| 527 // Load the extension to install the event listener. | 527 // Load the extension to install the event listener. |
| 528 const Extension* extension = LoadExtension( | 528 const Extension* extension = LoadExtension( |
| 529 test_data_dir_.AppendASCII("settings/managed_storage_events")); | 529 test_data_dir_.AppendASCII("settings/managed_storage_events")); |
| 530 ASSERT_TRUE(extension); | 530 ASSERT_TRUE(extension); |
| 531 // Wait until the extension sends the "ready" message. | 531 // Wait until the extension sends the "ready" message. |
| 532 ASSERT_TRUE(ready_listener.WaitUntilSatisfied()); | 532 ASSERT_TRUE(ready_listener.WaitUntilSatisfied()); |
| 533 | 533 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 564 // Disable the 'managed' namespace. | 564 // Disable the 'managed' namespace. |
| 565 StorageFrontend* frontend = StorageFrontend::Get(browser()->profile()); | 565 StorageFrontend* frontend = StorageFrontend::Get(browser()->profile()); |
| 566 frontend->DisableStorageForTesting(MANAGED); | 566 frontend->DisableStorageForTesting(MANAGED); |
| 567 EXPECT_FALSE(frontend->IsStorageEnabled(MANAGED)); | 567 EXPECT_FALSE(frontend->IsStorageEnabled(MANAGED)); |
| 568 // Now run the extension. | 568 // Now run the extension. |
| 569 ASSERT_TRUE(RunExtensionTest("settings/managed_storage_disabled")) | 569 ASSERT_TRUE(RunExtensionTest("settings/managed_storage_disabled")) |
| 570 << message_; | 570 << message_; |
| 571 } | 571 } |
| 572 | 572 |
| 573 } // namespace extensions | 573 } // namespace extensions |
| OLD | NEW |