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

Side by Side Diff: chrome/browser/extensions/app_notification_manager_sync_unittest.cc

Issue 10698014: [Sync] Rename csync namespace to syncer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 5 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) 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/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "chrome/browser/extensions/app_notification.h" 9 #include "chrome/browser/extensions/app_notification.h"
10 #include "chrome/browser/extensions/app_notification_manager.h" 10 #include "chrome/browser/extensions/app_notification_manager.h"
11 #include "chrome/test/base/testing_profile.h" 11 #include "chrome/test/base/testing_profile.h"
12 #include "content/public/test/test_browser_thread.h" 12 #include "content/public/test/test_browser_thread.h"
13 #include "sync/api/sync_error_factory.h" 13 #include "sync/api/sync_error_factory.h"
14 #include "sync/api/sync_error_factory_mock.h" 14 #include "sync/api/sync_error_factory_mock.h"
15 #include "sync/protocol/app_notification_specifics.pb.h" 15 #include "sync/protocol/app_notification_specifics.pb.h"
16 #include "sync/protocol/sync.pb.h" 16 #include "sync/protocol/sync.pb.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 using content::BrowserThread; 19 using content::BrowserThread;
20 using ::testing::_; 20 using ::testing::_;
21 using ::testing::Return; 21 using ::testing::Return;
22 22
23 namespace { 23 namespace {
24 24
25 // Extract notification guid from csync::SyncData. 25 // Extract notification guid from syncer::SyncData.
26 std::string GetGuid(const csync::SyncData& sync_data) { 26 std::string GetGuid(const syncer::SyncData& sync_data) {
27 return sync_data.GetSpecifics().app_notification().guid(); 27 return sync_data.GetSpecifics().app_notification().guid();
28 } 28 }
29 29
30 // Dummy SyncChangeProcessor used to help review what SyncChanges are pushed 30 // Dummy SyncChangeProcessor used to help review what SyncChanges are pushed
31 // back up to Sync. 31 // back up to Sync.
32 class TestChangeProcessor : public csync::SyncChangeProcessor { 32 class TestChangeProcessor : public syncer::SyncChangeProcessor {
33 public: 33 public:
34 TestChangeProcessor() { } 34 TestChangeProcessor() { }
35 virtual ~TestChangeProcessor() { } 35 virtual ~TestChangeProcessor() { }
36 36
37 // Store a copy of all the changes passed in so we can examine them later. 37 // Store a copy of all the changes passed in so we can examine them later.
38 virtual csync::SyncError ProcessSyncChanges( 38 virtual syncer::SyncError ProcessSyncChanges(
39 const tracked_objects::Location& from_here, 39 const tracked_objects::Location& from_here,
40 const csync::SyncChangeList& change_list) { 40 const syncer::SyncChangeList& change_list) {
41 // change_map_.erase(change_map_.begin(), change_map_.end()); 41 // change_map_.erase(change_map_.begin(), change_map_.end());
42 for (csync::SyncChangeList::const_iterator iter = change_list.begin(); 42 for (syncer::SyncChangeList::const_iterator iter = change_list.begin();
43 iter != change_list.end(); ++iter) { 43 iter != change_list.end(); ++iter) {
44 change_map_[GetGuid(iter->sync_data())] = *iter; 44 change_map_[GetGuid(iter->sync_data())] = *iter;
45 } 45 }
46 46
47 return csync::SyncError(); 47 return syncer::SyncError();
48 } 48 }
49 49
50 bool ContainsGuid(const std::string& guid) { 50 bool ContainsGuid(const std::string& guid) {
51 return change_map_.find(guid) != change_map_.end(); 51 return change_map_.find(guid) != change_map_.end();
52 } 52 }
53 53
54 csync::SyncChange GetChangeByGuid(const std::string& guid) { 54 syncer::SyncChange GetChangeByGuid(const std::string& guid) {
55 DCHECK(ContainsGuid(guid)); 55 DCHECK(ContainsGuid(guid));
56 return change_map_[guid]; 56 return change_map_[guid];
57 } 57 }
58 58
59 size_t change_list_size() { return change_map_.size(); } 59 size_t change_list_size() { return change_map_.size(); }
60 60
61 private: 61 private:
62 // Track the changes received in ProcessSyncChanges. 62 // Track the changes received in ProcessSyncChanges.
63 std::map<std::string, csync::SyncChange> change_map_; 63 std::map<std::string, syncer::SyncChange> change_map_;
64 64
65 DISALLOW_COPY_AND_ASSIGN(TestChangeProcessor); 65 DISALLOW_COPY_AND_ASSIGN(TestChangeProcessor);
66 }; 66 };
67 67
68 class SyncChangeProcessorDelegate : public csync::SyncChangeProcessor { 68 class SyncChangeProcessorDelegate : public syncer::SyncChangeProcessor {
69 public: 69 public:
70 explicit SyncChangeProcessorDelegate(csync::SyncChangeProcessor* recipient) 70 explicit SyncChangeProcessorDelegate(syncer::SyncChangeProcessor* recipient)
71 : recipient_(recipient) { 71 : recipient_(recipient) {
72 DCHECK(recipient_); 72 DCHECK(recipient_);
73 } 73 }
74 virtual ~SyncChangeProcessorDelegate() {} 74 virtual ~SyncChangeProcessorDelegate() {}
75 75
76 // csync::SyncChangeProcessor implementation. 76 // syncer::SyncChangeProcessor implementation.
77 virtual csync::SyncError ProcessSyncChanges( 77 virtual syncer::SyncError ProcessSyncChanges(
78 const tracked_objects::Location& from_here, 78 const tracked_objects::Location& from_here,
79 const csync::SyncChangeList& change_list) OVERRIDE { 79 const syncer::SyncChangeList& change_list) OVERRIDE {
80 return recipient_->ProcessSyncChanges(from_here, change_list); 80 return recipient_->ProcessSyncChanges(from_here, change_list);
81 } 81 }
82 82
83 private: 83 private:
84 // The recipient of all sync changes. 84 // The recipient of all sync changes.
85 csync::SyncChangeProcessor* recipient_; 85 syncer::SyncChangeProcessor* recipient_;
86 86
87 DISALLOW_COPY_AND_ASSIGN(SyncChangeProcessorDelegate); 87 DISALLOW_COPY_AND_ASSIGN(SyncChangeProcessorDelegate);
88 }; 88 };
89 89
90 } // namespace 90 } // namespace
91 91
92 class AppNotificationManagerSyncTest : public testing::Test { 92 class AppNotificationManagerSyncTest : public testing::Test {
93 public: 93 public:
94 AppNotificationManagerSyncTest() 94 AppNotificationManagerSyncTest()
95 : ui_thread_(BrowserThread::UI, &ui_loop_), 95 : ui_thread_(BrowserThread::UI, &ui_loop_),
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 static void WaitForFileThread() { 128 static void WaitForFileThread() {
129 BrowserThread::PostTask(BrowserThread::FILE, 129 BrowserThread::PostTask(BrowserThread::FILE,
130 FROM_HERE, 130 FROM_HERE,
131 base::Bind(&PostQuitToUIThread)); 131 base::Bind(&PostQuitToUIThread));
132 MessageLoop::current()->Run(); 132 MessageLoop::current()->Run();
133 } 133 }
134 134
135 AppNotificationManager* model() { return model_.get(); } 135 AppNotificationManager* model() { return model_.get(); }
136 TestChangeProcessor* processor() { return sync_processor_.get(); } 136 TestChangeProcessor* processor() { return sync_processor_.get(); }
137 137
138 scoped_ptr<csync::SyncChangeProcessor> PassProcessor() { 138 scoped_ptr<syncer::SyncChangeProcessor> PassProcessor() {
139 return sync_processor_delegate_.PassAs<csync::SyncChangeProcessor>(); 139 return sync_processor_delegate_.PassAs<syncer::SyncChangeProcessor>();
140 } 140 }
141 141
142 // Creates a notification whose properties are set from the given integer. 142 // Creates a notification whose properties are set from the given integer.
143 static AppNotification* CreateNotification(int suffix) { 143 static AppNotification* CreateNotification(int suffix) {
144 return CreateNotification(false, suffix); 144 return CreateNotification(false, suffix);
145 } 145 }
146 static AppNotification* CreateNotification(bool is_local, int suffix) { 146 static AppNotification* CreateNotification(bool is_local, int suffix) {
147 std::string s = base::IntToString(suffix); 147 std::string s = base::IntToString(suffix);
148 return CreateNotification( 148 return CreateNotification(
149 is_local, suffix, "guid" + s, "ext" + s, "text" + s, "body" + s, 149 is_local, suffix, "guid" + s, "ext" + s, "text" + s, "body" + s,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 AppNotification* notif = new AppNotification( 181 AppNotification* notif = new AppNotification(
182 is_local, base::Time::FromInternalValue(time), 182 is_local, base::Time::FromInternalValue(time),
183 guid, extension_id, title, body); 183 guid, extension_id, title, body);
184 if (!link_url.empty()) 184 if (!link_url.empty())
185 notif->set_link_url(GURL(link_url)); 185 notif->set_link_url(GURL(link_url));
186 if (!link_text.empty()) 186 if (!link_text.empty())
187 notif->set_link_text(link_text); 187 notif->set_link_text(link_text);
188 return notif; 188 return notif;
189 } 189 }
190 190
191 static csync::SyncData CreateSyncData(int suffix) { 191 static syncer::SyncData CreateSyncData(int suffix) {
192 scoped_ptr<AppNotification> notif(CreateNotification(suffix)); 192 scoped_ptr<AppNotification> notif(CreateNotification(suffix));
193 return AppNotificationManager::CreateSyncDataFromNotification(*notif); 193 return AppNotificationManager::CreateSyncDataFromNotification(*notif);
194 } 194 }
195 static csync::SyncData CreateSyncData( 195 static syncer::SyncData CreateSyncData(
196 int suffix, const std::string& extension_id) { 196 int suffix, const std::string& extension_id) {
197 scoped_ptr<AppNotification> notif( 197 scoped_ptr<AppNotification> notif(
198 CreateNotification(false, suffix, extension_id)); 198 CreateNotification(false, suffix, extension_id));
199 return AppNotificationManager::CreateSyncDataFromNotification(*notif); 199 return AppNotificationManager::CreateSyncDataFromNotification(*notif);
200 } 200 }
201 201
202 // Helper to create csync::SyncChange. Takes ownership of |notif|. 202 // Helper to create syncer::SyncChange. Takes ownership of |notif|.
203 static csync::SyncChange CreateSyncChange( 203 static syncer::SyncChange CreateSyncChange(
204 csync::SyncChange::SyncChangeType type, 204 syncer::SyncChange::SyncChangeType type,
205 AppNotification* notif) { 205 AppNotification* notif) {
206 // Take control of notif to clean it up after we create data out of it. 206 // Take control of notif to clean it up after we create data out of it.
207 scoped_ptr<AppNotification> scoped_notif(notif); 207 scoped_ptr<AppNotification> scoped_notif(notif);
208 return csync::SyncChange( 208 return syncer::SyncChange(
209 type, AppNotificationManager::CreateSyncDataFromNotification(*notif)); 209 type, AppNotificationManager::CreateSyncDataFromNotification(*notif));
210 } 210 }
211 211
212 void AssertSyncChange(const csync::SyncChange& change, 212 void AssertSyncChange(const syncer::SyncChange& change,
213 csync::SyncChange::SyncChangeType type, 213 syncer::SyncChange::SyncChangeType type,
214 const AppNotification& notif) { 214 const AppNotification& notif) {
215 ASSERT_EQ(type, change.change_type()); 215 ASSERT_EQ(type, change.change_type());
216 scoped_ptr<AppNotification> notif2( 216 scoped_ptr<AppNotification> notif2(
217 AppNotificationManager::CreateNotificationFromSyncData( 217 AppNotificationManager::CreateNotificationFromSyncData(
218 change.sync_data())); 218 change.sync_data()));
219 ASSERT_TRUE(notif.Equals(*notif2)); 219 ASSERT_TRUE(notif.Equals(*notif2));
220 } 220 }
221 221
222 protected: 222 protected:
223 MessageLoop ui_loop_; 223 MessageLoop ui_loop_;
224 content::TestBrowserThread ui_thread_; 224 content::TestBrowserThread ui_thread_;
225 content::TestBrowserThread file_thread_; 225 content::TestBrowserThread file_thread_;
226 226
227 // We keep two TemplateURLServices to test syncing between them. 227 // We keep two TemplateURLServices to test syncing between them.
228 ScopedTempDir temp_dir_; 228 ScopedTempDir temp_dir_;
229 scoped_ptr<TestingProfile> profile_; 229 scoped_ptr<TestingProfile> profile_;
230 scoped_refptr<AppNotificationManager> model_; 230 scoped_refptr<AppNotificationManager> model_;
231 231
232 scoped_ptr<TestChangeProcessor> sync_processor_; 232 scoped_ptr<TestChangeProcessor> sync_processor_;
233 scoped_ptr<SyncChangeProcessorDelegate> sync_processor_delegate_; 233 scoped_ptr<SyncChangeProcessorDelegate> sync_processor_delegate_;
234 234
235 DISALLOW_COPY_AND_ASSIGN(AppNotificationManagerSyncTest); 235 DISALLOW_COPY_AND_ASSIGN(AppNotificationManagerSyncTest);
236 }; 236 };
237 237
238 // Create an AppNotification, convert it to csync::SyncData and convert it back. 238 // Create an AppNotification, convert it to SyncData and convert it back.
239 TEST_F(AppNotificationManagerSyncTest, NotificationToSyncDataToNotification) { 239 TEST_F(AppNotificationManagerSyncTest, NotificationToSyncDataToNotification) {
240 { // Partial properties set. 240 { // Partial properties set.
241 scoped_ptr<AppNotification> notif1(CreateNotificationNoLink(1)); 241 scoped_ptr<AppNotification> notif1(CreateNotificationNoLink(1));
242 csync::SyncData sync_data = 242 syncer::SyncData sync_data =
243 AppNotificationManager::CreateSyncDataFromNotification(*notif1); 243 AppNotificationManager::CreateSyncDataFromNotification(*notif1);
244 scoped_ptr<AppNotification> notif2( 244 scoped_ptr<AppNotification> notif2(
245 AppNotificationManager::CreateNotificationFromSyncData(sync_data)); 245 AppNotificationManager::CreateNotificationFromSyncData(sync_data));
246 EXPECT_TRUE(notif2.get()); 246 EXPECT_TRUE(notif2.get());
247 EXPECT_TRUE(notif1->Equals(*notif2)); 247 EXPECT_TRUE(notif1->Equals(*notif2));
248 } 248 }
249 { // All properties set. 249 { // All properties set.
250 scoped_ptr<AppNotification> notif1(CreateNotification(1)); 250 scoped_ptr<AppNotification> notif1(CreateNotification(1));
251 csync::SyncData sync_data = 251 syncer::SyncData sync_data =
252 AppNotificationManager::CreateSyncDataFromNotification(*notif1); 252 AppNotificationManager::CreateSyncDataFromNotification(*notif1);
253 scoped_ptr<AppNotification> notif2( 253 scoped_ptr<AppNotification> notif2(
254 AppNotificationManager::CreateNotificationFromSyncData(sync_data)); 254 AppNotificationManager::CreateNotificationFromSyncData(sync_data));
255 EXPECT_TRUE(notif2.get()); 255 EXPECT_TRUE(notif2.get());
256 EXPECT_TRUE(notif1->Equals(*notif2)); 256 EXPECT_TRUE(notif1->Equals(*notif2));
257 } 257 }
258 } 258 }
259 259
260 // GetAllSyncData returns all notifications since none are marked local only. 260 // GetAllSyncData returns all notifications since none are marked local only.
261 TEST_F(AppNotificationManagerSyncTest, GetAllSyncDataNoLocal) { 261 TEST_F(AppNotificationManagerSyncTest, GetAllSyncDataNoLocal) {
262 model()->Add(CreateNotificationNoLink(1)); 262 model()->Add(CreateNotificationNoLink(1));
263 model()->Add(CreateNotification(2)); 263 model()->Add(CreateNotification(2));
264 model()->Add(CreateNotification(3)); 264 model()->Add(CreateNotification(3));
265 csync::SyncDataList all_sync_data = 265 syncer::SyncDataList all_sync_data =
266 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS); 266 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS);
267 267
268 EXPECT_EQ(3U, all_sync_data.size()); 268 EXPECT_EQ(3U, all_sync_data.size());
269 269
270 for (csync::SyncDataList::const_iterator iter = all_sync_data.begin(); 270 for (syncer::SyncDataList::const_iterator iter = all_sync_data.begin();
271 iter != all_sync_data.end(); ++iter) { 271 iter != all_sync_data.end(); ++iter) {
272 scoped_ptr<AppNotification> notif1( 272 scoped_ptr<AppNotification> notif1(
273 AppNotificationManager::CreateNotificationFromSyncData(*iter)); 273 AppNotificationManager::CreateNotificationFromSyncData(*iter));
274 274
275 const std::string& guid = notif1->guid(); 275 const std::string& guid = notif1->guid();
276 const std::string& ext_id = notif1->extension_id(); 276 const std::string& ext_id = notif1->extension_id();
277 277
278 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); 278 const AppNotification* notif2 = model()->GetNotification(ext_id, guid);
279 ASSERT_TRUE(notif1->Equals(*notif2)); 279 ASSERT_TRUE(notif1->Equals(*notif2));
280 } 280 }
281 } 281 }
282 282
283 // GetAllSyncData should not return notifications marked as local only. 283 // GetAllSyncData should not return notifications marked as local only.
284 TEST_F(AppNotificationManagerSyncTest, GetAllSyncDataSomeLocal) { 284 TEST_F(AppNotificationManagerSyncTest, GetAllSyncDataSomeLocal) {
285 model()->Add(CreateNotificationNoLink(1)); 285 model()->Add(CreateNotificationNoLink(1));
286 model()->Add(CreateNotification(true, 2)); 286 model()->Add(CreateNotification(true, 2));
287 model()->Add(CreateNotification(3)); 287 model()->Add(CreateNotification(3));
288 model()->Add(CreateNotification(true, 4)); 288 model()->Add(CreateNotification(true, 4));
289 model()->Add(CreateNotification(5)); 289 model()->Add(CreateNotification(5));
290 csync::SyncDataList all_sync_data = 290 syncer::SyncDataList all_sync_data =
291 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS); 291 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS);
292 292
293 EXPECT_EQ(3U, all_sync_data.size()); 293 EXPECT_EQ(3U, all_sync_data.size());
294 294
295 for (csync::SyncDataList::const_iterator iter = all_sync_data.begin(); 295 for (syncer::SyncDataList::const_iterator iter = all_sync_data.begin();
296 iter != all_sync_data.end(); ++iter) { 296 iter != all_sync_data.end(); ++iter) {
297 scoped_ptr<AppNotification> notif1( 297 scoped_ptr<AppNotification> notif1(
298 AppNotificationManager::CreateNotificationFromSyncData(*iter)); 298 AppNotificationManager::CreateNotificationFromSyncData(*iter));
299 const std::string& guid = notif1->guid(); 299 const std::string& guid = notif1->guid();
300 const std::string& ext_id = notif1->extension_id(); 300 const std::string& ext_id = notif1->extension_id();
301 301
302 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); 302 const AppNotification* notif2 = model()->GetNotification(ext_id, guid);
303 ASSERT_TRUE(notif1->Equals(*notif2)); 303 ASSERT_TRUE(notif1->Equals(*notif2));
304 } 304 }
305 } 305 }
306 306
307 // Model assocation: both models are empty. 307 // Model assocation: both models are empty.
308 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothEmpty) { 308 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothEmpty) {
309 model()->MergeDataAndStartSyncing( 309 model()->MergeDataAndStartSyncing(
310 syncable::APP_NOTIFICATIONS, 310 syncable::APP_NOTIFICATIONS,
311 csync::SyncDataList(), // Empty. 311 syncer::SyncDataList(), // Empty.
312 PassProcessor(), 312 PassProcessor(),
313 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 313 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
314 314
315 EXPECT_EQ(0U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); 315 EXPECT_EQ(0U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size());
316 EXPECT_EQ(0U, processor()->change_list_size()); 316 EXPECT_EQ(0U, processor()->change_list_size());
317 } 317 }
318 318
319 // Model assocation: empty sync model and non-empty local model. 319 // Model assocation: empty sync model and non-empty local model.
320 TEST_F(AppNotificationManagerSyncTest, ModelAssocModelEmpty) { 320 TEST_F(AppNotificationManagerSyncTest, ModelAssocModelEmpty) {
321 csync::SyncDataList initial_data; 321 syncer::SyncDataList initial_data;
322 initial_data.push_back(CreateSyncData(1)); 322 initial_data.push_back(CreateSyncData(1));
323 initial_data.push_back(CreateSyncData(2)); 323 initial_data.push_back(CreateSyncData(2));
324 initial_data.push_back(CreateSyncData(3)); 324 initial_data.push_back(CreateSyncData(3));
325 initial_data.push_back(CreateSyncData(4)); 325 initial_data.push_back(CreateSyncData(4));
326 326
327 model()->MergeDataAndStartSyncing( 327 model()->MergeDataAndStartSyncing(
328 syncable::APP_NOTIFICATIONS, 328 syncable::APP_NOTIFICATIONS,
329 initial_data, 329 initial_data,
330 PassProcessor(), 330 PassProcessor(),
331 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 331 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
332 332
333 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); 333 EXPECT_EQ(4U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size());
334 // Model should all of the initial sync data. 334 // Model should all of the initial sync data.
335 for (csync::SyncDataList::const_iterator iter = initial_data.begin(); 335 for (syncer::SyncDataList::const_iterator iter = initial_data.begin();
336 iter != initial_data.end(); ++iter) { 336 iter != initial_data.end(); ++iter) {
337 scoped_ptr<AppNotification> notif1( 337 scoped_ptr<AppNotification> notif1(
338 AppNotificationManager::CreateNotificationFromSyncData(*iter)); 338 AppNotificationManager::CreateNotificationFromSyncData(*iter));
339 const std::string& ext_id = notif1->extension_id(); 339 const std::string& ext_id = notif1->extension_id();
340 const std::string& guid = notif1->guid(); 340 const std::string& guid = notif1->guid();
341 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); 341 const AppNotification* notif2 = model()->GetNotification(ext_id, guid);
342 EXPECT_TRUE(notif2); 342 EXPECT_TRUE(notif2);
343 EXPECT_TRUE(notif1->Equals(*notif2)); 343 EXPECT_TRUE(notif1->Equals(*notif2));
344 } 344 }
345 345
346 EXPECT_EQ(0U, processor()->change_list_size()); 346 EXPECT_EQ(0U, processor()->change_list_size());
347 } 347 }
348 348
349 // Model has some notifications, some of them are local only. Sync has some 349 // Model has some notifications, some of them are local only. Sync has some
350 // notifications. No items match up. 350 // notifications. No items match up.
351 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptyNoOverlap) { 351 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptyNoOverlap) {
352 AppNotification* n1 = CreateNotification(1); 352 AppNotification* n1 = CreateNotification(1);
353 model()->Add(n1); 353 model()->Add(n1);
354 AppNotification* n2 = CreateNotification(true, 2); 354 AppNotification* n2 = CreateNotification(true, 2);
355 model()->Add(n2); 355 model()->Add(n2);
356 AppNotification* n3 = CreateNotification(3); 356 AppNotification* n3 = CreateNotification(3);
357 model()->Add(n3); 357 model()->Add(n3);
358 358
359 csync::SyncDataList initial_data; 359 syncer::SyncDataList initial_data;
360 initial_data.push_back(CreateSyncData(4)); 360 initial_data.push_back(CreateSyncData(4));
361 initial_data.push_back(CreateSyncData(5)); 361 initial_data.push_back(CreateSyncData(5));
362 initial_data.push_back(CreateSyncData(6)); 362 initial_data.push_back(CreateSyncData(6));
363 initial_data.push_back(CreateSyncData(7)); 363 initial_data.push_back(CreateSyncData(7));
364 364
365 model()->MergeDataAndStartSyncing( 365 model()->MergeDataAndStartSyncing(
366 syncable::APP_NOTIFICATIONS, 366 syncable::APP_NOTIFICATIONS,
367 initial_data, 367 initial_data,
368 PassProcessor(), 368 PassProcessor(),
369 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 369 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
370 370
371 EXPECT_EQ(6U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); 371 EXPECT_EQ(6U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size());
372 for (csync::SyncDataList::const_iterator iter = initial_data.begin(); 372 for (syncer::SyncDataList::const_iterator iter = initial_data.begin();
373 iter != initial_data.end(); ++iter) { 373 iter != initial_data.end(); ++iter) {
374 scoped_ptr<AppNotification> notif1( 374 scoped_ptr<AppNotification> notif1(
375 AppNotificationManager::CreateNotificationFromSyncData(*iter)); 375 AppNotificationManager::CreateNotificationFromSyncData(*iter));
376 const std::string& ext_id = notif1->extension_id(); 376 const std::string& ext_id = notif1->extension_id();
377 const std::string& guid = notif1->guid(); 377 const std::string& guid = notif1->guid();
378 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); 378 const AppNotification* notif2 = model()->GetNotification(ext_id, guid);
379 EXPECT_TRUE(notif2); 379 EXPECT_TRUE(notif2);
380 EXPECT_TRUE(notif1->Equals(*notif2)); 380 EXPECT_TRUE(notif1->Equals(*notif2));
381 } 381 }
382 EXPECT_TRUE(model()->GetNotification(n1->extension_id(), n1->guid())); 382 EXPECT_TRUE(model()->GetNotification(n1->extension_id(), n1->guid()));
383 EXPECT_TRUE(model()->GetNotification(n2->extension_id(), n2->guid())); 383 EXPECT_TRUE(model()->GetNotification(n2->extension_id(), n2->guid()));
384 EXPECT_TRUE(model()->GetNotification(n3->extension_id(), n3->guid())); 384 EXPECT_TRUE(model()->GetNotification(n3->extension_id(), n3->guid()));
385 385
386 EXPECT_EQ(2U, processor()->change_list_size()); 386 EXPECT_EQ(2U, processor()->change_list_size());
387 EXPECT_TRUE(processor()->ContainsGuid(n1->guid())); 387 EXPECT_TRUE(processor()->ContainsGuid(n1->guid()));
388 EXPECT_EQ(csync::SyncChange::ACTION_ADD, 388 EXPECT_EQ(syncer::SyncChange::ACTION_ADD,
389 processor()->GetChangeByGuid(n1->guid()).change_type()); 389 processor()->GetChangeByGuid(n1->guid()).change_type());
390 EXPECT_FALSE(processor()->ContainsGuid(n2->guid())); 390 EXPECT_FALSE(processor()->ContainsGuid(n2->guid()));
391 EXPECT_TRUE(processor()->ContainsGuid(n3->guid())); 391 EXPECT_TRUE(processor()->ContainsGuid(n3->guid()));
392 EXPECT_EQ(csync::SyncChange::ACTION_ADD, 392 EXPECT_EQ(syncer::SyncChange::ACTION_ADD,
393 processor()->GetChangeByGuid(n3->guid()).change_type()); 393 processor()->GetChangeByGuid(n3->guid()).change_type());
394 } 394 }
395 395
396 // Model has some notifications, some of them are local only. Sync has some 396 // Model has some notifications, some of them are local only. Sync has some
397 // notifications. Some items match up. 397 // notifications. Some items match up.
398 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptySomeOverlap) { 398 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptySomeOverlap) {
399 AppNotification* n1 = CreateNotification(1); 399 AppNotification* n1 = CreateNotification(1);
400 model()->Add(n1); 400 model()->Add(n1);
401 AppNotification* n2 = CreateNotification(true, 2); 401 AppNotification* n2 = CreateNotification(true, 2);
402 model()->Add(n2); 402 model()->Add(n2);
403 AppNotification* n3 = CreateNotification(3); 403 AppNotification* n3 = CreateNotification(3);
404 model()->Add(n3); 404 model()->Add(n3);
405 AppNotification* n4 = CreateNotification(4); 405 AppNotification* n4 = CreateNotification(4);
406 model()->Add(n4); 406 model()->Add(n4);
407 407
408 csync::SyncDataList initial_data; 408 syncer::SyncDataList initial_data;
409 initial_data.push_back(CreateSyncData(5)); 409 initial_data.push_back(CreateSyncData(5));
410 initial_data.push_back( 410 initial_data.push_back(
411 AppNotificationManager::CreateSyncDataFromNotification(*n1)); 411 AppNotificationManager::CreateSyncDataFromNotification(*n1));
412 initial_data.push_back(CreateSyncData(6)); 412 initial_data.push_back(CreateSyncData(6));
413 initial_data.push_back( 413 initial_data.push_back(
414 AppNotificationManager::CreateSyncDataFromNotification(*n4)); 414 AppNotificationManager::CreateSyncDataFromNotification(*n4));
415 initial_data.push_back(CreateSyncData(7)); 415 initial_data.push_back(CreateSyncData(7));
416 416
417 model()->MergeDataAndStartSyncing( 417 model()->MergeDataAndStartSyncing(
418 syncable::APP_NOTIFICATIONS, 418 syncable::APP_NOTIFICATIONS,
419 initial_data, 419 initial_data,
420 PassProcessor(), 420 PassProcessor(),
421 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 421 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
422 422
423 EXPECT_EQ(6U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); 423 EXPECT_EQ(6U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size());
424 for (csync::SyncDataList::const_iterator iter = initial_data.begin(); 424 for (syncer::SyncDataList::const_iterator iter = initial_data.begin();
425 iter != initial_data.end(); ++iter) { 425 iter != initial_data.end(); ++iter) {
426 scoped_ptr<AppNotification> notif1( 426 scoped_ptr<AppNotification> notif1(
427 AppNotificationManager::CreateNotificationFromSyncData(*iter)); 427 AppNotificationManager::CreateNotificationFromSyncData(*iter));
428 const std::string& ext_id = notif1->extension_id(); 428 const std::string& ext_id = notif1->extension_id();
429 const std::string& guid = notif1->guid(); 429 const std::string& guid = notif1->guid();
430 const AppNotification* notif2 = model()->GetNotification(ext_id, guid); 430 const AppNotification* notif2 = model()->GetNotification(ext_id, guid);
431 EXPECT_TRUE(notif2); 431 EXPECT_TRUE(notif2);
432 EXPECT_TRUE(notif1->Equals(*notif2)); 432 EXPECT_TRUE(notif1->Equals(*notif2));
433 } 433 }
434 EXPECT_TRUE(model()->GetNotification(n1->extension_id(), n1->guid())); 434 EXPECT_TRUE(model()->GetNotification(n1->extension_id(), n1->guid()));
435 EXPECT_TRUE(model()->GetNotification(n2->extension_id(), n2->guid())); 435 EXPECT_TRUE(model()->GetNotification(n2->extension_id(), n2->guid()));
436 EXPECT_TRUE(model()->GetNotification(n3->extension_id(), n3->guid())); 436 EXPECT_TRUE(model()->GetNotification(n3->extension_id(), n3->guid()));
437 EXPECT_TRUE(model()->GetNotification(n4->extension_id(), n4->guid())); 437 EXPECT_TRUE(model()->GetNotification(n4->extension_id(), n4->guid()));
438 438
439 EXPECT_EQ(1U, processor()->change_list_size()); 439 EXPECT_EQ(1U, processor()->change_list_size());
440 EXPECT_FALSE(processor()->ContainsGuid(n1->guid())); 440 EXPECT_FALSE(processor()->ContainsGuid(n1->guid()));
441 EXPECT_FALSE(processor()->ContainsGuid(n2->guid())); 441 EXPECT_FALSE(processor()->ContainsGuid(n2->guid()));
442 EXPECT_TRUE(processor()->ContainsGuid(n3->guid())); 442 EXPECT_TRUE(processor()->ContainsGuid(n3->guid()));
443 EXPECT_EQ(csync::SyncChange::ACTION_ADD, 443 EXPECT_EQ(syncer::SyncChange::ACTION_ADD,
444 processor()->GetChangeByGuid(n3->guid()).change_type()); 444 processor()->GetChangeByGuid(n3->guid()).change_type());
445 EXPECT_FALSE(processor()->ContainsGuid(n4->guid())); 445 EXPECT_FALSE(processor()->ContainsGuid(n4->guid()));
446 } 446 }
447 447
448 // When an item that matches up in model and sync is different, an error 448 // When an item that matches up in model and sync is different, an error
449 // should be returned. 449 // should be returned.
450 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptyTitleMismatch) { 450 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptyTitleMismatch) {
451 AppNotification* n1 = CreateNotification(1); 451 AppNotification* n1 = CreateNotification(1);
452 model()->Add(n1); 452 model()->Add(n1);
453 AppNotification* n2 = CreateNotification(true, 2); 453 AppNotification* n2 = CreateNotification(true, 2);
454 model()->Add(n2); 454 model()->Add(n2);
455 455
456 csync::SyncDataList initial_data; 456 syncer::SyncDataList initial_data;
457 initial_data.push_back(CreateSyncData(1)); 457 initial_data.push_back(CreateSyncData(1));
458 scoped_ptr<AppNotification> n1_a(CreateNotification( 458 scoped_ptr<AppNotification> n1_a(CreateNotification(
459 n1->is_local(), n1->creation_time().ToInternalValue(), 459 n1->is_local(), n1->creation_time().ToInternalValue(),
460 n1->guid(), n1->extension_id(), 460 n1->guid(), n1->extension_id(),
461 n1->title() + "_changed", // different title 461 n1->title() + "_changed", // different title
462 n1->body(), n1->link_url().spec(), n1->link_text())); 462 n1->body(), n1->link_url().spec(), n1->link_text()));
463 initial_data.push_back( 463 initial_data.push_back(
464 AppNotificationManager::CreateSyncDataFromNotification(*n1_a)); 464 AppNotificationManager::CreateSyncDataFromNotification(*n1_a));
465 465
466 scoped_ptr<csync::SyncErrorFactoryMock> error_handler( 466 scoped_ptr<syncer::SyncErrorFactoryMock> error_handler(
467 new csync::SyncErrorFactoryMock()); 467 new syncer::SyncErrorFactoryMock());
468 EXPECT_CALL(*error_handler, CreateAndUploadError(_, _)). 468 EXPECT_CALL(*error_handler, CreateAndUploadError(_, _)).
469 WillOnce( 469 WillOnce(
470 Return( 470 Return(
471 csync::SyncError( 471 syncer::SyncError(
472 FROM_HERE, "error", syncable::APP_NOTIFICATIONS))); 472 FROM_HERE, "error", syncable::APP_NOTIFICATIONS)));
473 473
474 csync::SyncError sync_error = model()->MergeDataAndStartSyncing( 474 syncer::SyncError sync_error = model()->MergeDataAndStartSyncing(
475 syncable::APP_NOTIFICATIONS, 475 syncable::APP_NOTIFICATIONS,
476 initial_data, 476 initial_data,
477 PassProcessor(), 477 PassProcessor(),
478 error_handler.PassAs<csync::SyncErrorFactory>()); 478 error_handler.PassAs<syncer::SyncErrorFactory>());
479 479
480 EXPECT_TRUE(sync_error.IsSet()); 480 EXPECT_TRUE(sync_error.IsSet());
481 EXPECT_EQ(syncable::APP_NOTIFICATIONS, sync_error.type()); 481 EXPECT_EQ(syncable::APP_NOTIFICATIONS, sync_error.type());
482 EXPECT_EQ(0U, processor()->change_list_size()); 482 EXPECT_EQ(0U, processor()->change_list_size());
483 } 483 }
484 484
485 // When an item in sync matches with a local-only item in model, an error 485 // When an item in sync matches with a local-only item in model, an error
486 // should be returned. 486 // should be returned.
487 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptyMatchesLocal) { 487 TEST_F(AppNotificationManagerSyncTest, ModelAssocBothNonEmptyMatchesLocal) {
488 AppNotification* n1 = CreateNotification(1); 488 AppNotification* n1 = CreateNotification(1);
489 model()->Add(n1); 489 model()->Add(n1);
490 AppNotification* n2 = CreateNotification(true, 2); 490 AppNotification* n2 = CreateNotification(true, 2);
491 model()->Add(n2); 491 model()->Add(n2);
492 492
493 csync::SyncDataList initial_data; 493 syncer::SyncDataList initial_data;
494 initial_data.push_back(CreateSyncData(1)); 494 initial_data.push_back(CreateSyncData(1));
495 scoped_ptr<AppNotification> n2_a(CreateNotification(2)); 495 scoped_ptr<AppNotification> n2_a(CreateNotification(2));
496 initial_data.push_back( 496 initial_data.push_back(
497 AppNotificationManager::CreateSyncDataFromNotification(*n2_a)); 497 AppNotificationManager::CreateSyncDataFromNotification(*n2_a));
498 498
499 scoped_ptr<csync::SyncErrorFactoryMock> error_handler( 499 scoped_ptr<syncer::SyncErrorFactoryMock> error_handler(
500 new csync::SyncErrorFactoryMock()); 500 new syncer::SyncErrorFactoryMock());
501 EXPECT_CALL(*error_handler, CreateAndUploadError(_, _)). 501 EXPECT_CALL(*error_handler, CreateAndUploadError(_, _)).
502 WillOnce( 502 WillOnce(
503 Return( 503 Return(
504 csync::SyncError( 504 syncer::SyncError(
505 FROM_HERE, "error", syncable::APP_NOTIFICATIONS))); 505 FROM_HERE, "error", syncable::APP_NOTIFICATIONS)));
506 506
507 csync::SyncError sync_error = model()->MergeDataAndStartSyncing( 507 syncer::SyncError sync_error = model()->MergeDataAndStartSyncing(
508 syncable::APP_NOTIFICATIONS, 508 syncable::APP_NOTIFICATIONS,
509 initial_data, 509 initial_data,
510 PassProcessor(), 510 PassProcessor(),
511 error_handler.PassAs<csync::SyncErrorFactory>()); 511 error_handler.PassAs<syncer::SyncErrorFactory>());
512 512
513 EXPECT_TRUE(sync_error.IsSet()); 513 EXPECT_TRUE(sync_error.IsSet());
514 EXPECT_EQ(syncable::APP_NOTIFICATIONS, sync_error.type()); 514 EXPECT_EQ(syncable::APP_NOTIFICATIONS, sync_error.type());
515 EXPECT_EQ(0U, processor()->change_list_size()); 515 EXPECT_EQ(0U, processor()->change_list_size());
516 } 516 }
517 517
518 // Process sync changes when model is empty. 518 // Process sync changes when model is empty.
519 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesEmptyModel) { 519 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesEmptyModel) {
520 // We initially have no data. 520 // We initially have no data.
521 model()->MergeDataAndStartSyncing( 521 model()->MergeDataAndStartSyncing(
522 syncable::APP_NOTIFICATIONS, 522 syncable::APP_NOTIFICATIONS,
523 csync::SyncDataList(), 523 syncer::SyncDataList(),
524 PassProcessor(), 524 PassProcessor(),
525 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 525 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
526 526
527 // Set up a bunch of ADDs. 527 // Set up a bunch of ADDs.
528 csync::SyncChangeList changes; 528 syncer::SyncChangeList changes;
529 changes.push_back(CreateSyncChange( 529 changes.push_back(CreateSyncChange(
530 csync::SyncChange::ACTION_ADD, CreateNotification(1))); 530 syncer::SyncChange::ACTION_ADD, CreateNotification(1)));
531 changes.push_back(CreateSyncChange( 531 changes.push_back(CreateSyncChange(
532 csync::SyncChange::ACTION_ADD, CreateNotification(2))); 532 syncer::SyncChange::ACTION_ADD, CreateNotification(2)));
533 changes.push_back(CreateSyncChange( 533 changes.push_back(CreateSyncChange(
534 csync::SyncChange::ACTION_ADD, CreateNotification(3))); 534 syncer::SyncChange::ACTION_ADD, CreateNotification(3)));
535 535
536 model()->ProcessSyncChanges(FROM_HERE, changes); 536 model()->ProcessSyncChanges(FROM_HERE, changes);
537 537
538 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); 538 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size());
539 EXPECT_EQ(0U, processor()->change_list_size()); 539 EXPECT_EQ(0U, processor()->change_list_size());
540 } 540 }
541 541
542 // Process sync changes when model is not empty. 542 // Process sync changes when model is not empty.
543 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesNonEmptyModel) { 543 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesNonEmptyModel) {
544 AppNotification* n1 = CreateNotification(1); 544 AppNotification* n1 = CreateNotification(1);
545 model()->Add(n1); 545 model()->Add(n1);
546 AppNotification* n2 = CreateNotification(2); 546 AppNotification* n2 = CreateNotification(2);
547 model()->Add(n2); 547 model()->Add(n2);
548 model()->MergeDataAndStartSyncing( 548 model()->MergeDataAndStartSyncing(
549 syncable::APP_NOTIFICATIONS, 549 syncable::APP_NOTIFICATIONS,
550 csync::SyncDataList(), 550 syncer::SyncDataList(),
551 PassProcessor(), 551 PassProcessor(),
552 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 552 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
553 553
554 // Some adds and some deletes. 554 // Some adds and some deletes.
555 csync::SyncChangeList changes; 555 syncer::SyncChangeList changes;
556 changes.push_back(CreateSyncChange( 556 changes.push_back(CreateSyncChange(
557 csync::SyncChange::ACTION_ADD, CreateNotification(3))); 557 syncer::SyncChange::ACTION_ADD, CreateNotification(3)));
558 changes.push_back(CreateSyncChange( 558 changes.push_back(CreateSyncChange(
559 csync::SyncChange::ACTION_DELETE, n1->Copy())); 559 syncer::SyncChange::ACTION_DELETE, n1->Copy()));
560 changes.push_back(CreateSyncChange( 560 changes.push_back(CreateSyncChange(
561 csync::SyncChange::ACTION_ADD, CreateNotification(4))); 561 syncer::SyncChange::ACTION_ADD, CreateNotification(4)));
562 562
563 model()->ProcessSyncChanges(FROM_HERE, changes); 563 model()->ProcessSyncChanges(FROM_HERE, changes);
564 564
565 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); 565 EXPECT_EQ(3U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size());
566 EXPECT_EQ(2U, processor()->change_list_size()); 566 EXPECT_EQ(2U, processor()->change_list_size());
567 } 567 }
568 568
569 // Process sync changes should ignore a bad ADD. 569 // Process sync changes should ignore a bad ADD.
570 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadAdd) { 570 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadAdd) {
571 AppNotification* n1 = CreateNotification(1); 571 AppNotification* n1 = CreateNotification(1);
572 model()->Add(n1); 572 model()->Add(n1);
573 AppNotification* n2 = CreateNotification(2); 573 AppNotification* n2 = CreateNotification(2);
574 model()->Add(n2); 574 model()->Add(n2);
575 model()->MergeDataAndStartSyncing( 575 model()->MergeDataAndStartSyncing(
576 syncable::APP_NOTIFICATIONS, 576 syncable::APP_NOTIFICATIONS,
577 csync::SyncDataList(), 577 syncer::SyncDataList(),
578 PassProcessor(), 578 PassProcessor(),
579 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 579 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
580 580
581 // Some adds and some deletes. 581 // Some adds and some deletes.
582 csync::SyncChangeList changes; 582 syncer::SyncChangeList changes;
583 changes.push_back(CreateSyncChange( 583 changes.push_back(CreateSyncChange(
584 csync::SyncChange::ACTION_ADD, CreateNotification(1))); 584 syncer::SyncChange::ACTION_ADD, CreateNotification(1)));
585 585
586 csync::SyncError error = model()->ProcessSyncChanges(FROM_HERE, changes); 586 syncer::SyncError error = model()->ProcessSyncChanges(FROM_HERE, changes);
587 EXPECT_FALSE(error.IsSet()); 587 EXPECT_FALSE(error.IsSet());
588 588
589 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); 589 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size());
590 EXPECT_EQ(2U, processor()->change_list_size()); 590 EXPECT_EQ(2U, processor()->change_list_size());
591 } 591 }
592 592
593 // Process sync changes should ignore a bad DELETE. 593 // Process sync changes should ignore a bad DELETE.
594 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadDelete) { 594 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadDelete) {
595 AppNotification* n1 = CreateNotification(1); 595 AppNotification* n1 = CreateNotification(1);
596 model()->Add(n1); 596 model()->Add(n1);
597 AppNotification* n2 = CreateNotification(2); 597 AppNotification* n2 = CreateNotification(2);
598 model()->Add(n2); 598 model()->Add(n2);
599 model()->MergeDataAndStartSyncing( 599 model()->MergeDataAndStartSyncing(
600 syncable::APP_NOTIFICATIONS, 600 syncable::APP_NOTIFICATIONS,
601 csync::SyncDataList(), 601 syncer::SyncDataList(),
602 PassProcessor(), 602 PassProcessor(),
603 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 603 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
604 604
605 // Some adds and some deletes. 605 // Some adds and some deletes.
606 csync::SyncChangeList changes; 606 syncer::SyncChangeList changes;
607 changes.push_back(CreateSyncChange( 607 changes.push_back(CreateSyncChange(
608 csync::SyncChange::ACTION_DELETE, CreateNotification(3))); 608 syncer::SyncChange::ACTION_DELETE, CreateNotification(3)));
609 609
610 csync::SyncError error = model()->ProcessSyncChanges(FROM_HERE, changes); 610 syncer::SyncError error = model()->ProcessSyncChanges(FROM_HERE, changes);
611 EXPECT_FALSE(error.IsSet()); 611 EXPECT_FALSE(error.IsSet());
612 612
613 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); 613 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size());
614 EXPECT_EQ(2U, processor()->change_list_size()); 614 EXPECT_EQ(2U, processor()->change_list_size());
615 } 615 }
616 616
617 // Process sync changes should ignore bad UPDATEs. 617 // Process sync changes should ignore bad UPDATEs.
618 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadUpdates) { 618 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesIgnoreBadUpdates) {
619 AppNotification* n1 = CreateNotification(1); 619 AppNotification* n1 = CreateNotification(1);
620 model()->Add(n1); 620 model()->Add(n1);
621 AppNotification* n2 = CreateNotification(2); 621 AppNotification* n2 = CreateNotification(2);
622 model()->Add(n2); 622 model()->Add(n2);
623 model()->MergeDataAndStartSyncing( 623 model()->MergeDataAndStartSyncing(
624 syncable::APP_NOTIFICATIONS, 624 syncable::APP_NOTIFICATIONS,
625 csync::SyncDataList(), 625 syncer::SyncDataList(),
626 PassProcessor(), 626 PassProcessor(),
627 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 627 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
628 628
629 // Some adds and some deletes. 629 // Some adds and some deletes.
630 csync::SyncChangeList changes; 630 syncer::SyncChangeList changes;
631 changes.push_back(CreateSyncChange( 631 changes.push_back(CreateSyncChange(
632 csync::SyncChange::ACTION_UPDATE, CreateNotification(3))); 632 syncer::SyncChange::ACTION_UPDATE, CreateNotification(3)));
633 AppNotification* n2_changed = n2->Copy(); 633 AppNotification* n2_changed = n2->Copy();
634 n2_changed->set_link_text(n2_changed->link_text() + "-changed"); 634 n2_changed->set_link_text(n2_changed->link_text() + "-changed");
635 changes.push_back(CreateSyncChange( 635 changes.push_back(CreateSyncChange(
636 csync::SyncChange::ACTION_UPDATE, n2_changed)); 636 syncer::SyncChange::ACTION_UPDATE, n2_changed));
637 637
638 csync::SyncError error = model()->ProcessSyncChanges(FROM_HERE, changes); 638 syncer::SyncError error = model()->ProcessSyncChanges(FROM_HERE, changes);
639 EXPECT_FALSE(error.IsSet()); 639 EXPECT_FALSE(error.IsSet());
640 640
641 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); 641 EXPECT_EQ(2U, model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size());
642 EXPECT_EQ(2U, processor()->change_list_size()); 642 EXPECT_EQ(2U, processor()->change_list_size());
643 } 643 }
644 644
645 // Process over 15 changes when model is not empty. 645 // Process over 15 changes when model is not empty.
646 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesEmptyModelWithMax) { 646 TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesEmptyModelWithMax) {
647 const std::string& ext_id = "e1"; 647 const std::string& ext_id = "e1";
648 model()->MergeDataAndStartSyncing( 648 model()->MergeDataAndStartSyncing(
649 syncable::APP_NOTIFICATIONS, 649 syncable::APP_NOTIFICATIONS,
650 csync::SyncDataList(), 650 syncer::SyncDataList(),
651 PassProcessor(), 651 PassProcessor(),
652 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 652 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
653 for (unsigned int i = 0; 653 for (unsigned int i = 0;
654 i < AppNotificationManager::kMaxNotificationPerApp * 2; i++) { 654 i < AppNotificationManager::kMaxNotificationPerApp * 2; i++) {
655 csync::SyncChangeList changes; 655 syncer::SyncChangeList changes;
656 changes.push_back(CreateSyncChange( 656 changes.push_back(CreateSyncChange(
657 csync::SyncChange::ACTION_ADD, CreateNotification(false, i, ext_id))); 657 syncer::SyncChange::ACTION_ADD, CreateNotification(false, i, ext_id)));
658 model()->ProcessSyncChanges(FROM_HERE, changes); 658 model()->ProcessSyncChanges(FROM_HERE, changes);
659 if (i < AppNotificationManager::kMaxNotificationPerApp) { 659 if (i < AppNotificationManager::kMaxNotificationPerApp) {
660 EXPECT_EQ(i + 1, 660 EXPECT_EQ(i + 1,
661 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); 661 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size());
662 } else { 662 } else {
663 EXPECT_EQ(AppNotificationManager::kMaxNotificationPerApp, 663 EXPECT_EQ(AppNotificationManager::kMaxNotificationPerApp,
664 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); 664 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size());
665 for (unsigned int j = i; j > i - 5; j--) { 665 for (unsigned int j = i; j > i - 5; j--) {
666 EXPECT_EQ( 666 EXPECT_EQ(
667 AppNotificationManager::kMaxNotificationPerApp, 667 AppNotificationManager::kMaxNotificationPerApp,
668 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size()); 668 model()->GetAllSyncData(syncable::APP_NOTIFICATIONS).size());
669 } 669 }
670 } 670 }
671 } 671 }
672 } 672 }
673 673
674 // Stop syncing sets state correctly. 674 // Stop syncing sets state correctly.
675 TEST_F(AppNotificationManagerSyncTest, StopSyncing) { 675 TEST_F(AppNotificationManagerSyncTest, StopSyncing) {
676 EXPECT_FALSE(model()->sync_processor_.get()); 676 EXPECT_FALSE(model()->sync_processor_.get());
677 EXPECT_FALSE(model()->models_associated_); 677 EXPECT_FALSE(model()->models_associated_);
678 678
679 model()->MergeDataAndStartSyncing( 679 model()->MergeDataAndStartSyncing(
680 syncable::APP_NOTIFICATIONS, 680 syncable::APP_NOTIFICATIONS,
681 csync::SyncDataList(), 681 syncer::SyncDataList(),
682 PassProcessor(), 682 PassProcessor(),
683 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 683 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
684 684
685 EXPECT_TRUE(model()->sync_processor_.get()); 685 EXPECT_TRUE(model()->sync_processor_.get());
686 EXPECT_TRUE(model()->models_associated_); 686 EXPECT_TRUE(model()->models_associated_);
687 687
688 model()->StopSyncing(syncable::APP_NOTIFICATIONS); 688 model()->StopSyncing(syncable::APP_NOTIFICATIONS);
689 EXPECT_FALSE(model()->sync_processor_.get()); 689 EXPECT_FALSE(model()->sync_processor_.get());
690 EXPECT_FALSE(model()->models_associated_); 690 EXPECT_FALSE(model()->models_associated_);
691 } 691 }
692 692
693 // Adds get pushed to sync but local only are skipped. 693 // Adds get pushed to sync but local only are skipped.
694 TEST_F(AppNotificationManagerSyncTest, AddsGetsSynced) { 694 TEST_F(AppNotificationManagerSyncTest, AddsGetsSynced) {
695 model()->MergeDataAndStartSyncing( 695 model()->MergeDataAndStartSyncing(
696 syncable::APP_NOTIFICATIONS, 696 syncable::APP_NOTIFICATIONS,
697 csync::SyncDataList(), 697 syncer::SyncDataList(),
698 PassProcessor(), 698 PassProcessor(),
699 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 699 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
700 700
701 AppNotification* n1 = CreateNotification(1); 701 AppNotification* n1 = CreateNotification(1);
702 model()->Add(n1); 702 model()->Add(n1);
703 AppNotification* n2 = CreateNotification(2); 703 AppNotification* n2 = CreateNotification(2);
704 model()->Add(n2); 704 model()->Add(n2);
705 AppNotification* n3 = CreateNotification(true, 2); 705 AppNotification* n3 = CreateNotification(true, 2);
706 model()->Add(n3); 706 model()->Add(n3);
707 707
708 EXPECT_EQ(2U, processor()->change_list_size()); 708 EXPECT_EQ(2U, processor()->change_list_size());
709 EXPECT_TRUE(processor()->ContainsGuid(n1->guid())); 709 EXPECT_TRUE(processor()->ContainsGuid(n1->guid()));
710 csync::SyncChange c1 = processor()->GetChangeByGuid(n1->guid()); 710 syncer::SyncChange c1 = processor()->GetChangeByGuid(n1->guid());
711 AssertSyncChange(c1, csync::SyncChange::ACTION_ADD, *n1); 711 AssertSyncChange(c1, syncer::SyncChange::ACTION_ADD, *n1);
712 csync::SyncChange c2 = processor()->GetChangeByGuid(n2->guid()); 712 syncer::SyncChange c2 = processor()->GetChangeByGuid(n2->guid());
713 AssertSyncChange(c2, csync::SyncChange::ACTION_ADD, *n2); 713 AssertSyncChange(c2, syncer::SyncChange::ACTION_ADD, *n2);
714 } 714 }
715 715
716 // Clear all gets pushed to sync. 716 // Clear all gets pushed to sync.
717 TEST_F(AppNotificationManagerSyncTest, ClearAllGetsSynced) { 717 TEST_F(AppNotificationManagerSyncTest, ClearAllGetsSynced) {
718 const std::string& ext_id = "e1"; 718 const std::string& ext_id = "e1";
719 scoped_ptr<AppNotification> n1(CreateNotification(false, 1, ext_id)); 719 scoped_ptr<AppNotification> n1(CreateNotification(false, 1, ext_id));
720 scoped_ptr<AppNotification> n2(CreateNotification(false, 2, ext_id)); 720 scoped_ptr<AppNotification> n2(CreateNotification(false, 2, ext_id));
721 scoped_ptr<AppNotification> n3(CreateNotification(false, 3, ext_id)); 721 scoped_ptr<AppNotification> n3(CreateNotification(false, 3, ext_id));
722 scoped_ptr<AppNotification> n4(CreateNotification(4)); 722 scoped_ptr<AppNotification> n4(CreateNotification(4));
723 723
724 csync::SyncDataList initial_data; 724 syncer::SyncDataList initial_data;
725 initial_data.push_back( 725 initial_data.push_back(
726 AppNotificationManager::CreateSyncDataFromNotification(*n1)); 726 AppNotificationManager::CreateSyncDataFromNotification(*n1));
727 initial_data.push_back( 727 initial_data.push_back(
728 AppNotificationManager::CreateSyncDataFromNotification(*n2)); 728 AppNotificationManager::CreateSyncDataFromNotification(*n2));
729 initial_data.push_back( 729 initial_data.push_back(
730 AppNotificationManager::CreateSyncDataFromNotification(*n3)); 730 AppNotificationManager::CreateSyncDataFromNotification(*n3));
731 initial_data.push_back( 731 initial_data.push_back(
732 AppNotificationManager::CreateSyncDataFromNotification(*n4)); 732 AppNotificationManager::CreateSyncDataFromNotification(*n4));
733 model()->MergeDataAndStartSyncing( 733 model()->MergeDataAndStartSyncing(
734 syncable::APP_NOTIFICATIONS, 734 syncable::APP_NOTIFICATIONS,
735 initial_data, 735 initial_data,
736 PassProcessor(), 736 PassProcessor(),
737 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 737 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
738 738
739 model()->ClearAll(ext_id); 739 model()->ClearAll(ext_id);
740 740
741 EXPECT_EQ(3U, processor()->change_list_size()); 741 EXPECT_EQ(3U, processor()->change_list_size());
742 EXPECT_TRUE(processor()->ContainsGuid(n1->guid())); 742 EXPECT_TRUE(processor()->ContainsGuid(n1->guid()));
743 csync::SyncChange c1 = processor()->GetChangeByGuid(n1->guid()); 743 syncer::SyncChange c1 = processor()->GetChangeByGuid(n1->guid());
744 AssertSyncChange(c1, csync::SyncChange::ACTION_DELETE, *n1); 744 AssertSyncChange(c1, syncer::SyncChange::ACTION_DELETE, *n1);
745 csync::SyncChange c2 = processor()->GetChangeByGuid(n2->guid()); 745 syncer::SyncChange c2 = processor()->GetChangeByGuid(n2->guid());
746 AssertSyncChange(c2, csync::SyncChange::ACTION_DELETE, *n2); 746 AssertSyncChange(c2, syncer::SyncChange::ACTION_DELETE, *n2);
747 csync::SyncChange c3 = processor()->GetChangeByGuid(n3->guid()); 747 syncer::SyncChange c3 = processor()->GetChangeByGuid(n3->guid());
748 AssertSyncChange(c3, csync::SyncChange::ACTION_DELETE, *n3); 748 AssertSyncChange(c3, syncer::SyncChange::ACTION_DELETE, *n3);
749 } 749 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/app_notification_manager.cc ('k') | chrome/browser/extensions/app_sync_bundle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698