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 "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/extensions/api/storage/settings_frontend.h" | 10 #include "chrome/browser/extensions/api/storage/settings_frontend.h" |
11 #include "chrome/browser/extensions/api/storage/settings_namespace.h" | 11 #include "chrome/browser/extensions/api/storage/settings_namespace.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_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
15 #include "chrome/browser/extensions/extension_system_factory.h" | 15 #include "chrome/browser/extensions/extension_system_factory.h" |
16 #include "chrome/browser/extensions/extension_test_message_listener.h" | 16 #include "chrome/browser/extensions/extension_test_message_listener.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
20 #include "extensions/browser/extension_system.h" | 20 #include "extensions/browser/extension_system.h" |
21 #include "extensions/common/value_builder.h" | 21 #include "extensions/common/value_builder.h" |
| 22 #include "sync/api/fake_sync_change_processor.h" |
22 #include "sync/api/sync_change.h" | 23 #include "sync/api/sync_change.h" |
23 #include "sync/api/sync_change_processor.h" | 24 #include "sync/api/sync_change_processor.h" |
| 25 #include "sync/api/sync_change_processor_wrapper_for_test.h" |
24 #include "sync/api/sync_error_factory.h" | 26 #include "sync/api/sync_error_factory.h" |
25 #include "sync/api/sync_error_factory_mock.h" | 27 #include "sync/api/sync_error_factory_mock.h" |
26 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
27 | 29 |
28 #if defined(ENABLE_CONFIGURATION_POLICY) | 30 #if defined(ENABLE_CONFIGURATION_POLICY) |
29 #include "chrome/browser/policy/schema_registry_service.h" | 31 #include "chrome/browser/policy/schema_registry_service.h" |
30 #include "chrome/browser/policy/schema_registry_service_factory.h" | 32 #include "chrome/browser/policy/schema_registry_service_factory.h" |
31 #include "components/policy/core/browser/browser_policy_connector.h" | 33 #include "components/policy/core/browser/browser_policy_connector.h" |
32 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 34 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
33 #include "components/policy/core/common/policy_bundle.h" | 35 #include "components/policy/core/common/policy_bundle.h" |
(...skipping 18 matching lines...) Expand all Loading... |
52 namespace { | 54 namespace { |
53 | 55 |
54 // TODO(kalman): test both EXTENSION_SETTINGS and APP_SETTINGS. | 56 // TODO(kalman): test both EXTENSION_SETTINGS and APP_SETTINGS. |
55 const syncer::ModelType kModelType = syncer::EXTENSION_SETTINGS; | 57 const syncer::ModelType kModelType = syncer::EXTENSION_SETTINGS; |
56 | 58 |
57 // 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 |
58 // 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 |
59 // the extension. | 61 // the extension. |
60 const char kManagedStorageExtensionId[] = "kjmkgkdkpedkejedfhmfcenooemhbpbo"; | 62 const char kManagedStorageExtensionId[] = "kjmkgkdkpedkejedfhmfcenooemhbpbo"; |
61 | 63 |
62 class NoopSyncChangeProcessor : public syncer::SyncChangeProcessor { | |
63 public: | |
64 virtual syncer::SyncError ProcessSyncChanges( | |
65 const tracked_objects::Location& from_here, | |
66 const syncer::SyncChangeList& change_list) OVERRIDE { | |
67 return syncer::SyncError(); | |
68 } | |
69 | |
70 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const | |
71 OVERRIDE { | |
72 return syncer::SyncDataList(); | |
73 } | |
74 | |
75 virtual ~NoopSyncChangeProcessor() {}; | |
76 }; | |
77 | |
78 class SyncChangeProcessorDelegate : public syncer::SyncChangeProcessor { | |
79 public: | |
80 explicit SyncChangeProcessorDelegate(syncer::SyncChangeProcessor* recipient) | |
81 : recipient_(recipient) { | |
82 DCHECK(recipient_); | |
83 } | |
84 virtual ~SyncChangeProcessorDelegate() {} | |
85 | |
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); | |
91 } | |
92 | |
93 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const | |
94 OVERRIDE { | |
95 return recipient_->GetAllSyncData(type); | |
96 } | |
97 | |
98 private: | |
99 // The recipient of all sync changes. | |
100 syncer::SyncChangeProcessor* recipient_; | |
101 | |
102 DISALLOW_COPY_AND_ASSIGN(SyncChangeProcessorDelegate); | |
103 }; | |
104 | |
105 class MockSchemaRegistryObserver : public policy::SchemaRegistry::Observer { | 64 class MockSchemaRegistryObserver : public policy::SchemaRegistry::Observer { |
106 public: | 65 public: |
107 MockSchemaRegistryObserver() {} | 66 MockSchemaRegistryObserver() {} |
108 virtual ~MockSchemaRegistryObserver() {} | 67 virtual ~MockSchemaRegistryObserver() {} |
109 | 68 |
110 MOCK_METHOD1(OnSchemaRegistryUpdated, void(bool)); | 69 MOCK_METHOD1(OnSchemaRegistryUpdated, void(bool)); |
111 MOCK_METHOD0(OnSchemaRegistryReady, void()); | 70 MOCK_METHOD0(OnSchemaRegistryReady, void()); |
112 }; | 71 }; |
113 | 72 |
114 } // namespace | 73 } // namespace |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 message->SetString("action", action); | 181 message->SetString("action", action); |
223 message->SetBoolean("isFinalAction", is_final_action); | 182 message->SetBoolean("isFinalAction", is_final_action); |
224 std::string message_json; | 183 std::string message_json; |
225 base::JSONWriter::Write(message.get(), &message_json); | 184 base::JSONWriter::Write(message.get(), &message_json); |
226 return message_json; | 185 return message_json; |
227 } | 186 } |
228 | 187 |
229 void InitSyncWithSyncableService( | 188 void InitSyncWithSyncableService( |
230 syncer::SyncChangeProcessor* sync_processor, | 189 syncer::SyncChangeProcessor* sync_processor, |
231 syncer::SyncableService* settings_service) { | 190 syncer::SyncableService* settings_service) { |
232 EXPECT_FALSE(settings_service->MergeDataAndStartSyncing( | 191 EXPECT_FALSE( |
233 kModelType, | 192 settings_service->MergeDataAndStartSyncing( |
234 syncer::SyncDataList(), | 193 kModelType, |
235 scoped_ptr<syncer::SyncChangeProcessor>( | 194 syncer::SyncDataList(), |
236 new SyncChangeProcessorDelegate(sync_processor)), | 195 scoped_ptr<syncer::SyncChangeProcessor>( |
237 scoped_ptr<syncer::SyncErrorFactory>( | 196 new syncer::SyncChangeProcessorWrapperForTest( |
238 new syncer::SyncErrorFactoryMock())).error().IsSet()); | 197 sync_processor)), |
| 198 scoped_ptr<syncer::SyncErrorFactory>( |
| 199 new syncer::SyncErrorFactoryMock())) |
| 200 .error() |
| 201 .IsSet()); |
239 } | 202 } |
240 | 203 |
241 void SendChangesToSyncableService( | 204 void SendChangesToSyncableService( |
242 const syncer::SyncChangeList& change_list, | 205 const syncer::SyncChangeList& change_list, |
243 syncer::SyncableService* settings_service) { | 206 syncer::SyncableService* settings_service) { |
244 EXPECT_FALSE( | 207 EXPECT_FALSE( |
245 settings_service->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); | 208 settings_service->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); |
246 } | 209 } |
247 | 210 |
248 protected: | 211 protected: |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 ResultCatcher catcher, catcher_incognito; | 326 ResultCatcher catcher, catcher_incognito; |
364 catcher.RestrictToProfile(browser()->profile()); | 327 catcher.RestrictToProfile(browser()->profile()); |
365 catcher_incognito.RestrictToProfile( | 328 catcher_incognito.RestrictToProfile( |
366 browser()->profile()->GetOffTheRecordProfile()); | 329 browser()->profile()->GetOffTheRecordProfile()); |
367 | 330 |
368 const Extension* extension = | 331 const Extension* extension = |
369 LoadAndReplyWhenSatisfied(SYNC, | 332 LoadAndReplyWhenSatisfied(SYNC, |
370 "assertNoNotifications", "assertNoNotifications", "split_incognito"); | 333 "assertNoNotifications", "assertNoNotifications", "split_incognito"); |
371 const std::string& extension_id = extension->id(); | 334 const std::string& extension_id = extension->id(); |
372 | 335 |
373 NoopSyncChangeProcessor sync_processor; | 336 syncer::FakeSyncChangeProcessor sync_processor; |
374 InitSync(&sync_processor); | 337 InitSync(&sync_processor); |
375 | 338 |
376 // Set "foo" to "bar" via sync. | 339 // Set "foo" to "bar" via sync. |
377 syncer::SyncChangeList sync_changes; | 340 syncer::SyncChangeList sync_changes; |
378 base::StringValue bar("bar"); | 341 base::StringValue bar("bar"); |
379 sync_changes.push_back(settings_sync_util::CreateAdd( | 342 sync_changes.push_back(settings_sync_util::CreateAdd( |
380 extension_id, "foo", bar, kModelType)); | 343 extension_id, "foo", bar, kModelType)); |
381 SendChanges(sync_changes); | 344 SendChanges(sync_changes); |
382 | 345 |
383 ReplyWhenSatisfied(SYNC, | 346 ReplyWhenSatisfied(SYNC, |
(...skipping 24 matching lines...) Expand all Loading... |
408 ResultCatcher catcher, catcher_incognito; | 371 ResultCatcher catcher, catcher_incognito; |
409 catcher.RestrictToProfile(browser()->profile()); | 372 catcher.RestrictToProfile(browser()->profile()); |
410 catcher_incognito.RestrictToProfile( | 373 catcher_incognito.RestrictToProfile( |
411 browser()->profile()->GetOffTheRecordProfile()); | 374 browser()->profile()->GetOffTheRecordProfile()); |
412 | 375 |
413 const Extension* extension = | 376 const Extension* extension = |
414 LoadAndReplyWhenSatisfied(LOCAL, | 377 LoadAndReplyWhenSatisfied(LOCAL, |
415 "assertNoNotifications", "assertNoNotifications", "split_incognito"); | 378 "assertNoNotifications", "assertNoNotifications", "split_incognito"); |
416 const std::string& extension_id = extension->id(); | 379 const std::string& extension_id = extension->id(); |
417 | 380 |
418 NoopSyncChangeProcessor sync_processor; | 381 syncer::FakeSyncChangeProcessor sync_processor; |
419 InitSync(&sync_processor); | 382 InitSync(&sync_processor); |
420 | 383 |
421 // Set "foo" to "bar" via sync. | 384 // Set "foo" to "bar" via sync. |
422 syncer::SyncChangeList sync_changes; | 385 syncer::SyncChangeList sync_changes; |
423 base::StringValue bar("bar"); | 386 base::StringValue bar("bar"); |
424 sync_changes.push_back(settings_sync_util::CreateAdd( | 387 sync_changes.push_back(settings_sync_util::CreateAdd( |
425 extension_id, "foo", bar, kModelType)); | 388 extension_id, "foo", bar, kModelType)); |
426 SendChanges(sync_changes); | 389 SendChanges(sync_changes); |
427 | 390 |
428 ReplyWhenSatisfied(LOCAL, "assertNoNotifications", "assertNoNotifications"); | 391 ReplyWhenSatisfied(LOCAL, "assertNoNotifications", "assertNoNotifications"); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 SettingsFrontend* frontend = | 576 SettingsFrontend* frontend = |
614 browser()->profile()->GetExtensionService()->settings_frontend(); | 577 browser()->profile()->GetExtensionService()->settings_frontend(); |
615 frontend->DisableStorageForTesting(MANAGED); | 578 frontend->DisableStorageForTesting(MANAGED); |
616 EXPECT_FALSE(frontend->IsStorageEnabled(MANAGED)); | 579 EXPECT_FALSE(frontend->IsStorageEnabled(MANAGED)); |
617 // Now run the extension. | 580 // Now run the extension. |
618 ASSERT_TRUE(RunExtensionTest("settings/managed_storage_disabled")) | 581 ASSERT_TRUE(RunExtensionTest("settings/managed_storage_disabled")) |
619 << message_; | 582 << message_; |
620 } | 583 } |
621 | 584 |
622 } // namespace extensions | 585 } // namespace extensions |
OLD | NEW |