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 "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" 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 const Extension* extension = LoadAndLaunchPlatformApp(app_path, "launched"); 22 ASSERT_TRUE(extension); 23 24 content::WindowedNotificationObserver event_page_suspended( 25 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, 26 content::NotificationService::AllSources()); 27 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); 33 34 // Verify that the event page is destroyed. 35 event_page_suspended.Wait(); 36 } 37 }; 38 39 } // namespace 40 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. IN_PROC_BROWSER_TEST_F(AppEventPageTest,OnSuspendNoApiUse)43IN_PROC_BROWSER_TEST_F(AppEventPageTest, OnSuspendNoApiUse) { 44 TestUnloadEventPage("event_page/suspend_simple"); 45 } 46 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 IN_PROC_BROWSER_TEST_F(AppEventPageTest,OnSuspendUseStorageApi)50IN_PROC_BROWSER_TEST_F(AppEventPageTest, OnSuspendUseStorageApi) { 51 TestUnloadEventPage("event_page/suspend_storage_api"); 52 } 53