Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / extensions / notifications_apitest.cc
blob508840b77a67226ca0caa6fb9e7ef7fed466c677
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.
5 #include "chrome/browser/extensions/extension_apitest.h"
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"
18 class NotificationIdleTest : public ExtensionApiTest {
19 protected:
20 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
21 ExtensionApiTest::SetUpCommandLine(command_line);
23 command_line->AppendSwitchASCII(
24 extensions::switches::kEventPageIdleTime, "1000");
25 command_line->AppendSwitchASCII(
26 extensions::switches::kEventPageSuspendingTime, "1000");
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;
40 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, NotificationsNoPermission) {
41 ASSERT_TRUE(RunExtensionTest("notifications/has_not_permission")) << message_;
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_;
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_;
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
71 IN_PROC_BROWSER_TEST_F(NotificationIdleTest, MAYBE_NotificationsAllowUnload) {
72 const extensions::Extension* extension =
73 LoadExtensionAndWait("notifications/api/unload");
74 ASSERT_TRUE(extension) << message_;
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()));