summaryrefslogtreecommitdiffstats
path: root/chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc')
-rw-r--r--chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc345
1 files changed, 20 insertions, 325 deletions
diff --git a/chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc b/chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc
index 5f30cac..caedb24 100644
--- a/chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc
+++ b/chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc
@@ -11,14 +11,13 @@
#include "chrome/browser/notifications/notification_test_util.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h"
+#include "chrome/browser/notifications/sync_notifier/sync_notifier_test_utils.h"
#include "chrome/browser/notifications/sync_notifier/synced_notification.h"
#include "chrome/browser/profiles/profile.h"
#include "sync/api/sync_change.h"
#include "sync/api/sync_change_processor.h"
#include "sync/api/sync_error_factory.h"
#include "sync/api/sync_error_factory_mock.h"
-#include "sync/protocol/sync.pb.h"
-#include "sync/protocol/synced_notification_specifics.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/message_center/message_center_util.h"
@@ -34,75 +33,8 @@ using notifier::ChromeNotifierService;
namespace {
-const char kAppId1[] = "fboilmbenheemaomgaeehigklolhkhnf";
-const char kAppId2[] = "fbcmoldooppoahjhfflnmljoanccekpf";
-const char kAppId3[] = "fbcmoldooppoahjhfflnmljoanccek33";
-const char kAppId4[] = "fbcmoldooppoahjhfflnmljoanccek44";
-const char kAppId5[] = "fbcmoldooppoahjhfflnmljoanccek55";
-const char kAppId6[] = "fbcmoldooppoahjhfflnmljoanccek66";
-const char kAppId7[] = "fbcmoldooppoahjhfflnmljoanccek77";
-const char kKey1[] = "foo";
-const char kKey2[] = "bar";
-const char kKey3[] = "bat";
-const char kKey4[] = "baz";
-const char kKey5[] = "foobar";
-const char kKey6[] = "fu";
-const char kKey7[] = "meta";
-const char kIconUrl[] = "http://www.google.com/icon1.jpg";
-const char kTitle1[] = "New appointment at 2:15";
-const char kTitle2[] = "Email from Mark: Upcoming Ski trip";
-const char kTitle3[] = "Weather alert - light rain tonight.";
-const char kTitle4[] = "Zombie Alert on I-405";
-const char kTitle5[] = "5-dimensional plutonian steam hockey scores";
-const char kTitle6[] = "Conterfactuals Inc Stock report";
-const char kTitle7[] = "Push Messaging app updated";
-const char kText1[] = "Space Needle, 12:00 pm";
-const char kText2[] = "Stevens Pass is our first choice.";
-const char kText3[] = "More rain expected in the Seattle area tonight.";
-const char kText4[] = "Traffic slowdown as motorists are hitting zombies";
-const char kText5[] = "Neptune wins, pi to e";
-const char kText6[] = "Beef flavored base for soups";
-const char kText7[] = "You now have the latest version of Push Messaging App.";
-const char kIconUrl1[] = "http://www.google.com/icon1.jpg";
-const char kIconUrl2[] = "http://www.google.com/icon2.jpg";
-const char kIconUrl3[] = "http://www.google.com/icon3.jpg";
-const char kIconUrl4[] = "http://www.google.com/icon4.jpg";
-const char kIconUrl5[] = "http://www.google.com/icon5.jpg";
-const char kIconUrl6[] = "http://www.google.com/icon6.jpg";
-const char kIconUrl7[] = "http://www.google.com/icon7.jpg";
-const char kImageUrl1[] = "http://www.google.com/image1.jpg";
-const char kImageUrl2[] = "http://www.google.com/image2.jpg";
-const char kImageUrl3[] = "http://www.google.com/image3.jpg";
-const char kImageUrl4[] = "http://www.google.com/image4.jpg";
-const char kImageUrl5[] = "http://www.google.com/image5.jpg";
-const char kImageUrl6[] = "http://www.google.com/image6.jpg";
-const char kImageUrl7[] = "http://www.google.com/image7.jpg";
-const char kExpectedOriginUrl[] =
- "chrome-extension://fboilmbenheemaomgaeehigklolhkhnf/";
-const char kDefaultDestinationTitle[] = "Open web page";
-const char kDefaultDestinationIconUrl[] = "http://www.google.com/image4.jpg";
-const char kDefaultDestinationUrl[] = "http://www.google.com";
-const char kButtonOneTitle[] = "Read";
-const char kButtonOneIconUrl[] = "http://www.google.com/image8.jpg";
-const char kButtonOneUrl[] = "http://www.google.com/do-something1";
-const char kButtonTwoTitle[] = "Reply";
-const char kButtonTwoIconUrl[] = "http://www.google.com/image9.jpg";
-const char kButtonTwoUrl[] = "http://www.google.com/do-something2";
-const char kContainedTitle1[] = "Today's Picnic moved";
-const char kContainedTitle2[] = "Group Run Today";
-const char kContainedTitle3[] = "Starcraft Tonight";
-const char kContainedMessage1[] = "Due to rain, we will be inside the cafe.";
-const char kContainedMessage2[] = "Meet at noon in the Gym.";
-const char kContainedMessage3[] = "Let's play starcraft tonight on the LAN.";
-const int64 kFakeCreationTime = 42;
-const int kProtobufPriority = static_cast<int>(
- sync_pb::CoalescedSyncedNotification_Priority_LOW);
const int kNotificationPriority = static_cast<int>(
message_center::LOW_PRIORITY);
-const sync_pb::CoalescedSyncedNotification_ReadState kDismissed =
- sync_pb::CoalescedSyncedNotification_ReadState_DISMISSED;
-const sync_pb::CoalescedSyncedNotification_ReadState kUnread =
- sync_pb::CoalescedSyncedNotification_ReadState_UNREAD;
// Extract notification id from syncer::SyncData.
std::string GetNotificationId(const SyncData& sync_data) {
@@ -297,243 +229,6 @@ class ChromeNotifierServiceTest : public testing::Test {
ChromeNotifierService::CreateSyncDataFromNotification(*notification));
}
- // Helper to create syncer::SyncData.
- static SyncData CreateSyncData(
- const std::string& title,
- const std::string& text,
- const std::string& app_icon_url,
- const std::string& image_url,
- const std::string& app_id,
- const std::string& key,
- const sync_pb::CoalescedSyncedNotification_ReadState read_state) {
- // CreateLocalData makes a copy of this, so this can safely live
- // on the stack.
- EntitySpecifics entity_specifics;
-
- // Get a writeable pointer to the sync notifications specifics inside the
- // entity specifics.
- SyncedNotificationSpecifics* specifics =
- entity_specifics.mutable_synced_notification();
-
- specifics->mutable_coalesced_notification()->
- set_app_id(app_id);
-
- specifics->mutable_coalesced_notification()->
- set_key(key);
-
- specifics->mutable_coalesced_notification()->
- set_priority(static_cast<sync_pb::CoalescedSyncedNotification_Priority>(
- kProtobufPriority));
-
- // Set the title.
- specifics->mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_expanded_info()->
- mutable_simple_expanded_layout()->
- set_title(title);
-
- // Set the text.
- specifics->mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_expanded_info()->
- mutable_simple_expanded_layout()->
- set_text(text);
-
- // Set the heading.
- specifics->
- mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_collapsed_info()->
- mutable_simple_collapsed_layout()->
- set_heading(title);
-
- // Add the collapsed info and set the app_icon_url on it.
- specifics->
- mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_expanded_info()->
- add_collapsed_info();
- specifics->
- mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_expanded_info()->
- mutable_collapsed_info(0)->
- mutable_simple_collapsed_layout()->
- mutable_app_icon()->
- set_url(app_icon_url);
-
- // Add the media object and set the image url on it.
- specifics->
- mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_expanded_info()->
- mutable_simple_expanded_layout()->
- add_media();
- specifics->
- mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_expanded_info()->
- mutable_simple_expanded_layout()->
- mutable_media(0)->
- mutable_image()->
- set_url(image_url);
-
- specifics->mutable_coalesced_notification()->
- set_creation_time_msec(kFakeCreationTime);
-
- specifics->mutable_coalesced_notification()->
- set_read_state(read_state);
-
- // Contained notification one.
- // We re-use the collapsed info we added for the app_icon_url,
- // so no need to create another one here.
- specifics->mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_expanded_info()->
- mutable_collapsed_info(0)->
- mutable_simple_collapsed_layout()->
- set_heading(kContainedTitle1);
- specifics->mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_expanded_info()->
- mutable_collapsed_info(0)->
- mutable_simple_collapsed_layout()->
- set_description(kContainedMessage1);
-
- // Contained notification two.
- specifics->mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_expanded_info()->
- add_collapsed_info();
- specifics->mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_expanded_info()->
- mutable_collapsed_info(1)->
- mutable_simple_collapsed_layout()->
- set_heading(kContainedTitle2);
- specifics->mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_expanded_info()->
- mutable_collapsed_info(1)->
- mutable_simple_collapsed_layout()->
- set_description(kContainedMessage2);
-
- // Contained notification three.
- specifics->mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_expanded_info()->
- add_collapsed_info();
- specifics->mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_expanded_info()->
- mutable_collapsed_info(2)->
- mutable_simple_collapsed_layout()->
- set_heading(kContainedTitle3);
- specifics->mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_expanded_info()->
- mutable_collapsed_info(2)->
- mutable_simple_collapsed_layout()->
- set_description(kContainedMessage3);
-
- // Default Destination.
- specifics->mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_collapsed_info()->
- mutable_default_destination()->
- set_text(kDefaultDestinationTitle);
- specifics->mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_collapsed_info()->
- mutable_default_destination()->
- mutable_icon()->
- set_url(kDefaultDestinationIconUrl);
- specifics->mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_collapsed_info()->
- mutable_default_destination()->
- mutable_icon()->
- set_alt_text(kDefaultDestinationTitle);
- specifics->mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_collapsed_info()->
- mutable_default_destination()->
- set_url(kDefaultDestinationUrl);
-
- // Buttons are represented as targets.
-
- // Button One.
- specifics->mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_collapsed_info()->
- add_target();
- specifics->mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_collapsed_info()->
- mutable_target(0)->
- mutable_action()->
- set_text(kButtonOneTitle);
- specifics->mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_collapsed_info()->
- mutable_target(0)->
- mutable_action()->
- mutable_icon()->
- set_url(kButtonOneIconUrl);
- specifics->mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_collapsed_info()->
- mutable_target(0)->
- mutable_action()->
- mutable_icon()->
- set_alt_text(kButtonOneTitle);
- specifics->mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_collapsed_info()->
- mutable_target(0)->
- mutable_action()->
- set_url(kButtonOneUrl);
-
- // Button Two.
- specifics->mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_collapsed_info()->
- add_target();
- specifics->mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_collapsed_info()->
- mutable_target(1)->
- mutable_action()->
- set_text(kButtonTwoTitle);
- specifics->mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_collapsed_info()->
- mutable_target(1)->
- mutable_action()->
- mutable_icon()->
- set_url(kButtonTwoIconUrl);
- specifics->mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_collapsed_info()->
- mutable_target(1)->
- mutable_action()->
- mutable_icon()->
- set_alt_text(kButtonTwoTitle);
- specifics->mutable_coalesced_notification()->
- mutable_render_info()->
- mutable_collapsed_info()->
- mutable_target(1)->
- mutable_action()->
- set_url(kButtonTwoUrl);
-
- SyncData sync_data = SyncData::CreateLocalData(
- "syncer::SYNCED_NOTIFICATIONS",
- "ChromeNotifierServiceUnitTest",
- entity_specifics);
-
- return sync_data;
- }
-
private:
scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
scoped_ptr<syncer::SyncChangeProcessor> sync_processor_delegate_;
@@ -643,13 +338,13 @@ TEST_F(ChromeNotifierServiceTest, LocalRemoteBothNonEmptyNoOverlap) {
// Ensure the local store now has all local and remote notifications.
EXPECT_EQ(7U, notifier.GetAllSyncData(SYNCED_NOTIFICATIONS).size());
- EXPECT_TRUE(notifier.FindNotificationByKey(kKey1));
- EXPECT_TRUE(notifier.FindNotificationByKey(kKey2));
- EXPECT_TRUE(notifier.FindNotificationByKey(kKey3));
- EXPECT_TRUE(notifier.FindNotificationByKey(kKey4));
- EXPECT_TRUE(notifier.FindNotificationByKey(kKey5));
- EXPECT_TRUE(notifier.FindNotificationByKey(kKey6));
- EXPECT_TRUE(notifier.FindNotificationByKey(kKey7));
+ EXPECT_TRUE(notifier.FindNotificationById(kKey1));
+ EXPECT_TRUE(notifier.FindNotificationById(kKey2));
+ EXPECT_TRUE(notifier.FindNotificationById(kKey3));
+ EXPECT_TRUE(notifier.FindNotificationById(kKey4));
+ EXPECT_TRUE(notifier.FindNotificationById(kKey5));
+ EXPECT_TRUE(notifier.FindNotificationById(kKey6));
+ EXPECT_TRUE(notifier.FindNotificationById(kKey7));
// Test the type conversion and construction functions.
for (SyncDataList::const_iterator iter = initial_data.begin();
@@ -659,14 +354,14 @@ TEST_F(ChromeNotifierServiceTest, LocalRemoteBothNonEmptyNoOverlap) {
// TODO(petewil): Revisit this when we add version info to notifications.
const std::string& key = notification1->GetKey();
const SyncedNotification* notification2 =
- notifier.FindNotificationByKey(key);
+ notifier.FindNotificationById(key);
EXPECT_TRUE(NULL != notification2);
EXPECT_TRUE(notification1->EqualsIgnoringReadState(*notification2));
EXPECT_EQ(notification1->GetReadState(), notification2->GetReadState());
}
- EXPECT_TRUE(notifier.FindNotificationByKey(kKey1));
- EXPECT_TRUE(notifier.FindNotificationByKey(kKey2));
- EXPECT_TRUE(notifier.FindNotificationByKey(kKey3));
+ EXPECT_TRUE(notifier.FindNotificationById(kKey1));
+ EXPECT_TRUE(notifier.FindNotificationById(kKey2));
+ EXPECT_TRUE(notifier.FindNotificationById(kKey3));
}
// Test the local store having the read bit unset, the remote store having
@@ -699,11 +394,11 @@ TEST_F(ChromeNotifierServiceTest, ModelAssocBothNonEmptyReadMismatch1) {
// state of the first is now read.
EXPECT_EQ(2U, notifier.GetAllSyncData(syncer::SYNCED_NOTIFICATIONS).size());
SyncedNotification* notification1 =
- notifier.FindNotificationByKey(kKey1);
+ notifier.FindNotificationById(kKey1);
EXPECT_FALSE(NULL == notification1);
EXPECT_EQ(SyncedNotification::kDismissed, notification1->GetReadState());
- EXPECT_TRUE(notifier.FindNotificationByKey(kKey2));
- EXPECT_FALSE(notifier.FindNotificationByKey(kKey3));
+ EXPECT_TRUE(notifier.FindNotificationById(kKey2));
+ EXPECT_FALSE(notifier.FindNotificationById(kKey3));
// Make sure that the notification manager was told to dismiss the
// notification.
@@ -744,11 +439,11 @@ TEST_F(ChromeNotifierServiceTest, ModelAssocBothNonEmptyReadMismatch2) {
// state of the first is now read.
EXPECT_EQ(2U, notifier.GetAllSyncData(syncer::SYNCED_NOTIFICATIONS).size());
SyncedNotification* notification1 =
- notifier.FindNotificationByKey(kKey1);
+ notifier.FindNotificationById(kKey1);
EXPECT_FALSE(NULL == notification1);
EXPECT_EQ(SyncedNotification::kDismissed, notification1->GetReadState());
- EXPECT_TRUE(notifier.FindNotificationByKey(kKey2));
- EXPECT_FALSE(notifier.FindNotificationByKey(kKey3));
+ EXPECT_TRUE(notifier.FindNotificationById(kKey2));
+ EXPECT_FALSE(notifier.FindNotificationById(kKey3));
// Ensure the new data will be sent to the remote store for notification1.
EXPECT_EQ(1U, processor()->change_list_size());
@@ -782,11 +477,11 @@ TEST_F(ChromeNotifierServiceTest, ModelAssocBothNonEmptyWithUpdate) {
// Ensure the local store still has only one notification
EXPECT_EQ(1U, notifier.GetAllSyncData(syncer::SYNCED_NOTIFICATIONS).size());
SyncedNotification* notification1 =
- notifier.FindNotificationByKey(kKey1);
+ notifier.FindNotificationById(kKey1);
EXPECT_FALSE(NULL == notification1);
EXPECT_EQ(SyncedNotification::kUnread, notification1->GetReadState());
- EXPECT_EQ(kTitle2, notification1->GetTitle());
+ EXPECT_EQ(std::string(kTitle2), notification1->GetTitle());
// Ensure no new data will be sent to the remote store for notification1.
EXPECT_EQ(0U, processor()->change_list_size());