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

Unified Diff: chrome/browser/notifications/notification_browsertest.cc

Issue 15025002: Remove ENABLE_MESSAGE_CENTER (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixing static initializer Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/notifications/notification_browsertest.cc
diff --git a/chrome/browser/notifications/notification_browsertest.cc b/chrome/browser/notifications/notification_browsertest.cc
index f524d34ea88b16ac233f3d40b6dcc187adb3e348..4a3179655aebd5146e08a17da8d9c7ef354465d9 100644
--- a/chrome/browser/notifications/notification_browsertest.cc
+++ b/chrome/browser/notifications/notification_browsertest.cc
@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/callback.h"
+#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/run_loop.h"
@@ -44,25 +45,14 @@
#include "net/test/spawned_test_server/spawned_test_server.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/window_open_disposition.h"
-
-// TODO(kbr): remove: http://crbug.com/222296
-#if defined(OS_MACOSX)
-#import "base/mac/mac_util.h"
-#endif
-
-#if defined(ENABLE_MESSAGE_CENTER)
-#include "base/command_line.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/message_center_observer.h"
#include "ui/message_center/message_center_switches.h"
-#endif
+#include "ui/message_center/message_center_util.h"
-// Mac implementation of message_center is incomplete. The code builds, but
-// the tests do not pass <http://crbug.com/179904>.
-#if defined(ENABLE_MESSAGE_CENTER) && !defined(OS_MACOSX)
-#define ENABLE_MESSAGE_CENTER_TESTING 1
-#else
-#define ENABLE_MESSAGE_CENTER_TESTING 0
+// TODO(kbr): remove: http://crbug.com/222296
+#if defined(OS_MACOSX)
+#import "base/mac/mac_util.h"
#endif
namespace {
@@ -75,9 +65,15 @@ enum InfobarAction {
DENY,
};
-#if ENABLE_MESSAGE_CENTER_TESTING
+class NotificationChangeObserver {
+public:
+ virtual ~NotificationChangeObserver() {}
+ virtual bool Wait() = 0;
+};
+
class MessageCenterChangeObserver
- : public message_center::MessageCenterObserver {
+ : public message_center::MessageCenterObserver,
+ public NotificationChangeObserver {
public:
MessageCenterChangeObserver()
: notification_received_(false) {
@@ -88,7 +84,8 @@ class MessageCenterChangeObserver
message_center::MessageCenter::Get()->RemoveObserver(this);
}
- bool Wait() {
+ // NotificationChangeObserver:
+ virtual bool Wait() OVERRIDE {
if (notification_received_)
return true;
@@ -97,15 +94,17 @@ class MessageCenterChangeObserver
return notification_received_;
}
- // overridden from message_center::MessageCenterObserver:
+ // message_center::MessageCenterObserver:
virtual void OnNotificationAdded(
const std::string& notification_id) OVERRIDE {
OnMessageCenterChanged();
}
+
virtual void OnNotificationRemoved(const std::string& notification_id,
bool by_user) OVERRIDE {
OnMessageCenterChanged();
}
+
virtual void OnNotificationUpdated(
const std::string& notification_id) OVERRIDE {
OnMessageCenterChanged();
@@ -123,11 +122,9 @@ class MessageCenterChangeObserver
DISALLOW_COPY_AND_ASSIGN(MessageCenterChangeObserver);
};
-typedef MessageCenterChangeObserver NotificationChangeObserver;
-
-#else
-
-class NotificationBalloonChangeObserver : public content::NotificationObserver {
+class NotificationBalloonChangeObserver
+ : public content::NotificationObserver,
+ public NotificationChangeObserver {
public:
NotificationBalloonChangeObserver()
: collection_(BalloonNotificationUIManager::GetInstanceForTesting()->
@@ -149,7 +146,8 @@ class NotificationBalloonChangeObserver : public content::NotificationObserver {
collection_->set_on_collection_changed_callback(base::Closure());
}
- bool Wait() {
+ // NotificationChangeObserver:
+ virtual bool Wait() OVERRIDE {
if (!Check()) {
running_ = true;
message_loop_runner_ = new content::MessageLoopRunner;
@@ -178,7 +176,7 @@ class NotificationBalloonChangeObserver : public content::NotificationObserver {
Check();
}
- // Overridden from content::NotificationObserver:
+ // content::NotificationObserver:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE {
@@ -201,10 +199,6 @@ class NotificationBalloonChangeObserver : public content::NotificationObserver {
DISALLOW_COPY_AND_ASSIGN(NotificationBalloonChangeObserver);
};
-typedef NotificationBalloonChangeObserver NotificationChangeObserver;
-
-#endif // ENABLE_MESSAGE_CENTER
-
} // namespace
class NotificationsTest : public InProcessBrowserTest {
@@ -217,15 +211,13 @@ class NotificationsTest : public InProcessBrowserTest {
int GetNotificationCount();
+ NotificationChangeObserver* CreateObserver();
+
void CloseBrowserWindow(Browser* browser);
void CrashTab(Browser* browser, int index);
-#if ENABLE_MESSAGE_CENTER_TESTING
- virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
-#else
const std::deque<Balloon*>& GetActiveBalloons();
void CrashNotification(Balloon* balloon);
bool CloseNotificationAndWait(const Notification& notification);
-#endif
void SetDefaultPermissionSetting(ContentSetting setting);
void DenyOrigin(const GURL& origin);
@@ -270,12 +262,19 @@ void NotificationsTest::SetUpInProcessBrowserTestFixture() {
}
int NotificationsTest::GetNotificationCount() {
-#if ENABLE_MESSAGE_CENTER_TESTING
- return message_center::MessageCenter::Get()->NotificationCount();
-#else
- return BalloonNotificationUIManager::GetInstanceForTesting()->
- balloon_collection()->GetActiveBalloons().size();
-#endif // ENABLE_MESSAGE_CENTER_TESTING
+ if (message_center::IsRichNotificationEnabled()) {
+ return message_center::MessageCenter::Get()->NotificationCount();
+ } else {
+ return BalloonNotificationUIManager::GetInstanceForTesting()->
+ balloon_collection()->GetActiveBalloons().size();
+ }
+}
+
+NotificationChangeObserver* NotificationsTest::CreateObserver() {
+ if (message_center::IsRichNotificationEnabled())
+ return new MessageCenterChangeObserver();
+ else
+ return new NotificationBalloonChangeObserver();
}
void NotificationsTest::CloseBrowserWindow(Browser* browser) {
@@ -290,15 +289,6 @@ void NotificationsTest::CrashTab(Browser* browser, int index) {
content::CrashTab(browser->tab_strip_model()->GetWebContentsAt(index));
}
-#if ENABLE_MESSAGE_CENTER_TESTING
-// Overriden from InProcessBrowserTest:
-void NotificationsTest::SetUpCommandLine(CommandLine* command_line) {
- InProcessBrowserTest::SetUpCommandLine(command_line);
- command_line->AppendSwitch(
- message_center::switches::kEnableRichNotifications);
-}
-#else
-
const std::deque<Balloon*>& NotificationsTest::GetActiveBalloons() {
return BalloonNotificationUIManager::GetInstanceForTesting()->
balloon_collection()->GetActiveBalloons();
@@ -310,16 +300,14 @@ void NotificationsTest::CrashNotification(Balloon* balloon) {
bool NotificationsTest::CloseNotificationAndWait(
const Notification& notification) {
- NotificationChangeObserver observer;
+ scoped_ptr<NotificationChangeObserver> observer(CreateObserver());
bool success = g_browser_process->notification_ui_manager()->
CancelById(notification.notification_id());
if (success)
- return observer.Wait();
+ return observer->Wait();
return false;
}
-#endif // !ENABLE_MESSAGE_CENTER_TESTING
-
void NotificationsTest::SetDefaultPermissionSetting(ContentSetting setting) {
DesktopNotificationService* service = GetDesktopNotificationService();
service->SetDefaultContentSetting(setting);
@@ -365,14 +353,14 @@ std::string NotificationsTest::CreateNotification(
"createNotification('%s', '%s', '%s', '%s');",
icon, title, body, replace_id);
- NotificationChangeObserver observer;
+ scoped_ptr<NotificationChangeObserver> observer(CreateObserver());
std::string result;
bool success = content::ExecuteScriptAndExtractString(
browser->tab_strip_model()->GetActiveWebContents(),
script,
&result);
if (success && result != "-1" && wait_for_new_balloon)
- success = observer.Wait();
+ success = observer->Wait();
EXPECT_TRUE(success);
return result;
@@ -410,7 +398,7 @@ bool NotificationsTest::CancelNotification(
"cancelNotification('%s');",
notification_id);
- NotificationChangeObserver observer;
+ scoped_ptr<NotificationChangeObserver> observer(CreateObserver());
std::string result;
bool success = content::ExecuteScriptAndExtractString(
browser->tab_strip_model()->GetActiveWebContents(),
@@ -418,7 +406,7 @@ bool NotificationsTest::CancelNotification(
&result);
if (!success || result != "1")
return false;
- return observer.Wait();
+ return observer->Wait();
}
bool NotificationsTest::PerformActionOnInfobar(
@@ -542,20 +530,20 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) {
GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl);
ASSERT_EQ(1, GetNotificationCount());
-#if ENABLE_MESSAGE_CENTER_TESTING
- message_center::NotificationList::Notifications notifications =
- message_center::MessageCenter::Get()->GetNotifications();
- EXPECT_EQ(ASCIIToUTF16("My Title"), (*notifications.rbegin())->title());
- EXPECT_EQ(ASCIIToUTF16("My Body"), (*notifications.rbegin())->message());
-#else
- const std::deque<Balloon*>& balloons = GetActiveBalloons();
- ASSERT_EQ(1U, balloons.size());
- Balloon* balloon = balloons[0];
- const Notification& notification = balloon->notification();
- EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url());
- EXPECT_EQ(ASCIIToUTF16("My Title"), notification.title());
- EXPECT_EQ(ASCIIToUTF16("My Body"), notification.body());
-#endif
+ if (message_center::IsRichNotificationEnabled()) {
+ message_center::NotificationList::Notifications notifications =
+ message_center::MessageCenter::Get()->GetNotifications();
+ EXPECT_EQ(ASCIIToUTF16("My Title"), (*notifications.rbegin())->title());
+ EXPECT_EQ(ASCIIToUTF16("My Body"), (*notifications.rbegin())->message());
+ } else {
+ const std::deque<Balloon*>& balloons = GetActiveBalloons();
+ ASSERT_EQ(1U, balloons.size());
+ Balloon* balloon = balloons[0];
+ const Notification& notification = balloon->notification();
+ EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url());
+ EXPECT_EQ(ASCIIToUTF16("My Title"), notification.title());
+ EXPECT_EQ(ASCIIToUTF16("My Body"), notification.body());
+ }
}
IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseNotification) {
@@ -573,16 +561,16 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseNotification) {
EXPECT_NE("-1", result);
ASSERT_EQ(1, GetNotificationCount());
-#if ENABLE_MESSAGE_CENTER_TESTING
- message_center::NotificationList::Notifications notifications =
- message_center::MessageCenter::Get()->GetNotifications();
- message_center::MessageCenter::Get()->RemoveNotification(
- (*notifications.rbegin())->id(),
- true); // by_user
-#else
- const std::deque<Balloon*>& balloons = GetActiveBalloons();
- EXPECT_TRUE(CloseNotificationAndWait(balloons[0]->notification()));
-#endif // ENABLE_MESSAGE_CENTER_TESTING
+ if (message_center::IsRichNotificationEnabled()) {
+ message_center::NotificationList::Notifications notifications =
+ message_center::MessageCenter::Get()->GetNotifications();
+ message_center::MessageCenter::Get()->RemoveNotification(
+ (*notifications.rbegin())->id(),
+ true); // by_user
+ } else {
+ const std::deque<Balloon*>& balloons = GetActiveBalloons();
+ EXPECT_TRUE(CloseNotificationAndWait(balloons[0]->notification()));
+ }
ASSERT_EQ(0, GetNotificationCount());
}
@@ -765,16 +753,16 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateDenyCloseNotifications) {
ASSERT_TRUE(CheckOriginInSetting(settings, test_page_url_.GetOrigin()));
EXPECT_EQ(1, GetNotificationCount());
-#if ENABLE_MESSAGE_CENTER_TESTING
- message_center::NotificationList::Notifications notifications =
- message_center::MessageCenter::Get()->GetNotifications();
- message_center::MessageCenter::Get()->RemoveNotification(
- (*notifications.rbegin())->id(),
- true); // by_user
-#else
- const std::deque<Balloon*>& balloons = GetActiveBalloons();
- ASSERT_TRUE(CloseNotificationAndWait(balloons[0]->notification()));
-#endif // ENABLE_MESSAGE_CENTER_TESTING
+ if (message_center::IsRichNotificationEnabled()) {
+ message_center::NotificationList::Notifications notifications =
+ message_center::MessageCenter::Get()->GetNotifications();
+ message_center::MessageCenter::Get()->RemoveNotification(
+ (*notifications.rbegin())->id(),
+ true); // by_user
+ } else {
+ const std::deque<Balloon*>& balloons = GetActiveBalloons();
+ ASSERT_TRUE(CloseNotificationAndWait(balloons[0]->notification()));
+ }
ASSERT_EQ(0, GetNotificationCount());
}
@@ -836,9 +824,11 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest,
CrashTab(browser(), 0);
}
-// Notifications don't have their own process with the message center.
-#if !ENABLE_MESSAGE_CENTER_TESTING
IN_PROC_BROWSER_TEST_F(NotificationsTest, TestKillNotificationProcess) {
+ // Notifications don't have their own process with the message center.
+ if (message_center::IsRichNotificationEnabled())
+ return;
+
#if defined(OS_MACOSX)
// TODO(kbr): re-enable: http://crbug.com/222296
if (base::mac::IsOSMountainLionOrLater())
@@ -855,7 +845,6 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestKillNotificationProcess) {
CrashNotification(balloons[0]);
ASSERT_EQ(0, GetNotificationCount());
}
-#endif
IN_PROC_BROWSER_TEST_F(NotificationsTest, TestIncognitoNotification) {
#if defined(OS_MACOSX)
@@ -958,20 +947,20 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNotificationReplacement) {
browser(), false, "no_such_file.png", "Title2", "Body2", "chat");
EXPECT_NE("-1", result);
-#if ENABLE_MESSAGE_CENTER_TESTING
- ASSERT_EQ(1, GetNotificationCount());
- message_center::NotificationList::Notifications notifications =
- message_center::MessageCenter::Get()->GetNotifications();
- EXPECT_EQ(ASCIIToUTF16("Title2"), (*notifications.rbegin())->title());
- EXPECT_EQ(ASCIIToUTF16("Body2"), (*notifications.rbegin())->message());
-#else
- const std::deque<Balloon*>& balloons = GetActiveBalloons();
- ASSERT_EQ(1U, balloons.size());
- Balloon* balloon = balloons[0];
- const Notification& notification = balloon->notification();
- GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl);
- EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url());
- EXPECT_EQ(ASCIIToUTF16("Title2"), notification.title());
- EXPECT_EQ(ASCIIToUTF16("Body2"), notification.body());
-#endif
+ if (message_center::IsRichNotificationEnabled()) {
+ ASSERT_EQ(1, GetNotificationCount());
+ message_center::NotificationList::Notifications notifications =
+ message_center::MessageCenter::Get()->GetNotifications();
+ EXPECT_EQ(ASCIIToUTF16("Title2"), (*notifications.rbegin())->title());
+ EXPECT_EQ(ASCIIToUTF16("Body2"), (*notifications.rbegin())->message());
+ } else {
+ const std::deque<Balloon*>& balloons = GetActiveBalloons();
+ ASSERT_EQ(1U, balloons.size());
+ Balloon* balloon = balloons[0];
+ const Notification& notification = balloon->notification();
+ GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl);
+ EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url());
+ EXPECT_EQ(ASCIIToUTF16("Title2"), notification.title());
+ EXPECT_EQ(ASCIIToUTF16("Body2"), notification.body());
+ }
}
« no previous file with comments | « chrome/browser/notifications/notification.cc ('k') | chrome/browser/notifications/notification_ui_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698