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 3// found in the LICENSE file. 4 5#include "chrome/browser/extensions/extension_apitest.h" 6 7#include "chrome/browser/notifications/desktop_notification_service.h" 8#include "chrome/browser/notifications/desktop_notification_service_factory.h" 9#include "chrome/browser/profiles/profile.h" 10#include "chrome/browser/ui/browser.h" 11#include "chrome/browser/extensions/extension_process_manager.h" 12#include "chrome/browser/extensions/lazy_background_page_test_util.h" 13#include "chrome/common/chrome_switches.h" 14#include "chrome/common/extensions/extension.h" 15#include "ui/message_center/message_center_switches.h" 16#include "ui/message_center/message_center_util.h" 17 18class NotificationIdleTest : public ExtensionApiTest { 19 protected: 20 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 21 ExtensionApiTest::SetUpCommandLine(command_line); 22 23 command_line->AppendSwitchASCII(switches::kEventPageIdleTime, "1"); 24 command_line->AppendSwitchASCII(switches::kEventPageSuspendingTime, "1"); 25 } 26 27 const extensions::Extension* LoadExtensionAndWait( 28 const std::string& test_name) { 29 LazyBackgroundObserver page_complete; 30 base::FilePath extdir = test_data_dir_.AppendASCII(test_name); 31 const extensions::Extension* extension = LoadExtension(extdir); 32 if (extension) 33 page_complete.Wait(); 34 return extension; 35 } 36}; 37 38IN_PROC_BROWSER_TEST_F(ExtensionApiTest, NotificationsNoPermission) { 39 ASSERT_TRUE(RunExtensionTest("notifications/has_not_permission")) << message_; 40} 41 42// This test verifies that on RichNotification-enabled platforms HTML 43// notificaitons are disabled. 44#if defined(RUN_MESSAGE_CENTER_TESTS) 45#define MAYBE_NoHTMLNotifications NoHTMLNotifications 46#else 47#define MAYBE_NoHTMLNotifications DISABLED_NoHTMLNotifications 48#endif 49IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_NoHTMLNotifications) { 50 ASSERT_TRUE(message_center::IsRichNotificationEnabled()); 51 ASSERT_TRUE(RunExtensionTest("notifications/no_html")) << message_; 52} 53 54IN_PROC_BROWSER_TEST_F(ExtensionApiTest, NotificationsHasPermission) { 55 DesktopNotificationServiceFactory::GetForProfile(browser()->profile()) 56 ->GrantPermission(GURL( 57 "chrome-extension://peoadpeiejnhkmpaakpnompolbglelel")); 58 ASSERT_TRUE(RunExtensionTest("notifications/has_permission_prefs")) 59 << message_; 60} 61 62 // MessaceCenter-specific test. 63#if defined(RUN_MESSAGE_CENTER_TESTS) 64#define MAYBE_NotificationsAllowUnload NotificationsAllowUnload 65#else 66#define MAYBE_NotificationsAllowUnload DISABLED_NotificationsAllowUnload 67#endif 68 69IN_PROC_BROWSER_TEST_F(NotificationIdleTest, MAYBE_NotificationsAllowUnload) { 70 const extensions::Extension* extension = 71 LoadExtensionAndWait("notifications/api/unload"); 72 ASSERT_TRUE(extension) << message_; 73 74 // Lazy Background Page has been shut down. 75 ExtensionProcessManager* pm = 76 extensions::ExtensionSystem::Get(profile())->process_manager(); 77 EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_)); 78} 79