summaryrefslogtreecommitdiffstats
path: root/chrome/browser/notifications/sync_notifier
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/notifications/sync_notifier')
-rw-r--r--chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.cc52
-rw-r--r--chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.h12
-rw-r--r--chrome/browser/notifications/sync_notifier/chrome_notifier_delegate_browsertest.cc160
-rw-r--r--chrome/browser/notifications/sync_notifier/chrome_notifier_service.cc11
-rw-r--r--chrome/browser/notifications/sync_notifier/chrome_notifier_service.h11
-rw-r--r--chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc345
-rw-r--r--chrome/browser/notifications/sync_notifier/sync_notifier_test_utils.cc198
-rw-r--r--chrome/browser/notifications/sync_notifier/sync_notifier_test_utils.h97
-rw-r--r--chrome/browser/notifications/sync_notifier/synced_notification.cc171
-rw-r--r--chrome/browser/notifications/sync_notifier/synced_notification.h20
-rw-r--r--chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc334
11 files changed, 647 insertions, 764 deletions
diff --git a/chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.cc b/chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.cc
index f61714e..794cb5f 100644
--- a/chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.cc
+++ b/chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.cc
@@ -5,25 +5,67 @@
#include "chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.h"
#include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h"
+#include "chrome/browser/notifications/sync_notifier/synced_notification.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_finder.h"
+#include "content/public/browser/page_navigator.h"
namespace notifier {
-ChromeNotifierDelegate::ChromeNotifierDelegate(const std::string& id,
- ChromeNotifierService* notifier)
- : id_(id), chrome_notifier_(notifier) {}
+ChromeNotifierDelegate::ChromeNotifierDelegate(
+ const std::string& notification_id,
+ ChromeNotifierService* notifier)
+ : notification_id_(notification_id), chrome_notifier_(notifier) {}
ChromeNotifierDelegate::~ChromeNotifierDelegate() {}
std::string ChromeNotifierDelegate::id() const {
- return id_;
+ return notification_id_;
}
content::RenderViewHost* ChromeNotifierDelegate::GetRenderViewHost() const {
return NULL;
}
+// TODO(petewil) Add the ability to do URL actions also.
+void ChromeNotifierDelegate::Click() {
+ SyncedNotification* notification =
+ chrome_notifier_->FindNotificationById(notification_id_);
+ if (notification == NULL)
+ return;
+
+ GURL destination = notification->GetDefaultDestinationUrl();
+ NavigateToUrl(destination);
+}
+
+// TODO(petewil) Add the ability to do URL actions also.
+void ChromeNotifierDelegate::ButtonClick(int button_index) {
+ SyncedNotification* notification =
+ chrome_notifier_->FindNotificationById(notification_id_);
+ if (notification) {
+ GURL destination = notification->GetButtonUrl(button_index);
+ NavigateToUrl(destination);
+ }
+}
+
+void ChromeNotifierDelegate::NavigateToUrl(const GURL& destination) const {
+ if (!destination.is_valid())
+ return;
+
+ content::OpenURLParams openParams(destination, content::Referrer(),
+ NEW_FOREGROUND_TAB,
+ content::PAGE_TRANSITION_LINK, false);
+ Browser* browser = chrome::FindLastActiveWithProfile(
+ chrome_notifier_->profile(),
+ chrome::GetActiveDesktop());
+ // Navigate to the URL in a new tab.
+ if (browser != NULL)
+ browser->OpenURL(openParams);
+
+}
+
void ChromeNotifierDelegate::Close(bool by_user) {
if (by_user)
- chrome_notifier_->MarkNotificationAsDismissed(id_);
+ chrome_notifier_->MarkNotificationAsDismissed(notification_id_);
}
} // namespace notifier
diff --git a/chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.h b/chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.h
index ad462b8..79e1554 100644
--- a/chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.h
+++ b/chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.h
@@ -8,6 +8,7 @@
#include <string>
#include "chrome/browser/notifications/notification_delegate.h"
+#include "googleurl/src/gurl.h"
namespace notifier {
@@ -19,21 +20,26 @@ class ChromeNotifierService;
class ChromeNotifierDelegate : public NotificationDelegate {
public:
- explicit ChromeNotifierDelegate(const std::string& id,
+ // We use an id instead of a notification so we can check to see if the
+ // notification still exists before acting on it instead of using a ref count.
+ explicit ChromeNotifierDelegate(const std::string& notification_id,
ChromeNotifierService* notifier);
// NotificationDelegate interface.
virtual void Display() OVERRIDE {}
virtual void Error() OVERRIDE {}
virtual void Close(bool by_user) OVERRIDE;
- virtual void Click() OVERRIDE {}
+ virtual void Click() OVERRIDE;
+ virtual void ButtonClick(int button_index) OVERRIDE;
virtual std::string id() const OVERRIDE;
+
virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE;
private:
virtual ~ChromeNotifierDelegate();
+ void NavigateToUrl(const GURL& destination) const;
- const std::string id_;
+ const std::string notification_id_;
ChromeNotifierService* const chrome_notifier_;
DISALLOW_COPY_AND_ASSIGN(ChromeNotifierDelegate);
diff --git a/chrome/browser/notifications/sync_notifier/chrome_notifier_delegate_browsertest.cc b/chrome/browser/notifications/sync_notifier/chrome_notifier_delegate_browsertest.cc
new file mode 100644
index 0000000..753b1fcb
--- /dev/null
+++ b/chrome/browser/notifications/sync_notifier/chrome_notifier_delegate_browsertest.cc
@@ -0,0 +1,160 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.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_manager.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "content/public/browser/navigation_controller.h"
+#include "content/public/browser/navigation_entry.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "content/public/test/test_utils.h"
+#include "sync/api/sync_change.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/message_center/notification_types.h"
+
+namespace {
+const char kTestNotificationId[] = "SomeRandomNotificationId";
+const int kNotificationPriority = static_cast<int>(
+ message_center::LOW_PRIORITY);
+} // namespace
+
+class StubChromeNotifierService : public notifier::ChromeNotifierService {
+ public:
+ StubChromeNotifierService()
+ : ChromeNotifierService(ProfileManager::GetDefaultProfile(), NULL) {}
+
+ virtual ~StubChromeNotifierService() {}
+
+ virtual void MarkNotificationAsDismissed(const std::string& id) OVERRIDE {
+ dismissed_id_ = id;
+ }
+
+ notifier::SyncedNotification* CreateNotification(
+ 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,
+ sync_pb::CoalescedSyncedNotification_ReadState read_state) {
+ syncer::SyncData sync_data = CreateSyncData(title, text, app_icon_url,
+ image_url,app_id, key,
+ read_state);
+ // Set enough fields in sync_data, including specifics, for our tests
+ // to pass.
+ return new notifier::SyncedNotification(sync_data);
+ }
+
+ // For testing, just return our test notification no matter what key the
+ // caller sends.
+ virtual notifier::SyncedNotification* FindNotificationById(
+ const std::string& id) OVERRIDE {
+ return CreateNotification(
+ kTitle1, kText1, kIconUrl1, kImageUrl1, kAppId1, kKey1, kUnread);
+ }
+
+ const std::string& dismissed_id() { return dismissed_id_; }
+
+ private:
+ std::string dismissed_id_;
+};
+
+class ChromeNotifierDelegateBrowserTest : public InProcessBrowserTest {};
+
+// Test will not have access to the browser profile on linux aura
+#if defined(OS_LINUX) && defined(USE_AURA)
+#define MAYBE_ClickTest \
+ DISABLED_ClickTest
+#else
+#define MAYBE_ClickTest \
+ ClickTest
+#endif
+
+IN_PROC_BROWSER_TEST_F(ChromeNotifierDelegateBrowserTest, MAYBE_ClickTest) {
+ std::string id(kTestNotificationId);
+ StubChromeNotifierService notifier;
+ notifier::ChromeNotifierDelegate* delegate =
+ new notifier::ChromeNotifierDelegate(id, &notifier);
+
+ // Set up an observer to wait for the navigation
+ content::WindowedNotificationObserver observer(
+ chrome::NOTIFICATION_TAB_ADDED,
+ content::NotificationService::AllSources());
+
+ delegate->Click();
+
+ // Wait for navigation to finish.
+ observer.Wait();
+
+ // Verify the navigation happened as expected - we should be on chrome://flags
+ GURL url(kDefaultDestinationUrl);
+ content::WebContents* tab =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ ASSERT_EQ(url, tab->GetController().GetActiveEntry()->GetVirtualURL());
+}
+
+// Test will not have access to the browser profile on linux aura.
+#if defined(OS_LINUX) && defined(USE_AURA)
+#define MAYBE_ButtonClickTest \
+ DISABLED_ButtonClickTest
+#else
+#define MAYBE_ButtonClickTest \
+ ButtonClickTest
+#endif
+
+IN_PROC_BROWSER_TEST_F(ChromeNotifierDelegateBrowserTest,
+ MAYBE_ButtonClickTest) {
+ std::string id(kTestNotificationId);
+ StubChromeNotifierService notifier;
+ notifier::ChromeNotifierDelegate* delegate =
+ new notifier::ChromeNotifierDelegate(id, &notifier);
+
+ // Set up an observer to wait for the navigation
+ content::WindowedNotificationObserver observer(
+ chrome::NOTIFICATION_TAB_ADDED,
+ content::NotificationService::AllSources());
+
+ delegate->ButtonClick(0);
+
+ // Wait for navigation to finish.
+ observer.Wait();
+
+ // Verify the navigation happened as expected - we should be on chrome://sync
+ content::WebContents* tab;
+ GURL url1(kButtonOneUrl);
+ tab = browser()->tab_strip_model()->GetActiveWebContents();
+ ASSERT_EQ(url1, tab->GetController().GetActiveEntry()->GetVirtualURL());
+
+
+ delegate->ButtonClick(1);
+
+ // Wait for navigation to finish.
+ observer.Wait();
+
+ // Verify the navigation happened as expected - we should be on chrome://sync
+ GURL url2(kButtonTwoUrl);
+ tab = browser()->tab_strip_model()->GetActiveWebContents();
+ ASSERT_EQ(url2, tab->GetController().GetActiveEntry()->GetVirtualURL());
+}
+
+IN_PROC_BROWSER_TEST_F(ChromeNotifierDelegateBrowserTest, CloseTest) {
+ std::string id(kTestNotificationId);
+ StubChromeNotifierService notifier;
+ notifier::ChromeNotifierDelegate* delegate =
+ new notifier::ChromeNotifierDelegate(id, &notifier);
+
+ delegate->Close(false);
+ ASSERT_EQ("", notifier.dismissed_id());
+
+ delegate->Close(true);
+ ASSERT_EQ(kTestNotificationId, notifier.dismissed_id());
+}
diff --git a/chrome/browser/notifications/sync_notifier/chrome_notifier_service.cc b/chrome/browser/notifications/sync_notifier/chrome_notifier_service.cc
index c97d37d..c533c17 100644
--- a/chrome/browser/notifications/sync_notifier/chrome_notifier_service.cc
+++ b/chrome/browser/notifications/sync_notifier/chrome_notifier_service.cc
@@ -13,6 +13,7 @@
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/profiles/profile.h"
+#include "googleurl/src/gurl.h"
#include "grit/ui_strings.h"
#include "sync/api/sync_change.h"
#include "sync/api/sync_change_processor.h"
@@ -76,7 +77,7 @@ syncer::SyncMergeResult ChromeNotifierService::MergeDataAndStartSyncing(
// Process each incoming remote notification.
const std::string& key = incoming->GetKey();
DCHECK_GT(key.length(), 0U);
- SyncedNotification* found = FindNotificationByKey(key);
+ SyncedNotification* found = FindNotificationById(key);
if (NULL == found) {
// If there are no conflicts, copy in the data from remote.
@@ -248,8 +249,8 @@ scoped_ptr<SyncedNotification>
// This returns a pointer into a vector that we own. Caller must not free it.
// Returns NULL if no match is found.
-SyncedNotification* ChromeNotifierService::FindNotificationByKey(
- const std::string& key) {
+SyncedNotification* ChromeNotifierService::FindNotificationById(
+ const std::string& notification_id) {
// TODO(petewil): We can make a performance trade off here.
// While the vector has good locality of reference, a map has faster lookup.
// Based on how big we expect this to get, maybe change this to a map.
@@ -258,7 +259,7 @@ SyncedNotification* ChromeNotifierService::FindNotificationByKey(
it != notification_data_.end();
++it) {
SyncedNotification* notification = *it;
- if (key == notification->GetKey())
+ if (notification_id == notification->GetKey())
return *it;
}
@@ -288,7 +289,7 @@ void ChromeNotifierService::GetSyncedNotificationServices(
void ChromeNotifierService::MarkNotificationAsDismissed(
const std::string& key) {
- SyncedNotification* notification = FindNotificationByKey(key);
+ SyncedNotification* notification = FindNotificationById(key);
CHECK(notification != NULL);
notification->NotificationHasBeenDismissed();
diff --git a/chrome/browser/notifications/sync_notifier/chrome_notifier_service.h b/chrome/browser/notifications/sync_notifier/chrome_notifier_service.h
index 52fd6bf..b423703 100644
--- a/chrome/browser/notifications/sync_notifier/chrome_notifier_service.h
+++ b/chrome/browser/notifications/sync_notifier/chrome_notifier_service.h
@@ -57,22 +57,25 @@ class ChromeNotifierService : public syncer::SyncableService,
const syncer::SyncData& sync_data);
// Get a pointer to a notification. ChromeNotifierService owns this pointer.
- // The caller must not free it.
- notifier::SyncedNotification* FindNotificationByKey(const std::string& key);
+ virtual notifier::SyncedNotification* FindNotificationById(
+ const std::string& notification_id);
// Get the list of synced notification services and fill their meta data to
// |notifiers|.
void GetSyncedNotificationServices(
std::vector<message_center::Notifier*>* notifiers);
- // Called when we dismiss a notification.
- void MarkNotificationAsDismissed(const std::string& id);
+ // Called when we dismiss a notification. This is virtual so that test
+ // subclasses can override it.
+ virtual void MarkNotificationAsDismissed(const std::string& id);
// Called when a notier is enabled or disabled.
void OnSyncedNotificationServiceEnabled(
const std::string& notifier_id,
bool enabled);
+ Profile* profile() const { return profile_; }
+
// Functions for test.
void AddForTest(scoped_ptr<notifier::SyncedNotification> notification);
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());
diff --git a/chrome/browser/notifications/sync_notifier/sync_notifier_test_utils.cc b/chrome/browser/notifications/sync_notifier/sync_notifier_test_utils.cc
new file mode 100644
index 0000000..e560baf
--- /dev/null
+++ b/chrome/browser/notifications/sync_notifier/sync_notifier_test_utils.cc
@@ -0,0 +1,198 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/notifications/sync_notifier/sync_notifier_test_utils.h"
+
+// Fake data for creating a SyncData object to use in creating a
+// SyncedNotification.
+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 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 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 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[] = "chrome://flags";
+const char kButtonOneTitle[] = "Read";
+const char kButtonOneIconUrl[] = "http://www.google.com/image8.jpg";
+const char kButtonOneUrl[] = "chrome://sync";
+const char kButtonTwoTitle[] = "Reply";
+const char kButtonTwoIconUrl[] = "http://www.google.com/image9.jpg";
+const char kButtonTwoUrl[] = "chrome://about";
+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.";
+
+syncer::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.
+ sync_pb::EntitySpecifics entity_specifics;
+
+ // Get a writeable pointer to the sync notifications specifics inside the
+ // entity specifics.
+ sync_pb::SyncedNotificationSpecifics* specifics =
+ entity_specifics.mutable_synced_notification();
+
+ // Get pointers to sub structures.
+ sync_pb::CoalescedSyncedNotification* coalesced_notification =
+ specifics->mutable_coalesced_notification();
+ sync_pb::SyncedNotificationRenderInfo* render_info =
+ coalesced_notification->mutable_render_info();
+ sync_pb::ExpandedInfo* expanded_info =
+ render_info->mutable_expanded_info();
+ sync_pb::SimpleExpandedLayout* simple_expanded_layout =
+ expanded_info->mutable_simple_expanded_layout();
+ sync_pb::CollapsedInfo* collapsed_info =
+ render_info->mutable_collapsed_info();
+ sync_pb::SimpleCollapsedLayout* simple_collapsed_layout =
+ collapsed_info->mutable_simple_collapsed_layout();
+ sync_pb::SyncedNotificationDestination* default_destination =
+ collapsed_info->mutable_default_destination();
+
+ coalesced_notification->set_app_id(app_id);
+
+ coalesced_notification->set_key(key);
+
+ coalesced_notification->
+ set_priority(static_cast<sync_pb::CoalescedSyncedNotification_Priority>(
+ kProtobufPriority));
+
+ // Set the title.
+ simple_expanded_layout->set_title(title);
+
+ // Set the text.
+ simple_expanded_layout->set_text(text);
+
+ // Set the heading.
+ simple_collapsed_layout->set_heading(title);
+
+ // Add the collapsed info and set the app_icon_url on it.
+ expanded_info->add_collapsed_info();
+ 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.
+ simple_expanded_layout->add_media();
+ simple_expanded_layout->
+ mutable_media(0)->
+ mutable_image()->
+ set_url(image_url);
+
+ coalesced_notification->set_creation_time_msec(kFakeCreationTime);
+
+ 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.
+ sync_pb::SimpleCollapsedLayout* notification_layout1 =
+ expanded_info->
+ mutable_collapsed_info(0)->
+ mutable_simple_collapsed_layout();
+ notification_layout1->set_heading(kContainedTitle1);
+ notification_layout1->set_description(kContainedMessage1);
+
+ // Contained notification two.
+ expanded_info->add_collapsed_info();
+ sync_pb::SimpleCollapsedLayout* notification_layout2 =
+ expanded_info->
+ mutable_collapsed_info(1)->
+ mutable_simple_collapsed_layout();
+ notification_layout2->set_heading(kContainedTitle2);
+ notification_layout2->set_description(kContainedMessage2);
+
+ // Contained notification three.
+ expanded_info->add_collapsed_info();
+ sync_pb::SimpleCollapsedLayout* notification_layout3 =
+ expanded_info->
+ mutable_collapsed_info(2)->
+ mutable_simple_collapsed_layout();
+ notification_layout3->set_heading(kContainedTitle3);
+ notification_layout3->set_description(kContainedMessage3);
+
+ // Default Destination.
+ default_destination->set_text(kDefaultDestinationTitle);
+ default_destination->mutable_icon()->set_url(kDefaultDestinationIconUrl);
+ default_destination->mutable_icon()->set_alt_text(kDefaultDestinationTitle);
+ default_destination->set_url(kDefaultDestinationUrl);
+
+ // Buttons are represented as targets.
+
+ // Button One.
+ collapsed_info->add_target();
+ sync_pb::SyncedNotificationAction* action1 =
+ collapsed_info->mutable_target(0)->mutable_action();
+ action1->set_text(kButtonOneTitle);
+ action1->mutable_icon()->set_url(kButtonOneIconUrl);
+ action1->mutable_icon()->set_alt_text(kButtonOneTitle);
+ action1->set_url(kButtonOneUrl);
+
+ // Button Two.
+ collapsed_info->add_target();
+ sync_pb::SyncedNotificationAction* action2 =
+ collapsed_info->mutable_target(1)->mutable_action();
+ action2->set_text(kButtonOneTitle);
+ action2->mutable_icon()->set_url(kButtonTwoIconUrl);
+ action2->mutable_icon()->set_alt_text(kButtonTwoTitle);
+ action2->set_url(kButtonTwoUrl);
+
+ syncer::SyncData sync_data = syncer::SyncData::CreateLocalData(
+ "syncer::SYNCED_NOTIFICATIONS",
+ "ChromeNotifierServiceUnitTest",
+ entity_specifics);
+
+ return sync_data;
+}
diff --git a/chrome/browser/notifications/sync_notifier/sync_notifier_test_utils.h b/chrome/browser/notifications/sync_notifier/sync_notifier_test_utils.h
new file mode 100644
index 0000000..be33257
--- /dev/null
+++ b/chrome/browser/notifications/sync_notifier/sync_notifier_test_utils.h
@@ -0,0 +1,97 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_SYNC_NOTIFIER_TEST_UTILS_H_
+#define CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_SYNC_NOTIFIER_TEST_UTILS_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "sync/api/sync_data.h"
+#include "sync/protocol/sync.pb.h"
+#include "sync/protocol/synced_notification_specifics.pb.h"
+
+
+// Fake data for creating a SyncedNotification.
+extern const char kAppId1[];
+extern const char kAppId2[];
+extern const char kAppId3[];
+extern const char kAppId4[];
+extern const char kAppId5[];
+extern const char kAppId6[];
+extern const char kAppId7[];
+extern const char kKey1[];
+extern const char kKey2[];
+extern const char kKey3[];
+extern const char kKey4[];
+extern const char kKey5[];
+extern const char kKey6[];
+extern const char kKey7[];
+extern const char kIconUrl1[];
+extern const char kIconUrl2[];
+extern const char kIconUrl3[];
+extern const char kIconUrl4[];
+extern const char kIconUrl5[];
+extern const char kIconUrl6[];
+extern const char kIconUrl7[];
+extern const char kTitle1[];
+extern const char kTitle2[];
+extern const char kTitle3[];
+extern const char kTitle4[];
+extern const char kTitle5[];
+extern const char kTitle6[];
+extern const char kTitle7[];
+extern const char kText1[];
+extern const char kText2[];
+extern const char kText3[];
+extern const char kText4[];
+extern const char kText5[];
+extern const char kText6[];
+extern const char kText7[];
+extern const char kImageUrl1[];
+extern const char kImageUrl2[];
+extern const char kImageUrl3[];
+extern const char kImageUrl4[];
+extern const char kImageUrl5[];
+extern const char kImageUrl6[];
+extern const char kImageUrl7[];
+extern const char kExpectedOriginUrl[];
+extern const char kDefaultDestinationTitle[];
+extern const char kDefaultDestinationIconUrl[];
+extern const char kDefaultDestinationUrl[];
+extern const char kButtonOneTitle[];
+extern const char kButtonOneIconUrl[];
+extern const char kButtonOneUrl[];
+extern const char kButtonTwoTitle[];
+extern const char kButtonTwoIconUrl[];
+extern const char kButtonTwoUrl[];
+extern const char kContainedTitle1[];
+extern const char kContainedTitle2[];
+extern const char kContainedTitle3[];
+extern const char kContainedMessage1[];
+extern const char kContainedMessage2[];
+extern const char kContainedMessage3[];
+const uint64 kFakeCreationTime = 42;
+const int kProtobufPriority = static_cast<int>(
+ sync_pb::CoalescedSyncedNotification_Priority_LOW);
+
+const sync_pb::CoalescedSyncedNotification_ReadState kRead =
+ sync_pb::CoalescedSyncedNotification_ReadState_READ;
+const sync_pb::CoalescedSyncedNotification_ReadState kDismissed =
+ sync_pb::CoalescedSyncedNotification_ReadState_DISMISSED;
+const sync_pb::CoalescedSyncedNotification_ReadState kUnread =
+ sync_pb::CoalescedSyncedNotification_ReadState_UNREAD;
+
+// This function builds the sync data object we use to create a testing
+// notification.
+syncer::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);
+
+#endif // CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_SYNC_NOTIFIER_TEST_UTILS_H_
diff --git a/chrome/browser/notifications/sync_notifier/synced_notification.cc b/chrome/browser/notifications/sync_notifier/synced_notification.cc
index 43eafd9..851c5d6 100644
--- a/chrome/browser/notifications/sync_notifier/synced_notification.cc
+++ b/chrome/browser/notifications/sync_notifier/synced_notification.cc
@@ -22,6 +22,10 @@
namespace {
const char kExtensionScheme[] = "chrome-extension://";
+// Today rich notifications only supports two buttons, make sure we don't
+// try to supply them with more than this number of buttons.
+const unsigned int kMaxNotificationButtonIndex = 2;
+
bool UseRichNotifications() {
return message_center::IsRichNotificationEnabled();
}
@@ -79,11 +83,11 @@ void SyncedNotification::OnFetchComplete(const GURL url,
if (GetImageUrl() == url && bitmap != NULL) {
image_bitmap_ = gfx::Image::CreateFrom1xBitmap(*bitmap);
}
- if (GetButtonOneIconUrl() == url.spec() && bitmap != NULL) {
- button_one_bitmap_ = gfx::Image::CreateFrom1xBitmap(*bitmap);
- }
- if (GetButtonTwoIconUrl() == url.spec() && bitmap != NULL) {
- button_two_bitmap_ = gfx::Image::CreateFrom1xBitmap(*bitmap);
+
+ // If this URL matches one or more button bitmaps, save them off.
+ for (unsigned int i = 0; i < GetButtonCount(); ++i) {
+ if (GetButtonIconUrl(i) == url && bitmap != NULL)
+ button_bitmaps_[i] = gfx::Image::CreateFrom1xBitmap(*bitmap);
}
// Count off the bitmaps as they arrive.
@@ -112,17 +116,16 @@ void SyncedNotification::QueueBitmapFetchJobs(
profile_ = profile;
DCHECK_EQ(active_fetcher_count_, 0);
- // Get the URLs that we might need to fetch from Synced Notification.
- // TODO(petewil): Clean up the fact that icon and image return a GURL, and
- // button urls return a string.
- // TODO(petewil): Eventually refactor this to accept an arbitrary number of
- // button URLs.
+ // Ensure our bitmap vector has as many entries as there are buttons,
+ // so that when the bitmaps arrive the vector has a slot for them.
+ for (unsigned int i = 0; i < GetButtonCount(); ++i) {
+ button_bitmaps_.push_back(gfx::Image());
+ AddBitmapToFetchQueue(GetButtonIconUrl(i));
+ }
// If the URL is non-empty, add it to our queue of URLs to fetch.
AddBitmapToFetchQueue(GetAppIconUrl());
AddBitmapToFetchQueue(GetImageUrl());
- AddBitmapToFetchQueue(GURL(GetButtonOneIconUrl()));
- AddBitmapToFetchQueue(GURL(GetButtonTwoIconUrl()));
// If there are no bitmaps, call show now.
if (active_fetcher_count_ == 0) {
@@ -155,7 +158,6 @@ void SyncedNotification::AddBitmapToFetchQueue(const GURL& url) {
void SyncedNotification::Show(NotificationUIManager* notification_manager,
ChromeNotifierService* notifier_service,
Profile* profile) {
-
// Let NotificationUIManager know that the notification has been dismissed.
if (SyncedNotification::kRead == GetReadState() ||
SyncedNotification::kDismissed == GetReadState() ) {
@@ -184,10 +186,7 @@ void SyncedNotification::Show(NotificationUIManager* notification_manager,
base::Time::FromDoubleT(static_cast<double>(GetCreationTime()));
int priority = GetPriority();
int notification_count = GetNotificationCount();
- int button_count = GetButtonCount();
- // TODO(petewil): Refactor this for an arbitrary number of buttons.
- std::string button_one_title = GetButtonOneTitle();
- std::string button_two_title = GetButtonTwoTitle();
+ unsigned int button_count = GetButtonCount();
// Deduce which notification template to use from the data.
message_center::NotificationType notification_type =
@@ -206,16 +205,23 @@ void SyncedNotification::Show(NotificationUIManager* notification_manager,
rich_notification_data.timestamp = creation_time;
if (priority != SyncedNotification::kUndefinedPriority)
rich_notification_data.priority = priority;
- if (!button_one_title.empty()) {
- message_center::ButtonInfo button_info(UTF8ToUTF16(button_one_title));
- if (!button_one_bitmap_.IsEmpty())
- button_info.icon = button_one_bitmap_;
- rich_notification_data.buttons.push_back(button_info);
- }
- if (!button_two_title.empty()) {
- message_center::ButtonInfo button_info(UTF8ToUTF16(button_two_title));
- if (!button_two_bitmap_.IsEmpty())
- button_info.icon = button_two_bitmap_;
+
+ // Fill in the button data.
+ // TODO(petewil): Today Rich notifiations are limited to two buttons.
+ // When rich notifications supports more, remove the
+ // "&& i < kMaxNotificationButtonIndex" below.
+ for (unsigned int i = 0;
+ i < button_count
+ && i < button_bitmaps_.size()
+ && i < kMaxNotificationButtonIndex;
+ ++i) {
+ // Stop at the first button with no title
+ std::string title = GetButtonTitle(i);
+ if (title.empty())
+ break;
+ message_center::ButtonInfo button_info(UTF8ToUTF16(title));
+ if (!button_bitmaps_[i].IsEmpty())
+ button_info.icon = button_bitmaps_[i];
rich_notification_data.buttons.push_back(button_info);
}
@@ -284,27 +290,29 @@ bool SyncedNotification::EqualsIgnoringReadState(
GetPriority() == other.GetPriority() &&
GetDefaultDestinationTitle() == other.GetDefaultDestinationTitle() &&
GetDefaultDestinationIconUrl() == other.GetDefaultDestinationIconUrl() &&
- GetButtonOneTitle() == other.GetButtonOneTitle() &&
- GetButtonOneIconUrl() == other.GetButtonOneIconUrl() &&
- GetButtonTwoTitle() == other.GetButtonTwoTitle() &&
- GetButtonTwoIconUrl() == other.GetButtonTwoIconUrl() &&
GetNotificationCount() == other.GetNotificationCount() &&
GetButtonCount() == other.GetButtonCount()) {
+
// If all the surface data matched, check, to see if contained data also
- // matches.
+ // matches, titles and messages.
size_t count = GetNotificationCount();
for (size_t ii = 0; ii < count; ++ii) {
- // Check the contained titles match
if (GetContainedNotificationTitle(ii) !=
other.GetContainedNotificationTitle(ii))
return false;
- // Check the contained messages match
if (GetContainedNotificationMessage(ii) !=
other.GetContainedNotificationMessage(ii))
return false;
}
- // TODO(petewil): When I make buttons into a vector, check them here too.
+ // Make sure buttons match.
+ count = GetButtonCount();
+ for (size_t jj = 0; jj < count; ++jj) {
+ if (GetButtonTitle(jj) != other.GetButtonTitle(jj))
+ return false;
+ if (GetButtonIconUrl(jj) != other.GetButtonIconUrl(jj))
+ return false;
+ }
// If buttons and notifications matched, they are equivalent.
return true;
@@ -473,12 +481,12 @@ int SyncedNotification::GetPriority() const {
}
}
-int SyncedNotification::GetNotificationCount() const {
+size_t SyncedNotification::GetNotificationCount() const {
return specifics_.coalesced_notification().render_info().
expanded_info().collapsed_info_size();
}
-int SyncedNotification::GetButtonCount() const {
+size_t SyncedNotification::GetButtonCount() const {
return specifics_.coalesced_notification().render_info().collapsed_info().
target_size();
}
@@ -492,94 +500,59 @@ std::string SyncedNotification::GetDefaultDestinationTitle() const {
default_destination().icon().alt_text();
}
-std::string SyncedNotification::GetDefaultDestinationIconUrl() const {
+GURL SyncedNotification::GetDefaultDestinationIconUrl() const {
if (!specifics_.coalesced_notification().render_info().collapsed_info().
default_destination().icon().has_url()) {
- return std::string();
+ return GURL();
}
- return specifics_.coalesced_notification().render_info().collapsed_info().
- default_destination().icon().url();
+ return GURL(specifics_.coalesced_notification().render_info().
+ collapsed_info().default_destination().icon().url());
}
-std::string SyncedNotification::GetDefaultDestinationUrl() const {
+GURL SyncedNotification::GetDefaultDestinationUrl() const {
if (!specifics_.coalesced_notification().render_info().collapsed_info().
default_destination().has_url()) {
- return std::string();
- }
- return specifics_.coalesced_notification().render_info().collapsed_info().
- default_destination().url();
-}
-
-std::string SyncedNotification::GetButtonOneTitle() const {
- // Must ensure that we have a target before trying to access it.
- if (GetButtonCount() < 1)
- return std::string();
- if (!specifics_.coalesced_notification().render_info().collapsed_info().
- target(0).action().icon().has_alt_text()) {
- return std::string();
- }
- return specifics_.coalesced_notification().render_info().collapsed_info().
- target(0).action().icon().alt_text();
-}
-
-std::string SyncedNotification::GetButtonOneIconUrl() const {
- // Must ensure that we have a target before trying to access it.
- if (GetButtonCount() < 1)
- return std::string();
- if (!specifics_.coalesced_notification().render_info().collapsed_info().
- target(0).action().icon().has_url()) {
- return std::string();
- }
- return specifics_.coalesced_notification().render_info().collapsed_info().
- target(0).action().icon().url();
-}
-
-std::string SyncedNotification::GetButtonOneUrl() const {
- // Must ensure that we have a target before trying to access it.
- if (GetButtonCount() < 1)
- return std::string();
- if (!specifics_.coalesced_notification().render_info().collapsed_info().
- target(0).action().has_url()) {
- return std::string();
+ return GURL();
}
- return specifics_.coalesced_notification().render_info().collapsed_info().
- target(0).action().url();
+ return GURL(specifics_.coalesced_notification().render_info().
+ collapsed_info().default_destination().url());
}
-std::string SyncedNotification::GetButtonTwoTitle() const {
+std::string SyncedNotification::GetButtonTitle(
+ unsigned int which_button) const {
// Must ensure that we have a target before trying to access it.
- if (GetButtonCount() < 2)
+ if (GetButtonCount() <= which_button)
return std::string();
if (!specifics_.coalesced_notification().render_info().collapsed_info().
- target(1).action().icon().has_alt_text()) {
+ target(which_button).action().icon().has_alt_text()) {
return std::string();
}
return specifics_.coalesced_notification().render_info().collapsed_info().
- target(1).action().icon().alt_text();
+ target(which_button).action().icon().alt_text();
}
-std::string SyncedNotification::GetButtonTwoIconUrl() const {
+GURL SyncedNotification::GetButtonIconUrl(unsigned int which_button) const {
// Must ensure that we have a target before trying to access it.
- if (GetButtonCount() < 2)
- return std::string();
+ if (GetButtonCount() <= which_button)
+ return GURL();
if (!specifics_.coalesced_notification().render_info().collapsed_info().
- target(1).action().icon().has_url()) {
- return std::string();
+ target(which_button).action().icon().has_url()) {
+ return GURL();
}
- return specifics_.coalesced_notification().render_info().collapsed_info().
- target(1).action().icon().url();
+ return GURL(specifics_.coalesced_notification().render_info().
+ collapsed_info().target(which_button).action().icon().url());
}
-std::string SyncedNotification::GetButtonTwoUrl() const {
+GURL SyncedNotification::GetButtonUrl(unsigned int which_button) const {
// Must ensure that we have a target before trying to access it.
- if (GetButtonCount() < 2)
- return std::string();
+ if (GetButtonCount() <= which_button)
+ return GURL();
if (!specifics_.coalesced_notification().render_info().collapsed_info().
- target(1).action().has_url()) {
- return std::string();
+ target(which_button).action().has_url()) {
+ return GURL();
}
- return specifics_.coalesced_notification().render_info().collapsed_info().
- target(1).action().url();
+ return GURL(specifics_.coalesced_notification().render_info().
+ collapsed_info().target(which_button).action().url());
}
std::string SyncedNotification::GetContainedNotificationTitle(
diff --git a/chrome/browser/notifications/sync_notifier/synced_notification.h b/chrome/browser/notifications/sync_notifier/synced_notification.h
index 52f37ee..fd3ee55 100644
--- a/chrome/browser/notifications/sync_notifier/synced_notification.h
+++ b/chrome/browser/notifications/sync_notifier/synced_notification.h
@@ -62,16 +62,13 @@ class SyncedNotification : public NotificationBitmapFetcherDelegate {
uint64 GetCreationTime() const;
int GetPriority() const;
std::string GetDefaultDestinationTitle() const;
- std::string GetDefaultDestinationIconUrl() const;
- std::string GetDefaultDestinationUrl() const;
- std::string GetButtonOneTitle() const;
- std::string GetButtonOneIconUrl() const;
- std::string GetButtonOneUrl() const;
- std::string GetButtonTwoTitle() const;
- std::string GetButtonTwoIconUrl() const;
- std::string GetButtonTwoUrl() const;
- int GetNotificationCount() const;
- int GetButtonCount() const;
+ GURL GetDefaultDestinationIconUrl() const;
+ GURL GetDefaultDestinationUrl() const;
+ std::string GetButtonTitle(unsigned int which_button) const;
+ GURL GetButtonIconUrl(unsigned int which_button) const;
+ GURL GetButtonUrl(unsigned int which_button) const;
+ size_t GetNotificationCount() const;
+ size_t GetButtonCount() const;
std::string GetContainedNotificationTitle(int index) const;
std::string GetContainedNotificationMessage(int index) const;
@@ -116,8 +113,7 @@ class SyncedNotification : public NotificationBitmapFetcherDelegate {
int active_fetcher_count_;
gfx::Image app_icon_bitmap_;
gfx::Image image_bitmap_;
- gfx::Image button_one_bitmap_;
- gfx::Image button_two_bitmap_;
+ std::vector<gfx::Image> button_bitmaps_;
FRIEND_TEST_ALL_PREFIXES(SyncedNotificationTest, AddBitmapToFetchQueueTest);
FRIEND_TEST_ALL_PREFIXES(SyncedNotificationTest, OnFetchCompleteTest);
diff --git a/chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc b/chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc
index 8ee17a5..abb60a26 100644
--- a/chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc
+++ b/chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc
@@ -10,13 +10,11 @@
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/notifications/notification_test_util.h"
#include "chrome/browser/notifications/notification_ui_manager.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 "content/public/browser/browser_thread.h"
#include "content/public/test/test_browser_thread.h"
-#include "sync/api/sync_data.h"
-#include "sync/protocol/sync.pb.h"
-#include "sync/protocol/synced_notification_specifics.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/message_center/message_center_util.h"
@@ -28,9 +26,6 @@ using sync_pb::EntitySpecifics;
using sync_pb::SyncedNotificationSpecifics;
namespace {
-const uint64 kFakeCreationTime = 42;
-const int kProtobufPriority = static_cast<int>(
- sync_pb::CoalescedSyncedNotification_Priority_LOW);
const int kNotificationPriority = static_cast<int>(
message_center::LOW_PRIORITY);
@@ -38,46 +33,6 @@ bool UseRichNotifications() {
return message_center::IsRichNotificationEnabled();
}
-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 kAppId1[] = "fboilmbenheemaomgaeehigklolhkhnf";
-const char kAppId2[] = "fbcmoldooppoahjhfflnmljoanccekpf";
-const char kKey1[] = "foo";
-const char kKey2[] = "bar";
-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 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 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 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/image5.jpg";
-const char kButtonOneUrl[] = "http://www.google.com/do-something1";
-const char kButtonTwoTitle[] = "Reply";
-const char kButtonTwoIconUrl[] = "http://www.google.com/image6.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 char kExpectedOriginUrl[] =
- "chrome-extension://fboilmbenheemaomgaeehigklolhkhnf/";
-
-const sync_pb::CoalescedSyncedNotification_ReadState kRead =
- sync_pb::CoalescedSyncedNotification_ReadState_READ;
-const sync_pb::CoalescedSyncedNotification_ReadState kUnread =
- sync_pb::CoalescedSyncedNotification_ReadState_UNREAD;
-const sync_pb::CoalescedSyncedNotification_ReadState kDismissed =
- sync_pb::CoalescedSyncedNotification_ReadState_DISMISSED;
} // namespace
namespace notifier {
@@ -192,246 +147,6 @@ class SyncedNotificationTest : public testing::Test {
syncer::SyncData sync_data4_;
private:
- // 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",
- "SyncedNotificationTest",
- entity_specifics);
-
- return sync_data;
- }
-
- private:
base::MessageLoopForIO message_loop_;
content::TestBrowserThread ui_thread_;
@@ -485,8 +200,8 @@ TEST_F(SyncedNotificationTest, GetReadStateTest) {
// TODO(petewil): Improve ctor to pass in an image and type so this test can
// pass on actual data.
TEST_F(SyncedNotificationTest, GetImageURLTest) {
- std::string found_image_url = notification1_->GetImageUrl().spec();
- std::string expected_image_url = kImageUrl1;
+ GURL found_image_url = notification1_->GetImageUrl();
+ GURL expected_image_url = GURL(kImageUrl1);
EXPECT_EQ(expected_image_url, found_image_url);
}
@@ -522,29 +237,29 @@ TEST_F(SyncedNotificationTest, GetNotificationCountTest) {
TEST_F(SyncedNotificationTest, GetDefaultDestinationDataTest) {
std::string default_destination_title =
notification1_->GetDefaultDestinationTitle();
- std::string default_destination_icon_url =
+ GURL default_destination_icon_url =
notification1_->GetDefaultDestinationIconUrl();
- std::string default_destination_url =
+ GURL default_destination_url =
notification1_->GetDefaultDestinationUrl();
EXPECT_EQ(std::string(kDefaultDestinationTitle), default_destination_title);
- EXPECT_EQ(std::string(kDefaultDestinationIconUrl),
+ EXPECT_EQ(GURL(kDefaultDestinationIconUrl),
default_destination_icon_url);
- EXPECT_EQ(std::string(kDefaultDestinationUrl), default_destination_url);
+ EXPECT_EQ(GURL(kDefaultDestinationUrl), default_destination_url);
}
TEST_F(SyncedNotificationTest, GetButtonDataTest) {
- std::string button_one_title = notification1_->GetButtonOneTitle();
- std::string button_one_icon_url = notification1_->GetButtonOneIconUrl();
- std::string button_one_url = notification1_->GetButtonOneUrl();
- std::string button_two_title = notification1_->GetButtonTwoTitle();
- std::string button_two_icon_url = notification1_->GetButtonTwoIconUrl();
- std::string button_two_url = notification1_->GetButtonTwoUrl();
+ std::string button_one_title = notification1_->GetButtonTitle(0);
+ GURL button_one_icon_url = notification1_->GetButtonIconUrl(0);
+ GURL button_one_url = notification1_->GetButtonUrl(0);
+ std::string button_two_title = notification1_->GetButtonTitle(1);
+ GURL button_two_icon_url = notification1_->GetButtonIconUrl(1);
+ GURL button_two_url = notification1_->GetButtonUrl(1);
EXPECT_EQ(std::string(kButtonOneTitle), button_one_title);
- EXPECT_EQ(std::string(kButtonOneIconUrl), button_one_icon_url);
- EXPECT_EQ(std::string(kButtonOneUrl), button_one_url);
+ EXPECT_EQ(GURL(kButtonOneIconUrl), button_one_icon_url);
+ EXPECT_EQ(GURL(kButtonOneUrl), button_one_url);
EXPECT_EQ(std::string(kButtonTwoTitle), button_two_title);
- EXPECT_EQ(std::string(kButtonTwoIconUrl), button_two_icon_url);
- EXPECT_EQ(std::string(kButtonTwoUrl), button_two_url);
+ EXPECT_EQ(GURL(kButtonTwoIconUrl), button_two_icon_url);
+ EXPECT_EQ(GURL(kButtonTwoUrl), button_two_url);
}
TEST_F(SyncedNotificationTest, ContainedNotificationTest) {
@@ -603,17 +318,14 @@ TEST_F(SyncedNotificationTest, ShowTest) {
// Check the base fields of the notification.
EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE, notification.type());
- EXPECT_EQ(kTitle1, UTF16ToUTF8(notification.title()));
- EXPECT_EQ(kText1, UTF16ToUTF8(notification.message()));
- EXPECT_EQ(kExpectedOriginUrl, notification.origin_url().spec());
- EXPECT_EQ(kKey1, UTF16ToUTF8(notification.replace_id()));
+ EXPECT_EQ(std::string(kTitle1), UTF16ToUTF8(notification.title()));
+ EXPECT_EQ(std::string(kText1), UTF16ToUTF8(notification.message()));
+ EXPECT_EQ(std::string(kExpectedOriginUrl), notification.origin_url().spec());
+ EXPECT_EQ(std::string(kKey1), UTF16ToUTF8(notification.replace_id()));
EXPECT_EQ(kFakeCreationTime, notification.timestamp().ToDoubleT());
EXPECT_EQ(kNotificationPriority, notification.priority());
- EXPECT_EQ(UTF8ToUTF16(kButtonOneTitle), notification.buttons()[0].title);
- EXPECT_EQ(UTF8ToUTF16(kButtonTwoTitle), notification.buttons()[1].title);
-
EXPECT_EQ(UTF8ToUTF16(kContainedTitle1), notification.items()[0].title);
EXPECT_EQ(UTF8ToUTF16(kContainedTitle2), notification.items()[1].title);
EXPECT_EQ(UTF8ToUTF16(kContainedTitle3), notification.items()[2].title);
@@ -684,9 +396,9 @@ TEST_F(SyncedNotificationTest, OnFetchCompleteTest) {
// Since we check Show() thoroughly in its own test, we only check cursorily.
EXPECT_EQ(message_center::NOTIFICATION_TYPE_IMAGE,
notification_manager.notification().type());
- EXPECT_EQ(kTitle1,
+ EXPECT_EQ(std::string(kTitle1),
UTF16ToUTF8(notification_manager.notification().title()));
- EXPECT_EQ(kText1,
+ EXPECT_EQ(std::string(kText1),
UTF16ToUTF8(notification_manager.notification().message()));
// TODO(petewil): Check that the bitmap in the notification is what we expect.