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