| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/extension_apitest.h" | 5 #include "chrome/browser/extensions/extension_apitest.h" |
| 6 | 6 |
| 7 #include "chrome/browser/notifications/desktop_notification_service.h" | 7 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 8 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 8 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 | |
| 12 #if defined(ENABLE_MESSAGE_CENTER) | |
| 13 | |
| 14 #include "chrome/browser/extensions/extension_process_manager.h" | 11 #include "chrome/browser/extensions/extension_process_manager.h" |
| 15 #include "chrome/browser/extensions/lazy_background_page_test_util.h" | 12 #include "chrome/browser/extensions/lazy_background_page_test_util.h" |
| 16 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
| 18 #include "ui/message_center/message_center_switches.h" | 15 #include "ui/message_center/message_center_switches.h" |
| 19 #include "ui/message_center/message_center_util.h" | 16 #include "ui/message_center/message_center_util.h" |
| 20 | 17 |
| 21 class RichWebkitNotificationTest : public ExtensionApiTest { | 18 class NotificationIdleTest : public ExtensionApiTest { |
| 22 protected: | 19 protected: |
| 23 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 20 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 24 ExtensionApiTest::SetUpCommandLine(command_line); | 21 ExtensionApiTest::SetUpCommandLine(command_line); |
| 25 command_line->AppendSwitch( | |
| 26 message_center::switches::kEnableRichNotifications); | |
| 27 } | |
| 28 }; | |
| 29 | |
| 30 class DisabledRichWebkitNotificationTest : public ExtensionApiTest { | |
| 31 protected: | |
| 32 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
| 33 ExtensionApiTest::SetUpCommandLine(command_line); | |
| 34 command_line->AppendSwitch( | |
| 35 message_center::switches::kDisableRichNotifications); | |
| 36 } | |
| 37 }; | |
| 38 | |
| 39 class NotificationIdleTest : public RichWebkitNotificationTest { | |
| 40 protected: | |
| 41 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
| 42 RichWebkitNotificationTest::SetUpCommandLine(command_line); | |
| 43 | 22 |
| 44 command_line->AppendSwitchASCII(switches::kEventPageIdleTime, "1"); | 23 command_line->AppendSwitchASCII(switches::kEventPageIdleTime, "1"); |
| 45 command_line->AppendSwitchASCII(switches::kEventPageSuspendingTime, "1"); | 24 command_line->AppendSwitchASCII(switches::kEventPageSuspendingTime, "1"); |
| 46 } | 25 } |
| 47 | 26 |
| 48 const extensions::Extension* LoadExtensionAndWait( | 27 const extensions::Extension* LoadExtensionAndWait( |
| 49 const std::string& test_name) { | 28 const std::string& test_name) { |
| 50 LazyBackgroundObserver page_complete; | 29 LazyBackgroundObserver page_complete; |
| 51 base::FilePath extdir = test_data_dir_.AppendASCII(test_name); | 30 base::FilePath extdir = test_data_dir_.AppendASCII(test_name); |
| 52 const extensions::Extension* extension = LoadExtension(extdir); | 31 const extensions::Extension* extension = LoadExtension(extdir); |
| 53 if (extension) | 32 if (extension) |
| 54 page_complete.Wait(); | 33 page_complete.Wait(); |
| 55 return extension; | 34 return extension; |
| 56 } | 35 } |
| 57 }; | 36 }; |
| 58 | 37 |
| 59 #endif | |
| 60 | |
| 61 // TODO(kbr): remove: http://crbug.com/222296 | 38 // TODO(kbr): remove: http://crbug.com/222296 |
| 62 #if defined(OS_MACOSX) | 39 #if defined(OS_MACOSX) |
| 63 #import "base/mac/mac_util.h" | 40 #import "base/mac/mac_util.h" |
| 64 #endif | 41 #endif |
| 65 | 42 |
| 66 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, NotificationsNoPermission) { | 43 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, NotificationsNoPermission) { |
| 67 #if defined(OS_LINUX) && defined(TOOLKIT_VIEWS) | |
| 68 // Notifications not supported on linux/views yet. | |
| 69 #else | |
| 70 ASSERT_TRUE(RunExtensionTest("notifications/has_not_permission")) << message_; | 44 ASSERT_TRUE(RunExtensionTest("notifications/has_not_permission")) << message_; |
| 71 #endif | |
| 72 } | 45 } |
| 73 | 46 |
| 74 #if defined(ENABLE_MESSAGE_CENTER) | 47 // This test verifies that on RichNotification-enabled platforms HTML |
| 75 IN_PROC_BROWSER_TEST_F(RichWebkitNotificationTest, NoHTMLNotifications) { | 48 // notificaitons are disabled. |
| 49 #if defined(RUN_MESSAGE_CENTER_TESTS) |
| 50 #define MAYBE_NoHTMLNotifications NoHTMLNotifications |
| 51 #else |
| 52 #define MAYBE_NoHTMLNotifications DISABLED_NoHTMLNotifications |
| 53 #endif |
| 54 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_NoHTMLNotifications) { |
| 55 ASSERT_TRUE(message_center::IsRichNotificationEnabled()); |
| 76 ASSERT_TRUE(RunExtensionTest("notifications/no_html")) << message_; | 56 ASSERT_TRUE(RunExtensionTest("notifications/no_html")) << message_; |
| 77 } | 57 } |
| 78 | 58 |
| 79 #if !defined(OS_CHROMEOS) | 59 // This test verifies that on platforms other then RichNotification-enabled |
| 80 // HTML notifications fail on ChromeOS whether or not rich notifications | 60 // HTML notificaitons are enabled. |
| 81 // are enabled. | 61 #if defined(RUN_MESSAGE_CENTER_TESTS) |
| 82 IN_PROC_BROWSER_TEST_F(DisabledRichWebkitNotificationTest, | 62 #define MAYBE_HasHTMLNotificationsAndManifestPermission \ |
| 83 HasHTMLNotifications) { | 63 DISABLED_HasHTMLNotificationsAndManifestPermission |
| 64 #else |
| 65 #define MAYBE_HasHTMLNotificationsAndManifestPermission \ |
| 66 HasHTMLNotificationsAndManifestPermission |
| 67 #endif |
| 68 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, |
| 69 MAYBE_HasHTMLNotificationsAndManifestPermission) { |
| 84 ASSERT_FALSE(message_center::IsRichNotificationEnabled()); | 70 ASSERT_FALSE(message_center::IsRichNotificationEnabled()); |
| 85 ASSERT_TRUE(RunExtensionTest("notifications/has_permission_manifest")) | 71 ASSERT_TRUE(RunExtensionTest("notifications/has_permission_manifest")) |
| 86 << message_; | 72 << message_; |
| 87 } | 73 } |
| 88 #endif | |
| 89 | |
| 90 #elif !defined(OS_LINUX) || !defined(TOOLKIT_VIEWS) | |
| 91 // Notifications not supported on linux/views yet. | |
| 92 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, | |
| 93 NotificationsHasPermissionManifest) { | |
| 94 ASSERT_TRUE(RunExtensionTest("notifications/has_permission_manifest")) | |
| 95 << message_; | |
| 96 } | |
| 97 #endif | |
| 98 | 74 |
| 99 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, NotificationsHasPermission) { | 75 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, NotificationsHasPermission) { |
| 100 #if defined(OS_LINUX) && defined(TOOLKIT_VIEWS) | |
| 101 // Notifications not supported on linux/views yet. | |
| 102 #else | |
| 103 | |
| 104 #if defined(OS_MACOSX) | 76 #if defined(OS_MACOSX) |
| 105 // TODO(kbr): re-enable: http://crbug.com/222296 | 77 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 106 if (base::mac::IsOSMountainLionOrLater()) | 78 if (base::mac::IsOSMountainLionOrLater()) |
| 107 return; | 79 return; |
| 108 #endif | 80 #endif |
| 109 | 81 |
| 110 DesktopNotificationServiceFactory::GetForProfile(browser()->profile()) | 82 DesktopNotificationServiceFactory::GetForProfile(browser()->profile()) |
| 111 ->GrantPermission(GURL( | 83 ->GrantPermission(GURL( |
| 112 "chrome-extension://peoadpeiejnhkmpaakpnompolbglelel")); | 84 "chrome-extension://peoadpeiejnhkmpaakpnompolbglelel")); |
| 113 ASSERT_TRUE(RunExtensionTest("notifications/has_permission_prefs")) | 85 ASSERT_TRUE(RunExtensionTest("notifications/has_permission_prefs")) |
| 114 << message_; | 86 << message_; |
| 115 #endif | |
| 116 } | 87 } |
| 117 | 88 |
| 118 #if defined(ENABLE_MESSAGE_CENTER) | 89 // MessaceCenter-specific test. |
| 119 IN_PROC_BROWSER_TEST_F(NotificationIdleTest, NotificationsAllowUnload) { | 90 #if defined(RUN_MESSAGE_CENTER_TESTS) |
| 91 #define MAYBE_NotificationsAllowUnload NotificationsAllowUnload |
| 92 #else |
| 93 #define MAYBE_NotificationsAllowUnload DISABLED_NotificationsAllowUnload |
| 94 #endif |
| 95 |
| 96 IN_PROC_BROWSER_TEST_F(NotificationIdleTest, MAYBE_NotificationsAllowUnload) { |
| 120 const extensions::Extension* extension = | 97 const extensions::Extension* extension = |
| 121 LoadExtensionAndWait("notifications/api/unload"); | 98 LoadExtensionAndWait("notifications/api/unload"); |
| 122 ASSERT_TRUE(extension) << message_; | 99 ASSERT_TRUE(extension) << message_; |
| 123 | 100 |
| 124 // Lazy Background Page has been shut down. | 101 // Lazy Background Page has been shut down. |
| 125 ExtensionProcessManager* pm = | 102 ExtensionProcessManager* pm = |
| 126 extensions::ExtensionSystem::Get(profile())->process_manager(); | 103 extensions::ExtensionSystem::Get(profile())->process_manager(); |
| 127 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); | 104 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); |
| 128 } | 105 } |
| 129 #endif | |
| OLD | NEW |