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_profile_util.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "extensions/browser/process_manager.h"
12 #include "extensions/common/extension.h"
14 class NotificationIdleTest
: public ExtensionApiTest
{
16 void SetUpOnMainThread() override
{
17 ExtensionApiTest::SetUpOnMainThread();
19 extensions::ProcessManager::SetEventPageIdleTimeForTesting(1);
20 extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(1);
23 const extensions::Extension
* LoadExtensionAndWait(
24 const std::string
& test_name
) {
25 LazyBackgroundObserver page_complete
;
26 base::FilePath extdir
= test_data_dir_
.AppendASCII(test_name
);
27 const extensions::Extension
* extension
= LoadExtension(extdir
);
34 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, NotificationsNoPermission
) {
35 ASSERT_TRUE(RunExtensionTest("notifications/has_not_permission")) << message_
;
38 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, NotificationsHasPermission
) {
39 DesktopNotificationProfileUtil::GrantPermission(browser()->profile(),
40 GURL("chrome-extension://peoadpeiejnhkmpaakpnompolbglelel"));
42 ASSERT_TRUE(RunExtensionTest("notifications/has_permission_prefs"))
46 // MessaceCenter-specific test.
47 #if defined(RUN_MESSAGE_CENTER_TESTS)
48 #define MAYBE_NotificationsAllowUnload NotificationsAllowUnload
50 #define MAYBE_NotificationsAllowUnload DISABLED_NotificationsAllowUnload
53 IN_PROC_BROWSER_TEST_F(NotificationIdleTest
, MAYBE_NotificationsAllowUnload
) {
54 const extensions::Extension
* extension
=
55 LoadExtensionAndWait("notifications/api/unload");
56 ASSERT_TRUE(extension
) << message_
;
58 // Lazy Background Page has been shut down.
59 extensions::ProcessManager
* pm
= extensions::ProcessManager::Get(profile());
60 EXPECT_FALSE(pm
->GetBackgroundHostForExtension(last_loaded_extension_id()));