Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / apps / event_page_browsertest.cc
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/extensions/extension_test_message_listener.h"
7 #include "content/public/browser/notification_service.h"
8 #include "content/public/test/browser_test.h"
9 #include "content/public/test/test_utils.h"
10 #include "extensions/browser/notification_types.h"
11
12 using extensions::Extension;
13 using extensions::PlatformAppBrowserTest;
14
15 namespace {
16
17 class AppEventPageTest : public PlatformAppBrowserTest {
18  protected:
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     apps::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.
43 IN_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
50 IN_PROC_BROWSER_TEST_F(AppEventPageTest, OnSuspendUseStorageApi) {
51   TestUnloadEventPage("event_page/suspend_storage_api");
52 }