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

Side by Side Diff: chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc

Issue 22470006: Process incoming updates and deletes properly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates and deletes: CR feedback from DewittJ and Zea Created 7 years, 4 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
« no previous file with comments | « chrome/browser/notifications/sync_notifier/chrome_notifier_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <map> 5 #include <map>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/notifications/notification.h" 10 #include "chrome/browser/notifications/notification.h"
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 SyncChange::ACTION_ADD, CreateNotification( 303 SyncChange::ACTION_ADD, CreateNotification(
304 kTitle3, kText3, kIconUrl3, kImageUrl3, kAppId3, kKey3, kUnread))); 304 kTitle3, kText3, kIconUrl3, kImageUrl3, kAppId3, kKey3, kUnread)));
305 305
306 notifier.ProcessSyncChanges(FROM_HERE, changes); 306 notifier.ProcessSyncChanges(FROM_HERE, changes);
307 307
308 EXPECT_EQ(3U, notifier.GetAllSyncData(SYNCED_NOTIFICATIONS).size()); 308 EXPECT_EQ(3U, notifier.GetAllSyncData(SYNCED_NOTIFICATIONS).size());
309 // TODO(petewil): verify that the list entries have expected values to make 309 // TODO(petewil): verify that the list entries have expected values to make
310 // this test more robust. 310 // this test more robust.
311 } 311 }
312 312
313 // Process sync changes when there is no local data.
314 TEST_F(ChromeNotifierServiceTest, ProcessSyncChangesNonEmptyModel) {
315 StubNotificationUIManager notification_manager;
316 ChromeNotifierService notifier(NULL, &notification_manager);
317 notifier.set_avoid_bitmap_fetching_for_test(true);
318
319 // Create some local fake data.
320 scoped_ptr<SyncedNotification> n1(CreateNotification(
321 kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kUnread));
322 notifier.AddForTest(n1.Pass());
323 scoped_ptr<SyncedNotification> n2(CreateNotification(
324 kTitle2, kText2, kIconUrl2, kImageUrl2, kAppId2, kKey2, kUnread));
325 notifier.AddForTest(n2.Pass());
326 scoped_ptr<SyncedNotification> n3(CreateNotification(
327 kTitle3, kText3, kIconUrl3, kImageUrl3, kAppId3, kKey3, kUnread));
328 notifier.AddForTest(n3.Pass());
329
330 notifier.MergeDataAndStartSyncing(
331 SYNCED_NOTIFICATIONS,
332 SyncDataList(),
333 PassProcessor(),
334 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
335
336 // Set up some ADDs, some UPDATES, and some DELETEs
337 SyncChangeList changes;
338 changes.push_back(CreateSyncChange(
339 SyncChange::ACTION_ADD, CreateNotification(
340 kTitle4, kText4, kIconUrl4, kImageUrl4, kAppId4, kKey4, kUnread)));
341 changes.push_back(CreateSyncChange(
342 SyncChange::ACTION_UPDATE, CreateNotification(
343 kTitle2, kText2, kIconUrl2, kImageUrl2, kAppId2, kKey2, kRead)));
344 changes.push_back(CreateSyncChange(
345 SyncChange::ACTION_DELETE, CreateNotification(
346 kTitle3, kText3, kIconUrl3, kImageUrl3, kAppId3, kKey3, kDismissed)));
347
348 // Simulate incoming new notifications at runtime.
349 notifier.ProcessSyncChanges(FROM_HERE, changes);
350
351 // We should find notifications 1, 2, and 4, but not 3.
352 EXPECT_EQ(3U, notifier.GetAllSyncData(SYNCED_NOTIFICATIONS).size());
353 EXPECT_TRUE(notifier.FindNotificationById(kKey1));
354 EXPECT_TRUE(notifier.FindNotificationById(kKey2));
355 EXPECT_FALSE(notifier.FindNotificationById(kKey3));
356 EXPECT_TRUE(notifier.FindNotificationById(kKey4));
357 }
358
359 // Process sync changes that arrive before the change they are supposed to
360 // modify.
361 TEST_F(ChromeNotifierServiceTest, ProcessSyncChangesOutOfOrder) {
362 StubNotificationUIManager notification_manager;
363 ChromeNotifierService notifier(NULL, &notification_manager);
364 notifier.set_avoid_bitmap_fetching_for_test(true);
365
366 // Create some local fake data.
367 scoped_ptr<SyncedNotification> n1(CreateNotification(
368 kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kUnread));
369 notifier.AddForTest(n1.Pass());
370 scoped_ptr<SyncedNotification> n2(CreateNotification(
371 kTitle2, kText2, kIconUrl2, kImageUrl2, kAppId2, kKey2, kUnread));
372 notifier.AddForTest(n2.Pass());
373 scoped_ptr<SyncedNotification> n3(CreateNotification(
374 kTitle3, kText3, kIconUrl3, kImageUrl3, kAppId3, kKey3, kUnread));
375 notifier.AddForTest(n3.Pass());
376
377 notifier.MergeDataAndStartSyncing(
378 SYNCED_NOTIFICATIONS,
379 SyncDataList(),
380 PassProcessor(),
381 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
382
383 SyncChangeList changes;
384 // UPDATE a notification we have not seen an add for.
385 changes.push_back(CreateSyncChange(
386 SyncChange::ACTION_UPDATE, CreateNotification(
387 kTitle4, kText4, kIconUrl4, kImageUrl4, kAppId4, kKey4, kUnread)));
388 // ADD a notification that we already have.
389 changes.push_back(CreateSyncChange(
390 SyncChange::ACTION_ADD, CreateNotification(
391 kTitle2, kText2, kIconUrl2, kImageUrl2, kAppId2, kKey2, kRead)));
392 // DELETE a notification we have not seen yet.
393 changes.push_back(CreateSyncChange(
394 SyncChange::ACTION_DELETE, CreateNotification(
395 kTitle5, kText5, kIconUrl5, kImageUrl5, kAppId5, kKey5, kDismissed)));
396
397 // Simulate incoming new notifications at runtime.
398 notifier.ProcessSyncChanges(FROM_HERE, changes);
399
400 // We should find notifications 1, 2, 3, and 4, but not 5.
401 EXPECT_EQ(4U, notifier.GetAllSyncData(SYNCED_NOTIFICATIONS).size());
402 EXPECT_TRUE(notifier.FindNotificationById(kKey1));
403 EXPECT_TRUE(notifier.FindNotificationById(kKey2));
404 EXPECT_TRUE(notifier.FindNotificationById(kKey3));
405 EXPECT_TRUE(notifier.FindNotificationById(kKey4));
406 EXPECT_FALSE(notifier.FindNotificationById(kKey5));
407 }
408
409
313 // Model has some notifications, some of them are local only. Sync has some 410 // Model has some notifications, some of them are local only. Sync has some
314 // notifications. No items match up. 411 // notifications. No items match up.
315 TEST_F(ChromeNotifierServiceTest, LocalRemoteBothNonEmptyNoOverlap) { 412 TEST_F(ChromeNotifierServiceTest, LocalRemoteBothNonEmptyNoOverlap) {
316 StubNotificationUIManager notification_manager; 413 StubNotificationUIManager notification_manager;
317 ChromeNotifierService notifier(NULL, &notification_manager); 414 ChromeNotifierService notifier(NULL, &notification_manager);
318 notifier.set_avoid_bitmap_fetching_for_test(true); 415 notifier.set_avoid_bitmap_fetching_for_test(true);
319 416
320 // Create some local fake data. 417 // Create some local fake data.
321 scoped_ptr<SyncedNotification> n1(CreateNotification( 418 scoped_ptr<SyncedNotification> n1(CreateNotification(
322 kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kUnread)); 419 kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kUnread));
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 EXPECT_EQ(std::string(kTitle2), notification1->GetTitle()); 591 EXPECT_EQ(std::string(kTitle2), notification1->GetTitle());
495 592
496 // Ensure no new data will be sent to the remote store for notification1. 593 // Ensure no new data will be sent to the remote store for notification1.
497 EXPECT_EQ(0U, processor()->change_list_size()); 594 EXPECT_EQ(0U, processor()->change_list_size());
498 EXPECT_FALSE(processor()->ContainsId(kKey1)); 595 EXPECT_FALSE(processor()->ContainsId(kKey1));
499 } 596 }
500 597
501 // TODO(petewil): There are more tests to add, such as when we add an API 598 // TODO(petewil): There are more tests to add, such as when we add an API
502 // to allow data entry from the client, we might have a more up to date 599 // to allow data entry from the client, we might have a more up to date
503 // item on the client than the server, or we might have a merge conflict. 600 // item on the client than the server, or we might have a merge conflict.
OLDNEW
« no previous file with comments | « chrome/browser/notifications/sync_notifier/chrome_notifier_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698