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 "content/public/browser/notification_service.h"
7 #include "content/public/test/browser_test.h"
8 #include "content/public/test/test_utils.h"
9 #include "extensions/browser/notification_types.h"
10 #include "extensions/test/extension_test_message_listener.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 const Extension
* extension
= LoadAndLaunchPlatformApp(app_path
, "launched");
22 ASSERT_TRUE(extension
);
24 content::WindowedNotificationObserver
event_page_suspended(
25 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED
,
26 content::NotificationService::AllSources());
28 // Close the app window.
29 EXPECT_EQ(1U, GetAppWindowCount());
30 extensions::AppWindow
* app_window
= GetFirstAppWindow();
31 ASSERT_TRUE(app_window
);
32 CloseAppWindow(app_window
);
34 // Verify that the event page is destroyed.
35 event_page_suspended
.Wait();
41 // Tests that an app's event page will eventually be unloaded. The onSuspend
42 // event handler of this app does not make any API calls.
43 IN_PROC_BROWSER_TEST_F(AppEventPageTest
, OnSuspendNoApiUse
) {
44 TestUnloadEventPage("event_page/suspend_simple");
47 // Tests that an app's event page will eventually be unloaded. The onSuspend
48 // event handler of this app calls a chrome.storage API function.
49 // See: http://crbug.com/296834
50 IN_PROC_BROWSER_TEST_F(AppEventPageTest
, OnSuspendUseStorageApi
) {
51 TestUnloadEventPage("event_page/suspend_storage_api");