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

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

Issue 14631021: Revert 199625 "Remove ENABLE_MESSAGE_CENTER" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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: trunk/src/chrome/browser/notifications/notification_browsertest.cc
===================================================================
--- trunk/src/chrome/browser/notifications/notification_browsertest.cc (revision 199638)
+++ trunk/src/chrome/browser/notifications/notification_browsertest.cc (working copy)
@@ -7,7 +7,6 @@
#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"
@@ -45,16 +44,27 @@
#include "net/test/spawned_test_server/spawned_test_server.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/window_open_disposition.h"
-#include "ui/message_center/message_center.h"
-#include "ui/message_center/message_center_observer.h"
-#include "ui/message_center/message_center_switches.h"
-#include "ui/message_center/message_center_util.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
+
+// 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
+#endif
+
namespace {
const char kExpectedIconUrl[] = "files/notifications/no_such_file.png";
@@ -65,15 +75,9 @@
DENY,
};
-class NotificationChangeObserver {
-public:
- virtual ~NotificationChangeObserver() {}
- virtual bool Wait() = 0;
-};
-
+#if ENABLE_MESSAGE_CENTER_TESTING
class MessageCenterChangeObserver
- : public message_center::MessageCenterObserver,
- public NotificationChangeObserver {
+ : public message_center::MessageCenterObserver {
public:
MessageCenterChangeObserver()
: notification_received_(false) {
@@ -84,8 +88,7 @@
message_center::MessageCenter::Get()->RemoveObserver(this);
}
- // NotificationChangeObserver:
- virtual bool Wait() OVERRIDE {
+ bool Wait() {
if (notification_received_)
return true;
@@ -94,17 +97,15 @@
return notification_received_;
}
- // message_center::MessageCenterObserver:
+ // overridden from 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();
@@ -122,9 +123,11 @@
DISALLOW_COPY_AND_ASSIGN(MessageCenterChangeObserver);
};
-class NotificationBalloonChangeObserver
- : public content::NotificationObserver,
- public NotificationChangeObserver {
+typedef MessageCenterChangeObserver NotificationChangeObserver;
+
+#else
+
+class NotificationBalloonChangeObserver : public content::NotificationObserver {
public:
NotificationBalloonChangeObserver()
: collection_(BalloonNotificationUIManager::GetInstanceForTesting()->
@@ -146,8 +149,7 @@
collection_->set_on_collection_changed_callback(base::Closure());
}
- // NotificationChangeObserver:
- virtual bool Wait() OVERRIDE {
+ bool Wait() {
if (!Check()) {
running_ = true;
message_loop_runner_ = new content::MessageLoopRunner;
@@ -176,7 +178,7 @@
Check();
}
- // content::NotificationObserver:
+ // Overridden from content::NotificationObserver:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE {
@@ -199,6 +201,10 @@
DISALLOW_COPY_AND_ASSIGN(NotificationBalloonChangeObserver);
};
+typedef NotificationBalloonChangeObserver NotificationChangeObserver;
+
+#endif // ENABLE_MESSAGE_CENTER
+
} // namespace
class NotificationsTest : public InProcessBrowserTest {
@@ -211,13 +217,15 @@
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);
@@ -262,21 +270,14 @@
}
int NotificationsTest::GetNotificationCount() {
- if (message_center::IsRichNotificationEnabled()) {
- return message_center::MessageCenter::Get()->NotificationCount();
- } else {
- return BalloonNotificationUIManager::GetInstanceForTesting()->
- balloon_collection()->GetActiveBalloons().size();
- }
+#if ENABLE_MESSAGE_CENTER_TESTING
+ return message_center::MessageCenter::Get()->NotificationCount();
+#else
+ return BalloonNotificationUIManager::GetInstanceForTesting()->
+ balloon_collection()->GetActiveBalloons().size();
+#endif // ENABLE_MESSAGE_CENTER_TESTING
}
-NotificationChangeObserver* NotificationsTest::CreateObserver() {
- if (message_center::IsRichNotificationEnabled())
- return new MessageCenterChangeObserver();
- else
- return new NotificationBalloonChangeObserver();
-}
-
void NotificationsTest::CloseBrowserWindow(Browser* browser) {
content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_BROWSER_CLOSED,
@@ -289,6 +290,15 @@
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();
@@ -300,14 +310,16 @@
bool NotificationsTest::CloseNotificationAndWait(
const Notification& notification) {
- scoped_ptr<NotificationChangeObserver> observer(CreateObserver());
+ NotificationChangeObserver observer;
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);
@@ -353,14 +365,14 @@
"createNotification('%s', '%s', '%s', '%s');",
icon, title, body, replace_id);
- scoped_ptr<NotificationChangeObserver> observer(CreateObserver());
+ NotificationChangeObserver observer;
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;
@@ -398,7 +410,7 @@
"cancelNotification('%s');",
notification_id);
- scoped_ptr<NotificationChangeObserver> observer(CreateObserver());
+ NotificationChangeObserver observer;
std::string result;
bool success = content::ExecuteScriptAndExtractString(
browser->tab_strip_model()->GetActiveWebContents(),
@@ -406,7 +418,7 @@
&result);
if (!success || result != "1")
return false;
- return observer->Wait();
+ return observer.Wait();
}
bool NotificationsTest::PerformActionOnInfobar(
@@ -530,20 +542,20 @@
GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl);
ASSERT_EQ(1, GetNotificationCount());
- 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());
- }
+#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
}
IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseNotification) {
@@ -561,16 +573,16 @@
EXPECT_NE("-1", result);
ASSERT_EQ(1, GetNotificationCount());
- 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()));
- }
+#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
ASSERT_EQ(0, GetNotificationCount());
}
@@ -753,16 +765,16 @@
ASSERT_TRUE(CheckOriginInSetting(settings, test_page_url_.GetOrigin()));
EXPECT_EQ(1, GetNotificationCount());
- 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()));
- }
+#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
ASSERT_EQ(0, GetNotificationCount());
}
@@ -824,11 +836,9 @@
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())
@@ -845,6 +855,7 @@
CrashNotification(balloons[0]);
ASSERT_EQ(0, GetNotificationCount());
}
+#endif
IN_PROC_BROWSER_TEST_F(NotificationsTest, TestIncognitoNotification) {
#if defined(OS_MACOSX)
@@ -947,20 +958,20 @@
browser(), false, "no_such_file.png", "Title2", "Body2", "chat");
EXPECT_NE("-1", result);
- 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());
- }
+#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
}

Powered by Google App Engine
This is Rietveld 408576698