Remove ENABLE_MESSAGE_CENTER
Next step on re-factoring Notifications. This will bring the MessageCenter classes, most important message_center::Notification, into build on all systems, including those where the MessageCenter is not yet appearign in UI. This will allow to start using this Notification class in client code and remove the old Notification class defined in chrome/browser/notificaitons/notification.h
That will allow the clients that already use Rich Notifications to use richer data type support, for example supply an image bits for a Notification (as in Snapshot notifications).
This also removes a lot of compile-time @ifdefs and replaces them with checking a runtime flag which we already have anyways.
On Android and iOS, the MessageCenter is not compiled in, for the size concerns and uncertain story for notifications in general - the existing ENABLE_NOTIFICATIONS define is used for that.
BUG=174164
Review URL: https://chromiumcodereview.appspot.com/15025002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@199625 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
index 3ed9a38..a6685b9 100644
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -32,11 +32,8 @@
#include "ui/gfx/switches.h"
#include "ui/gl/gl_switches.h"
#include "ui/keyboard/keyboard_switches.h"
-#include "ui/surface/surface_switches.h"
-
-#if defined(ENABLE_MESSAGE_CENTER)
#include "ui/message_center/message_center_switches.h"
-#endif
+#include "ui/surface/surface_switches.h"
#if defined(USE_ASH)
#include "ash/ash_switches.h"
@@ -1297,7 +1294,6 @@
ENABLE_DISABLE_VALUE_TYPE(switches::kEnableTouchEditing,
switches::kDisableTouchEditing)
},
-#if defined(ENABLE_MESSAGE_CENTER)
{
"enable-rich-notifications",
IDS_FLAGS_ENABLE_RICH_NOTIFICATIONS_NAME,
@@ -1307,7 +1303,6 @@
message_center::switches::kEnableRichNotifications,
message_center::switches::kDisableRichNotifications)
},
-#endif
{
"enable-sync-synced-notifications",
IDS_FLAGS_ENABLE_SYNCED_NOTIFICATIONS_NAME,
diff --git a/chrome/browser/browser_process.h b/chrome/browser/browser_process.h
index 0b4c674..22b347c 100644
--- a/chrome/browser/browser_process.h
+++ b/chrome/browser/browser_process.h
@@ -54,11 +54,9 @@
class EventRouterForwarder;
}
-#if defined(ENABLE_MESSAGE_CENTER)
namespace message_center {
class MessageCenter;
}
-#endif
namespace net {
class URLRequestContextGetter;
@@ -114,10 +112,8 @@
// Returns the manager for desktop notifications.
virtual NotificationUIManager* notification_ui_manager() = 0;
-#if defined(ENABLE_MESSAGE_CENTER)
// MessageCenter is a global list of currently displayed notifications.
virtual message_center::MessageCenter* message_center() = 0;
-#endif
// Returns the state object for the thread that we perform I/O
// coordination on (network requests, communication with renderers,
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index 09868f1..37a8e41 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -89,6 +89,7 @@
#include "net/socket/client_socket_pool_manager.h"
#include "net/url_request/url_request_context_getter.h"
#include "ui/base/l10n/l10n_util.h"
+#include "ui/message_center/message_center.h"
#if defined(ENABLE_CONFIGURATION_POLICY)
#include "chrome/browser/policy/browser_policy_connector.h"
@@ -96,10 +97,6 @@
#include "chrome/browser/policy/policy_service_stub.h"
#endif // defined(ENABLE_CONFIGURATION_POLICY)
-#if defined(ENABLE_MESSAGE_CENTER)
-#include "ui/message_center/message_center.h"
-#endif
-
#if defined(OS_WIN)
#include "base/win/windows_version.h"
#include "ui/views/focus/view_storage.h"
@@ -205,9 +202,7 @@
extension_event_router_forwarder_ = new extensions::EventRouterForwarder;
ExtensionRendererState::GetInstance()->Init();
-#if defined(ENABLE_MESSAGE_CENTER)
message_center::MessageCenter::Initialize();
-#endif
}
BrowserProcessImpl::~BrowserProcessImpl() {
@@ -264,9 +259,7 @@
ExtensionRendererState::GetInstance()->Shutdown();
-#if defined(ENABLE_MESSAGE_CENTER)
message_center::MessageCenter::Shutdown();
-#endif
#if defined(ENABLE_CONFIGURATION_POLICY)
// The policy providers managed by |browser_policy_connector_| need to shut
@@ -480,12 +473,10 @@
return notification_ui_manager_.get();
}
-#if defined(ENABLE_MESSAGE_CENTER)
message_center::MessageCenter* BrowserProcessImpl::message_center() {
DCHECK(CalledOnValidThread());
return message_center::MessageCenter::Get();
}
-#endif
policy::BrowserPolicyConnector* BrowserProcessImpl::browser_policy_connector() {
DCHECK(CalledOnValidThread());
diff --git a/chrome/browser/browser_process_impl.h b/chrome/browser/browser_process_impl.h
index b1b8577..7010aa3 100644
--- a/chrome/browser/browser_process_impl.h
+++ b/chrome/browser/browser_process_impl.h
@@ -87,9 +87,7 @@
virtual extensions::EventRouterForwarder*
extension_event_router_forwarder() OVERRIDE;
virtual NotificationUIManager* notification_ui_manager() OVERRIDE;
-#if defined(ENABLE_MESSAGE_CENTER)
virtual message_center::MessageCenter* message_center() OVERRIDE;
-#endif
virtual policy::BrowserPolicyConnector* browser_policy_connector() OVERRIDE;
virtual policy::PolicyService* policy_service() OVERRIDE;
virtual IconManager* icon_manager() OVERRIDE;
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
index cec83967..6f75abf 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -128,6 +128,7 @@
#include "ppapi/host/ppapi_host.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
+#include "ui/message_center/message_center_util.h"
#include "webkit/glue/webpreferences.h"
#include "webkit/plugins/plugin_switches.h"
@@ -162,10 +163,6 @@
#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
#endif
-#if defined(ENABLE_MESSAGE_CENTER)
-#include "ui/message_center/message_center_util.h"
-#endif
-
#if defined(OS_ANDROID)
#include "ui/base/ui_base_paths.h"
#endif
@@ -1227,10 +1224,8 @@
if (content::IsThreadedCompositingEnabled())
command_line->AppendSwitch(switches::kEnableThreadedCompositing);
-#if defined(ENABLE_MESSAGE_CENTER)
if (message_center::IsRichNotificationEnabled())
command_line->AppendSwitch(switches::kDisableHTMLNotifications);
-#endif
// Please keep this in alphabetical order.
static const char* const kSwitchNames[] = {
diff --git a/chrome/browser/extensions/api/notifications/notifications_api.cc b/chrome/browser/extensions/api/notifications/notifications_api.cc
index 19a6626..e45df6f 100644
--- a/chrome/browser/extensions/api/notifications/notifications_api.cc
+++ b/chrome/browser/extensions/api/notifications/notifications_api.cc
@@ -21,6 +21,7 @@
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "googleurl/src/gurl.h"
+#include "ui/message_center/message_center_util.h"
namespace extensions {
@@ -141,38 +142,35 @@
NotificationsApiFunction::~NotificationsApiFunction() {
}
-// If older notification runtime is used, MessageCenter is not built.
-// Use simpler bridge then, ignoring all options.
-#if !defined (ENABLE_MESSAGE_CENTER)
void NotificationsApiFunction::CreateNotification(
const std::string& id,
api::notifications::NotificationOptions* options) {
- message_center::NotificationType type =
- MapApiTemplateTypeToType(options->type);
- GURL icon_url(UTF8ToUTF16(options->icon_url));
- string16 title(UTF8ToUTF16(options->title));
- string16 message(UTF8ToUTF16(options->message));
+ // If older notification runtime is used, use simpler bridge.
+ if (!message_center::IsRichNotificationEnabled()) {
+ message_center::NotificationType type =
+ MapApiTemplateTypeToType(options->type);
+ GURL icon_url(UTF8ToUTF16(options->icon_url));
+ string16 title(UTF8ToUTF16(options->title));
+ string16 message(UTF8ToUTF16(options->message));
- // Ignore options if running on the old notification runtime.
- scoped_ptr<DictionaryValue> optional_fields(new DictionaryValue());
+ // Ignore options if running on the old notification runtime.
+ scoped_ptr<DictionaryValue> optional_fields(new DictionaryValue());
- NotificationsApiDelegate* api_delegate(new NotificationsApiDelegate(
- this,
- profile(),
- extension_->id(),
- id)); // ownership is passed to Notification
- Notification notification(type, extension_->url(), icon_url, title, message,
- WebKit::WebTextDirectionDefault,
- UTF8ToUTF16(extension_->name()),
- UTF8ToUTF16(api_delegate->id()),
- optional_fields.get(), api_delegate);
+ NotificationsApiDelegate* api_delegate(new NotificationsApiDelegate(
+ this,
+ profile(),
+ extension_->id(),
+ id)); // ownership is passed to Notification
+ Notification notification(type, extension_->url(), icon_url, title, message,
+ WebKit::WebTextDirectionDefault,
+ UTF8ToUTF16(extension_->name()),
+ UTF8ToUTF16(api_delegate->id()),
+ optional_fields.get(), api_delegate);
- g_browser_process->notification_ui_manager()->Add(notification, profile());
-}
-#else // defined(ENABLE_MESSAGE_CENTER)
-void NotificationsApiFunction::CreateNotification(
- const std::string& id,
- api::notifications::NotificationOptions* options) {
+ g_browser_process->notification_ui_manager()->Add(notification, profile());
+ return;
+ }
+
message_center::NotificationType type =
MapApiTemplateTypeToType(options->type);
GURL icon_url(UTF8ToUTF16(options->icon_url));
@@ -251,7 +249,6 @@
g_browser_process->notification_ui_manager()->Add(notification, profile());
}
-#endif // !defined(ENABLE_MESSAGE_CENTER)
bool NotificationsApiFunction::IsNotificationsApiEnabled() {
DesktopNotificationService* service =
diff --git a/chrome/browser/extensions/api/notifications/notifications_apitest.cc b/chrome/browser/extensions/api/notifications/notifications_apitest.cc
index a251db9..e84c10a 100644
--- a/chrome/browser/extensions/api/notifications/notifications_apitest.cc
+++ b/chrome/browser/extensions/api/notifications/notifications_apitest.cc
@@ -274,12 +274,15 @@
ASSERT_TRUE(RunExtensionTest("notifications/api/csp")) << message_;
}
-#ifdef ENABLE_MESSAGE_CENTER
-#if !defined(OS_WIN) || !defined(USE_ASH)
+// MessaceCenter-specific test.
+#if defined(RUN_MESSAGE_CENTER_TESTS)
+#define MAYBE_TestByUser TestByUser
+#else
+#define MAYBE_TestByUser DISABLED_TestByUser
+#endif
-IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestByUser) {
- if (!message_center::IsRichNotificationEnabled())
- return;
+IN_PROC_BROWSER_TEST_F(NotificationsApiTest, MAYBE_TestByUser) {
+ ASSERT_TRUE(message_center::IsRichNotificationEnabled());
const extensions::Extension* extension =
LoadExtensionAndWait("notifications/api/by_user");
@@ -301,6 +304,3 @@
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
}
}
-
-#endif
-#endif
diff --git a/chrome/browser/extensions/extension_crash_recovery_browsertest.cc b/chrome/browser/extensions/extension_crash_recovery_browsertest.cc
index 287aea96..502b43d 100644
--- a/chrome/browser/extensions/extension_crash_recovery_browsertest.cc
+++ b/chrome/browser/extensions/extension_crash_recovery_browsertest.cc
@@ -25,13 +25,10 @@
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/result_codes.h"
-
-#if defined(ENABLE_MESSAGE_CENTER)
-#include "base/command_line.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/message_center_switches.h"
+#include "ui/message_center/message_center_util.h"
#include "ui/message_center/notification_list.h"
-#endif
using content::NavigationController;
using content::WebContents;
@@ -117,91 +114,64 @@
};
-// TODO(rsesek): Implement and enable these tests. http://crbug.com/179904
-#if defined(ENABLE_MESSAGE_CENTER) && !defined(OS_MACOSX)
-
-class MessageCenterExtensionCrashRecoveryTest
+class MAYBE_ExtensionCrashRecoveryTest
: public ExtensionCrashRecoveryTestBase {
protected:
- virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
- ExtensionCrashRecoveryTestBase::SetUpCommandLine(command_line);
- command_line->AppendSwitch(
- message_center::switches::kEnableRichNotifications);
- }
-
virtual void AcceptNotification(size_t index) OVERRIDE {
- message_center::MessageCenter* message_center =
- message_center::MessageCenter::Get();
- ASSERT_GT(message_center->NotificationCount(), index);
- message_center::NotificationList::Notifications::reverse_iterator it =
- message_center->GetNotifications().rbegin();
- for (size_t i=0; i < index; ++i)
- it++;
- std::string id = (*it)->id();
- message_center->ClickOnNotification(id);
+ if (message_center::IsRichNotificationEnabled()) {
+ message_center::MessageCenter* message_center =
+ message_center::MessageCenter::Get();
+ ASSERT_GT(message_center->NotificationCount(), index);
+ message_center::NotificationList::Notifications::reverse_iterator it =
+ message_center->GetNotifications().rbegin();
+ for (size_t i=0; i < index; ++i)
+ it++;
+ std::string id = (*it)->id();
+ message_center->ClickOnNotification(id);
+ } else {
+ Balloon* balloon = GetNotificationDelegate(index);
+ ASSERT_TRUE(balloon);
+ balloon->OnClick();
+ }
WaitForExtensionLoad();
}
virtual void CancelNotification(size_t index) OVERRIDE {
- message_center::MessageCenter* message_center =
- message_center::MessageCenter::Get();
- ASSERT_GT(message_center->NotificationCount(), index);
- message_center::NotificationList::Notifications::reverse_iterator it =
- message_center->GetNotifications().rbegin();
- for (size_t i=0; i < index; i++) { it++; }
- ASSERT_TRUE(
- g_browser_process->notification_ui_manager()->CancelById((*it)->id()));
+ if (message_center::IsRichNotificationEnabled()) {
+ message_center::MessageCenter* message_center =
+ message_center::MessageCenter::Get();
+ ASSERT_GT(message_center->NotificationCount(), index);
+ message_center::NotificationList::Notifications::reverse_iterator it =
+ message_center->GetNotifications().rbegin();
+ for (size_t i=0; i < index; i++) { it++; }
+ ASSERT_TRUE(g_browser_process->notification_ui_manager()->
+ CancelById((*it)->id()));
+ } else {
+ Balloon* balloon = GetNotificationDelegate(index);
+ ASSERT_TRUE(balloon);
+ std::string id = balloon->notification().notification_id();
+ ASSERT_TRUE(g_browser_process->notification_ui_manager()->CancelById(id));
+ }
}
virtual size_t CountBalloons() OVERRIDE {
- message_center::MessageCenter* message_center =
- message_center::MessageCenter::Get();
- return message_center->NotificationCount();
+ if (message_center::IsRichNotificationEnabled())
+ return message_center::MessageCenter::Get()->NotificationCount();
+
+ return BalloonNotificationUIManager::GetInstanceForTesting()->
+ balloon_collection()->GetActiveBalloons().size();
}
+
+private:
+ Balloon* GetNotificationDelegate(size_t index) {
+ BalloonNotificationUIManager* manager =
+ BalloonNotificationUIManager::GetInstanceForTesting();
+ BalloonCollection::Balloons balloons =
+ manager->balloon_collection()->GetActiveBalloons();
+ return index < balloons.size() ? balloons.at(index) : NULL;
+ }
};
-typedef MessageCenterExtensionCrashRecoveryTest
- MAYBE_ExtensionCrashRecoveryTest;
-
-#else // defined(ENABLED_MESSAGE_CENTER)
-
-class BalloonExtensionCrashRecoveryTest
- : public ExtensionCrashRecoveryTestBase {
- protected:
- virtual void AcceptNotification(size_t index) OVERRIDE {
- Balloon* balloon = GetNotificationDelegate(index);
- ASSERT_TRUE(balloon);
- balloon->OnClick();
- WaitForExtensionLoad();
- }
-
- virtual void CancelNotification(size_t index) OVERRIDE {
- Balloon* balloon = GetNotificationDelegate(index);
- ASSERT_TRUE(balloon);
- std::string id = balloon->notification().notification_id();
- ASSERT_TRUE(g_browser_process->notification_ui_manager()->CancelById(id));
- }
-
- virtual size_t CountBalloons() OVERRIDE {
- BalloonNotificationUIManager* manager =
- BalloonNotificationUIManager::GetInstanceForTesting();
- BalloonCollection::Balloons balloons =
- manager->balloon_collection()->GetActiveBalloons();
- return balloons.size();
- }
- private:
- Balloon* GetNotificationDelegate(size_t index) {
- BalloonNotificationUIManager* manager =
- BalloonNotificationUIManager::GetInstanceForTesting();
- BalloonCollection::Balloons balloons =
- manager->balloon_collection()->GetActiveBalloons();
- return index < balloons.size() ? balloons.at(index) : NULL;
- }
-};
-
-typedef BalloonExtensionCrashRecoveryTest MAYBE_ExtensionCrashRecoveryTest;
-#endif // defined(ENABLE_MESSAGE_CENTER)
-
IN_PROC_BROWSER_TEST_F(MAYBE_ExtensionCrashRecoveryTest, Basic) {
const size_t size_before = GetExtensionService()->extensions()->size();
const size_t crash_size_before =
diff --git a/chrome/browser/extensions/notifications_apitest.cc b/chrome/browser/extensions/notifications_apitest.cc
index a1a8b39..858c45ea 100644
--- a/chrome/browser/extensions/notifications_apitest.cc
+++ b/chrome/browser/extensions/notifications_apitest.cc
@@ -8,9 +8,6 @@
#include "chrome/browser/notifications/desktop_notification_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
-
-#if defined(ENABLE_MESSAGE_CENTER)
-
#include "chrome/browser/extensions/extension_process_manager.h"
#include "chrome/browser/extensions/lazy_background_page_test_util.h"
#include "chrome/common/chrome_switches.h"
@@ -18,28 +15,10 @@
#include "ui/message_center/message_center_switches.h"
#include "ui/message_center/message_center_util.h"
-class RichWebkitNotificationTest : public ExtensionApiTest {
+class NotificationIdleTest : public ExtensionApiTest {
protected:
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
ExtensionApiTest::SetUpCommandLine(command_line);
- command_line->AppendSwitch(
- message_center::switches::kEnableRichNotifications);
- }
-};
-
-class DisabledRichWebkitNotificationTest : public ExtensionApiTest {
- protected:
- virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
- ExtensionApiTest::SetUpCommandLine(command_line);
- command_line->AppendSwitch(
- message_center::switches::kDisableRichNotifications);
- }
-};
-
-class NotificationIdleTest : public RichWebkitNotificationTest {
- protected:
- virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
- RichWebkitNotificationTest::SetUpCommandLine(command_line);
command_line->AppendSwitchASCII(switches::kEventPageIdleTime, "1");
command_line->AppendSwitchASCII(switches::kEventPageSuspendingTime, "1");
@@ -56,51 +35,44 @@
}
};
-#endif
-
// TODO(kbr): remove: http://crbug.com/222296
#if defined(OS_MACOSX)
#import "base/mac/mac_util.h"
#endif
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, NotificationsNoPermission) {
-#if defined(OS_LINUX) && defined(TOOLKIT_VIEWS)
- // Notifications not supported on linux/views yet.
-#else
ASSERT_TRUE(RunExtensionTest("notifications/has_not_permission")) << message_;
-#endif
}
-#if defined(ENABLE_MESSAGE_CENTER)
-IN_PROC_BROWSER_TEST_F(RichWebkitNotificationTest, NoHTMLNotifications) {
+// This test verifies that on RichNotification-enabled platforms HTML
+// notificaitons are disabled.
+#if defined(RUN_MESSAGE_CENTER_TESTS)
+#define MAYBE_NoHTMLNotifications NoHTMLNotifications
+#else
+#define MAYBE_NoHTMLNotifications DISABLED_NoHTMLNotifications
+#endif
+IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_NoHTMLNotifications) {
+ ASSERT_TRUE(message_center::IsRichNotificationEnabled());
ASSERT_TRUE(RunExtensionTest("notifications/no_html")) << message_;
}
-#if !defined(OS_CHROMEOS)
-// HTML notifications fail on ChromeOS whether or not rich notifications
-// are enabled.
-IN_PROC_BROWSER_TEST_F(DisabledRichWebkitNotificationTest,
- HasHTMLNotifications) {
+// This test verifies that on platforms other then RichNotification-enabled
+// HTML notificaitons are enabled.
+#if defined(RUN_MESSAGE_CENTER_TESTS)
+#define MAYBE_HasHTMLNotificationsAndManifestPermission \
+ DISABLED_HasHTMLNotificationsAndManifestPermission
+#else
+#define MAYBE_HasHTMLNotificationsAndManifestPermission \
+ HasHTMLNotificationsAndManifestPermission
+#endif
+IN_PROC_BROWSER_TEST_F(ExtensionApiTest,
+ MAYBE_HasHTMLNotificationsAndManifestPermission) {
ASSERT_FALSE(message_center::IsRichNotificationEnabled());
ASSERT_TRUE(RunExtensionTest("notifications/has_permission_manifest"))
<< message_;
}
-#endif
-
-#elif !defined(OS_LINUX) || !defined(TOOLKIT_VIEWS)
-// Notifications not supported on linux/views yet.
-IN_PROC_BROWSER_TEST_F(ExtensionApiTest,
- NotificationsHasPermissionManifest) {
- ASSERT_TRUE(RunExtensionTest("notifications/has_permission_manifest"))
- << message_;
-}
-#endif
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, NotificationsHasPermission) {
-#if defined(OS_LINUX) && defined(TOOLKIT_VIEWS)
- // Notifications not supported on linux/views yet.
-#else
-
#if defined(OS_MACOSX)
// TODO(kbr): re-enable: http://crbug.com/222296
if (base::mac::IsOSMountainLionOrLater())
@@ -112,11 +84,16 @@
"chrome-extension://peoadpeiejnhkmpaakpnompolbglelel"));
ASSERT_TRUE(RunExtensionTest("notifications/has_permission_prefs"))
<< message_;
-#endif
}
-#if defined(ENABLE_MESSAGE_CENTER)
-IN_PROC_BROWSER_TEST_F(NotificationIdleTest, NotificationsAllowUnload) {
+ // MessaceCenter-specific test.
+#if defined(RUN_MESSAGE_CENTER_TESTS)
+#define MAYBE_NotificationsAllowUnload NotificationsAllowUnload
+#else
+#define MAYBE_NotificationsAllowUnload DISABLED_NotificationsAllowUnload
+#endif
+
+IN_PROC_BROWSER_TEST_F(NotificationIdleTest, MAYBE_NotificationsAllowUnload) {
const extensions::Extension* extension =
LoadExtensionAndWait("notifications/api/unload");
ASSERT_TRUE(extension) << message_;
@@ -126,4 +103,3 @@
extensions::ExtensionSystem::Get(profile())->process_manager();
EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_));
}
-#endif
diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc
index e2127ea936..54b3d05 100644
--- a/chrome/browser/notifications/desktop_notification_service.cc
+++ b/chrome/browser/notifications/desktop_notification_service.cc
@@ -43,6 +43,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
+#include "ui/message_center/message_center_util.h"
#include "ui/message_center/notifier_settings.h"
#include "ui/webui/web_ui_util.h"
@@ -57,15 +58,6 @@
namespace {
-bool UsesTextNotifications() {
-#if defined(USE_ASH)
- return true;
-#else
- return
- g_browser_process->notification_ui_manager()->DelegatesToMessageCenter();
-#endif
-}
-
void ToggleListPrefItem(PrefService* prefs, const char* key,
const std::string& item, bool flag) {
ListPrefUpdate update(prefs, key);
@@ -239,12 +231,10 @@
// static
void DesktopNotificationService::RegisterUserPrefs(
user_prefs::PrefRegistrySyncable* registry) {
-#if defined(OS_CHROMEOS) || defined(ENABLE_MESSAGE_CENTER)
registry->RegisterListPref(prefs::kMessageCenterDisabledExtensionIds,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
registry->RegisterListPref(prefs::kMessageCenterDisabledSystemComponentIds,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
-#endif
}
// static
@@ -307,7 +297,7 @@
const string16& replace_id,
NotificationDelegate* delegate,
Profile* profile) {
- if (UsesTextNotifications()) {
+ if (message_center::IsRichNotificationEnabled()) {
// For message center create a non-HTML notification with |icon_url|.
Notification notification(origin_url, icon_url, title, message,
WebKit::WebTextDirectionDefault,
@@ -335,7 +325,7 @@
NotificationDelegate* delegate,
Profile* profile) {
- if (UsesTextNotifications()) {
+ if (message_center::IsRichNotificationEnabled()) {
// For message center create a non-HTML notification with |icon|.
Notification notification(origin_url, icon, title, message,
WebKit::WebTextDirectionDefault,
@@ -362,7 +352,6 @@
NotificationUIManager* ui_manager)
: profile_(profile),
ui_manager_(ui_manager) {
-#if defined(ENABLE_MESSAGE_CENTER)
OnDisabledExtensionIdsChanged();
OnDisabledSystemComponentIdsChanged();
disabled_extension_id_pref_.Init(
@@ -377,13 +366,9 @@
base::Bind(
&DesktopNotificationService::OnDisabledSystemComponentIdsChanged,
base::Unretained(this)));
-#endif
}
DesktopNotificationService::~DesktopNotificationService() {
-#if defined(ENABLE_MESSAGE_CENTER)
- disabled_extension_id_pref_.Destroy();
-#endif
}
void DesktopNotificationService::GrantPermission(const GURL& origin) {
@@ -592,7 +577,6 @@
&disabled_extension_ids_);
}
-#if defined(ENABLE_MESSAGE_CENTER)
bool DesktopNotificationService::IsSystemComponentEnabled(
message_center::Notifier::SystemComponentNotifierType type) {
return disabled_system_component_ids_.find(message_center::ToString(type)) ==
@@ -616,7 +600,6 @@
prefs::kMessageCenterDisabledSystemComponentIds,
&disabled_system_component_ids_);
}
-#endif
WebKit::WebNotificationPresenter::Permission
DesktopNotificationService::HasPermission(const GURL& origin) {
diff --git a/chrome/browser/notifications/desktop_notifications_unittest.cc b/chrome/browser/notifications/desktop_notifications_unittest.cc
index 50caecc..dbf7e1c 100644
--- a/chrome/browser/notifications/desktop_notifications_unittest.cc
+++ b/chrome/browser/notifications/desktop_notifications_unittest.cc
@@ -15,10 +15,7 @@
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "content/public/common/show_desktop_notification_params.h"
-
-#if defined(ENABLE_MESSAGE_CENTER)
#include "ui/message_center/message_center.h"
-#endif
#if defined(USE_ASH)
#include "ash/shell.h"
@@ -116,11 +113,9 @@
WebKit::initialize(webkit_platform_support_.Get());
ui::ScopedAnimationDurationScaleMode normal_duration_mode(
ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
-#if defined(ENABLE_MESSAGE_CENTER)
// The message center is notmally initialized on |g_browser_process| which
// is not created for these tests.
message_center::MessageCenter::Initialize();
-#endif
// MockBalloonCollection retrieves information about the screen on creation.
// So it is necessary to make sure the desktop gets created first.
ash::Shell::CreateInstance(new ash::test::TestShellDelegate);
@@ -143,11 +138,9 @@
#if defined(USE_ASH)
active_desktop_monitor_.reset();
ash::Shell::DeleteInstance();
-#if defined(ENABLE_MESSAGE_CENTER)
// The message center is notmally shutdown on |g_browser_process| which
// is not created for these tests.
message_center::MessageCenter::Shutdown();
-#endif
aura::Env::DeleteInstance();
WebKit::shutdown();
#endif
diff --git a/chrome/browser/notifications/message_center_notifications_browsertest.cc b/chrome/browser/notifications/message_center_notifications_browsertest.cc
index 556eb5a..71cc0a66 100644
--- a/chrome/browser/notifications/message_center_notifications_browsertest.cc
+++ b/chrome/browser/notifications/message_center_notifications_browsertest.cc
@@ -16,10 +16,8 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "ui/message_center/message_center.h"
-
-#if defined(ENABLE_MESSAGE_CENTER)
#include "ui/message_center/message_center_switches.h"
-#endif
+#include "ui/message_center/message_center_util.h"
class MessageCenterNotificationsTest : public InProcessBrowserTest {
public:
@@ -98,19 +96,36 @@
IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, RetrieveBaseParts) {
// Make sure comamnd-line switch has an effect.
- EXPECT_TRUE(NotificationUIManager::DelegatesToMessageCenter());
+ EXPECT_EQ(NotificationUIManager::DelegatesToMessageCenter(),
+ message_center::IsRichNotificationEnabled());
EXPECT_TRUE(manager());
EXPECT_TRUE(message_center());
}
-IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, BasicAddCancel) {
+// MessaceCenter-specific test.
+#if defined(RUN_MESSAGE_CENTER_TESTS)
+#define MAYBE_BasicAddCancel BasicAddCancel
+#else
+#define MAYBE_BasicAddCancel DISABLED_BasicAddCancel
+#endif
+
+IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, MAYBE_BasicAddCancel) {
+ EXPECT_TRUE(NotificationUIManager::DelegatesToMessageCenter());
manager()->Add(CreateTestNotification("hey"), profile());
EXPECT_EQ(1u, message_center()->NotificationCount());
manager()->CancelById("hey");
EXPECT_EQ(0u, message_center()->NotificationCount());
}
-IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, BasicDelegate) {
+// MessaceCenter-specific test.
+#if defined(RUN_MESSAGE_CENTER_TESTS)
+#define MAYBE_BasicDelegate BasicDelegate
+#else
+#define MAYBE_BasicDelegate DISABLED_BasicDelegate
+#endif
+
+IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, MAYBE_BasicDelegate) {
+ EXPECT_TRUE(NotificationUIManager::DelegatesToMessageCenter());
TestDelegate* delegate;
manager()->Add(CreateTestNotification("hey", &delegate), profile());
// Verify that delegate accumulated correct log of events.
@@ -121,7 +136,16 @@
delegate->Release();
}
-IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, ButtonClickedDelegate) {
+// MessaceCenter-specific test.
+#if defined(RUN_MESSAGE_CENTER_TESTS)
+#define MAYBE_ButtonClickedDelegate ButtonClickedDelegate
+#else
+#define MAYBE_ButtonClickedDelegate DISABLED_ButtonClickedDelegate
+#endif
+
+IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest,
+ MAYBE_ButtonClickedDelegate) {
+ EXPECT_TRUE(NotificationUIManager::DelegatesToMessageCenter());
TestDelegate* delegate;
manager()->Add(CreateTestNotification("n", &delegate), profile());
message_center()->ClickOnNotificationButton("n", 1);
diff --git a/chrome/browser/notifications/notification.cc b/chrome/browser/notifications/notification.cc
index 1077b048a..b45bf1e 100644
--- a/chrome/browser/notifications/notification.cc
+++ b/chrome/browser/notifications/notification.cc
@@ -127,9 +127,7 @@
}
void Notification::DisableTimeout() {
-#if defined(ENABLE_MESSAGE_CENTER)
if (!optional_fields_.get())
optional_fields_.reset(new base::DictionaryValue());
optional_fields_->SetBoolean(message_center::kPrivateNeverTimeoutKey, true);
-#endif
}
diff --git a/chrome/browser/notifications/notification_browsertest.cc b/chrome/browser/notifications/notification_browsertest.cc
index f524d34..4a317965 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,27 +45,16 @@
#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";
@@ -75,9 +65,15 @@
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 @@
message_center::MessageCenter::Get()->RemoveObserver(this);
}
- bool Wait() {
+ // NotificationChangeObserver:
+ virtual bool Wait() OVERRIDE {
if (notification_received_)
return true;
@@ -97,15 +94,17 @@
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 @@
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 @@
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 @@
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 @@
DISALLOW_COPY_AND_ASSIGN(NotificationBalloonChangeObserver);
};
-typedef NotificationBalloonChangeObserver NotificationChangeObserver;
-
-#endif // ENABLE_MESSAGE_CENTER
-
} // namespace
class NotificationsTest : public InProcessBrowserTest {
@@ -217,15 +211,13 @@
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 @@
}
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 @@
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 @@
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 @@
"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 @@
"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 @@
&result);
if (!success || result != "1")
return false;
- return observer.Wait();
+ return observer->Wait();
}
bool NotificationsTest::PerformActionOnInfobar(
@@ -542,20 +530,20 @@
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 @@
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 @@
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 @@
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 @@
CrashNotification(balloons[0]);
ASSERT_EQ(0, GetNotificationCount());
}
-#endif
IN_PROC_BROWSER_TEST_F(NotificationsTest, TestIncognitoNotification) {
#if defined(OS_MACOSX)
@@ -958,20 +947,20 @@
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());
+ }
}
diff --git a/chrome/browser/notifications/notification_ui_manager.cc b/chrome/browser/notifications/notification_ui_manager.cc
index a562557..1b1d62dc 100644
--- a/chrome/browser/notifications/notification_ui_manager.cc
+++ b/chrome/browser/notifications/notification_ui_manager.cc
@@ -4,13 +4,10 @@
#include "chrome/browser/notifications/notification_ui_manager.h"
-#include "chrome/browser/notifications/balloon_notification_ui_manager.h"
-
-#if defined(ENABLE_MESSAGE_CENTER)
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/notifications/balloon_notification_ui_manager.h"
#include "chrome/browser/notifications/message_center_notification_manager.h"
#include "ui/message_center/message_center_util.h"
-#endif
// static
bool NotificationUIManager::DelegatesToMessageCenter() {
@@ -19,20 +16,17 @@
// the message center.
#if defined(OS_CHROMEOS)
return true;
-#elif defined(ENABLE_MESSAGE_CENTER)
- return message_center::IsRichNotificationEnabled();
#endif
- return false;
+ return message_center::IsRichNotificationEnabled();
}
#if !defined(OS_MACOSX)
// static
NotificationUIManager* NotificationUIManager::Create(PrefService* local_state) {
-#if defined(ENABLE_MESSAGE_CENTER)
if (DelegatesToMessageCenter())
return new MessageCenterNotificationManager(
g_browser_process->message_center());
-#endif
+
BalloonNotificationUIManager* balloon_manager =
new BalloonNotificationUIManager(local_state);
balloon_manager->SetBalloonCollection(BalloonCollection::Create());
diff --git a/chrome/browser/notifications/notification_ui_manager_mac.mm b/chrome/browser/notifications/notification_ui_manager_mac.mm
index 7e1af003..59339ed 100644
--- a/chrome/browser/notifications/notification_ui_manager_mac.mm
+++ b/chrome/browser/notifications/notification_ui_manager_mac.mm
@@ -7,14 +7,11 @@
#include "base/mac/cocoa_protocols.h"
#include "base/mac/mac_util.h"
#include "base/strings/sys_string_conversions.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/notifications/balloon_notification_ui_manager.h"
-
-#if defined(ENABLE_MESSAGE_CENTER)
-#include "chrome/browser/browser_process.h"
#include "chrome/browser/notifications/message_center_notification_manager.h"
#include "ui/message_center/message_center_util.h"
-#endif
@class NSUserNotificationCenter;
@@ -100,14 +97,12 @@
// static
NotificationUIManager* NotificationUIManager::Create(PrefService* local_state) {
-#if defined(ENABLE_MESSAGE_CENTER)
// TODO(rsesek): Remove this function and merge it with the one in
// notification_ui_manager.cc.
if (DelegatesToMessageCenter()) {
return new MessageCenterNotificationManager(
g_browser_process->message_center());
}
-#endif
BalloonNotificationUIManager* balloon_manager = NULL;
if (base::mac::IsOSMountainLionOrLater())
diff --git a/chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc b/chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc
index bb7182b1..0fee623 100644
--- a/chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc
+++ b/chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc
@@ -18,6 +18,7 @@
#include "sync/protocol/sync.pb.h"
#include "sync/protocol/synced_notification_specifics.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/message_center/message_center_util.h"
using sync_pb::SyncedNotificationSpecifics;
using sync_pb::EntitySpecifics;
@@ -94,12 +95,8 @@
const int64 kFakeCreationTime = 42;
const int kProtobufPriority = static_cast<int>(
sync_pb::CoalescedSyncedNotification_Priority_LOW);
-#if defined (ENABLE_MESSAGE_CENTER)
const int kNotificationPriority = static_cast<int>(
message_center::LOW_PRIORITY);
-#else // ENABLE_MESSAGE_CENTER
-const int kNotificationPriority = 1;
-#endif // ENABLE_MESSAGE_CENTER
const sync_pb::CoalescedSyncedNotification_ReadState kDismissed =
sync_pb::CoalescedSyncedNotification_ReadState_DISMISSED;
const sync_pb::CoalescedSyncedNotification_ReadState kUnread =
diff --git a/chrome/browser/notifications/sync_notifier/synced_notification.cc b/chrome/browser/notifications/sync_notifier/synced_notification.cc
index 23883b2..813846d 100644
--- a/chrome/browser/notifications/sync_notifier/synced_notification.cc
+++ b/chrome/browser/notifications/sync_notifier/synced_notification.cc
@@ -13,20 +13,14 @@
#include "chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.h"
#include "sync/protocol/sync.pb.h"
#include "sync/protocol/synced_notification_specifics.pb.h"
-#if defined(ENABLE_MESSAGE_CENTER)
#include "ui/message_center/message_center_util.h"
#include "ui/message_center/notification_types.h"
-#endif // ENABLE_MESSAGE_CENTER
namespace {
const char kExtensionScheme[] = "chrome-extension://";
bool UseRichNotifications() {
-#if defined(ENABLE_MESSAGE_CENTER)
return message_center::IsRichNotificationEnabled();
-#else // ENABLE_MESSAGE_CENTER
- return false;
-#endif // ENABLE_MESSAGE_CENTER
}
} // namespace
@@ -90,8 +84,6 @@
// Some inputs and fields are only used if there is a notification center.
if (UseRichNotifications()) {
-
-#if defined(ENABLE_MESSAGE_CENTER)
double creation_time = static_cast<double>(GetCreationTime());
int priority = GetPriority();
int notification_count = GetNotificationCount();
@@ -162,8 +154,6 @@
delegate);
notification_manager->Add(ui_notification, profile);
-#endif // ENABLE_MESSAGE_CENTER
-
} else {
Notification ui_notification(GetOriginUrl(),
@@ -339,7 +329,6 @@
return kUndefinedPriority;
int protobuf_priority = specifics_.coalesced_notification().priority();
-#if defined(ENABLE_MESSAGE_CENTER)
// Convert the prioroty to the scheme used by the notification center.
if (protobuf_priority ==
sync_pb::CoalescedSyncedNotification_Priority_LOW) {
@@ -358,11 +347,6 @@
protobuf_priority);
return kUndefinedPriority;
}
-
-#else // ENABLE_MESSAGE_CENTER
- return protobuf_priority;
-
-#endif // ENABLE_MESSAGE_CENTER
}
int SyncedNotification::GetNotificationCount() const {
diff --git a/chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc b/chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc
index 3ccd4c2..87810cc 100644
--- a/chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc
+++ b/chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc
@@ -13,10 +13,8 @@
#include "sync/protocol/sync.pb.h"
#include "sync/protocol/synced_notification_specifics.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
-#if defined(ENABLE_MESSAGE_CENTER)
#include "ui/message_center/message_center_util.h"
#include "ui/message_center/notification_types.h"
-#endif // ENABLE_MESSAGE_CENTER
using syncer::SyncData;
using notifier::SyncedNotification;
@@ -28,19 +26,11 @@
const uint64 kFakeCreationTime = 42;
const int kProtobufPriority = static_cast<int>(
sync_pb::CoalescedSyncedNotification_Priority_LOW);
-#if defined (ENABLE_MESSAGE_CENTER)
const int kNotificationPriority = static_cast<int>(
message_center::LOW_PRIORITY);
-#else // ENABLE_MESSAGE_CENTER
-const int kNotificationPriority = 1;
-#endif // ENABLE_MESSAGE_CENTER
bool UseRichNotifications() {
-#if defined(ENABLE_MESSAGE_CENTER)
return message_center::IsRichNotificationEnabled();
-#else // ENABLE_MESSAGE_CENTER
- return false;
-#endif // ENABLE_MESSAGE_CENTER
}
const char kTitle1[] = "New appointment at 2:15";
@@ -572,8 +562,6 @@
if (!UseRichNotifications())
return;
-#if defined(ENABLE_MESSAGE_CENTER)
-
StubNotificationUIManager notification_manager;
// Call the method under test using the pre-populated data.
@@ -635,8 +623,6 @@
<< "Expected: " << expected_fields
<< ", but actual: " << *actual_fields;
-#endif // ENABLE_MESSAGE_CENTER
-
}
// TODO(petewil): Add a test for a notification being read and or deleted.
diff --git a/chrome/browser/task_manager/task_manager_notification_browsertest.cc b/chrome/browser/task_manager/task_manager_notification_browsertest.cc
index 73f9657..eb51693 100644
--- a/chrome/browser/task_manager/task_manager_notification_browsertest.cc
+++ b/chrome/browser/task_manager/task_manager_notification_browsertest.cc
@@ -19,10 +19,7 @@
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/common/content_switches.h"
#include "testing/gtest/include/gtest/gtest.h"
-
-#if !defined(ENABLE_MESSAGE_CENTER)
-// These tests do not apply with Message Center platforms
-// where notifications do not instantiate a new renderer.
+#include "ui/message_center/message_center_util.h"
class TaskManagerNotificationBrowserTest : public ExtensionBrowserTest {
public:
@@ -48,6 +45,11 @@
#endif
IN_PROC_BROWSER_TEST_F(TaskManagerNotificationBrowserTest,
MAYBE_NoticeNotificationChanges) {
+ // These tests do not apply with Message Center platforms
+ // where notifications do not instantiate a new renderer.
+ if (message_center::IsRichNotificationEnabled())
+ return;
+
EXPECT_EQ(0, model()->ResourceCount());
// Show the task manager.
@@ -79,5 +81,3 @@
notifications->CancelById(n2.notification_id());
TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
}
-
-#endif // !ENABLE_MESSAGE_CENTER