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

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

Issue 12717010: Widen Data Pipes and newer protobufs (Closed) Base URL: http://git.chromium.org/chromium/src.git@newProtobufs
Patch Set: Synced Notifications newer protobufs - CR fixes per DCheng Created 7 years, 8 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
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 "chrome/browser/notifications/notification_ui_manager.h" 8 #include "chrome/browser/notifications/notification_ui_manager.h"
9 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" 9 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h"
10 #include "chrome/browser/notifications/sync_notifier/synced_notification.h" 10 #include "chrome/browser/notifications/sync_notifier/synced_notification.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 const int64 kFakeCreationTime = 42; 45 const int64 kFakeCreationTime = 42;
46 const sync_pb::CoalescedSyncedNotification_ReadState kDismissed = 46 const sync_pb::CoalescedSyncedNotification_ReadState kDismissed =
47 sync_pb::CoalescedSyncedNotification_ReadState_DISMISSED; 47 sync_pb::CoalescedSyncedNotification_ReadState_DISMISSED;
48 const sync_pb::CoalescedSyncedNotification_ReadState kUnread = 48 const sync_pb::CoalescedSyncedNotification_ReadState kUnread =
49 sync_pb::CoalescedSyncedNotification_ReadState_UNREAD; 49 sync_pb::CoalescedSyncedNotification_ReadState_UNREAD;
50 50
51 // Extract notification id from syncer::SyncData. 51 // Extract notification id from syncer::SyncData.
52 std::string GetNotificationId(const SyncData& sync_data) { 52 std::string GetNotificationId(const SyncData& sync_data) {
53 SyncedNotificationSpecifics specifics = sync_data.GetSpecifics(). 53 SyncedNotificationSpecifics specifics = sync_data.GetSpecifics().
54 synced_notification(); 54 synced_notification();
55
55 return specifics.coalesced_notification().key(); 56 return specifics.coalesced_notification().key();
56 } 57 }
57 58
58 // Stub out the NotificationUIManager for unit testing. 59 // Stub out the NotificationUIManager for unit testing.
59 class StubNotificationUIManager : public NotificationUIManager { 60 class StubNotificationUIManager : public NotificationUIManager {
60 public: 61 public:
61 StubNotificationUIManager() {} 62 StubNotificationUIManager() {}
62 virtual ~StubNotificationUIManager() {} 63 virtual ~StubNotificationUIManager() {}
63 64
64 // Adds a notification to be displayed. Virtual for unit test override. 65 // Adds a notification to be displayed. Virtual for unit test override.
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 const std::string& key, 213 const std::string& key,
213 const std::string& external_id, 214 const std::string& external_id,
214 sync_pb::CoalescedSyncedNotification_ReadState read_state) { 215 sync_pb::CoalescedSyncedNotification_ReadState read_state) {
215 // CreateLocalData makes a copy of this, so this can safely live 216 // CreateLocalData makes a copy of this, so this can safely live
216 // on the stack. 217 // on the stack.
217 EntitySpecifics entity_specifics; 218 EntitySpecifics entity_specifics;
218 219
219 SyncedNotificationSpecifics* specifics = 220 SyncedNotificationSpecifics* specifics =
220 entity_specifics.mutable_synced_notification(); 221 entity_specifics.mutable_synced_notification();
221 222
222 specifics->mutable_coalesced_notification()-> 223 specifics->
224 mutable_coalesced_notification()->
223 set_app_id(app_id); 225 set_app_id(app_id);
224 226
225 specifics->mutable_coalesced_notification()-> 227 specifics->
228 mutable_coalesced_notification()->
226 set_key(key); 229 set_key(key);
227 230
228 specifics->mutable_coalesced_notification()-> 231 specifics->
232 mutable_coalesced_notification()->
229 mutable_render_info()-> 233 mutable_render_info()->
230 mutable_expanded_info()-> 234 mutable_expanded_info()->
231 mutable_simple_expanded_layout()-> 235 mutable_simple_expanded_layout()->
232 set_title(message); 236 set_title(message);
233 237
234 specifics-> 238 specifics->
235 mutable_coalesced_notification()-> 239 mutable_coalesced_notification()->
236 set_creation_time_msec(kFakeCreationTime); 240 set_creation_time_msec(kFakeCreationTime);
237 241
238 specifics-> 242 specifics->
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 358
355 // Merge the local and remote data. 359 // Merge the local and remote data.
356 notifier.MergeDataAndStartSyncing( 360 notifier.MergeDataAndStartSyncing(
357 SYNCED_NOTIFICATIONS, 361 SYNCED_NOTIFICATIONS,
358 initial_data, 362 initial_data,
359 PassProcessor(), 363 PassProcessor(),
360 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 364 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
361 365
362 // Ensure the local store now has all local and remote notifications. 366 // Ensure the local store now has all local and remote notifications.
363 EXPECT_EQ(7U, notifier.GetAllSyncData(SYNCED_NOTIFICATIONS).size()); 367 EXPECT_EQ(7U, notifier.GetAllSyncData(SYNCED_NOTIFICATIONS).size());
364 EXPECT_TRUE(notifier.FindNotificationById(kKey1)); 368 EXPECT_TRUE(notifier.FindNotificationByKey(kKey1));
365 EXPECT_TRUE(notifier.FindNotificationById(kKey2)); 369 EXPECT_TRUE(notifier.FindNotificationByKey(kKey2));
366 EXPECT_TRUE(notifier.FindNotificationById(kKey3)); 370 EXPECT_TRUE(notifier.FindNotificationByKey(kKey3));
367 EXPECT_TRUE(notifier.FindNotificationById(kKey4)); 371 EXPECT_TRUE(notifier.FindNotificationByKey(kKey4));
368 EXPECT_TRUE(notifier.FindNotificationById(kKey5)); 372 EXPECT_TRUE(notifier.FindNotificationByKey(kKey5));
369 EXPECT_TRUE(notifier.FindNotificationById(kKey6)); 373 EXPECT_TRUE(notifier.FindNotificationByKey(kKey6));
370 EXPECT_TRUE(notifier.FindNotificationById(kKey7)); 374 EXPECT_TRUE(notifier.FindNotificationByKey(kKey7));
371 375
372 // Test the type conversion and construction functions. 376 // Test the type conversion and construction functions.
373 for (SyncDataList::const_iterator iter = initial_data.begin(); 377 for (SyncDataList::const_iterator iter = initial_data.begin();
374 iter != initial_data.end(); ++iter) { 378 iter != initial_data.end(); ++iter) {
375 scoped_ptr<SyncedNotification> notification1( 379 scoped_ptr<SyncedNotification> notification1(
376 ChromeNotifierService::CreateNotificationFromSyncData(*iter)); 380 ChromeNotifierService::CreateNotificationFromSyncData(*iter));
377 // TODO(petewil): Revisit this when we add version info to notifications. 381 // TODO(petewil): Revisit this when we add version info to notifications.
378 const std::string& id = notification1->notification_id(); 382 const std::string& key = notification1->key();
379 const SyncedNotification* notification2 = notifier.FindNotificationById(id); 383 const SyncedNotification* notification2 =
384 notifier.FindNotificationByKey(key);
380 EXPECT_TRUE(NULL != notification2); 385 EXPECT_TRUE(NULL != notification2);
381 EXPECT_TRUE(notification1->EqualsIgnoringReadState(*notification2)); 386 EXPECT_TRUE(notification1->EqualsIgnoringReadState(*notification2));
382 EXPECT_EQ(notification1->read_state(), notification2->read_state()); 387 EXPECT_EQ(notification1->read_state(), notification2->read_state());
383 } 388 }
384 EXPECT_TRUE(notifier.FindNotificationById(kKey1)); 389 EXPECT_TRUE(notifier.FindNotificationByKey(kKey1));
385 EXPECT_TRUE(notifier.FindNotificationById(kKey2)); 390 EXPECT_TRUE(notifier.FindNotificationByKey(kKey2));
386 EXPECT_TRUE(notifier.FindNotificationById(kKey3)); 391 EXPECT_TRUE(notifier.FindNotificationByKey(kKey3));
387 } 392 }
388 393
389 // Test the local store having the read bit unset, the remote store having 394 // Test the local store having the read bit unset, the remote store having
390 // it set. 395 // it set.
391 TEST_F(ChromeNotifierServiceTest, ModelAssocBothNonEmptyReadMismatch1) { 396 TEST_F(ChromeNotifierServiceTest, ModelAssocBothNonEmptyReadMismatch1) {
392 StubNotificationUIManager notification_manager; 397 StubNotificationUIManager notification_manager;
393 ChromeNotifierService notifier(NULL, &notification_manager); 398 ChromeNotifierService notifier(NULL, &notification_manager);
394 399
395 // Create some local fake data. 400 // Create some local fake data.
396 scoped_ptr<SyncedNotification> n1(CreateNotification( 401 scoped_ptr<SyncedNotification> n1(CreateNotification(
(...skipping 11 matching lines...) Expand all
408 notifier.MergeDataAndStartSyncing( 413 notifier.MergeDataAndStartSyncing(
409 syncer::SYNCED_NOTIFICATIONS, 414 syncer::SYNCED_NOTIFICATIONS,
410 initial_data, 415 initial_data,
411 PassProcessor(), 416 PassProcessor(),
412 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 417 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
413 418
414 // Ensure the local store still has only two notifications, and the read 419 // Ensure the local store still has only two notifications, and the read
415 // state of the first is now read. 420 // state of the first is now read.
416 EXPECT_EQ(2U, notifier.GetAllSyncData(syncer::SYNCED_NOTIFICATIONS).size()); 421 EXPECT_EQ(2U, notifier.GetAllSyncData(syncer::SYNCED_NOTIFICATIONS).size());
417 SyncedNotification* notification1 = 422 SyncedNotification* notification1 =
418 notifier.FindNotificationById(kKey1); 423 notifier.FindNotificationByKey(kKey1);
419 EXPECT_FALSE(NULL == notification1); 424 EXPECT_FALSE(NULL == notification1);
420 EXPECT_EQ(SyncedNotification::kDismissed, notification1->read_state()); 425 EXPECT_EQ(kDismissed, notification1->read_state());
421 EXPECT_TRUE(notifier.FindNotificationById(kKey2)); 426 EXPECT_TRUE(notifier.FindNotificationByKey(kKey2));
422 EXPECT_FALSE(notifier.FindNotificationById(kKey3)); 427 EXPECT_FALSE(notifier.FindNotificationByKey(kKey3));
423 428
424 // Ensure no new data will be sent to the remote store for notification1. 429 // Ensure no new data will be sent to the remote store for notification1.
425 EXPECT_EQ(0U, processor()->change_list_size()); 430 EXPECT_EQ(0U, processor()->change_list_size());
426 EXPECT_FALSE(processor()->ContainsId(kKey1)); 431 EXPECT_FALSE(processor()->ContainsId(kKey1));
427 } 432 }
428 433
429 // Test when the local store has the read bit set, and the remote store has 434 // Test when the local store has the read bit set, and the remote store has
430 // it unset. 435 // it unset.
431 TEST_F(ChromeNotifierServiceTest, ModelAssocBothNonEmptyReadMismatch2) { 436 TEST_F(ChromeNotifierServiceTest, ModelAssocBothNonEmptyReadMismatch2) {
432 StubNotificationUIManager notification_manager; 437 StubNotificationUIManager notification_manager;
(...skipping 15 matching lines...) Expand all
448 notifier.MergeDataAndStartSyncing( 453 notifier.MergeDataAndStartSyncing(
449 syncer::SYNCED_NOTIFICATIONS, 454 syncer::SYNCED_NOTIFICATIONS,
450 initial_data, 455 initial_data,
451 PassProcessor(), 456 PassProcessor(),
452 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 457 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
453 458
454 // Ensure the local store still has only two notifications, and the read 459 // Ensure the local store still has only two notifications, and the read
455 // state of the first is now read. 460 // state of the first is now read.
456 EXPECT_EQ(2U, notifier.GetAllSyncData(syncer::SYNCED_NOTIFICATIONS).size()); 461 EXPECT_EQ(2U, notifier.GetAllSyncData(syncer::SYNCED_NOTIFICATIONS).size());
457 SyncedNotification* notification1 = 462 SyncedNotification* notification1 =
458 notifier.FindNotificationById(kKey1); 463 notifier.FindNotificationByKey(kKey1);
459 EXPECT_FALSE(NULL == notification1); 464 EXPECT_FALSE(NULL == notification1);
460 EXPECT_EQ(SyncedNotification::kDismissed, notification1->read_state()); 465 EXPECT_EQ(kDismissed, notification1->read_state());
461 EXPECT_TRUE(notifier.FindNotificationById(kKey2)); 466 EXPECT_TRUE(notifier.FindNotificationByKey(kKey2));
462 EXPECT_FALSE(notifier.FindNotificationById(kKey3)); 467 EXPECT_FALSE(notifier.FindNotificationByKey(kKey3));
463 468
464 // Ensure the new data will be sent to the remote store for notification1. 469 // Ensure the new data will be sent to the remote store for notification1.
465 EXPECT_EQ(1U, processor()->change_list_size()); 470 EXPECT_EQ(1U, processor()->change_list_size());
466 EXPECT_TRUE(processor()->ContainsId(kKey1)); 471 EXPECT_TRUE(processor()->ContainsId(kKey1));
467 EXPECT_EQ(SyncChange::ACTION_UPDATE, processor()->GetChangeById( 472 EXPECT_EQ(SyncChange::ACTION_UPDATE, processor()->GetChangeById(
468 kKey1).change_type()); 473 kKey1).change_type());
469 } 474 }
470 475
471 // We have a notification in the local store, we get an updated version 476 // We have a notification in the local store, we get an updated version
472 // of the same notification remotely, it should take precedence. 477 // of the same notification remotely, it should take precedence.
(...skipping 13 matching lines...) Expand all
486 // Merge the local and remote data. 491 // Merge the local and remote data.
487 notifier.MergeDataAndStartSyncing( 492 notifier.MergeDataAndStartSyncing(
488 syncer::SYNCED_NOTIFICATIONS, 493 syncer::SYNCED_NOTIFICATIONS,
489 initial_data, 494 initial_data,
490 PassProcessor(), 495 PassProcessor(),
491 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 496 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
492 497
493 // Ensure the local store still has only one notification 498 // Ensure the local store still has only one notification
494 EXPECT_EQ(1U, notifier.GetAllSyncData(syncer::SYNCED_NOTIFICATIONS).size()); 499 EXPECT_EQ(1U, notifier.GetAllSyncData(syncer::SYNCED_NOTIFICATIONS).size());
495 SyncedNotification* notification1 = 500 SyncedNotification* notification1 =
496 notifier.FindNotificationById(kKey1); 501 notifier.FindNotificationByKey(kKey1);
502
497 EXPECT_FALSE(NULL == notification1); 503 EXPECT_FALSE(NULL == notification1);
498 EXPECT_EQ(SyncedNotification::kUnread, notification1->read_state()); 504 EXPECT_EQ(kUnread, notification1->read_state());
499 EXPECT_EQ("One", notification1->title()); 505 EXPECT_EQ("One", notification1->title());
500 EXPECT_EQ("Eleven", notification1->first_external_id());
501 506
502 // Ensure no new data will be sent to the remote store for notification1. 507 // Ensure no new data will be sent to the remote store for notification1.
503 EXPECT_EQ(0U, processor()->change_list_size()); 508 EXPECT_EQ(0U, processor()->change_list_size());
504 EXPECT_FALSE(processor()->ContainsId(kKey1)); 509 EXPECT_FALSE(processor()->ContainsId(kKey1));
505 } 510 }
506 511
507 // TODO(petewil): There are more tests to add, such as when we add an API 512 // TODO(petewil): There are more tests to add, such as when we add an API
508 // to allow data entry from the client, we might have a more up to date 513 // to allow data entry from the client, we might have a more up to date
509 // item on the client than the server, or we might have a merge conflict. 514 // item on the client than the server, or we might have a merge conflict.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698