From 9e9fff083f6742c63ba154f11d458866e99c6ed9 Mon Sep 17 00:00:00 2001 From: "oshima@chromium.org" Date: Fri, 26 Feb 2010 18:56:17 +0000 Subject: Adding sticky field to Notification BUG=33306 TEST=modified and added new test (TestSticky) to DesktopNotificationsTest Review URL: http://codereview.chromium.org/661155 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40139 0039d316-1c4b-4281-b951-d872f2087c98 --- .../notifications/desktop_notification_service.cc | 12 +++--- .../notifications/desktop_notification_service.h | 9 ++-- .../desktop_notifications_unittest.cc | 49 ++++++++++++++++------ chrome/browser/notifications/notification.h | 17 ++++++-- chrome/browser/renderer_host/render_view_host.cc | 4 +- 5 files changed, 66 insertions(+), 25 deletions(-) (limited to 'chrome') diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc index 3f1237b..8096379 100644 --- a/chrome/browser/notifications/desktop_notification_service.cc +++ b/chrome/browser/notifications/desktop_notification_service.cc @@ -332,20 +332,21 @@ bool DesktopNotificationService::CancelDesktopNotification( scoped_refptr proxy( new NotificationObjectProxy(process_id, route_id, notification_id, false)); - Notification notif(GURL(), GURL(), L"", proxy); + Notification notif(GURL(), GURL(), L"", proxy, false); return ui_manager_->Cancel(notif); } bool DesktopNotificationService::ShowDesktopNotification( const GURL& origin, const GURL& url, int process_id, int route_id, - DesktopNotificationSource source, int notification_id) { + DesktopNotificationSource source, int notification_id, + bool sticky) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); NotificationObjectProxy* proxy = new NotificationObjectProxy(process_id, route_id, notification_id, source == WorkerNotification); - Notification notif(origin, url, DisplayNameForOrigin(origin), proxy); + Notification notif(origin, url, DisplayNameForOrigin(origin), proxy, sticky); ShowNotification(notif); return true; } @@ -353,7 +354,8 @@ bool DesktopNotificationService::ShowDesktopNotification( bool DesktopNotificationService::ShowDesktopNotificationText( const GURL& origin, const GURL& icon, const string16& title, const string16& text, int process_id, int route_id, - DesktopNotificationSource source, int notification_id) { + DesktopNotificationSource source, int notification_id, + bool sticky) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); NotificationObjectProxy* proxy = new NotificationObjectProxy(process_id, route_id, @@ -362,7 +364,7 @@ bool DesktopNotificationService::ShowDesktopNotificationText( // "upconvert" the string parameters to a data: URL. string16 data_url = CreateDataUrl(icon, title, text); Notification notif( - origin, GURL(data_url), DisplayNameForOrigin(origin), proxy); + origin, GURL(data_url), DisplayNameForOrigin(origin), proxy, sticky); ShowNotification(notif); return true; } diff --git a/chrome/browser/notifications/desktop_notification_service.h b/chrome/browser/notifications/desktop_notification_service.h index b384a79..b1050c9 100644 --- a/chrome/browser/notifications/desktop_notification_service.h +++ b/chrome/browser/notifications/desktop_notification_service.h @@ -49,13 +49,16 @@ class DesktopNotificationService : public NotificationObserver { // is the origin of the script. |source| indicates whether the // script is in a worker or page. |notification_id| is an opaque // value to be passed back to the process when events occur on - // this notification. + // this notification. |sticky| is used to indicate that the notification + // is sticky and cannot be dismissed by a user. bool ShowDesktopNotification(const GURL& origin, const GURL& url, int process_id, int route_id, DesktopNotificationSource source, - int notification_id); + int notification_id, + bool sticky); bool ShowDesktopNotificationText(const GURL& origin, const GURL& icon, const string16& title, const string16& text, int process_id, - int route_id, DesktopNotificationSource source, int notification_id); + int route_id, DesktopNotificationSource source, int notification_id, + bool sticky); // Cancels a notification. If it has already been shown, it will be // removed from the screen. If it hasn't been shown yet, it won't be diff --git a/chrome/browser/notifications/desktop_notifications_unittest.cc b/chrome/browser/notifications/desktop_notifications_unittest.cc index 186dd5f..04b0931 100644 --- a/chrome/browser/notifications/desktop_notifications_unittest.cc +++ b/chrome/browser/notifications/desktop_notifications_unittest.cc @@ -33,7 +33,8 @@ void MockBalloonCollection::Add(const Notification& notification, Notification test_notification(notification.origin_url(), notification.content_url(), notification.display_source(), - log_proxy_.get()); + log_proxy_.get(), + notification.sticky()); BalloonCollectionImpl::Add(test_notification, profile); } @@ -41,7 +42,8 @@ bool MockBalloonCollection::Remove(const Notification& notification) { Notification test_notification(notification.origin_url(), notification.content_url(), notification.display_source(), - log_proxy_.get()); + log_proxy_.get(), + notification.sticky()); return BalloonCollectionImpl::Remove(test_notification); } @@ -97,20 +99,25 @@ TEST_F(DesktopNotificationsTest, TestShow) { EXPECT_TRUE(service_->ShowDesktopNotificationText( GURL("http://www.google.com"), GURL("/icon.png"), ASCIIToUTF16("Title"), ASCIIToUTF16("Text"), - 0, 0, DesktopNotificationService::PageNotification, 1)); + 0, 0, DesktopNotificationService::PageNotification, 1, false)); MessageLoopForUI::current()->RunAllPending(); EXPECT_EQ(1, balloon_collection_->count()); EXPECT_TRUE(service_->ShowDesktopNotification( GURL("http://www.google.com"), GURL("http://www.google.com/notification.html"), - 0, 0, DesktopNotificationService::PageNotification, 2)); + 0, 0, DesktopNotificationService::PageNotification, 2, false)); MessageLoopForUI::current()->RunAllPending(); EXPECT_EQ(2, balloon_collection_->count()); EXPECT_EQ("notification displayed\n" "notification displayed\n", log_output_); + + std::set::iterator iter = balloon_collection_->balloons().begin(); + EXPECT_FALSE((*iter)->notification().sticky()); + iter++; + EXPECT_FALSE((*iter)->notification().sticky()); } TEST_F(DesktopNotificationsTest, TestClose) { @@ -118,7 +125,7 @@ TEST_F(DesktopNotificationsTest, TestClose) { EXPECT_TRUE(service_->ShowDesktopNotificationText( GURL("http://www.google.com"), GURL("/icon.png"), ASCIIToUTF16("Title"), ASCIIToUTF16("Text"), - 0, 0, DesktopNotificationService::PageNotification, 1)); + 0, 0, DesktopNotificationService::PageNotification, 1, false)); MessageLoopForUI::current()->RunAllPending(); EXPECT_EQ(1, balloon_collection_->count()); @@ -146,7 +153,7 @@ TEST_F(DesktopNotificationsTest, TestCancel) { GURL("http://www.google.com"), GURL("/icon.png"), ASCIIToUTF16("Title"), ASCIIToUTF16("Text"), process_id, route_id, DesktopNotificationService::PageNotification, - notification_id)); + notification_id, false)); MessageLoopForUI::current()->RunAllPending(); EXPECT_EQ(1, balloon_collection_->count()); @@ -173,7 +180,7 @@ TEST_F(DesktopNotificationsTest, TestPositioning) { EXPECT_TRUE(service_->ShowDesktopNotificationText( GURL("http://www.google.com"), GURL("/icon.png"), ASCIIToUTF16("Title"), ASCIIToUTF16("Text"), - 0, 0, DesktopNotificationService::PageNotification, id)); + 0, 0, DesktopNotificationService::PageNotification, id, false)); expected_log.append("notification displayed\n"); int top = balloon_collection_->UppermostVerticalPosition(); if (id > 0) @@ -194,12 +201,12 @@ TEST_F(DesktopNotificationsTest, TestVariableSize) { "Really Really Really Really Really Really " "Really Really Really Really Really Really Really Long Title"), ASCIIToUTF16("Text"), - 0, 0, DesktopNotificationService::PageNotification, 0)); + 0, 0, DesktopNotificationService::PageNotification, 0, false)); expected_log.append("notification displayed\n"); EXPECT_TRUE(service_->ShowDesktopNotificationText( GURL("http://short.google.com"), GURL("/icon.png"), ASCIIToUTF16("Short title"), ASCIIToUTF16("Text"), - 0, 0, DesktopNotificationService::PageNotification, 1)); + 0, 0, DesktopNotificationService::PageNotification, 1, false)); expected_log.append("notification displayed\n"); std::set& balloons = balloon_collection_->balloons(); @@ -230,7 +237,7 @@ TEST_F(DesktopNotificationsTest, TestQueueing) { GURL("http://www.google.com"), GURL("/icon.png"), ASCIIToUTF16("Title"), ASCIIToUTF16("Text"), process_id, route_id, - DesktopNotificationService::PageNotification, id)); + DesktopNotificationService::PageNotification, id, false)); } MessageLoopForUI::current()->RunAllPending(); @@ -280,7 +287,7 @@ TEST_F(DesktopNotificationsTest, TestEarlyDestruction) { EXPECT_TRUE(service_->ShowDesktopNotificationText( GURL("http://www.google.com"), GURL("/icon.png"), ASCIIToUTF16("Title"), ASCIIToUTF16("Text"), - 0, 0, DesktopNotificationService::PageNotification, id)); + 0, 0, DesktopNotificationService::PageNotification, id, false)); } service_.reset(NULL); } @@ -293,7 +300,7 @@ TEST_F(DesktopNotificationsTest, TestUserInputEscaping) { GURL("/icon.png"), ASCIIToUTF16(""), ASCIIToUTF16("this text is in italics"), - 0, 0, DesktopNotificationService::PageNotification, 1)); + 0, 0, DesktopNotificationService::PageNotification, 1, false)); MessageLoopForUI::current()->RunAllPending(); EXPECT_EQ(1, balloon_collection_->count()); @@ -302,3 +309,21 @@ TEST_F(DesktopNotificationsTest, TestUserInputEscaping) { EXPECT_EQ(std::string::npos, data_url.spec().find("