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 "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/extensions/extension_test_message_listener.h" | 9 #include "chrome/browser/extensions/extension_test_message_listener.h" |
10 #include "chrome/browser/extensions/settings/settings_frontend.h" | 10 #include "chrome/browser/extensions/settings/settings_frontend.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 } | 132 } |
133 | 133 |
134 void SendChanges(const syncer::SyncChangeList& change_list) { | 134 void SendChanges(const syncer::SyncChangeList& change_list) { |
135 MessageLoop::current()->RunAllPending(); | 135 MessageLoop::current()->RunAllPending(); |
136 SendChangesToSyncableService( | 136 SendChangesToSyncableService( |
137 change_list, | 137 change_list, |
138 browser()->profile()->GetExtensionService()->settings_frontend()-> | 138 browser()->profile()->GetExtensionService()->settings_frontend()-> |
139 GetBackendForSync(kModelType)); | 139 GetBackendForSync(kModelType)); |
140 } | 140 } |
141 | 141 |
| 142 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 143 void SetPolicies(const base::DictionaryValue& policies) { |
| 144 scoped_ptr<policy::PolicyBundle> bundle(new policy::PolicyBundle()); |
| 145 policy::PolicyMap& policy_map = bundle->Get( |
| 146 policy::POLICY_DOMAIN_EXTENSIONS, kManagedStorageExtensionId); |
| 147 policy_map.LoadFrom( |
| 148 &policies, policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER); |
| 149 policy_provider_.UpdatePolicy(bundle.Pass()); |
| 150 } |
| 151 #endif |
| 152 |
142 private: | 153 private: |
143 const Extension* MaybeLoadAndReplyWhenSatisfied( | 154 const Extension* MaybeLoadAndReplyWhenSatisfied( |
144 Namespace settings_namespace, | 155 Namespace settings_namespace, |
145 const std::string& normal_action, | 156 const std::string& normal_action, |
146 const std::string& incognito_action, | 157 const std::string& incognito_action, |
147 // May be NULL to imply not loading the extension. | 158 // May be NULL to imply not loading the extension. |
148 const std::string* extension_dir, | 159 const std::string* extension_dir, |
149 bool is_final_action) { | 160 bool is_final_action) { |
150 ExtensionTestMessageListener listener("waiting", true); | 161 ExtensionTestMessageListener listener("waiting", true); |
151 ExtensionTestMessageListener listener_incognito("waiting_incognito", true); | 162 ExtensionTestMessageListener listener_incognito("waiting_incognito", true); |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 .Append("two") | 433 .Append("two") |
423 .Append("three")) | 434 .Append("three")) |
424 .Set("dict-policy", extensions::DictionaryBuilder() | 435 .Set("dict-policy", extensions::DictionaryBuilder() |
425 .Set("list", extensions::ListBuilder() | 436 .Set("list", extensions::ListBuilder() |
426 .Append(extensions::DictionaryBuilder() | 437 .Append(extensions::DictionaryBuilder() |
427 .Set("one", 1) | 438 .Set("one", 1) |
428 .Set("two", 2)) | 439 .Set("two", 2)) |
429 .Append(extensions::DictionaryBuilder() | 440 .Append(extensions::DictionaryBuilder() |
430 .Set("three", 3)))) | 441 .Set("three", 3)))) |
431 .Build(); | 442 .Build(); |
432 | 443 SetPolicies(*policy); |
433 scoped_ptr<policy::PolicyBundle> bundle(new policy::PolicyBundle()); | |
434 policy::PolicyMap& policy_map = | |
435 bundle->Get(policy::POLICY_DOMAIN_EXTENSIONS, kManagedStorageExtensionId); | |
436 policy_map.LoadFrom( | |
437 policy.get(), policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER); | |
438 policy_provider_.UpdatePolicy(bundle.Pass()); | |
439 | |
440 // Now run the extension. | 444 // Now run the extension. |
441 ASSERT_TRUE(RunExtensionTest("settings/managed_storage")) << message_; | 445 ASSERT_TRUE(RunExtensionTest("settings/managed_storage")) << message_; |
442 } | 446 } |
443 #endif | 447 |
| 448 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, ManagedStorageEvents) { |
| 449 ResultCatcher catcher; |
| 450 |
| 451 // Set policies for the test extension. |
| 452 scoped_ptr<base::DictionaryValue> policy = extensions::DictionaryBuilder() |
| 453 .Set("constant-policy", "aaa") |
| 454 .Set("changes-policy", "bbb") |
| 455 .Set("deleted-policy", "ccc") |
| 456 .Build(); |
| 457 SetPolicies(*policy); |
| 458 |
| 459 ExtensionTestMessageListener ready_listener("ready", false); |
| 460 // Load the extension to install the event listener. |
| 461 const Extension* extension = LoadExtension( |
| 462 test_data_dir_.AppendASCII("settings/managed_storage_events")); |
| 463 ASSERT_TRUE(extension); |
| 464 // Wait until the extension sends the "ready" message. |
| 465 ASSERT_TRUE(ready_listener.WaitUntilSatisfied()); |
| 466 |
| 467 // Now change the policies and wait until the extension is done. |
| 468 policy = extensions::DictionaryBuilder() |
| 469 .Set("constant-policy", "aaa") |
| 470 .Set("changes-policy", "ddd") |
| 471 .Set("new-policy", "eee") |
| 472 .Build(); |
| 473 SetPolicies(*policy); |
| 474 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 475 } |
| 476 #endif // defined(ENABLE_CONFIGURATION_POLICY) |
444 | 477 |
445 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, ManagedStorageDisabled) { | 478 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, ManagedStorageDisabled) { |
446 // Disable the 'managed' namespace. This is redundant when | 479 // Disable the 'managed' namespace. This is redundant when |
447 // ENABLE_CONFIGURATION_POLICY is not defined. | 480 // ENABLE_CONFIGURATION_POLICY is not defined. |
448 SettingsFrontend* frontend = | 481 SettingsFrontend* frontend = |
449 browser()->profile()->GetExtensionService()->settings_frontend(); | 482 browser()->profile()->GetExtensionService()->settings_frontend(); |
450 frontend->DisableStorageForTesting(MANAGED); | 483 frontend->DisableStorageForTesting(MANAGED); |
451 EXPECT_FALSE(frontend->IsStorageEnabled(MANAGED)); | 484 EXPECT_FALSE(frontend->IsStorageEnabled(MANAGED)); |
452 | |
453 // Set a policy for the extension. | |
454 scoped_ptr<policy::PolicyBundle> bundle(new policy::PolicyBundle()); | |
455 policy::PolicyMap& policy_map = | |
456 bundle->Get(policy::POLICY_DOMAIN_EXTENSIONS, kManagedStorageExtensionId); | |
457 policy_map.Set( | |
458 "policy", policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER, | |
459 base::Value::CreateStringValue("policy_value")); | |
460 policy_provider_.UpdatePolicy(bundle.Pass()); | |
461 | |
462 // Now run the extension. | 485 // Now run the extension. |
463 ASSERT_TRUE(RunExtensionTest("settings/managed_storage_disabled")) | 486 ASSERT_TRUE(RunExtensionTest("settings/managed_storage_disabled")) |
464 << message_; | 487 << message_; |
465 } | 488 } |
466 | 489 |
467 } // namespace extensions | 490 } // namespace extensions |
OLD | NEW |