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