Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: chrome/browser/extensions/platform_app_browsertest_util.cc

Issue 11117011: Keep browser process alive while there are platform apps with background pages running. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Test Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/platform_app_browsertest_util.h" 5 #include "chrome/browser/extensions/platform_app_browsertest_util.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "chrome/browser/extensions/api/tabs/tabs.h" 9 #include "chrome/browser/extensions/api/tabs/tabs.h"
10 #include "chrome/browser/extensions/extension_function_test_utils.h" 10 #include "chrome/browser/extensions/extension_function_test_utils.h"
11 #include "chrome/browser/extensions/extension_test_message_listener.h"
12 #include "chrome/browser/extensions/platform_app_service.h"
11 #include "chrome/browser/extensions/shell_window_registry.h" 13 #include "chrome/browser/extensions/shell_window_registry.h"
12 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/extensions/application_launch.h" 15 #include "chrome/browser/ui/extensions/application_launch.h"
14 #include "chrome/browser/ui/extensions/shell_window.h" 16 #include "chrome/browser/ui/extensions/shell_window.h"
17 #include "chrome/common/chrome_notification_types.h"
15 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
16 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
17 #include "content/public/test/test_utils.h" 20 #include "content/public/test/test_utils.h"
18 21
19 using content::WebContents; 22 using content::WebContents;
20 23
21 namespace utils = extension_function_test_utils; 24 namespace utils = extension_function_test_utils;
22 25
23 namespace extensions { 26 namespace extensions {
24 27
25 void PlatformAppBrowserTest::SetUpCommandLine(CommandLine* command_line) { 28 void PlatformAppBrowserTest::SetUpCommandLine(CommandLine* command_line) {
26 // Skips ExtensionApiTest::SetUpCommandLine. 29 // Skips ExtensionApiTest::SetUpCommandLine.
27 ExtensionBrowserTest::SetUpCommandLine(command_line); 30 ExtensionBrowserTest::SetUpCommandLine(command_line);
31 }
28 32
29 // Make event pages get suspended quicker. 33 const Extension* PlatformAppBrowserTest::LoadPlatformApp(const char* name) {
30 command_line->AppendSwitchASCII(switches::kEventPageIdleTime, "1"); 34 PlatformAppService::CreateInstance(browser()->profile());
31 command_line->AppendSwitchASCII(switches::kEventPageUnloadingTime, "1"); 35 const Extension* extension = LoadExtension(
36 test_data_dir_.AppendASCII("platform_apps").AppendASCII(name));
37 EXPECT_TRUE(extension);
38
39 return extension;
40 }
41
42 const Extension* PlatformAppBrowserTest::InstallPlatformApp(
43 const char* name) {
44 PlatformAppService::CreateInstance(browser()->profile());
45 const Extension* extension = InstallExtension(
46 test_data_dir_.AppendASCII("platform_apps").AppendASCII(name), 1);
47 EXPECT_TRUE(extension);
48
49 return extension;
32 } 50 }
33 51
34 const Extension* PlatformAppBrowserTest::LoadAndLaunchPlatformApp( 52 const Extension* PlatformAppBrowserTest::LoadAndLaunchPlatformApp(
35 const char* name) { 53 const char* name) {
36 content::WindowedNotificationObserver app_loaded_observer( 54 ExtensionTestMessageListener launched_listener("Launched", false);
37 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
38 content::NotificationService::AllSources());
39 55
40 const Extension* extension = LoadExtension( 56 const Extension* extension = LoadPlatformApp(name);
41 test_data_dir_.AppendASCII("platform_apps").AppendASCII(name));
42 EXPECT_TRUE(extension);
43
44 application_launch::OpenApplication(application_launch::LaunchParams( 57 application_launch::OpenApplication(application_launch::LaunchParams(
45 browser()->profile(), extension, extension_misc::LAUNCH_NONE, 58 browser()->profile(), extension, extension_misc::LAUNCH_NONE,
46 NEW_WINDOW)); 59 NEW_WINDOW));
47 60
48 app_loaded_observer.Wait(); 61 launched_listener.WaitUntilSatisfied();
49 62
50 return extension; 63 return extension;
51 } 64 }
52 65
53 const Extension* PlatformAppBrowserTest::InstallAndLaunchPlatformApp( 66 const Extension* PlatformAppBrowserTest::InstallAndLaunchPlatformApp(
54 const char* name) { 67 const char* name) {
55 content::WindowedNotificationObserver app_loaded_observer( 68 ExtensionTestMessageListener launched_listener("Launched", false);
56 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
57 content::NotificationService::AllSources());
58 69
59 const Extension* extension = InstallExtension( 70 const Extension* extension = InstallPlatformApp(name);
60 test_data_dir_.AppendASCII("platform_apps").AppendASCII(name), 1);
61 EXPECT_TRUE(extension);
62
63 application_launch::OpenApplication(application_launch::LaunchParams( 71 application_launch::OpenApplication(application_launch::LaunchParams(
64 browser()->profile(), extension, extension_misc::LAUNCH_NONE, 72 browser()->profile(), extension, extension_misc::LAUNCH_NONE,
65 NEW_WINDOW)); 73 NEW_WINDOW));
66 74
67 app_loaded_observer.Wait(); 75 launched_listener.WaitUntilSatisfied();
68 76
69 return extension; 77 return extension;
70 } 78 }
71 79
72 WebContents* PlatformAppBrowserTest::GetFirstShellWindowWebContents() { 80 WebContents* PlatformAppBrowserTest::GetFirstShellWindowWebContents() {
73 ShellWindow* window = GetFirstShellWindow(); 81 ShellWindow* window = GetFirstShellWindow();
74 if (window) 82 if (window)
75 return window->web_contents(); 83 return window->web_contents();
76 84
77 return NULL; 85 return NULL;
78 } 86 }
79 87
80 ShellWindow* PlatformAppBrowserTest::GetFirstShellWindow() { 88 ShellWindow* PlatformAppBrowserTest::GetFirstShellWindow() {
81 ShellWindowRegistry* app_registry = 89 ShellWindowRegistry* app_registry =
82 ShellWindowRegistry::Get(browser()->profile()); 90 ShellWindowRegistry::Get(browser()->profile());
83 ShellWindowRegistry::const_iterator iter; 91 ShellWindowRegistry::const_iterator iter;
84 ShellWindowRegistry::ShellWindowSet shell_windows = 92 ShellWindowRegistry::ShellWindowSet shell_windows =
85 app_registry->shell_windows(); 93 app_registry->shell_windows();
86 for (iter = shell_windows.begin(); iter != shell_windows.end(); ++iter) { 94 for (iter = shell_windows.begin(); iter != shell_windows.end(); ++iter)
87 return *iter; 95 return *iter;
88 }
89 96
90 return NULL; 97 return NULL;
91 } 98 }
92 99
93 size_t PlatformAppBrowserTest::RunGetWindowsFunctionForExtension( 100 size_t PlatformAppBrowserTest::RunGetWindowsFunctionForExtension(
94 const Extension* extension) { 101 const Extension* extension) {
95 scoped_refptr<GetAllWindowsFunction> function = new GetAllWindowsFunction(); 102 scoped_refptr<GetAllWindowsFunction> function = new GetAllWindowsFunction();
96 function->set_extension(extension); 103 function->set_extension(extension);
97 scoped_ptr<base::ListValue> result(utils::ToList( 104 scoped_ptr<base::ListValue> result(utils::ToList(
98 utils::RunFunctionAndReturnSingleResult(function.get(), 105 utils::RunFunctionAndReturnSingleResult(function.get(),
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 command_line->AppendArgPath(test_doc); 143 command_line->AppendArgPath(test_doc);
137 } 144 }
138 145
139 ShellWindow* PlatformAppBrowserTest::CreateShellWindow( 146 ShellWindow* PlatformAppBrowserTest::CreateShellWindow(
140 const Extension* extension) { 147 const Extension* extension) {
141 ShellWindow::CreateParams params; 148 ShellWindow::CreateParams params;
142 return ShellWindow::Create( 149 return ShellWindow::Create(
143 browser()->profile(), extension, GURL(""), params); 150 browser()->profile(), extension, GURL(""), params);
144 } 151 }
145 152
146 void PlatformAppBrowserTest::CloseShellWindow(ShellWindow* window) {
147 content::WindowedNotificationObserver destroyed_observer(
148 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
149 content::NotificationService::AllSources());
150 window->GetBaseWindow()->Close();
151 destroyed_observer.Wait();
152 }
153
154 } // namespace extensions 153 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698