summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/about_flags.cc7
-rw-r--r--chrome/browser/browser_process.h4
-rw-r--r--chrome/browser/browser_process_impl.cc11
-rw-r--r--chrome/browser/browser_process_impl.h2
-rw-r--r--chrome/browser/chrome_content_browser_client.cc7
-rw-r--r--chrome/browser/extensions/api/notifications/notifications_api.cc55
-rw-r--r--chrome/browser/extensions/api/notifications/notifications_apitest.cc16
-rw-r--r--chrome/browser/extensions/extension_crash_recovery_browsertest.cc118
-rw-r--r--chrome/browser/extensions/notifications_apitest.cc80
-rw-r--r--chrome/browser/notifications/desktop_notification_service.cc23
-rw-r--r--chrome/browser/notifications/desktop_notifications_unittest.cc7
-rw-r--r--chrome/browser/notifications/message_center_notifications_browsertest.cc38
-rw-r--r--chrome/browser/notifications/notification.cc2
-rw-r--r--chrome/browser/notifications/notification_browsertest.cc209
-rw-r--r--chrome/browser/notifications/notification_ui_manager.cc12
-rw-r--r--chrome/browser/notifications/notification_ui_manager_mac.mm7
-rw-r--r--chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc5
-rw-r--r--chrome/browser/notifications/sync_notifier/synced_notification.cc16
-rw-r--r--chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc14
-rw-r--r--chrome/browser/task_manager/task_manager_notification_browsertest.cc12
-rw-r--r--chrome/chrome_browser.gypi13
-rw-r--r--chrome/chrome_browser_ui.gypi6
-rw-r--r--chrome/chrome_tests.gypi10
-rw-r--r--chrome/test/base/testing_browser_process.cc7
-rw-r--r--chrome/test/base/testing_browser_process.h2
-rw-r--r--chrome/test/base/view_event_test_base.cc9
26 files changed, 435 insertions, 257 deletions
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
index a6685b9..3ed9a38 100644
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -32,9 +32,12 @@
#include "ui/gfx/switches.h"
#include "ui/gl/gl_switches.h"
#include "ui/keyboard/keyboard_switches.h"
-#include "ui/message_center/message_center_switches.h"
#include "ui/surface/surface_switches.h"
+#if defined(ENABLE_MESSAGE_CENTER)
+#include "ui/message_center/message_center_switches.h"
+#endif
+
#if defined(USE_ASH)
#include "ash/ash_switches.h"
#endif
@@ -1294,6 +1297,7 @@ const Experiment kExperiments[] = {
ENABLE_DISABLE_VALUE_TYPE(switches::kEnableTouchEditing,
switches::kDisableTouchEditing)
},
+#if defined(ENABLE_MESSAGE_CENTER)
{
"enable-rich-notifications",
IDS_FLAGS_ENABLE_RICH_NOTIFICATIONS_NAME,
@@ -1303,6 +1307,7 @@ const Experiment kExperiments[] = {
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 22b347c..0b4c674 100644
--- a/chrome/browser/browser_process.h
+++ b/chrome/browser/browser_process.h
@@ -54,9 +54,11 @@ namespace extensions {
class EventRouterForwarder;
}
+#if defined(ENABLE_MESSAGE_CENTER)
namespace message_center {
class MessageCenter;
}
+#endif
namespace net {
class URLRequestContextGetter;
@@ -112,8 +114,10 @@ class BrowserProcess {
// 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 d65c37a..dca205e 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -89,7 +89,6 @@
#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"
@@ -97,6 +96,10 @@
#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"
@@ -200,7 +203,9 @@ BrowserProcessImpl::BrowserProcessImpl(
extension_event_router_forwarder_ = new extensions::EventRouterForwarder;
ExtensionRendererState::GetInstance()->Init();
+#if defined(ENABLE_MESSAGE_CENTER)
message_center::MessageCenter::Initialize();
+#endif
}
BrowserProcessImpl::~BrowserProcessImpl() {
@@ -257,7 +262,9 @@ void BrowserProcessImpl::StartTearDown() {
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
@@ -471,10 +478,12 @@ NotificationUIManager* BrowserProcessImpl::notification_ui_manager() {
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 7010aa3..b1b8577 100644
--- a/chrome/browser/browser_process_impl.h
+++ b/chrome/browser/browser_process_impl.h
@@ -87,7 +87,9 @@ class BrowserProcessImpl : public BrowserProcess,
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 6f75abf..cec8396 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -128,7 +128,6 @@
#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"
@@ -163,6 +162,10 @@
#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
@@ -1224,8 +1227,10 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
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 e45df6f..19a6626 100644
--- a/chrome/browser/extensions/api/notifications/notifications_api.cc
+++ b/chrome/browser/extensions/api/notifications/notifications_api.cc
@@ -21,7 +21,6 @@
#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 {
@@ -142,35 +141,38 @@ NotificationsApiFunction::NotificationsApiFunction() {
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) {
- // 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());
-
- 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());
- return;
- }
+ 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());
+
+ 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) {
message_center::NotificationType type =
MapApiTemplateTypeToType(options->type);
GURL icon_url(UTF8ToUTF16(options->icon_url));
@@ -249,6 +251,7 @@ void NotificationsApiFunction::CreateNotification(
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 e84c10a..a251db9 100644
--- a/chrome/browser/extensions/api/notifications/notifications_apitest.cc
+++ b/chrome/browser/extensions/api/notifications/notifications_apitest.cc
@@ -274,15 +274,12 @@ IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestCSP) {
ASSERT_TRUE(RunExtensionTest("notifications/api/csp")) << message_;
}
-// MessaceCenter-specific test.
-#if defined(RUN_MESSAGE_CENTER_TESTS)
-#define MAYBE_TestByUser TestByUser
-#else
-#define MAYBE_TestByUser DISABLED_TestByUser
-#endif
+#ifdef ENABLE_MESSAGE_CENTER
+#if !defined(OS_WIN) || !defined(USE_ASH)
-IN_PROC_BROWSER_TEST_F(NotificationsApiTest, MAYBE_TestByUser) {
- ASSERT_TRUE(message_center::IsRichNotificationEnabled());
+IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestByUser) {
+ if (!message_center::IsRichNotificationEnabled())
+ return;
const extensions::Extension* extension =
LoadExtensionAndWait("notifications/api/by_user");
@@ -304,3 +301,6 @@ IN_PROC_BROWSER_TEST_F(NotificationsApiTest, MAYBE_TestByUser) {
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 502b43d..287aea9 100644
--- a/chrome/browser/extensions/extension_crash_recovery_browsertest.cc
+++ b/chrome/browser/extensions/extension_crash_recovery_browsertest.cc
@@ -25,10 +25,13 @@
#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;
@@ -114,64 +117,91 @@ class ExtensionCrashRecoveryTestBase : public ExtensionBrowserTest {
};
-class MAYBE_ExtensionCrashRecoveryTest
+// TODO(rsesek): Implement and enable these tests. http://crbug.com/179904
+#if defined(ENABLE_MESSAGE_CENTER) && !defined(OS_MACOSX)
+
+class MessageCenterExtensionCrashRecoveryTest
: 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 {
- 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();
- }
+ 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);
WaitForExtensionLoad();
}
virtual void CancelNotification(size_t index) OVERRIDE {
- 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));
- }
+ 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()));
}
virtual size_t CountBalloons() OVERRIDE {
- if (message_center::IsRichNotificationEnabled())
- return message_center::MessageCenter::Get()->NotificationCount();
+ message_center::MessageCenter* message_center =
+ message_center::MessageCenter::Get();
+ return message_center->NotificationCount();
+ }
+};
+
+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();
+ }
- return BalloonNotificationUIManager::GetInstanceForTesting()->
- balloon_collection()->GetActiveBalloons().size();
+ 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));
}
-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;
- }
+ 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 858c45e..a1a8b39 100644
--- a/chrome/browser/extensions/notifications_apitest.cc
+++ b/chrome/browser/extensions/notifications_apitest.cc
@@ -8,6 +8,9 @@
#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"
@@ -15,10 +18,28 @@
#include "ui/message_center/message_center_switches.h"
#include "ui/message_center/message_center_util.h"
-class NotificationIdleTest : public ExtensionApiTest {
+class RichWebkitNotificationTest : 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");
@@ -35,44 +56,51 @@ class NotificationIdleTest : public ExtensionApiTest {
}
};
+#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
}
-// 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());
+#if defined(ENABLE_MESSAGE_CENTER)
+IN_PROC_BROWSER_TEST_F(RichWebkitNotificationTest, NoHTMLNotifications) {
ASSERT_TRUE(RunExtensionTest("notifications/no_html")) << message_;
}
-// 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
+#if !defined(OS_CHROMEOS)
+// HTML notifications fail on ChromeOS whether or not rich notifications
+// are enabled.
+IN_PROC_BROWSER_TEST_F(DisabledRichWebkitNotificationTest,
+ HasHTMLNotifications) {
+ 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,
- MAYBE_HasHTMLNotificationsAndManifestPermission) {
- ASSERT_FALSE(message_center::IsRichNotificationEnabled());
+ 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())
@@ -84,16 +112,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, NotificationsHasPermission) {
"chrome-extension://peoadpeiejnhkmpaakpnompolbglelel"));
ASSERT_TRUE(RunExtensionTest("notifications/has_permission_prefs"))
<< message_;
-}
-
- // 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) {
+#if defined(ENABLE_MESSAGE_CENTER)
+IN_PROC_BROWSER_TEST_F(NotificationIdleTest, NotificationsAllowUnload) {
const extensions::Extension* extension =
LoadExtensionAndWait("notifications/api/unload");
ASSERT_TRUE(extension) << message_;
@@ -103,3 +126,4 @@ IN_PROC_BROWSER_TEST_F(NotificationIdleTest, MAYBE_NotificationsAllowUnload) {
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 54b3d05..e2127ea 100644
--- a/chrome/browser/notifications/desktop_notification_service.cc
+++ b/chrome/browser/notifications/desktop_notification_service.cc
@@ -43,7 +43,6 @@
#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"
@@ -58,6 +57,15 @@ const ContentSetting kDefaultSetting = CONTENT_SETTING_ASK;
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);
@@ -231,10 +239,12 @@ bool NotificationPermissionInfoBarDelegate::Cancel() {
// 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
@@ -297,7 +307,7 @@ std::string DesktopNotificationService::AddNotification(
const string16& replace_id,
NotificationDelegate* delegate,
Profile* profile) {
- if (message_center::IsRichNotificationEnabled()) {
+ if (UsesTextNotifications()) {
// For message center create a non-HTML notification with |icon_url|.
Notification notification(origin_url, icon_url, title, message,
WebKit::WebTextDirectionDefault,
@@ -325,7 +335,7 @@ std::string DesktopNotificationService::AddIconNotification(
NotificationDelegate* delegate,
Profile* profile) {
- if (message_center::IsRichNotificationEnabled()) {
+ if (UsesTextNotifications()) {
// For message center create a non-HTML notification with |icon|.
Notification notification(origin_url, icon, title, message,
WebKit::WebTextDirectionDefault,
@@ -352,6 +362,7 @@ DesktopNotificationService::DesktopNotificationService(
NotificationUIManager* ui_manager)
: profile_(profile),
ui_manager_(ui_manager) {
+#if defined(ENABLE_MESSAGE_CENTER)
OnDisabledExtensionIdsChanged();
OnDisabledSystemComponentIdsChanged();
disabled_extension_id_pref_.Init(
@@ -366,9 +377,13 @@ DesktopNotificationService::DesktopNotificationService(
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) {
@@ -577,6 +592,7 @@ void DesktopNotificationService::OnDisabledExtensionIdsChanged() {
&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)) ==
@@ -600,6 +616,7 @@ void DesktopNotificationService::OnDisabledSystemComponentIdsChanged() {
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 dbf7e1c..50caecc 100644
--- a/chrome/browser/notifications/desktop_notifications_unittest.cc
+++ b/chrome/browser/notifications/desktop_notifications_unittest.cc
@@ -15,7 +15,10 @@
#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"
@@ -113,9 +116,11 @@ void DesktopNotificationsTest::SetUp() {
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);
@@ -138,9 +143,11 @@ void DesktopNotificationsTest::TearDown() {
#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 71cc0a6..556eb5a 100644
--- a/chrome/browser/notifications/message_center_notifications_browsertest.cc
+++ b/chrome/browser/notifications/message_center_notifications_browsertest.cc
@@ -16,8 +16,10 @@
#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"
-#include "ui/message_center/message_center_util.h"
+#endif
class MessageCenterNotificationsTest : public InProcessBrowserTest {
public:
@@ -96,36 +98,19 @@ class MessageCenterNotificationsTest : public InProcessBrowserTest {
IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, RetrieveBaseParts) {
// Make sure comamnd-line switch has an effect.
- EXPECT_EQ(NotificationUIManager::DelegatesToMessageCenter(),
- message_center::IsRichNotificationEnabled());
+ EXPECT_TRUE(NotificationUIManager::DelegatesToMessageCenter());
EXPECT_TRUE(manager());
EXPECT_TRUE(message_center());
}
-// 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());
+IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, BasicAddCancel) {
manager()->Add(CreateTestNotification("hey"), profile());
EXPECT_EQ(1u, message_center()->NotificationCount());
manager()->CancelById("hey");
EXPECT_EQ(0u, message_center()->NotificationCount());
}
-// 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());
+IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, BasicDelegate) {
TestDelegate* delegate;
manager()->Add(CreateTestNotification("hey", &delegate), profile());
// Verify that delegate accumulated correct log of events.
@@ -136,16 +121,7 @@ IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, MAYBE_BasicDelegate) {
delegate->Release();
}
-// 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());
+IN_PROC_BROWSER_TEST_F(MessageCenterNotificationsTest, ButtonClickedDelegate) {
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 b45bf1e..1077b04 100644
--- a/chrome/browser/notifications/notification.cc
+++ b/chrome/browser/notifications/notification.cc
@@ -127,7 +127,9 @@ Notification& Notification::operator=(const Notification& notification) {
}
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 4a317965..f524d34 100644
--- a/chrome/browser/notifications/notification_browsertest.cc
+++ b/chrome/browser/notifications/notification_browsertest.cc
@@ -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 @@ enum InfobarAction {
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 @@ class MessageCenterChangeObserver
message_center::MessageCenter::Get()->RemoveObserver(this);
}
- // NotificationChangeObserver:
- virtual bool Wait() OVERRIDE {
+ bool Wait() {
if (notification_received_)
return true;
@@ -94,17 +97,15 @@ class MessageCenterChangeObserver
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 @@ class MessageCenterChangeObserver
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 @@ class NotificationBalloonChangeObserver
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 @@ class NotificationBalloonChangeObserver
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 @@ class NotificationBalloonChangeObserver
DISALLOW_COPY_AND_ASSIGN(NotificationBalloonChangeObserver);
};
+typedef NotificationBalloonChangeObserver NotificationChangeObserver;
+
+#endif // ENABLE_MESSAGE_CENTER
+
} // namespace
class NotificationsTest : public InProcessBrowserTest {
@@ -211,13 +217,15 @@ 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);
@@ -262,19 +270,12 @@ void NotificationsTest::SetUpInProcessBrowserTestFixture() {
}
int NotificationsTest::GetNotificationCount() {
- 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();
+#if ENABLE_MESSAGE_CENTER_TESTING
+ return message_center::MessageCenter::Get()->NotificationCount();
+#else
+ return BalloonNotificationUIManager::GetInstanceForTesting()->
+ balloon_collection()->GetActiveBalloons().size();
+#endif // ENABLE_MESSAGE_CENTER_TESTING
}
void NotificationsTest::CloseBrowserWindow(Browser* browser) {
@@ -289,6 +290,15 @@ 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();
@@ -300,14 +310,16 @@ void NotificationsTest::CrashNotification(Balloon* balloon) {
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 @@ std::string NotificationsTest::CreateNotification(
"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 @@ bool NotificationsTest::CancelNotification(
"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 @@ bool NotificationsTest::CancelNotification(
&result);
if (!success || result != "1")
return false;
- return observer->Wait();
+ return observer.Wait();
}
bool NotificationsTest::PerformActionOnInfobar(
@@ -530,20 +542,20 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) {
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 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCloseNotification) {
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 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateDenyCloseNotifications) {
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 @@ 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())
@@ -845,6 +855,7 @@ 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)
@@ -947,20 +958,20 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNotificationReplacement) {
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
}
diff --git a/chrome/browser/notifications/notification_ui_manager.cc b/chrome/browser/notifications/notification_ui_manager.cc
index 1b1d62dc..a562557 100644
--- a/chrome/browser/notifications/notification_ui_manager.cc
+++ b/chrome/browser/notifications/notification_ui_manager.cc
@@ -4,10 +4,13 @@
#include "chrome/browser/notifications/notification_ui_manager.h"
-#include "chrome/browser/browser_process.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
// static
bool NotificationUIManager::DelegatesToMessageCenter() {
@@ -16,17 +19,20 @@ bool NotificationUIManager::DelegatesToMessageCenter() {
// the message center.
#if defined(OS_CHROMEOS)
return true;
-#endif
+#elif defined(ENABLE_MESSAGE_CENTER)
return message_center::IsRichNotificationEnabled();
+#endif
+ return false;
}
#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 59339ed..7e1af00 100644
--- a/chrome/browser/notifications/notification_ui_manager_mac.mm
+++ b/chrome/browser/notifications/notification_ui_manager_mac.mm
@@ -7,11 +7,14 @@
#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;
@@ -97,12 +100,14 @@ NotificationUIManagerMac::ControllerNotification::~ControllerNotification() {
// 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 0fee623..bb7182b 100644
--- a/chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc
+++ b/chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc
@@ -18,7 +18,6 @@
#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;
@@ -95,8 +94,12 @@ const char kContainedMessage3[] = "Let's play starcraft tonight on the LAN.";
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 813846d..23883b2 100644
--- a/chrome/browser/notifications/sync_notifier/synced_notification.cc
+++ b/chrome/browser/notifications/sync_notifier/synced_notification.cc
@@ -13,14 +13,20 @@
#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
@@ -84,6 +90,8 @@ void SyncedNotification::Show(NotificationUIManager* notification_manager,
// 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();
@@ -154,6 +162,8 @@ void SyncedNotification::Show(NotificationUIManager* notification_manager,
delegate);
notification_manager->Add(ui_notification, profile);
+#endif // ENABLE_MESSAGE_CENTER
+
} else {
Notification ui_notification(GetOriginUrl(),
@@ -329,6 +339,7 @@ int SyncedNotification::GetPriority() const {
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) {
@@ -347,6 +358,11 @@ int SyncedNotification::GetPriority() const {
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 87810cc..3ccd4c2 100644
--- a/chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc
+++ b/chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc
@@ -13,8 +13,10 @@
#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;
@@ -26,11 +28,19 @@ namespace {
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";
@@ -562,6 +572,8 @@ TEST_F(SyncedNotificationTest, ShowTest) {
if (!UseRichNotifications())
return;
+#if defined(ENABLE_MESSAGE_CENTER)
+
StubNotificationUIManager notification_manager;
// Call the method under test using the pre-populated data.
@@ -623,6 +635,8 @@ TEST_F(SyncedNotificationTest, ShowTest) {
<< "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 eb51693..73f9657 100644
--- a/chrome/browser/task_manager/task_manager_notification_browsertest.cc
+++ b/chrome/browser/task_manager/task_manager_notification_browsertest.cc
@@ -19,7 +19,10 @@
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/common/content_switches.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/message_center/message_center_util.h"
+
+#if !defined(ENABLE_MESSAGE_CENTER)
+// These tests do not apply with Message Center platforms
+// where notifications do not instantiate a new renderer.
class TaskManagerNotificationBrowserTest : public ExtensionBrowserTest {
public:
@@ -45,11 +48,6 @@ class TaskManagerNotificationBrowserTest : public ExtensionBrowserTest {
#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.
@@ -81,3 +79,5 @@ IN_PROC_BROWSER_TEST_F(TaskManagerNotificationBrowserTest,
notifications->CancelById(n2.notification_id());
TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
}
+
+#endif // !ENABLE_MESSAGE_CENTER
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 2f289f5..5c585c2 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -54,7 +54,6 @@
'../third_party/zlib/zlib.gyp:minizip',
'../third_party/zlib/zlib.gyp:zlib',
'../ui/base/strings/ui_strings.gyp:ui_strings',
- '../ui/message_center/message_center.gyp:message_center',
'../ui/ui.gyp:shell_dialogs',
'../ui/ui.gyp:ui',
'../ui/ui.gyp:ui_resources',
@@ -2985,6 +2984,18 @@
'../ui/app_list/app_list.gyp:app_list',
]
}],
+ ['enable_message_center==1', {
+ 'dependencies': [
+ '../ui/message_center/message_center.gyp:message_center',
+ ],
+ }, { # enable_message_center==0
+ 'sources!': [
+ 'browser/notifications/message_center_notification_manager.cc',
+ 'browser/notifications/message_center_notification_manager.h',
+ 'browser/notifications/message_center_settings_controller.cc',
+ 'browser/notifications/message_center_settings_controller.h',
+ ],
+ }],
['enable_managed_users!=1', {
'sources/': [
['exclude', '^browser/managed_mode/'],
diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi
index 9c607df..8b4f310 100644
--- a/chrome/chrome_browser_ui.gypi
+++ b/chrome/chrome_browser_ui.gypi
@@ -48,7 +48,6 @@
'../third_party/libxml/libxml.gyp:libxml',
'../third_party/zlib/zlib.gyp:zlib',
'../ui/base/strings/ui_strings.gyp:ui_strings',
- '../ui/message_center/message_center.gyp:message_center',
'../ui/native_theme/native_theme.gyp:native_theme',
'../ui/snapshot/snapshot.gyp:snapshot',
'../ui/ui.gyp:ui',
@@ -2932,6 +2931,11 @@
['include', '^browser/ui/app_list/app_list_service_selector.cc'],
],
}],
+ ['enable_message_center==1', {
+ 'dependencies': [
+ '../ui/message_center/message_center.gyp:message_center',
+ ],
+ }],
],
},
],
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index eec3529..ae6c3de 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -478,6 +478,11 @@
'browser/ui/views/native_widget_win_interactive_uitest.cc',
],
}], # OS != "win"
+ ['enable_message_center==0', {
+ 'sources!': [
+ 'browser/ui/views/message_center/web_notification_tray_win_browsertest.cc',
+ ],
+ }], # enable_message_center
], # conditions
},
{
@@ -2030,6 +2035,11 @@
['exclude', '^browser/ui/app_list/'],
],
}],
+ ['enable_message_center==0', {
+ 'sources!': [
+ 'browser/notifications/message_center_notifications_browsertest.cc',
+ ],
+ }],
['enable_plugins==1', {
'dependencies': [
# Runtime dependency.
diff --git a/chrome/test/base/testing_browser_process.cc b/chrome/test/base/testing_browser_process.cc
index f40d38c..9418006 100644
--- a/chrome/test/base/testing_browser_process.cc
+++ b/chrome/test/base/testing_browser_process.cc
@@ -13,7 +13,6 @@
#include "content/public/browser/notification_service.h"
#include "net/url_request/url_request_context_getter.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/message_center/message_center.h"
#if !defined(OS_IOS)
#include "chrome/browser/media_galleries/media_file_system_registry.h"
@@ -37,6 +36,10 @@
#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
+
// static
TestingBrowserProcess* TestingBrowserProcess::GetGlobal() {
return static_cast<TestingBrowserProcess*>(g_browser_process);
@@ -197,9 +200,11 @@ NotificationUIManager* TestingBrowserProcess::notification_ui_manager() {
#endif
}
+#if defined(ENABLE_MESSAGE_CENTER)
message_center::MessageCenter* TestingBrowserProcess::message_center() {
return message_center::MessageCenter::Get();
}
+#endif
IntranetRedirectDetector* TestingBrowserProcess::intranet_redirect_detector() {
return NULL;
diff --git a/chrome/test/base/testing_browser_process.h b/chrome/test/base/testing_browser_process.h
index cc501fc..f5e589e 100644
--- a/chrome/test/base/testing_browser_process.h
+++ b/chrome/test/base/testing_browser_process.h
@@ -71,7 +71,9 @@ class TestingBrowserProcess : public BrowserProcess {
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 IntranetRedirectDetector* intranet_redirect_detector() OVERRIDE;
virtual AutomationProviderList* GetAutomationProviderList() OVERRIDE;
virtual void CreateDevToolsHttpProtocolHandler(
diff --git a/chrome/test/base/view_event_test_base.cc b/chrome/test/base/view_event_test_base.cc
index a23a9ca..d3d9c43 100644
--- a/chrome/test/base/view_event_test_base.cc
+++ b/chrome/test/base/view_event_test_base.cc
@@ -14,11 +14,14 @@
#include "content/public/browser/browser_thread.h"
#include "ui/base/ime/text_input_test_support.h"
#include "ui/compositor/test/compositor_test_support.h"
-#include "ui/message_center/message_center.h"
#include "ui/views/view.h"
#include "ui/views/widget/desktop_aura/desktop_screen.h"
#include "ui/views/widget/widget.h"
+#if defined(ENABLE_MESSAGE_CENTER)
+#include "ui/message_center/message_center.h"
+#endif
+
#if defined(USE_ASH)
#include "ash/shell.h"
#include "ash/test/test_shell_delegate.h"
@@ -109,9 +112,11 @@ void ViewEventTestBase::SetUp() {
gfx::Screen::SetScreenInstance(
gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen());
#else
+#if defined(ENABLE_MESSAGE_CENTER)
// Ash Shell can't just live on its own without a browser process, we need to
// also create the message center.
message_center::MessageCenter::Initialize();
+#endif
#if defined(OS_CHROMEOS)
chromeos::CrasAudioHandler::InitializeForTesting();
#endif
@@ -149,9 +154,11 @@ void ViewEventTestBase::TearDown() {
#if defined(OS_CHROMEOS)
chromeos::CrasAudioHandler::Shutdown();
#endif
+#if defined(ENABLE_MESSAGE_CENTER)
// Ash Shell can't just live on its own without a browser process, we need to
// also shut down the message center.
message_center::MessageCenter::Shutdown();
+#endif
aura::Env::DeleteInstance();
#endif
#elif defined(USE_AURA)