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
3 // found in the LICENSE file.
6 #include "base/json/json_writer.h"
7 #include "base/memory/ref_counted.h"
8 #include "base/run_loop.h"
9 #include "base/values.h"
10 #include "chrome/browser/extensions/api/storage/settings_frontend.h"
11 #include "chrome/browser/extensions/api/storage/settings_namespace.h"
12 #include "chrome/browser/extensions/api/storage/settings_sync_util.h"
13 #include "chrome/browser/extensions/extension_apitest.h"
14 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/extensions/extension_system_factory.h"
16 #include "chrome/browser/extensions/extension_test_message_listener.h"
17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/browser.h"
19 #include "chrome/test/base/ui_test_utils.h"
20 #include "extensions/browser/extension_system.h"
21 #include "extensions/common/value_builder.h"
22 #include "sync/api/sync_change.h"
23 #include "sync/api/sync_change_processor.h"
24 #include "sync/api/sync_error_factory.h"
25 #include "sync/api/sync_error_factory_mock.h"
26 #include "testing/gmock/include/gmock/gmock.h"
28 #if defined(ENABLE_CONFIGURATION_POLICY)
29 #include "chrome/browser/policy/schema_registry_service.h"
30 #include "chrome/browser/policy/schema_registry_service_factory.h"
31 #include "components/policy/core/browser/browser_policy_connector.h"
32 #include "components/policy/core/common/mock_configuration_policy_provider.h"
33 #include "components/policy/core/common/policy_bundle.h"
34 #include "components/policy/core/common/policy_map.h"
35 #include "components/policy/core/common/policy_namespace.h"
36 #include "components/policy/core/common/schema.h"
37 #include "components/policy/core/common/schema_map.h"
38 #include "components/policy/core/common/schema_registry.h"
41 namespace extensions {
43 using settings_namespace::LOCAL;
44 using settings_namespace::MANAGED;
45 using settings_namespace::Namespace;
46 using settings_namespace::SYNC;
47 using settings_namespace::ToString;
49 using testing::Return;
54 // TODO(kalman): test both EXTENSION_SETTINGS and APP_SETTINGS.
55 const syncer::ModelType kModelType = syncer::EXTENSION_SETTINGS;
57 // The managed_storage extension has a key defined in its manifest, so that
58 // its extension ID is well-known and the policy system can push policies for
60 const char kManagedStorageExtensionId[] = "kjmkgkdkpedkejedfhmfcenooemhbpbo";
62 class NoopSyncChangeProcessor : public syncer::SyncChangeProcessor {
64 virtual syncer::SyncError ProcessSyncChanges(
65 const tracked_objects::Location& from_here,
66 const syncer::SyncChangeList& change_list) OVERRIDE {
67 return syncer::SyncError();
70 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const
72 return syncer::SyncDataList();
75 virtual ~NoopSyncChangeProcessor() {};
78 class SyncChangeProcessorDelegate : public syncer::SyncChangeProcessor {
80 explicit SyncChangeProcessorDelegate(syncer::SyncChangeProcessor* recipient)
81 : recipient_(recipient) {
84 virtual ~SyncChangeProcessorDelegate() {}
86 // syncer::SyncChangeProcessor implementation.
87 virtual syncer::SyncError ProcessSyncChanges(
88 const tracked_objects::Location& from_here,
89 const syncer::SyncChangeList& change_list) OVERRIDE {
90 return recipient_->ProcessSyncChanges(from_here, change_list);
93 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const
95 return recipient_->GetAllSyncData(type);
99 // The recipient of all sync changes.
100 syncer::SyncChangeProcessor* recipient_;
102 DISALLOW_COPY_AND_ASSIGN(SyncChangeProcessorDelegate);
105 class MockSchemaRegistryObserver : public policy::SchemaRegistry::Observer {
107 MockSchemaRegistryObserver() {}
108 virtual ~MockSchemaRegistryObserver() {}
110 MOCK_METHOD1(OnSchemaRegistryUpdated, void(bool));
111 MOCK_METHOD0(OnSchemaRegistryReady, void());
116 class ExtensionSettingsApiTest : public ExtensionApiTest {
118 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
119 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
121 #if defined(ENABLE_CONFIGURATION_POLICY)
122 EXPECT_CALL(policy_provider_, IsInitializationComplete(_))
123 .WillRepeatedly(Return(true));
124 policy_provider_.SetAutoRefresh();
125 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(
130 void ReplyWhenSatisfied(
131 Namespace settings_namespace,
132 const std::string& normal_action,
133 const std::string& incognito_action) {
134 MaybeLoadAndReplyWhenSatisfied(
135 settings_namespace, normal_action, incognito_action, NULL, false);
138 const Extension* LoadAndReplyWhenSatisfied(
139 Namespace settings_namespace,
140 const std::string& normal_action,
141 const std::string& incognito_action,
142 const std::string& extension_dir) {
143 return MaybeLoadAndReplyWhenSatisfied(
151 void FinalReplyWhenSatisfied(
152 Namespace settings_namespace,
153 const std::string& normal_action,
154 const std::string& incognito_action) {
155 MaybeLoadAndReplyWhenSatisfied(
156 settings_namespace, normal_action, incognito_action, NULL, true);
159 void InitSync(syncer::SyncChangeProcessor* sync_processor) {
160 base::MessageLoop::current()->RunUntilIdle();
161 InitSyncWithSyncableService(
163 browser()->profile()->GetExtensionService()->settings_frontend()->
164 GetBackendForSync(kModelType));
167 void SendChanges(const syncer::SyncChangeList& change_list) {
168 base::MessageLoop::current()->RunUntilIdle();
169 SendChangesToSyncableService(
171 browser()->profile()->GetExtensionService()->settings_frontend()->
172 GetBackendForSync(kModelType));
175 #if defined(ENABLE_CONFIGURATION_POLICY)
176 void SetPolicies(const base::DictionaryValue& policies) {
177 scoped_ptr<policy::PolicyBundle> bundle(new policy::PolicyBundle());
178 policy::PolicyMap& policy_map = bundle->Get(policy::PolicyNamespace(
179 policy::POLICY_DOMAIN_EXTENSIONS, kManagedStorageExtensionId));
181 &policies, policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER);
182 policy_provider_.UpdatePolicy(bundle.Pass());
187 const Extension* MaybeLoadAndReplyWhenSatisfied(
188 Namespace settings_namespace,
189 const std::string& normal_action,
190 const std::string& incognito_action,
191 // May be NULL to imply not loading the extension.
192 const std::string* extension_dir,
193 bool is_final_action) {
194 ExtensionTestMessageListener listener("waiting", true);
195 ExtensionTestMessageListener listener_incognito("waiting_incognito", true);
197 // Only load the extension after the listeners have been set up, to avoid
198 // initialisation race conditions.
199 const Extension* extension = NULL;
201 extension = LoadExtensionIncognito(
202 test_data_dir_.AppendASCII("settings").AppendASCII(*extension_dir));
203 EXPECT_TRUE(extension);
206 EXPECT_TRUE(listener.WaitUntilSatisfied());
207 EXPECT_TRUE(listener_incognito.WaitUntilSatisfied());
210 CreateMessage(settings_namespace, normal_action, is_final_action));
211 listener_incognito.Reply(
212 CreateMessage(settings_namespace, incognito_action, is_final_action));
216 std::string CreateMessage(
217 Namespace settings_namespace,
218 const std::string& action,
219 bool is_final_action) {
220 scoped_ptr<base::DictionaryValue> message(new base::DictionaryValue());
221 message->SetString("namespace", ToString(settings_namespace));
222 message->SetString("action", action);
223 message->SetBoolean("isFinalAction", is_final_action);
224 std::string message_json;
225 base::JSONWriter::Write(message.get(), &message_json);
229 void InitSyncWithSyncableService(
230 syncer::SyncChangeProcessor* sync_processor,
231 syncer::SyncableService* settings_service) {
232 EXPECT_FALSE(settings_service->MergeDataAndStartSyncing(
234 syncer::SyncDataList(),
235 scoped_ptr<syncer::SyncChangeProcessor>(
236 new SyncChangeProcessorDelegate(sync_processor)),
237 scoped_ptr<syncer::SyncErrorFactory>(
238 new syncer::SyncErrorFactoryMock())).error().IsSet());
241 void SendChangesToSyncableService(
242 const syncer::SyncChangeList& change_list,
243 syncer::SyncableService* settings_service) {
245 settings_service->ProcessSyncChanges(FROM_HERE, change_list).IsSet());
249 #if defined(ENABLE_CONFIGURATION_POLICY)
250 policy::MockConfigurationPolicyProvider policy_provider_;
254 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, SimpleTest) {
255 ASSERT_TRUE(RunExtensionTest("settings/simple_test")) << message_;
258 // Structure of this test taken from IncognitoSplitMode.
259 // Note that only split-mode incognito is tested, because spanning mode
260 // incognito looks the same as normal mode when the only API activity comes
261 // from background pages.
262 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, SplitModeIncognito) {
263 // We need 2 ResultCatchers because we'll be running the same test in both
264 // regular and incognito mode.
265 ResultCatcher catcher, catcher_incognito;
266 catcher.RestrictToProfile(browser()->profile());
267 catcher_incognito.RestrictToProfile(
268 browser()->profile()->GetOffTheRecordProfile());
270 LoadAndReplyWhenSatisfied(SYNC,
271 "assertEmpty", "assertEmpty", "split_incognito");
272 ReplyWhenSatisfied(SYNC, "noop", "setFoo");
273 ReplyWhenSatisfied(SYNC, "assertFoo", "assertFoo");
274 ReplyWhenSatisfied(SYNC, "clear", "noop");
275 ReplyWhenSatisfied(SYNC, "assertEmpty", "assertEmpty");
276 ReplyWhenSatisfied(SYNC, "setFoo", "noop");
277 ReplyWhenSatisfied(SYNC, "assertFoo", "assertFoo");
278 ReplyWhenSatisfied(SYNC, "noop", "removeFoo");
279 FinalReplyWhenSatisfied(SYNC, "assertEmpty", "assertEmpty");
281 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
282 EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message();
285 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest,
286 OnChangedNotificationsBetweenBackgroundPages) {
287 // We need 2 ResultCatchers because we'll be running the same test in both
288 // regular and incognito mode.
289 ResultCatcher catcher, catcher_incognito;
290 catcher.RestrictToProfile(browser()->profile());
291 catcher_incognito.RestrictToProfile(
292 browser()->profile()->GetOffTheRecordProfile());
294 LoadAndReplyWhenSatisfied(SYNC,
295 "assertNoNotifications", "assertNoNotifications", "split_incognito");
296 ReplyWhenSatisfied(SYNC, "noop", "setFoo");
297 ReplyWhenSatisfied(SYNC,
298 "assertAddFooNotification", "assertAddFooNotification");
299 ReplyWhenSatisfied(SYNC, "clearNotifications", "clearNotifications");
300 ReplyWhenSatisfied(SYNC, "removeFoo", "noop");
301 FinalReplyWhenSatisfied(SYNC,
302 "assertDeleteFooNotification", "assertDeleteFooNotification");
304 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
305 EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message();
308 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest,
309 SyncAndLocalAreasAreSeparate) {
310 // We need 2 ResultCatchers because we'll be running the same test in both
311 // regular and incognito mode.
312 ResultCatcher catcher, catcher_incognito;
313 catcher.RestrictToProfile(browser()->profile());
314 catcher_incognito.RestrictToProfile(
315 browser()->profile()->GetOffTheRecordProfile());
317 LoadAndReplyWhenSatisfied(SYNC,
318 "assertNoNotifications", "assertNoNotifications", "split_incognito");
320 ReplyWhenSatisfied(SYNC, "noop", "setFoo");
321 ReplyWhenSatisfied(SYNC, "assertFoo", "assertFoo");
322 ReplyWhenSatisfied(SYNC,
323 "assertAddFooNotification", "assertAddFooNotification");
324 ReplyWhenSatisfied(LOCAL, "assertEmpty", "assertEmpty");
325 ReplyWhenSatisfied(LOCAL, "assertNoNotifications", "assertNoNotifications");
327 ReplyWhenSatisfied(SYNC, "clearNotifications", "clearNotifications");
329 ReplyWhenSatisfied(LOCAL, "setFoo", "noop");
330 ReplyWhenSatisfied(LOCAL, "assertFoo", "assertFoo");
331 ReplyWhenSatisfied(LOCAL,
332 "assertAddFooNotification", "assertAddFooNotification");
333 ReplyWhenSatisfied(SYNC, "assertFoo", "assertFoo");
334 ReplyWhenSatisfied(SYNC, "assertNoNotifications", "assertNoNotifications");
336 ReplyWhenSatisfied(LOCAL, "clearNotifications", "clearNotifications");
338 ReplyWhenSatisfied(LOCAL, "noop", "removeFoo");
339 ReplyWhenSatisfied(LOCAL, "assertEmpty", "assertEmpty");
340 ReplyWhenSatisfied(LOCAL,
341 "assertDeleteFooNotification", "assertDeleteFooNotification");
342 ReplyWhenSatisfied(SYNC, "assertFoo", "assertFoo");
343 ReplyWhenSatisfied(SYNC, "assertNoNotifications", "assertNoNotifications");
345 ReplyWhenSatisfied(LOCAL, "clearNotifications", "clearNotifications");
347 ReplyWhenSatisfied(SYNC, "removeFoo", "noop");
348 ReplyWhenSatisfied(SYNC, "assertEmpty", "assertEmpty");
349 ReplyWhenSatisfied(SYNC,
350 "assertDeleteFooNotification", "assertDeleteFooNotification");
351 ReplyWhenSatisfied(LOCAL, "assertNoNotifications", "assertNoNotifications");
352 FinalReplyWhenSatisfied(LOCAL, "assertEmpty", "assertEmpty");
354 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
355 EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message();
358 // Disabled, see crbug.com/101110
359 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest,
360 DISABLED_OnChangedNotificationsFromSync) {
361 // We need 2 ResultCatchers because we'll be running the same test in both
362 // regular and incognito mode.
363 ResultCatcher catcher, catcher_incognito;
364 catcher.RestrictToProfile(browser()->profile());
365 catcher_incognito.RestrictToProfile(
366 browser()->profile()->GetOffTheRecordProfile());
368 const Extension* extension =
369 LoadAndReplyWhenSatisfied(SYNC,
370 "assertNoNotifications", "assertNoNotifications", "split_incognito");
371 const std::string& extension_id = extension->id();
373 NoopSyncChangeProcessor sync_processor;
374 InitSync(&sync_processor);
376 // Set "foo" to "bar" via sync.
377 syncer::SyncChangeList sync_changes;
378 base::StringValue bar("bar");
379 sync_changes.push_back(settings_sync_util::CreateAdd(
380 extension_id, "foo", bar, kModelType));
381 SendChanges(sync_changes);
383 ReplyWhenSatisfied(SYNC,
384 "assertAddFooNotification", "assertAddFooNotification");
385 ReplyWhenSatisfied(SYNC, "clearNotifications", "clearNotifications");
387 // Remove "foo" via sync.
388 sync_changes.clear();
389 sync_changes.push_back(settings_sync_util::CreateDelete(
390 extension_id, "foo", kModelType));
391 SendChanges(sync_changes);
393 FinalReplyWhenSatisfied(SYNC,
394 "assertDeleteFooNotification", "assertDeleteFooNotification");
396 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
397 EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message();
400 // Disabled, see crbug.com/101110
402 // TODO: boring test, already done in the unit tests. What we really should be
403 // be testing is that the areas don't overlap.
404 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest,
405 DISABLED_OnChangedNotificationsFromSyncNotSentToLocal) {
406 // We need 2 ResultCatchers because we'll be running the same test in both
407 // regular and incognito mode.
408 ResultCatcher catcher, catcher_incognito;
409 catcher.RestrictToProfile(browser()->profile());
410 catcher_incognito.RestrictToProfile(
411 browser()->profile()->GetOffTheRecordProfile());
413 const Extension* extension =
414 LoadAndReplyWhenSatisfied(LOCAL,
415 "assertNoNotifications", "assertNoNotifications", "split_incognito");
416 const std::string& extension_id = extension->id();
418 NoopSyncChangeProcessor sync_processor;
419 InitSync(&sync_processor);
421 // Set "foo" to "bar" via sync.
422 syncer::SyncChangeList sync_changes;
423 base::StringValue bar("bar");
424 sync_changes.push_back(settings_sync_util::CreateAdd(
425 extension_id, "foo", bar, kModelType));
426 SendChanges(sync_changes);
428 ReplyWhenSatisfied(LOCAL, "assertNoNotifications", "assertNoNotifications");
430 // Remove "foo" via sync.
431 sync_changes.clear();
432 sync_changes.push_back(settings_sync_util::CreateDelete(
433 extension_id, "foo", kModelType));
434 SendChanges(sync_changes);
436 FinalReplyWhenSatisfied(LOCAL,
437 "assertNoNotifications", "assertNoNotifications");
439 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
440 EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message();
443 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, IsStorageEnabled) {
444 SettingsFrontend* frontend =
445 browser()->profile()->GetExtensionService()->settings_frontend();
446 EXPECT_TRUE(frontend->IsStorageEnabled(LOCAL));
447 EXPECT_TRUE(frontend->IsStorageEnabled(SYNC));
449 #if defined(ENABLE_CONFIGURATION_POLICY)
450 EXPECT_TRUE(frontend->IsStorageEnabled(MANAGED));
452 EXPECT_FALSE(frontend->IsStorageEnabled(MANAGED));
456 #if defined(ENABLE_CONFIGURATION_POLICY)
458 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, ExtensionsSchemas) {
459 // Verifies that the Schemas for the extensions domain are created on startup.
460 Profile* profile = browser()->profile();
461 ExtensionSystem* extension_system = ExtensionSystem::Get(profile);
462 if (!extension_system->ready().is_signaled()) {
463 // Wait until the extension system is ready.
464 base::RunLoop run_loop;
465 extension_system->ready().Post(FROM_HERE, run_loop.QuitClosure());
467 ASSERT_TRUE(extension_system->ready().is_signaled());
470 // This test starts without any test extensions installed.
471 EXPECT_FALSE(GetSingleLoadedExtension());
474 policy::SchemaRegistry* registry =
475 policy::SchemaRegistryServiceFactory::GetForContext(profile);
476 ASSERT_TRUE(registry);
477 EXPECT_FALSE(registry->schema_map()->GetSchema(policy::PolicyNamespace(
478 policy::POLICY_DOMAIN_EXTENSIONS, kManagedStorageExtensionId)));
480 MockSchemaRegistryObserver observer;
481 registry->AddObserver(&observer);
483 // Install a managed extension.
484 EXPECT_CALL(observer, OnSchemaRegistryUpdated(true));
485 const Extension* extension =
486 LoadExtension(test_data_dir_.AppendASCII("settings/managed_storage"));
487 ASSERT_TRUE(extension);
488 Mock::VerifyAndClearExpectations(&observer);
489 registry->RemoveObserver(&observer);
491 // Verify that its schema has been published, and verify its contents.
492 const policy::Schema* schema =
493 registry->schema_map()->GetSchema(policy::PolicyNamespace(
494 policy::POLICY_DOMAIN_EXTENSIONS, kManagedStorageExtensionId));
497 ASSERT_TRUE(schema->valid());
498 ASSERT_EQ(base::Value::TYPE_DICTIONARY, schema->type());
499 ASSERT_TRUE(schema->GetKnownProperty("string-policy").valid());
500 EXPECT_EQ(base::Value::TYPE_STRING,
501 schema->GetKnownProperty("string-policy").type());
502 ASSERT_TRUE(schema->GetKnownProperty("int-policy").valid());
503 EXPECT_EQ(base::Value::TYPE_INTEGER,
504 schema->GetKnownProperty("int-policy").type());
505 ASSERT_TRUE(schema->GetKnownProperty("double-policy").valid());
506 EXPECT_EQ(base::Value::TYPE_DOUBLE,
507 schema->GetKnownProperty("double-policy").type());
508 ASSERT_TRUE(schema->GetKnownProperty("boolean-policy").valid());
509 EXPECT_EQ(base::Value::TYPE_BOOLEAN,
510 schema->GetKnownProperty("boolean-policy").type());
512 policy::Schema list = schema->GetKnownProperty("list-policy");
513 ASSERT_TRUE(list.valid());
514 ASSERT_EQ(base::Value::TYPE_LIST, list.type());
515 ASSERT_TRUE(list.GetItems().valid());
516 EXPECT_EQ(base::Value::TYPE_STRING, list.GetItems().type());
518 policy::Schema dict = schema->GetKnownProperty("dict-policy");
519 ASSERT_TRUE(dict.valid());
520 ASSERT_EQ(base::Value::TYPE_DICTIONARY, dict.type());
521 list = dict.GetKnownProperty("list");
522 ASSERT_TRUE(list.valid());
523 ASSERT_EQ(base::Value::TYPE_LIST, list.type());
524 dict = list.GetItems();
525 ASSERT_TRUE(dict.valid());
526 ASSERT_EQ(base::Value::TYPE_DICTIONARY, dict.type());
527 ASSERT_TRUE(dict.GetProperty("anything").valid());
528 EXPECT_EQ(base::Value::TYPE_INTEGER, dict.GetProperty("anything").type());
531 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, ManagedStorage) {
532 // Set policies for the test extension.
533 scoped_ptr<base::DictionaryValue> policy = extensions::DictionaryBuilder()
534 .Set("string-policy", "value")
535 .Set("int-policy", -123)
536 .Set("double-policy", 456e7)
537 .SetBoolean("boolean-policy", true)
538 .Set("list-policy", extensions::ListBuilder()
542 .Set("dict-policy", extensions::DictionaryBuilder()
543 .Set("list", extensions::ListBuilder()
544 .Append(extensions::DictionaryBuilder()
547 .Append(extensions::DictionaryBuilder()
550 SetPolicies(*policy);
551 // Now run the extension.
552 ASSERT_TRUE(RunExtensionTest("settings/managed_storage")) << message_;
555 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest,
556 DISABLED_PRE_ManagedStorageEvents) {
557 ResultCatcher catcher;
559 // This test starts without any test extensions installed.
560 EXPECT_FALSE(GetSingleLoadedExtension());
563 // Set policies for the test extension.
564 scoped_ptr<base::DictionaryValue> policy = extensions::DictionaryBuilder()
565 .Set("constant-policy", "aaa")
566 .Set("changes-policy", "bbb")
567 .Set("deleted-policy", "ccc")
569 SetPolicies(*policy);
571 ExtensionTestMessageListener ready_listener("ready", false);
572 // Load the extension to install the event listener.
573 const Extension* extension = LoadExtension(
574 test_data_dir_.AppendASCII("settings/managed_storage_events"));
575 ASSERT_TRUE(extension);
576 // Wait until the extension sends the "ready" message.
577 ASSERT_TRUE(ready_listener.WaitUntilSatisfied());
579 // Now change the policies and wait until the extension is done.
580 policy = extensions::DictionaryBuilder()
581 .Set("constant-policy", "aaa")
582 .Set("changes-policy", "ddd")
583 .Set("new-policy", "eee")
585 SetPolicies(*policy);
586 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
589 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest,
590 DISABLED_ManagedStorageEvents) {
591 // This test runs after PRE_ManagedStorageEvents without having deleted the
592 // profile, so the extension is still around. While the browser restarted the
593 // policy went back to the empty default, and so the extension should receive
594 // the corresponding change events.
596 ResultCatcher catcher;
598 // Verify that the test extension is still installed.
599 const Extension* extension = GetSingleLoadedExtension();
600 ASSERT_TRUE(extension);
601 EXPECT_EQ(kManagedStorageExtensionId, extension->id());
603 // Running the test again skips the onInstalled callback, and just triggers
604 // the onChanged notification.
605 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
608 #endif // defined(ENABLE_CONFIGURATION_POLICY)
610 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, ManagedStorageDisabled) {
611 // Disable the 'managed' namespace. This is redundant when
612 // ENABLE_CONFIGURATION_POLICY is not defined.
613 SettingsFrontend* frontend =
614 browser()->profile()->GetExtensionService()->settings_frontend();
615 frontend->DisableStorageForTesting(MANAGED);
616 EXPECT_FALSE(frontend->IsStorageEnabled(MANAGED));
617 // Now run the extension.
618 ASSERT_TRUE(RunExtensionTest("settings/managed_storage_disabled"))
622 } // namespace extensions