• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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/apps/app_browsertest_util.h"
6 #include "chrome/browser/chrome_notification_types.h"
7 #include "chrome/browser/extensions/extension_test_message_listener.h"
8 #include "content/public/browser/notification_service.h"
9 #include "content/public/test/browser_test.h"
10 #include "content/public/test/test_utils.h"
11 
12 using extensions::Extension;
13 using extensions::PlatformAppBrowserTest;
14 
15 namespace {
16 
17 class AppEventPageTest : public PlatformAppBrowserTest {
18  protected:
TestUnloadEventPage(const char * app_path)19   void TestUnloadEventPage(const char* app_path) {
20     // Load and launch the app.
21     ExtensionTestMessageListener launched_listener("launched", false);
22     const Extension* extension = LoadAndLaunchPlatformApp(app_path);
23     ASSERT_TRUE(extension);
24     ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
25 
26     content::WindowedNotificationObserver event_page_suspended(
27         chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
28         content::NotificationService::AllSources());
29 
30     // Close the app window.
31     EXPECT_EQ(1U, GetShellWindowCount());
32     apps::ShellWindow* shell_window = GetFirstShellWindow();
33     ASSERT_TRUE(shell_window);
34     CloseShellWindow(shell_window);
35 
36     // Verify that the event page is destroyed.
37     event_page_suspended.Wait();
38   }
39 };
40 
41 }  // namespace
42 
43 // Tests that an app's event page will eventually be unloaded. The onSuspend
44 // event handler of this app does not make any API calls.
IN_PROC_BROWSER_TEST_F(AppEventPageTest,OnSuspendNoApiUse)45 IN_PROC_BROWSER_TEST_F(AppEventPageTest, OnSuspendNoApiUse) {
46   TestUnloadEventPage("event_page/suspend_simple");
47 }
48 
49 // Tests that an app's event page will eventually be unloaded. The onSuspend
50 // event handler of this app calls a chrome.storage API function.
51 // See: http://crbug.com/296834
IN_PROC_BROWSER_TEST_F(AppEventPageTest,OnSuspendUseStorageApi)52 IN_PROC_BROWSER_TEST_F(AppEventPageTest, OnSuspendUseStorageApi) {
53   TestUnloadEventPage("event_page/suspend_storage_api");
54 }
55