diff options
author | dewittj@chromium.org <dewittj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-05 06:42:44 +0000 |
---|---|---|
committer | dewittj@chromium.org <dewittj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-05 06:42:44 +0000 |
commit | 1c3db7ab55bd113078a54dceb9d1a0e5ab6a0793 (patch) | |
tree | f5c05e182787cccf5e51d0164be02944cd76a23c /ui/message_center | |
parent | c00cd0453269925c7952d8ee4fa8c02b45b7326b (diff) | |
download | chromium_src-1c3db7ab55bd113078a54dceb9d1a0e5ab6a0793.zip chromium_src-1c3db7ab55bd113078a54dceb9d1a0e5ab6a0793.tar.gz chromium_src-1c3db7ab55bd113078a54dceb9d1a0e5ab6a0793.tar.bz2 |
Enable users of NotificationUIManager to specify binary images.
This refactors message_center::Notification to hold a class
containing the optional data associated with the
notification. It also alters chrome/browser/notification so
that you can manually set this.
Ash tests only updated to use new API.
TBR=sky@chromium.org,stevenjb@chromium.org
BUG=227093
Review URL: https://chromiumcodereview.appspot.com/14631005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204181 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/message_center')
20 files changed, 558 insertions, 436 deletions
diff --git a/ui/message_center/cocoa/notification_controller_unittest.mm b/ui/message_center/cocoa/notification_controller_unittest.mm index 0c70e98..e60093b 100644 --- a/ui/message_center/cocoa/notification_controller_unittest.mm +++ b/ui/message_center/cocoa/notification_controller_unittest.mm @@ -103,6 +103,7 @@ TEST_F(NotificationControllerTest, BasicLayout) { "", ASCIIToUTF16("Added to circles"), ASCIIToUTF16("Jonathan and 5 others"), + gfx::Image(), string16(), std::string(), NULL, @@ -132,6 +133,7 @@ TEST_F(NotificationControllerTest, OverflowText) { ASCIIToUTF16("And even the message is long. This sure is a wordy " "notification. Are you really going to read this " "entire thing?"), + gfx::Image(), string16(), std::string(), NULL, @@ -152,6 +154,7 @@ TEST_F(NotificationControllerTest, Close) { "an_id", string16(), string16(), + gfx::Image(), string16(), std::string(), NULL, @@ -178,6 +181,7 @@ TEST_F(NotificationControllerTest, Update) { ASCIIToUTF16("A simple title"), ASCIIToUTF16("This message isn't too long and should fit in the" "default bounds."), + gfx::Image(), string16(), std::string(), NULL, @@ -211,6 +215,7 @@ TEST_F(NotificationControllerTest, Buttons) { "an_id", string16(), string16(), + gfx::Image(), string16(), std::string(), &buttons, @@ -235,6 +240,7 @@ TEST_F(NotificationControllerTest, Image) { "an_id", string16(), string16(), + gfx::Image(), string16(), std::string(), NULL, @@ -278,6 +284,7 @@ TEST_F(NotificationControllerTest, List) { "an_id", string16(), string16(), + gfx::Image(), string16(), std::string(), &items, diff --git a/ui/message_center/cocoa/popup_collection_unittest.mm b/ui/message_center/cocoa/popup_collection_unittest.mm index ee9f984..324d2a5 100644 --- a/ui/message_center/cocoa/popup_collection_unittest.mm +++ b/ui/message_center/cocoa/popup_collection_unittest.mm @@ -47,36 +47,47 @@ class PopupCollectionTest : public ui::CocoaTest { } void AddThreeNotifications() { - center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, - "1", - ASCIIToUTF16("One"), - ASCIIToUTF16("This is the first notification to" - " be displayed"), - string16(), - std::string(), - NULL, - NULL); - center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, - "2", - ASCIIToUTF16("Two"), - ASCIIToUTF16("This is the second notification."), - string16(), - std::string(), - NULL, - NULL); - center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, - "3", - ASCIIToUTF16("Three"), - ASCIIToUTF16("This is the third notification " - "that has a much longer body " - "than the other notifications. It " - "may not fit on the screen if we " - "set the screen size too small."), - string16(), - std::string(), - NULL, - NULL); - + scoped_ptr<message_center::Notification> notification; + notification.reset(new message_center::Notification( + message_center::NOTIFICATION_TYPE_SIMPLE, + "1", + ASCIIToUTF16("One"), + ASCIIToUTF16("This is the first notification to" + " be displayed"), + gfx::Image(), + string16(), + std::string(), + NULL, + NULL)); + center_->AddNotification(notification.Pass()); + + notification.reset(new message_center::Notification( + message_center::NOTIFICATION_TYPE_SIMPLE, + "2", + ASCIIToUTF16("Two"), + ASCIIToUTF16("This is the second notification."), + gfx::Image(), + string16(), + std::string(), + NULL, + NULL)); + center_->AddNotification(notification.Pass()); + + notification.reset(new message_center::Notification( + message_center::NOTIFICATION_TYPE_SIMPLE, + "3", + ASCIIToUTF16("Three"), + ASCIIToUTF16("This is the third notification " + "that has a much longer body " + "than the other notifications. It " + "may not fit on the screen if we " + "set the screen size too small."), + gfx::Image(), + string16(), + std::string(), + NULL, + NULL)); + center_->AddNotification(notification.Pass()); WaitForAnimationEnded(); } @@ -124,14 +135,19 @@ TEST_F(PopupCollectionTest, AttemptFourOneOffscreen) { AddThreeNotifications(); EXPECT_EQ(2u, [[collection_ popups] count]); // "3" does not fit on screen. - center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, - "4", - ASCIIToUTF16("Four"), - ASCIIToUTF16("This is the fourth notification."), - string16(), - std::string(), - NULL, - NULL); + scoped_ptr<message_center::Notification> notification; + + notification.reset(new message_center::Notification( + message_center::NOTIFICATION_TYPE_SIMPLE, + "4", + ASCIIToUTF16("Four"), + ASCIIToUTF16("This is the fourth notification."), + gfx::Image(), + string16(), + std::string(), + NULL, + NULL)); + center_->AddNotification(notification.Pass()); WaitForAnimationEnded(); // Remove "1" and "3" should fit on screen. @@ -170,14 +186,18 @@ TEST_F(PopupCollectionTest, LayoutSpacing) { scoped_ptr<base::DictionaryValue> optional(new base::DictionaryValue); optional->SetInteger(message_center::kPriorityKey, message_center::HIGH_PRIORITY); - center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, - "4", - ASCIIToUTF16("Four"), - ASCIIToUTF16("This is the fourth notification."), - string16(), - std::string(), - optional.get(), - NULL); + scoped_ptr<message_center::Notification> notification; + notification.reset(new message_center::Notification( + message_center::NOTIFICATION_TYPE_SIMPLE, + "4", + ASCIIToUTF16("Four"), + ASCIIToUTF16("This is the fourth notification."), + gfx::Image(), + string16(), + std::string(), + optional.get(), + NULL)); + center_->AddNotification(notification.Pass()); WaitForAnimationEnded(); EXPECT_TRUE(CheckSpacingBetween([popups objectAtIndex:2], [popups objectAtIndex:3])); @@ -203,32 +223,41 @@ TEST_F(PopupCollectionTest, TinyScreen) { [collection_ setScreenFrame:NSMakeRect(0, 0, 800, 100)]; EXPECT_EQ(0u, [[collection_ popups] count]); - center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, - "1", - ASCIIToUTF16("One"), - ASCIIToUTF16("This is the first notification to" - " be displayed"), - string16(), - std::string(), - NULL, - NULL); + scoped_ptr<message_center::Notification> notification; + notification.reset(new message_center::Notification( + message_center::NOTIFICATION_TYPE_SIMPLE, + "1", + ASCIIToUTF16("One"), + ASCIIToUTF16("This is the first notification to" + " be displayed"), + gfx::Image(), + string16(), + std::string(), + NULL, + NULL)); + center_->AddNotification(notification.Pass()); WaitForAnimationEnded(); EXPECT_EQ(1u, [[collection_ popups] count]); // Now give the notification a longer message so that it no longer fits. - center_->UpdateNotification("1", - "1", - ASCIIToUTF16("One"), - ASCIIToUTF16("This is now a very very very very " - "very very very very very very very " - "very very very very very very very " - "very very very very very very very " - "very very very very very very very " - "very very very very very very very " - "very very very very very very very " - "long notification."), - NULL, - NULL); + notification.reset(new message_center::Notification( + message_center::NOTIFICATION_TYPE_SIMPLE, + "1", + ASCIIToUTF16("One"), + ASCIIToUTF16("This is now a very very very very " + "very very very very very very very " + "very very very very very very very " + "very very very very very very very " + "very very very very very very very " + "very very very very very very very " + "very very very very very very very " + "long notification."), + gfx::Image(), + string16(), + std::string(), + NULL, + NULL)); + center_->UpdateNotification("1", notification.Pass()); WaitForAnimationEnded(); EXPECT_EQ(0u, [[collection_ popups] count]); } @@ -257,18 +286,22 @@ TEST_F(PopupCollectionTest, UpdateIconAndBody) { // Replace "1". controller = [[popups objectAtIndex:0] notificationController]; NSRect old_frame = [[controller view] frame]; - center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, - "1", - ASCIIToUTF16("One is going to get a much longer " - "title than it previously had."), - ASCIIToUTF16("This is the first notification to " - "be displayed, but it will also be " - "updated to have a significantly " - "longer body"), - string16(), - std::string(), - NULL, - NULL); + scoped_ptr<message_center::Notification> notification; + notification.reset(new message_center::Notification( + message_center::NOTIFICATION_TYPE_SIMPLE, + "1", + ASCIIToUTF16("One is going to get a much longer " + "title than it previously had."), + ASCIIToUTF16("This is the first notification to " + "be displayed, but it will also be " + "updated to have a significantly " + "longer body"), + gfx::Image(), + string16(), + std::string(), + NULL, + NULL)); + center_->AddNotification(notification.Pass()); WaitForAnimationEnded(); EXPECT_GT(NSHeight([[controller view] frame]), NSHeight(old_frame)); diff --git a/ui/message_center/cocoa/popup_controller_unittest.mm b/ui/message_center/cocoa/popup_controller_unittest.mm index dd2503c..81402e8 100644 --- a/ui/message_center/cocoa/popup_controller_unittest.mm +++ b/ui/message_center/cocoa/popup_controller_unittest.mm @@ -21,6 +21,7 @@ TEST_F(PopupControllerTest, Creation) { "", ASCIIToUTF16("Added to circles"), ASCIIToUTF16("Jonathan and 5 others"), + gfx::Image(), string16(), std::string(), NULL, diff --git a/ui/message_center/cocoa/tray_view_controller_unittest.mm b/ui/message_center/cocoa/tray_view_controller_unittest.mm index c32be80..aa370e1 100644 --- a/ui/message_center/cocoa/tray_view_controller_unittest.mm +++ b/ui/message_center/cocoa/tray_view_controller_unittest.mm @@ -36,14 +36,18 @@ class TrayViewControllerTest : public ui::CocoaTest { TEST_F(TrayViewControllerTest, AddRemoveOne) { NSScrollView* view = [[tray_ scrollView] documentView]; EXPECT_EQ(0u, [[view subviews] count]); - center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, - "1", - ASCIIToUTF16("First notification"), - ASCIIToUTF16("This is a simple test."), - string16(), - std::string(), - NULL, - NULL); + scoped_ptr<message_center::Notification> notification_data; + notification_data.reset(new message_center::Notification( + message_center::NOTIFICATION_TYPE_SIMPLE, + "1", + ASCIIToUTF16("First notification"), + ASCIIToUTF16("This is a simple test."), + gfx::Image(), + string16(), + std::string(), + NULL, + NULL)); + center_->AddNotification(notification_data.Pass()); [tray_ onMessageCenterTrayChanged]; ASSERT_EQ(1u, [[view subviews] count]); @@ -66,30 +70,40 @@ TEST_F(TrayViewControllerTest, AddRemoveOne) { TEST_F(TrayViewControllerTest, AddThreeClearAll) { NSScrollView* view = [[tray_ scrollView] documentView]; EXPECT_EQ(0u, [[view subviews] count]); - center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, - "1", - ASCIIToUTF16("First notification"), - ASCIIToUTF16("This is a simple test."), - string16(), - std::string(), - NULL, - NULL); - center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, - "2", - ASCIIToUTF16("Second notification"), - ASCIIToUTF16("This is a simple test."), - string16(), - std::string(), - NULL, - NULL); - center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, - "3", - ASCIIToUTF16("Third notification"), - ASCIIToUTF16("This is a simple test."), - string16(), - std::string(), - NULL, - NULL); + scoped_ptr<message_center::Notification> notification; + notification.reset(new message_center::Notification( + message_center::NOTIFICATION_TYPE_SIMPLE, + "1", + ASCIIToUTF16("First notification"), + ASCIIToUTF16("This is a simple test."), + gfx::Image(), + string16(), + std::string(), + NULL, + NULL)); + center_->AddNotification(notification.Pass()); + notification.reset(new message_center::Notification( + message_center::NOTIFICATION_TYPE_SIMPLE, + "2", + ASCIIToUTF16("Second notification"), + ASCIIToUTF16("This is a simple test."), + gfx::Image(), + string16(), + std::string(), + NULL, + NULL)); + center_->AddNotification(notification.Pass()); + notification.reset(new message_center::Notification( + message_center::NOTIFICATION_TYPE_SIMPLE, + "3", + ASCIIToUTF16("Third notification"), + ASCIIToUTF16("This is a simple test."), + gfx::Image(), + string16(), + std::string(), + NULL, + NULL)); + center_->AddNotification(notification.Pass()); [tray_ onMessageCenterTrayChanged]; ASSERT_EQ(3u, [[view subviews] count]); @@ -110,14 +124,18 @@ TEST_F(TrayViewControllerTest, NoClearAllWhenNoNotifications) { NSMinX([[tray_ pauseButton] frame])); // Add a notification. - center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, - "1", - ASCIIToUTF16("First notification"), - ASCIIToUTF16("This is a simple test."), - string16(), - std::string(), - NULL, - NULL); + scoped_ptr<message_center::Notification> notification; + notification.reset(new message_center::Notification( + message_center::NOTIFICATION_TYPE_SIMPLE, + "1", + ASCIIToUTF16("First notification"), + ASCIIToUTF16("This is a simple test."), + gfx::Image(), + string16(), + std::string(), + NULL, + NULL)); + center_->AddNotification(notification.Pass()); [tray_ onMessageCenterTrayChanged]; // Clear all should now be visible. @@ -126,14 +144,17 @@ TEST_F(TrayViewControllerTest, NoClearAllWhenNoNotifications) { NSMinX([[tray_ pauseButton] frame])); // Adding a second notification should keep things still visible. - center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, - "2", - ASCIIToUTF16("Second notification"), - ASCIIToUTF16("This is a simple test."), - string16(), - std::string(), - NULL, - NULL); + notification.reset(new message_center::Notification( + message_center::NOTIFICATION_TYPE_SIMPLE, + "2", + ASCIIToUTF16("Second notification"), + ASCIIToUTF16("This is a simple test."), + gfx::Image(), + string16(), + std::string(), + NULL, + NULL)); + center_->AddNotification(notification.Pass()); [tray_ onMessageCenterTrayChanged]; EXPECT_FALSE([[tray_ clearAllButton] isHidden]); EXPECT_GT(NSMinX([[tray_ clearAllButton] frame]), diff --git a/ui/message_center/fake_message_center.cc b/ui/message_center/fake_message_center.cc index b48961c..f8b94ef 100644 --- a/ui/message_center/fake_message_center.cc +++ b/ui/message_center/fake_message_center.cc @@ -55,23 +55,12 @@ NotificationList::PopupNotifications return NotificationList::PopupNotifications(); } -void FakeMessageCenter::AddNotification( - NotificationType type, - const std::string& id, - const string16& title, - const string16& message, - const string16& display_source, - const std::string& extension_id, - const base::DictionaryValue* optional_fields, - NotificationDelegate* delegate) {} +void FakeMessageCenter::AddNotification(scoped_ptr<Notification> notification) { +} void FakeMessageCenter::UpdateNotification( const std::string& old_id, - const std::string& new_id, - const string16& title, - const string16& message, - const base::DictionaryValue* optional_fields, - NotificationDelegate* delegate) {} + scoped_ptr<Notification> new_notification) {} void FakeMessageCenter::RemoveNotification(const std::string& id, bool by_user) { diff --git a/ui/message_center/fake_message_center.h b/ui/message_center/fake_message_center.h index 65ddc4b..1d75cd9 100644 --- a/ui/message_center/fake_message_center.h +++ b/ui/message_center/fake_message_center.h @@ -29,20 +29,11 @@ class FakeMessageCenter : public MessageCenter { virtual bool HasClickedListener(const std::string& id) OVERRIDE; virtual const NotificationList::Notifications& GetNotifications() OVERRIDE; virtual NotificationList::PopupNotifications GetPopupNotifications() OVERRIDE; - virtual void AddNotification(NotificationType type, - const std::string& id, - const string16& title, - const string16& message, - const string16& display_source, - const std::string& extension_id, - const base::DictionaryValue* optional_fields, - NotificationDelegate* delegate) OVERRIDE; + virtual void AddNotification(scoped_ptr<Notification> notification) OVERRIDE; virtual void UpdateNotification(const std::string& old_id, - const std::string& new_id, - const string16& title, - const string16& message, - const base::DictionaryValue* optional_fields, - NotificationDelegate* delegate) OVERRIDE; + scoped_ptr<Notification> new_notification) + OVERRIDE; + virtual void RemoveNotification(const std::string& id, bool by_user) OVERRIDE; virtual void RemoveAllNotifications(bool by_user) OVERRIDE; virtual void SetNotificationIcon(const std::string& notification_id, diff --git a/ui/message_center/message_center.h b/ui/message_center/message_center.h index 7be6cc8..ff247d3 100644 --- a/ui/message_center/message_center.h +++ b/ui/message_center/message_center.h @@ -84,32 +84,13 @@ class MESSAGE_CENTER_EXPORT MessageCenter { // Basic operations of notification: add/remove/update. - // Adds a new notification. |id| is a unique identifier, used to update or - // remove notifications. |title| and |meesage| describe the notification text. - // Use SetNotificationIcon, SetNotificationImage, or SetNotificationButtonIcon - // to set images. If |extension_id| is provided then 'Disable extension' will - // appear in a dropdown menu and the id will be used to disable notifications - // from the extension. Otherwise if |display_source| is provided, a menu item - // showing the source and allowing notifications from that source to be - // disabled will be shown. All actual disabling is handled by the Delegate. - virtual void AddNotification(NotificationType type, - const std::string& id, - const string16& title, - const string16& message, - const string16& display_source, - const std::string& extension_id, - const base::DictionaryValue* optional_fields, - NotificationDelegate* delegate) = 0; + // Adds a new notification. + virtual void AddNotification(scoped_ptr<Notification> notification) = 0; // Updates an existing notification with id = old_id and set its id to new_id. - // |delegate| and |optional_fields| can be NULL in case of no updates on - // those fields. - virtual void UpdateNotification(const std::string& old_id, - const std::string& new_id, - const string16& title, - const string16& message, - const base::DictionaryValue* optional_fields, - NotificationDelegate* delegate) = 0; + virtual void UpdateNotification( + const std::string& old_id, + scoped_ptr<Notification> new_notification) = 0; // Removes an existing notification. virtual void RemoveNotification(const std::string& id, bool by_user) = 0; diff --git a/ui/message_center/message_center_impl.cc b/ui/message_center/message_center_impl.cc index 58aebbb..68780c5 100644 --- a/ui/message_center/message_center_impl.cc +++ b/ui/message_center/message_center_impl.cc @@ -80,46 +80,31 @@ NotificationList::PopupNotifications //------------------------------------------------------------------------------ // Client code interface. +void MessageCenterImpl::AddNotification(scoped_ptr<Notification> notification) { + DCHECK(notification.get()); -void MessageCenterImpl::AddNotification( - NotificationType type, - const std::string& id, - const string16& title, - const string16& message, - const string16& display_source, - const std::string& extension_id, - const base::DictionaryValue* optional_fields, - NotificationDelegate* delegate) { // Sometimes the notification can be added with the same id and the // |notification_list| will replace the notification instead of adding new. // This is essentially an update rather than addition. + const std::string& id = notification->id(); bool already_exists = notification_list_->HasNotification(id); - notification_list_->AddNotification(type, - id, - title, - message, - display_source, - extension_id, - optional_fields, - delegate); + notification_list_->AddNotification(notification.Pass()); + if (already_exists) { - FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, - OnNotificationUpdated(id)); + FOR_EACH_OBSERVER( + MessageCenterObserver, observer_list_, OnNotificationUpdated(id)); } else { - FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, - OnNotificationAdded(id)); + FOR_EACH_OBSERVER( + MessageCenterObserver, observer_list_, OnNotificationAdded(id)); } } void MessageCenterImpl::UpdateNotification( const std::string& old_id, - const std::string& new_id, - const string16& title, - const string16& message, - const base::DictionaryValue* optional_fields, - NotificationDelegate* delegate) { - notification_list_->UpdateNotificationMessage( - old_id, new_id, title, message, optional_fields, delegate); + scoped_ptr<Notification> new_notification) { + std::string new_id = new_notification->id(); + notification_list_->UpdateNotificationMessage(old_id, + new_notification.Pass()); if (old_id == new_id) { FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, OnNotificationUpdated(new_id)); diff --git a/ui/message_center/message_center_impl.h b/ui/message_center/message_center_impl.h index 33e7a14..f39dc74 100644 --- a/ui/message_center/message_center_impl.h +++ b/ui/message_center/message_center_impl.h @@ -32,20 +32,10 @@ class MessageCenterImpl : public MessageCenter { virtual bool HasClickedListener(const std::string& id) OVERRIDE; virtual const NotificationList::Notifications& GetNotifications() OVERRIDE; virtual NotificationList::PopupNotifications GetPopupNotifications() OVERRIDE; - virtual void AddNotification(NotificationType type, - const std::string& id, - const string16& title, - const string16& message, - const string16& display_source, - const std::string& extension_id, - const base::DictionaryValue* optional_fields, - NotificationDelegate* delegate) OVERRIDE; + virtual void AddNotification(scoped_ptr<Notification> notification) OVERRIDE; virtual void UpdateNotification(const std::string& old_id, - const std::string& new_id, - const string16& title, - const string16& message, - const base::DictionaryValue* optional_fields, - NotificationDelegate* delegate) OVERRIDE; + scoped_ptr<Notification> new_notification) + OVERRIDE; virtual void RemoveNotification(const std::string& id, bool by_user) OVERRIDE; virtual void RemoveAllNotifications(bool by_user) OVERRIDE; virtual void SetNotificationIcon(const std::string& notification_id, diff --git a/ui/message_center/message_center_style.h b/ui/message_center/message_center_style.h index b54a624..a995cea 100644 --- a/ui/message_center/message_center_style.h +++ b/ui/message_center/message_center_style.h @@ -64,8 +64,11 @@ const int kButtonHeight = 38; // In DIPs. const int kButtonHorizontalPadding = 16; // In DIPs. const int kButtonIconTopPadding = 11; // In DIPs. const int kButtonIconToTitlePadding = 16; // In DIPs. + +#if !defined(OS_LINUX) || defined(USE_AURA) const SkColor kButtonSeparatorColor = SkColorSetRGB(234, 234, 234); const SkColor kHoveredButtonBackgroundColor = SkColorSetRGB(243, 243, 243); +#endif // Around notifications //////////////////////////////////////////////////////// diff --git a/ui/message_center/message_center_tray_unittest.cc b/ui/message_center/message_center_tray_unittest.cc index 1b774f8..b8aaad3 100644 --- a/ui/message_center/message_center_tray_unittest.cc +++ b/ui/message_center/message_center_tray_unittest.cc @@ -57,6 +57,19 @@ class MessageCenterTrayTest : public testing::Test { } protected: + void AddNotification(const std::string& id) { + scoped_ptr<Notification> notification( + new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, + id, + ASCIIToUTF16("Test Web Notification"), + ASCIIToUTF16("Notification message body."), + gfx::Image(), + ASCIIToUTF16("www.test.org"), + "" /* extension id */, + NULL /* optional_fields */, + NULL /* delegate */)); + message_center_->AddNotification(notification.Pass()); + } scoped_ptr<MockDelegate> delegate_; scoped_ptr<MessageCenterTray> message_center_tray_; MessageCenter* message_center_; @@ -102,14 +115,7 @@ TEST_F(MessageCenterTrayTest, BasicPopup) { ASSERT_FALSE(message_center_tray_->popups_visible()); ASSERT_FALSE(message_center_tray_->message_center_visible()); - message_center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, - "BasicPopup", - ASCIIToUTF16("Test Web Notification"), - ASCIIToUTF16("Notification message body."), - ASCIIToUTF16("www.test.org"), - "" /* extension id */, - NULL /* optional_fields */, - NULL /* delegate */); + AddNotification("BasicPopup"); ASSERT_TRUE(message_center_tray_->popups_visible()); ASSERT_FALSE(message_center_tray_->message_center_visible()); @@ -124,14 +130,7 @@ TEST_F(MessageCenterTrayTest, MessageCenterClosesPopups) { ASSERT_FALSE(message_center_tray_->popups_visible()); ASSERT_FALSE(message_center_tray_->message_center_visible()); - message_center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, - "MessageCenterClosesPopups", - ASCIIToUTF16("Test Web Notification"), - ASCIIToUTF16("Notification message body."), - ASCIIToUTF16("www.test.org"), - "" /* extension id */, - NULL /* optional_fields */, - NULL /* delegate */); + AddNotification("MessageCenterClosesPopups"); ASSERT_TRUE(message_center_tray_->popups_visible()); ASSERT_FALSE(message_center_tray_->message_center_visible()); @@ -142,14 +141,7 @@ TEST_F(MessageCenterTrayTest, MessageCenterClosesPopups) { ASSERT_FALSE(message_center_tray_->popups_visible()); ASSERT_TRUE(message_center_tray_->message_center_visible()); - message_center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, - "MessageCenterClosesPopups2", - ASCIIToUTF16("Test Web Notification"), - ASCIIToUTF16("Notification message body."), - ASCIIToUTF16("www.test.org"), - "" /* extension id */, - NULL /* optional_fields */, - NULL /* delegate */); + AddNotification("MessageCenterClosesPopups2"); message_center_tray_->ShowPopupBubble(); @@ -170,14 +162,7 @@ TEST_F(MessageCenterTrayTest, ShowBubbleFails) { ASSERT_FALSE(message_center_tray_->popups_visible()); ASSERT_FALSE(message_center_tray_->message_center_visible()); - message_center_->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, - "ShowBubbleFails", - ASCIIToUTF16("Test Web Notification"), - ASCIIToUTF16("Notification message body."), - ASCIIToUTF16("www.test.org"), - "" /* extension id */, - NULL /* optional_fields */, - NULL /* delegate */); + AddNotification("ShowBubbleFails"); message_center_tray_->ShowPopupBubble(); diff --git a/ui/message_center/notification.cc b/ui/message_center/notification.cc index c4db2d5..43e3de7 100644 --- a/ui/message_center/notification.cc +++ b/ui/message_center/notification.cc @@ -23,10 +23,27 @@ ButtonInfo::ButtonInfo(const string16& title) : title(title) { } +RichNotificationData::RichNotificationData() + : priority(DEFAULT_PRIORITY), + never_timeout(false), + timestamp(base::Time::Now()) {} + +RichNotificationData::RichNotificationData(const RichNotificationData& other) + : priority(other.priority), + never_timeout(other.never_timeout), + timestamp(other.timestamp), + expanded_message(other.expanded_message), + image(other.image), + items(other.items), + buttons(other.buttons) {} + +RichNotificationData::~RichNotificationData() {} + Notification::Notification(NotificationType type, const std::string& id, const string16& title, const string16& message, + const gfx::Image& icon, const string16& display_source, const std::string& extension_id, const DictionaryValue* optional_fields, @@ -35,48 +52,97 @@ Notification::Notification(NotificationType type, id_(id), title_(title), message_(message), + icon_(icon), display_source_(display_source), extension_id_(extension_id), - priority_(DEFAULT_PRIORITY), - timestamp_(base::Time::Now()), serial_number_(g_next_serial_number_++), shown_as_popup_(false), is_read_(false), is_expanded_(false), - never_timeout_(false), delegate_(delegate) { - // This can override some data members initialized to deafule values above. + // This can override some data members initialized to default values above. ApplyOptionalFields(optional_fields); } -Notification::~Notification() { +Notification::Notification(NotificationType type, + const std::string& id, + const string16& title, + const string16& message, + const gfx::Image& icon, + const string16& display_source, + const std::string& extension_id, + const RichNotificationData& optional_fields, + NotificationDelegate* delegate) + : type_(type), + id_(id), + title_(title), + message_(message), + icon_(icon), + display_source_(display_source), + extension_id_(extension_id), + serial_number_(g_next_serial_number_++), + optional_fields_(optional_fields), + delegate_(delegate) {} + +Notification::Notification(const Notification& other) + : type_(other.type_), + id_(other.id_), + title_(other.title_), + message_(other.message_), + icon_(other.icon_), + display_source_(other.display_source_), + extension_id_(other.extension_id_), + serial_number_(other.serial_number_), + optional_fields_(other.optional_fields_), + shown_as_popup_(other.shown_as_popup_), + is_read_(other.is_read_), + is_expanded_(other.is_expanded_), + delegate_(other.delegate_) {} + +Notification& Notification::operator=(const Notification& other) { + type_ = other.type_; + id_ = other.id_; + title_ = other.title_; + message_ = other.message_; + icon_ = other.icon_; + display_source_ = other.display_source_; + extension_id_ = other.extension_id_; + serial_number_ = other.serial_number_; + optional_fields_ = other.optional_fields_; + shown_as_popup_ = other.shown_as_popup_; + is_read_ = other.is_read_; + is_expanded_ = other.is_expanded_; + delegate_ = other.delegate_; + + return *this; } +Notification::~Notification() {} + void Notification::CopyState(Notification* base) { shown_as_popup_ = base->shown_as_popup(); is_read_ = base->is_read(); is_expanded_ = base->is_expanded(); - never_timeout_ = base->never_timeout(); if (!delegate_.get()) delegate_ = base->delegate(); + optional_fields_.never_timeout = base->never_timeout(); } -bool Notification::SetButtonIcon(size_t index, const gfx::Image& icon) { - if (index >= buttons_.size()) - return false; - buttons_[index].icon = icon; - return true; +void Notification::SetButtonIcon(size_t index, const gfx::Image& icon) { + if (index >= optional_fields_.buttons.size()) + return; + optional_fields_.buttons[index].icon = icon; } void Notification::ApplyOptionalFields(const DictionaryValue* fields) { if (!fields) return; - fields->GetInteger(kPriorityKey, &priority_); + fields->GetInteger(kPriorityKey, &optional_fields_.priority); if (fields->HasKey(kTimestampKey)) { std::string time_string; fields->GetString(kTimestampKey, &time_string); - base::Time::FromString(time_string.c_str(), ×tamp_); + base::Time::FromString(time_string.c_str(), &optional_fields_.timestamp); } if (fields->HasKey(kButtonOneTitleKey) || fields->HasKey(kButtonOneIconUrlKey)) { @@ -84,14 +150,14 @@ void Notification::ApplyOptionalFields(const DictionaryValue* fields) { string16 icon; if (fields->GetString(kButtonOneTitleKey, &title) || fields->GetString(kButtonOneIconUrlKey, &icon)) { - buttons_.push_back(ButtonInfo(title)); + optional_fields_.buttons.push_back(ButtonInfo(title)); if (fields->GetString(kButtonTwoTitleKey, &title) || fields->GetString(kButtonTwoIconUrlKey, &icon)) { - buttons_.push_back(ButtonInfo(title)); + optional_fields_.buttons.push_back(ButtonInfo(title)); } } } - fields->GetString(kExpandedMessageKey, &expanded_message_); + fields->GetString(kExpandedMessageKey, &optional_fields_.expanded_message); if (fields->HasKey(kItemsKey)) { const ListValue* items; CHECK(fields->GetList(kItemsKey, &items)); @@ -102,11 +168,11 @@ void Notification::ApplyOptionalFields(const DictionaryValue* fields) { items->GetDictionary(i, &item); item->GetString(kItemTitleKey, &title); item->GetString(kItemMessageKey, &message); - items_.push_back(NotificationItem(title, message)); + optional_fields_.items.push_back(NotificationItem(title, message)); } } - fields->GetBoolean(kPrivateNeverTimeoutKey, &never_timeout_); + fields->GetBoolean(kPrivateNeverTimeoutKey, &optional_fields_.never_timeout); } } // namespace message_center diff --git a/ui/message_center/notification.h b/ui/message_center/notification.h index 5f7ee12..c6c43b9 100644 --- a/ui/message_center/notification.h +++ b/ui/message_center/notification.h @@ -32,16 +32,45 @@ struct MESSAGE_CENTER_EXPORT ButtonInfo { ButtonInfo(const string16& title); }; +class MESSAGE_CENTER_EXPORT RichNotificationData { + public: + RichNotificationData(); + RichNotificationData(const RichNotificationData& other); + ~RichNotificationData(); + + int priority; + bool never_timeout; + base::Time timestamp; + string16 expanded_message; + gfx::Image image; + std::vector<NotificationItem> items; + std::vector<ButtonInfo> buttons; +}; + class MESSAGE_CENTER_EXPORT Notification { public: Notification(NotificationType type, const std::string& id, const string16& title, const string16& message, + const gfx::Image& icon, const string16& display_source, const std::string& extension_id, const DictionaryValue* optional_fields, // May be NULL. NotificationDelegate* delegate); // May be NULL. + + Notification(NotificationType type, + const std::string& id, + const string16& title, + const string16& message, + const gfx::Image& icon, + const string16& display_source, + const std::string& extension_id, + const RichNotificationData& optional_fields, + NotificationDelegate* delegate); + + Notification(const Notification& other); + Notification& operator=(const Notification& other); virtual ~Notification(); // Copies the internal on-memory state from |base|, i.e. shown_as_popup, @@ -52,26 +81,37 @@ class MESSAGE_CENTER_EXPORT Notification { const std::string& id() const { return id_; } const string16& title() const { return title_; } const string16& message() const { return message_; } + + // A display string for the source of the notification. const string16& display_source() const { return display_source_; } const std::string& extension_id() const { return extension_id_; } + void set_extension_id(const std::string& extension_id) { + extension_id_ = extension_id; + } // Begin unpacked values from optional_fields. - int priority() const { return priority_; } - base::Time timestamp() const { return timestamp_; } - const string16& expanded_message() const { return expanded_message_; } - const std::vector<NotificationItem>& items() const { return items_; } + int priority() const { return optional_fields_.priority; } + base::Time timestamp() const { return optional_fields_.timestamp; } + const string16& expanded_message() const { + return optional_fields_.expanded_message; + } + const std::vector<NotificationItem>& items() const { + return optional_fields_.items; + } // End unpacked values. // Images fetched asynchronously. const gfx::Image& icon() const { return icon_; } void set_icon(const gfx::Image& icon) { icon_ = icon; } - const gfx::Image& image() const { return image_; } - void set_image(const gfx::Image& image) { image_ = image; } + const gfx::Image& image() const { return optional_fields_.image; } + void set_image(const gfx::Image& image) { optional_fields_.image = image; } // Buttons, with icons fetched asynchronously. - const std::vector<ButtonInfo>& buttons() const { return buttons_; } - bool SetButtonIcon(size_t index, const gfx::Image& icon); + const std::vector<ButtonInfo>& buttons() const { + return optional_fields_.buttons; + } + void SetButtonIcon(size_t index, const gfx::Image& icon); bool shown_as_popup() const { return shown_as_popup_; } void set_shown_as_popup(bool shown_as_popup) { @@ -90,38 +130,56 @@ class MESSAGE_CENTER_EXPORT Notification { // The notification with lesser serial_number is considered 'older'. unsigned serial_number() { return serial_number_; } - bool never_timeout() const { return never_timeout_; } - NotificationDelegate* delegate() { return delegate_.get(); } + // Marks this explicitly to prevent the timeout dismiss of notification. + // This is used by webkit notifications to keep the existing behavior. + void set_never_timeout(bool never_timeout) { + optional_fields_.never_timeout = never_timeout; + } - private: - // Unpacks the provided |optional_fields| and applies the values to override - // the notification's data members. - void ApplyOptionalFields(const DictionaryValue* optional_fields); + bool never_timeout() const { return optional_fields_.never_timeout; } + NotificationDelegate* delegate() const { return delegate_.get(); } + const RichNotificationData& rich_notification_data() const { + return optional_fields_; + } + + // Delegate actions. + void Display() const { delegate()->Display(); } + void Error() const { delegate()->Error(); } + bool HasClickedListener() const { return delegate()->HasClickedListener(); } + void Click() const { delegate()->Click(); } + void ButtonClick(int index) const { delegate()->ButtonClick(index); } + void Close(bool by_user) const { delegate()->Close(by_user); } + protected: + // The type of notification we'd like displayed. NotificationType type_; + std::string id_; string16 title_; string16 message_; + + // Image data for the associated icon, used by Ash when available. + gfx::Image icon_; + + // The display string for the source of the notification. Could be + // the same as origin_url_, or the name of an extension. string16 display_source_; + + private: + // Unpacks the provided |optional_fields| and applies the values to override + // the notification's data members. + void ApplyOptionalFields(const DictionaryValue* optional_fields); + std::string extension_id_; - int priority_; - base::Time timestamp_; unsigned serial_number_; - string16 expanded_message_; - std::vector<NotificationItem> items_; - gfx::Image icon_; - gfx::Image image_; - std::vector<ButtonInfo> buttons_; + RichNotificationData optional_fields_; bool shown_as_popup_; // True if this has been shown as a popup. bool is_read_; // True if this has been seen in the message center. bool is_expanded_; // True if this has been expanded in the message center. - bool never_timeout_; // True if it doesn't timeout when it appears as a toast. // A proxy object that allows access back to the JavaScript object that // represents the notification, for firing events. scoped_refptr<NotificationDelegate> delegate_; - - DISALLOW_COPY_AND_ASSIGN(Notification); }; } // namespace message_center diff --git a/ui/message_center/notification_list.cc b/ui/message_center/notification_list.cc index 8770ee7..4191f7c 100644 --- a/ui/message_center/notification_list.cc +++ b/ui/message_center/notification_list.cc @@ -71,63 +71,33 @@ void NotificationList::SetMessageCenterVisible( } } -void NotificationList::AddNotification(NotificationType type, - const std::string& id, - const string16& title, - const string16& message, - const string16& display_source, - const std::string& extension_id, - const DictionaryValue* optional_fields, - NotificationDelegate* delegate) { - scoped_ptr<Notification> notification(new Notification(type, - id, - title, - message, - display_source, - extension_id, - optional_fields, - delegate)); +void NotificationList::AddNotification(scoped_ptr<Notification> notification) { PushNotification(notification.Pass()); } void NotificationList::UpdateNotificationMessage( const std::string& old_id, - const std::string& new_id, - const string16& title, - const string16& message, - const base::DictionaryValue* optional_fields, - NotificationDelegate* delegate) { + scoped_ptr<Notification> new_notification) { Notifications::iterator iter = GetNotification(old_id); if (iter == notifications_.end()) return; - // Copy and update a notification. It has an effect of setting a new timestamp - // if not overridden by optional_fields - scoped_ptr<Notification> notification( - new Notification((*iter)->type(), - new_id, - title, - message, - (*iter)->display_source(), - (*iter)->extension_id(), - optional_fields, - delegate)); - notification->CopyState(*iter); + new_notification->CopyState(*iter); // Handles priority promotion. If the notification is already dismissed but // the updated notification has higher priority, it should re-appear as a // toast. - if ((*iter)->priority() < notification->priority()) { - notification->set_is_read(false); - notification->set_shown_as_popup(false); + if ((*iter)->priority() < new_notification->priority()) { + new_notification->set_is_read(false); + new_notification->set_shown_as_popup(false); } // Do not use EraseNotification and PushNotification, since we don't want to // change unread counts nor to update is_read/shown_as_popup states. - Notification *old = *iter; + Notification* old = *iter; notifications_.erase(iter); delete old; - notifications_.insert(notification.release()); + notifications_.insert(new_notification.release()); } void NotificationList::RemoveNotification(const std::string& id) { @@ -199,7 +169,8 @@ bool NotificationList::SetNotificationButtonIcon( Notifications::iterator iter = GetNotification(notification_id); if (iter == notifications_.end()) return false; - return (*iter)->SetButtonIcon(button_index, image); + (*iter)->SetButtonIcon(button_index, image); + return true; } bool NotificationList::HasNotification(const std::string& id) { diff --git a/ui/message_center/notification_list.h b/ui/message_center/notification_list.h index 4155853..49dba30 100644 --- a/ui/message_center/notification_list.h +++ b/ui/message_center/notification_list.h @@ -58,21 +58,10 @@ class MESSAGE_CENTER_EXPORT NotificationList { void SetMessageCenterVisible(bool visible, std::set<std::string>* updated_ids); - void AddNotification(NotificationType type, - const std::string& id, - const string16& title, - const string16& message, - const string16& display_source, - const std::string& extension_id, - const base::DictionaryValue* optional_fields, - NotificationDelegate* delegate); + void AddNotification(scoped_ptr<Notification> notification); void UpdateNotificationMessage(const std::string& old_id, - const std::string& new_id, - const string16& title, - const string16& message, - const base::DictionaryValue* optional_fields, - NotificationDelegate* delegate); + scoped_ptr<Notification> new_notification); void RemoveNotification(const std::string& id); diff --git a/ui/message_center/notification_list_unittest.cc b/ui/message_center/notification_list_unittest.cc index 02e3a5d..710b229 100644 --- a/ui/message_center/notification_list_unittest.cc +++ b/ui/message_center/notification_list_unittest.cc @@ -32,15 +32,17 @@ class NotificationListTest : public testing::Test { // notification. std::string AddNotification(const base::DictionaryValue* optional_fields) { std::string new_id = base::StringPrintf(kIdFormat, counter_); - notification_list_->AddNotification( + scoped_ptr<Notification> notification(new Notification( message_center::NOTIFICATION_TYPE_SIMPLE, new_id, UTF8ToUTF16(base::StringPrintf(kTitleFormat, counter_)), UTF8ToUTF16(base::StringPrintf(kMessageFormat, counter_)), + gfx::Image(), UTF8ToUTF16(kDisplaySource), kExtensionId, optional_fields, - NULL); + NULL)); + notification_list_->AddNotification(notification.Pass()); counter_++; return new_id; } @@ -72,13 +74,13 @@ class NotificationListTest : public testing::Test { NotificationList* notification_list() { return notification_list_.get(); } - private: static const char kIdFormat[]; static const char kTitleFormat[]; static const char kMessageFormat[]; static const char kDisplaySource[]; static const char kExtensionId[]; + private: scoped_ptr<NotificationList> notification_list_; size_t counter_; @@ -164,12 +166,17 @@ TEST_F(NotificationListTest, UpdateNotification) { std::string id0 = AddNotification(NULL); std::string replaced = id0 + "_replaced"; EXPECT_EQ(1u, notification_list()->NotificationCount()); - notification_list()->UpdateNotificationMessage(id0, - replaced, - UTF8ToUTF16("newtitle"), - UTF8ToUTF16("newbody"), - NULL, - NULL); + scoped_ptr<Notification> notification( + new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, + replaced, + UTF8ToUTF16("newtitle"), + UTF8ToUTF16("newbody"), + gfx::Image(), + UTF8ToUTF16(kDisplaySource), + kExtensionId, + NULL, + NULL)); + notification_list()->UpdateNotificationMessage(id0, notification.Pass()); EXPECT_EQ(1u, notification_list()->NotificationCount()); const NotificationList::Notifications& notifications = notification_list()->GetNotifications(); @@ -179,38 +186,47 @@ TEST_F(NotificationListTest, UpdateNotification) { } TEST_F(NotificationListTest, GetNotificationsBySourceOrExtensions) { - notification_list()->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, - "id0", - UTF8ToUTF16("title0"), - UTF8ToUTF16("message0"), - UTF8ToUTF16("source0"), - "ext0", - NULL, - NULL); - notification_list()->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, - "id1", - UTF8ToUTF16("title1"), - UTF8ToUTF16("message1"), - UTF8ToUTF16("source0"), - "ext0", - NULL, - NULL); - notification_list()->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, - "id2", - UTF8ToUTF16("title1"), - UTF8ToUTF16("message1"), - UTF8ToUTF16("source1"), - "ext0", - NULL, - NULL); - notification_list()->AddNotification(message_center::NOTIFICATION_TYPE_SIMPLE, - "id3", - UTF8ToUTF16("title1"), - UTF8ToUTF16("message1"), - UTF8ToUTF16("source2"), - "ext1", - NULL, - NULL); + scoped_ptr<Notification> notification( + new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, + "id0", + UTF8ToUTF16("title0"), + UTF8ToUTF16("message0"), + gfx::Image(), + UTF8ToUTF16("source0"), + "ext0", + NULL, + NULL)); + notification_list()->AddNotification(notification.Pass()); + notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, + "id1", + UTF8ToUTF16("title1"), + UTF8ToUTF16("message1"), + gfx::Image(), + UTF8ToUTF16("source0"), + "ext0", + NULL, + NULL)); + notification_list()->AddNotification(notification.Pass()); + notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, + "id2", + UTF8ToUTF16("title1"), + UTF8ToUTF16("message1"), + gfx::Image(), + UTF8ToUTF16("source1"), + "ext0", + NULL, + NULL)); + notification_list()->AddNotification(notification.Pass()); + notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, + "id3", + UTF8ToUTF16("title1"), + UTF8ToUTF16("message1"), + gfx::Image(), + UTF8ToUTF16("source2"), + "ext1", + NULL, + NULL)); + notification_list()->AddNotification(notification.Pass()); NotificationList::Notifications by_source = notification_list()->GetNotificationsBySource("id0"); @@ -308,12 +324,17 @@ TEST_F(NotificationListTest, PriorityPromotion) { EXPECT_EQ(0u, GetPopupCounts()); base::DictionaryValue optional; optional.SetInteger(message_center::kPriorityKey, 1); - notification_list()->UpdateNotificationMessage(id0, - replaced, - UTF8ToUTF16("newtitle"), - UTF8ToUTF16("newbody"), - &optional, - NULL); + scoped_ptr<Notification> notification( + new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, + replaced, + UTF8ToUTF16("newtitle"), + UTF8ToUTF16("newbody"), + gfx::Image(), + UTF8ToUTF16(kDisplaySource), + kExtensionId, + &optional, + NULL)); + notification_list()->UpdateNotificationMessage(id0, notification.Pass()); EXPECT_EQ(1u, notification_list()->NotificationCount()); EXPECT_EQ(1u, GetPopupCounts()); const NotificationList::Notifications& notifications = @@ -335,31 +356,48 @@ TEST_F(NotificationListTest, PriorityPromotionWithPopups) { base::DictionaryValue priority_default; priority_default.SetInteger(message_center::kPriorityKey, static_cast<int>(DEFAULT_PRIORITY)); - notification_list()->UpdateNotificationMessage(id0, - id0, - UTF8ToUTF16("newtitle"), - UTF8ToUTF16("newbody"), - &priority_default, - NULL); + scoped_ptr<Notification> notification( + new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, + id0, + UTF8ToUTF16("newtitle"), + UTF8ToUTF16("newbody"), + gfx::Image(), + UTF8ToUTF16(kDisplaySource), + kExtensionId, + &priority_default, + NULL)); + notification_list()->UpdateNotificationMessage(id0, notification.Pass()); EXPECT_EQ(1u, GetPopupCounts()); notification_list()->MarkSinglePopupAsShown(id0, true); EXPECT_EQ(0u, GetPopupCounts()); // update with no promotion change for id0, it won't appear as a toast. - notification_list()->UpdateNotificationMessage( - id0, id0, UTF8ToUTF16("newtitle2"), UTF8ToUTF16("newbody2"), NULL, NULL); + notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, + id0, + UTF8ToUTF16("newtitle2"), + UTF8ToUTF16("newbody2"), + gfx::Image(), + UTF8ToUTF16(kDisplaySource), + kExtensionId, + NULL, + NULL)); + notification_list()->UpdateNotificationMessage(id0, notification.Pass()); EXPECT_EQ(0u, GetPopupCounts()); // id1 promoted to DEFAULT->HIGH, it'll appear as toast (popup). base::DictionaryValue priority_high; priority_high.SetInteger(message_center::kPriorityKey, static_cast<int>(HIGH_PRIORITY)); - notification_list()->UpdateNotificationMessage(id1, - id1, - UTF8ToUTF16("newtitle"), - UTF8ToUTF16("newbody"), - &priority_high, - NULL); + notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, + id1, + UTF8ToUTF16("newtitle"), + UTF8ToUTF16("newbody"), + gfx::Image(), + UTF8ToUTF16(kDisplaySource), + kExtensionId, + &priority_high, + NULL)); + notification_list()->UpdateNotificationMessage(id1, notification.Pass()); EXPECT_EQ(1u, GetPopupCounts()); notification_list()->MarkSinglePopupAsShown(id1, true); EXPECT_EQ(0u, GetPopupCounts()); @@ -368,23 +406,31 @@ TEST_F(NotificationListTest, PriorityPromotionWithPopups) { base::DictionaryValue priority_max; priority_max.SetInteger(message_center::kPriorityKey, static_cast<int>(MAX_PRIORITY)); - notification_list()->UpdateNotificationMessage(id1, - id1, - UTF8ToUTF16("newtitle2"), - UTF8ToUTF16("newbody2"), - &priority_max, - NULL); + notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, + id1, + UTF8ToUTF16("newtitle2"), + UTF8ToUTF16("newbody2"), + gfx::Image(), + UTF8ToUTF16(kDisplaySource), + kExtensionId, + &priority_max, + NULL)); + notification_list()->UpdateNotificationMessage(id1, notification.Pass()); EXPECT_EQ(1u, GetPopupCounts()); notification_list()->MarkSinglePopupAsShown(id1, true); EXPECT_EQ(0u, GetPopupCounts()); // id1 demoted to MAX->DEFAULT, no appearing as toast. - notification_list()->UpdateNotificationMessage(id1, - id1, - UTF8ToUTF16("newtitle3"), - UTF8ToUTF16("newbody3"), - &priority_default, - NULL); + notification.reset(new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, + id1, + UTF8ToUTF16("newtitle3"), + UTF8ToUTF16("newbody3"), + gfx::Image(), + UTF8ToUTF16(kDisplaySource), + kExtensionId, + &priority_default, + NULL)); + notification_list()->UpdateNotificationMessage(id1, notification.Pass()); EXPECT_EQ(0u, GetPopupCounts()); } @@ -513,12 +559,17 @@ TEST_F(NotificationListTest, UpdateAfterMarkedAsShown) { EXPECT_TRUE(n1->is_read()); const std::string replaced("test-replaced-id"); - notification_list()->UpdateNotificationMessage(id1, - replaced, - UTF8ToUTF16("newtitle"), - UTF8ToUTF16("newbody"), - NULL, - NULL); + scoped_ptr<Notification> notification( + new Notification(message_center::NOTIFICATION_TYPE_SIMPLE, + replaced, + UTF8ToUTF16("newtitle"), + UTF8ToUTF16("newbody"), + gfx::Image(), + UTF8ToUTF16(kDisplaySource), + kExtensionId, + NULL, + NULL)); + notification_list()->UpdateNotificationMessage(id1, notification.Pass()); n1 = GetNotification(id1); EXPECT_TRUE(n1 == NULL); const Notification* nr = GetNotification(replaced); diff --git a/ui/message_center/notification_types.cc b/ui/message_center/notification_types.cc index a391987..a54ed7b 100644 --- a/ui/message_center/notification_types.cc +++ b/ui/message_center/notification_types.cc @@ -6,10 +6,8 @@ namespace message_center { -const char kMessageIntentKey[] = "message_intent"; const char kPriorityKey[] = "priority"; const char kTimestampKey[] = "timestamp"; -const char kUnreadCountKey[] = "unread_count"; const char kButtonOneTitleKey[] = "button_one_title"; const char kButtonOneIconUrlKey[] = "button_one_icon_url"; const char kButtonTwoTitleKey[] = "button_two_title"; diff --git a/ui/message_center/notification_types.h b/ui/message_center/notification_types.h index 161fb14..c935cfa 100644 --- a/ui/message_center/notification_types.h +++ b/ui/message_center/notification_types.h @@ -15,7 +15,6 @@ namespace message_center { // Keys for optional fields in Notification. MESSAGE_CENTER_EXPORT extern const char kPriorityKey[]; MESSAGE_CENTER_EXPORT extern const char kTimestampKey[]; -MESSAGE_CENTER_EXPORT extern const char kUnreadCountKey[]; MESSAGE_CENTER_EXPORT extern const char kButtonOneTitleKey[]; MESSAGE_CENTER_EXPORT extern const char kButtonOneIconUrlKey[]; MESSAGE_CENTER_EXPORT extern const char kButtonTwoTitleKey[]; diff --git a/ui/message_center/views/message_center_view_unittest.cc b/ui/message_center/views/message_center_view_unittest.cc index 3a000f5..4e6c779 100644 --- a/ui/message_center/views/message_center_view_unittest.cc +++ b/ui/message_center/views/message_center_view_unittest.cc @@ -131,6 +131,7 @@ void MessageCenterViewTest::SetUp() { std::string("notification id"), UTF8ToUTF16("title"), UTF8ToUTF16("message"), + gfx::Image(), UTF8ToUTF16("display source"), std::string("extension id"), NULL, diff --git a/ui/message_center/views/message_popup_collection_unittest.cc b/ui/message_center/views/message_popup_collection_unittest.cc index a032aaf..46fbacd9 100644 --- a/ui/message_center/views/message_popup_collection_unittest.cc +++ b/ui/message_center/views/message_popup_collection_unittest.cc @@ -68,14 +68,17 @@ class MessagePopupCollectionTest : public views::ViewsTestBase { std::string AddNotification() { std::string id = base::IntToString(id_++); - MessageCenter::Get()->AddNotification(NOTIFICATION_TYPE_BASE_FORMAT, - id, - UTF8ToUTF16("test title"), - UTF8ToUTF16("test message"), - string16() /* display_source */, - "" /* extension_id */, - NULL /* optional_fields */, - NULL /* delegate */); + scoped_ptr<Notification> notification( + new Notification(NOTIFICATION_TYPE_BASE_FORMAT, + id, + UTF8ToUTF16("test title"), + UTF8ToUTF16("test message"), + gfx::Image(), + string16() /* display_source */, + "" /* extension_id */, + NULL /* optional_fields */, + NULL /* delegate */)); + MessageCenter::Get()->AddNotification(notification.Pass()); return id; } |