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.
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"
12 using extensions::Extension
;
13 using extensions::PlatformAppBrowserTest
;
17 class AppEventPageTest
: public PlatformAppBrowserTest
{
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());
26 content::WindowedNotificationObserver
event_page_suspended(
27 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED
,
28 content::NotificationService::AllSources());
30 // Close the app window.
31 EXPECT_EQ(1U, GetAppWindowCount());
32 apps::AppWindow
* app_window
= GetFirstAppWindow();
33 ASSERT_TRUE(app_window
);
34 CloseAppWindow(app_window
);
36 // Verify that the event page is destroyed.
37 event_page_suspended
.Wait();
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.
45 IN_PROC_BROWSER_TEST_F(AppEventPageTest
, OnSuspendNoApiUse
) {
46 TestUnloadEventPage("event_page/suspend_simple");
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
52 IN_PROC_BROWSER_TEST_F(AppEventPageTest
, OnSuspendUseStorageApi
) {
53 TestUnloadEventPage("event_page/suspend_storage_api");