Make default apps cache multiprofile friendly
[chromium-blink-merge.git] / chrome / browser / extensions / notifications_apitest.cc
blob0fd58123d4dee5f6cea30708f4880b8b779e3e74
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/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"
18 class NotificationIdleTest : public ExtensionApiTest {
19 protected:
20 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
21 ExtensionApiTest::SetUpCommandLine(command_line);
23 command_line->AppendSwitchASCII(switches::kEventPageIdleTime, "1");
24 command_line->AppendSwitchASCII(switches::kEventPageSuspendingTime, "1");
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;
38 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, NotificationsNoPermission) {
39 ASSERT_TRUE(RunExtensionTest("notifications/has_not_permission")) << message_;
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
49 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_NoHTMLNotifications) {
50 ASSERT_TRUE(message_center::IsRichNotificationEnabled());
51 ASSERT_TRUE(RunExtensionTest("notifications/no_html")) << message_;
54 IN_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_;
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
69 IN_PROC_BROWSER_TEST_F(NotificationIdleTest, MAYBE_NotificationsAllowUnload) {
70 const extensions::Extension* extension =
71 LoadExtensionAndWait("notifications/api/unload");
72 ASSERT_TRUE(extension) << message_;
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_));