Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: chrome/browser/extensions/settings/settings_apitest.cc

Issue 9427001: Extend TwoClientExtensionSettingsSyncTest to test app settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: oops Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/command_line.h" 6 #include "base/command_line.h"
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "chrome/browser/extensions/extension_apitest.h" 8 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/settings/settings_frontend.h" 10 #include "chrome/browser/extensions/settings/settings_frontend.h"
11 #include "chrome/browser/extensions/settings/settings_namespace.h" 11 #include "chrome/browser/extensions/settings/settings_namespace.h"
12 #include "chrome/browser/extensions/settings/settings_sync_util.h" 12 #include "chrome/browser/extensions/settings/settings_sync_util.h"
13 #include "chrome/browser/extensions/extension_test_message_listener.h" 13 #include "chrome/browser/extensions/extension_test_message_listener.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/sync/api/sync_change.h" 15 #include "chrome/browser/sync/api/sync_change.h"
16 #include "chrome/browser/sync/api/sync_change_processor.h" 16 #include "chrome/browser/sync/api/sync_change_processor.h"
17 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/test/base/ui_test_utils.h" 19 #include "chrome/test/base/ui_test_utils.h"
20 20
21 namespace extensions { 21 namespace extensions {
22 22
23 using namespace settings_namespace; 23 using namespace settings_namespace;
24 24
25 namespace { 25 namespace {
26 26
27 // TODO(kalman): test both EXTENSION_SETTINGS and APP_SETTINGS.
28 syncable::ModelType kModelType = syncable::EXTENSION_SETTINGS;
akalin 2012/02/27 23:42:10 const
not at google - send to devlin 2012/02/27 23:45:46 Done.
29
27 class NoopSyncChangeProcessor : public SyncChangeProcessor { 30 class NoopSyncChangeProcessor : public SyncChangeProcessor {
28 public: 31 public:
29 virtual SyncError ProcessSyncChanges( 32 virtual SyncError ProcessSyncChanges(
30 const tracked_objects::Location& from_here, 33 const tracked_objects::Location& from_here,
31 const SyncChangeList& change_list) OVERRIDE { 34 const SyncChangeList& change_list) OVERRIDE {
32 return SyncError(); 35 return SyncError();
33 } 36 }
34 37
35 virtual ~NoopSyncChangeProcessor() {}; 38 virtual ~NoopSyncChangeProcessor() {};
36 }; 39 };
(...skipping 27 matching lines...) Expand all
64 Namespace settings_namespace, 67 Namespace settings_namespace,
65 const std::string& normal_action, 68 const std::string& normal_action,
66 const std::string& incognito_action) { 69 const std::string& incognito_action) {
67 MaybeLoadAndReplyWhenSatisfied( 70 MaybeLoadAndReplyWhenSatisfied(
68 settings_namespace, normal_action, incognito_action, NULL, true); 71 settings_namespace, normal_action, incognito_action, NULL, true);
69 } 72 }
70 73
71 void InitSync(SyncChangeProcessor* sync_processor) { 74 void InitSync(SyncChangeProcessor* sync_processor) {
72 browser()->profile()->GetExtensionService()-> 75 browser()->profile()->GetExtensionService()->
73 settings_frontend()->RunWithSyncableService( 76 settings_frontend()->RunWithSyncableService(
74 // TODO(kalman): test both EXTENSION_SETTINGS and APP_SETTINGS. 77 kModelType,
75 syncable::EXTENSION_SETTINGS,
76 base::Bind( 78 base::Bind(
77 &ExtensionSettingsApiTest::InitSyncWithSyncableService, 79 &ExtensionSettingsApiTest::InitSyncWithSyncableService,
78 this, 80 this,
79 sync_processor)); 81 sync_processor));
80 MessageLoop::current()->RunAllPending(); 82 MessageLoop::current()->RunAllPending();
81 } 83 }
82 84
83 void SendChanges(const SyncChangeList& change_list) { 85 void SendChanges(const SyncChangeList& change_list) {
84 browser()->profile()->GetExtensionService()-> 86 browser()->profile()->GetExtensionService()->
85 settings_frontend()->RunWithSyncableService( 87 settings_frontend()->RunWithSyncableService(
86 // TODO(kalman): test both EXTENSION_SETTINGS and APP_SETTINGS. 88 kModelType,
87 syncable::EXTENSION_SETTINGS,
88 base::Bind( 89 base::Bind(
89 &ExtensionSettingsApiTest::SendChangesToSyncableService, 90 &ExtensionSettingsApiTest::SendChangesToSyncableService,
90 this, 91 this,
91 change_list)); 92 change_list));
92 MessageLoop::current()->RunAllPending(); 93 MessageLoop::current()->RunAllPending();
93 } 94 }
94 95
95 private: 96 private:
96 const Extension* MaybeLoadAndReplyWhenSatisfied( 97 const Extension* MaybeLoadAndReplyWhenSatisfied(
97 Namespace settings_namespace, 98 Namespace settings_namespace,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 message->SetString("action", action); 132 message->SetString("action", action);
132 message->SetBoolean("isFinalAction", is_final_action); 133 message->SetBoolean("isFinalAction", is_final_action);
133 std::string message_json; 134 std::string message_json;
134 base::JSONWriter::Write(message.get(), false, &message_json); 135 base::JSONWriter::Write(message.get(), false, &message_json);
135 return message_json; 136 return message_json;
136 } 137 }
137 138
138 void InitSyncWithSyncableService( 139 void InitSyncWithSyncableService(
139 SyncChangeProcessor* sync_processor, SyncableService* settings_service) { 140 SyncChangeProcessor* sync_processor, SyncableService* settings_service) {
140 EXPECT_FALSE(settings_service->MergeDataAndStartSyncing( 141 EXPECT_FALSE(settings_service->MergeDataAndStartSyncing(
141 syncable::EXTENSION_SETTINGS, 142 kModelType,
142 SyncDataList(), 143 SyncDataList(),
143 sync_processor).IsSet()); 144 sync_processor).IsSet());
144 } 145 }
145 146
146 void SendChangesToSyncableService( 147 void SendChangesToSyncableService(
147 const SyncChangeList& change_list, SyncableService* settings_service) { 148 const SyncChangeList& change_list, SyncableService* settings_service) {
148 EXPECT_FALSE( 149 EXPECT_FALSE(
149 settings_service->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); 150 settings_service->ProcessSyncChanges(FROM_HERE, change_list).IsSet());
150 } 151 }
151 }; 152 };
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 "assertNoNotifications", "assertNoNotifications", "split_incognito"); 284 "assertNoNotifications", "assertNoNotifications", "split_incognito");
284 const std::string& extension_id = extension->id(); 285 const std::string& extension_id = extension->id();
285 286
286 NoopSyncChangeProcessor sync_processor; 287 NoopSyncChangeProcessor sync_processor;
287 InitSync(&sync_processor); 288 InitSync(&sync_processor);
288 289
289 // Set "foo" to "bar" via sync. 290 // Set "foo" to "bar" via sync.
290 SyncChangeList sync_changes; 291 SyncChangeList sync_changes;
291 StringValue bar("bar"); 292 StringValue bar("bar");
292 sync_changes.push_back(settings_sync_util::CreateAdd( 293 sync_changes.push_back(settings_sync_util::CreateAdd(
293 extension_id, "foo", bar)); 294 extension_id, "foo", bar, kModelType));
294 SendChanges(sync_changes); 295 SendChanges(sync_changes);
295 296
296 ReplyWhenSatisfied(SYNC, 297 ReplyWhenSatisfied(SYNC,
297 "assertAddFooNotification", "assertAddFooNotification"); 298 "assertAddFooNotification", "assertAddFooNotification");
298 ReplyWhenSatisfied(SYNC, "clearNotifications", "clearNotifications"); 299 ReplyWhenSatisfied(SYNC, "clearNotifications", "clearNotifications");
299 300
300 // Remove "foo" via sync. 301 // Remove "foo" via sync.
301 sync_changes.clear(); 302 sync_changes.clear();
302 sync_changes.push_back(settings_sync_util::CreateDelete( 303 sync_changes.push_back(settings_sync_util::CreateDelete(
303 extension_id, "foo")); 304 extension_id, "foo", kModelType));
304 SendChanges(sync_changes); 305 SendChanges(sync_changes);
305 306
306 FinalReplyWhenSatisfied(SYNC, 307 FinalReplyWhenSatisfied(SYNC,
307 "assertDeleteFooNotification", "assertDeleteFooNotification"); 308 "assertDeleteFooNotification", "assertDeleteFooNotification");
308 309
309 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 310 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
310 EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message(); 311 EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message();
311 } 312 }
312 313
313 // Disabled, see crbug.com/101110 314 // Disabled, see crbug.com/101110
(...skipping 17 matching lines...) Expand all
331 "assertNoNotifications", "assertNoNotifications", "split_incognito"); 332 "assertNoNotifications", "assertNoNotifications", "split_incognito");
332 const std::string& extension_id = extension->id(); 333 const std::string& extension_id = extension->id();
333 334
334 NoopSyncChangeProcessor sync_processor; 335 NoopSyncChangeProcessor sync_processor;
335 InitSync(&sync_processor); 336 InitSync(&sync_processor);
336 337
337 // Set "foo" to "bar" via sync. 338 // Set "foo" to "bar" via sync.
338 SyncChangeList sync_changes; 339 SyncChangeList sync_changes;
339 StringValue bar("bar"); 340 StringValue bar("bar");
340 sync_changes.push_back(settings_sync_util::CreateAdd( 341 sync_changes.push_back(settings_sync_util::CreateAdd(
341 extension_id, "foo", bar)); 342 extension_id, "foo", bar, kModelType));
342 SendChanges(sync_changes); 343 SendChanges(sync_changes);
343 344
344 ReplyWhenSatisfied(LOCAL, "assertNoNotifications", "assertNoNotifications"); 345 ReplyWhenSatisfied(LOCAL, "assertNoNotifications", "assertNoNotifications");
345 346
346 // Remove "foo" via sync. 347 // Remove "foo" via sync.
347 sync_changes.clear(); 348 sync_changes.clear();
348 sync_changes.push_back(settings_sync_util::CreateDelete( 349 sync_changes.push_back(settings_sync_util::CreateDelete(
349 extension_id, "foo")); 350 extension_id, "foo", kModelType));
350 SendChanges(sync_changes); 351 SendChanges(sync_changes);
351 352
352 FinalReplyWhenSatisfied(LOCAL, 353 FinalReplyWhenSatisfied(LOCAL,
353 "assertNoNotifications", "assertNoNotifications"); 354 "assertNoNotifications", "assertNoNotifications");
354 355
355 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 356 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
356 EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message(); 357 EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message();
357 } 358 }
358 359
359 } // namespace extensions 360 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698