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

Side by Side Diff: chrome/browser/extensions/platform_app_browsertest.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: Delegated 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/test/test_timeouts.h" 6 #include "base/test/test_timeouts.h"
7 #include "base/threading/platform_thread.h" 7 #include "base/threading/platform_thread.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/automation/automation_util.h" 10 #include "chrome/browser/automation/automation_util.h"
11 #include "chrome/browser/debugger/devtools_window.h" 11 #include "chrome/browser/debugger/devtools_window.h"
12 #include "chrome/browser/extensions/app_restore_service_factory.h" 12 #include "chrome/browser/extensions/app_restore_service_factory.h"
13 #include "chrome/browser/extensions/app_restore_service.h" 13 #include "chrome/browser/extensions/app_restore_service.h"
14 #include "chrome/browser/extensions/extension_browsertest.h" 14 #include "chrome/browser/extensions/extension_browsertest.h"
15 #include "chrome/browser/extensions/extension_prefs.h" 15 #include "chrome/browser/extensions/extension_prefs.h"
16 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
17 #include "chrome/browser/extensions/extension_system.h" 17 #include "chrome/browser/extensions/extension_system.h"
18 #include "chrome/browser/extensions/extension_test_message_listener.h" 18 #include "chrome/browser/extensions/extension_test_message_listener.h"
19 #include "chrome/browser/extensions/platform_app_browsertest_util.h" 19 #include "chrome/browser/extensions/platform_app_browsertest_util.h"
20 #include "chrome/browser/extensions/platform_app_launcher.h" 20 #include "chrome/browser/extensions/platform_app_launcher.h"
21 #include "chrome/browser/extensions/shell_window_registry.h" 21 #include "chrome/browser/extensions/shell_window_registry.h"
22 #include "chrome/browser/tab_contents/render_view_context_menu.h" 22 #include "chrome/browser/tab_contents/render_view_context_menu.h"
23 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_window.h"
24 #include "chrome/browser/ui/browser_tabstrip.h" 25 #include "chrome/browser/ui/browser_tabstrip.h"
25 #include "chrome/browser/ui/extensions/application_launch.h" 26 #include "chrome/browser/ui/extensions/application_launch.h"
26 #include "chrome/browser/ui/extensions/shell_window.h" 27 #include "chrome/browser/ui/extensions/shell_window.h"
27 #include "chrome/browser/ui/tab_contents/tab_contents.h" 28 #include "chrome/browser/ui/tab_contents/tab_contents.h"
28 #include "chrome/common/chrome_notification_types.h" 29 #include "chrome/common/chrome_notification_types.h"
29 #include "chrome/common/url_constants.h" 30 #include "chrome/common/url_constants.h"
30 #include "chrome/test/base/ui_test_utils.h" 31 #include "chrome/test/base/ui_test_utils.h"
31 #include "content/public/browser/devtools_agent_host_registry.h" 32 #include "content/public/browser/devtools_agent_host_registry.h"
32 #include "content/public/browser/render_process_host.h" 33 #include "content/public/browser/render_process_host.h"
33 #include "content/public/browser/web_intents_dispatcher.h" 34 #include "content/public/browser/web_intents_dispatcher.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 144
144 } // namespace 145 } // namespace
145 146
146 // Tests that CreateShellWindow doesn't crash if you close it straight away. 147 // Tests that CreateShellWindow doesn't crash if you close it straight away.
147 // LauncherPlatformAppBrowserTest relies on this behaviour, but is only run for 148 // LauncherPlatformAppBrowserTest relies on this behaviour, but is only run for
148 // ash, so we test that it works here. 149 // ash, so we test that it works here.
149 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, CreateAndCloseShellWindow) { 150 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, CreateAndCloseShellWindow) {
150 const Extension* extension = LoadAndLaunchPlatformApp("minimal"); 151 const Extension* extension = LoadAndLaunchPlatformApp("minimal");
151 ShellWindow* window = CreateShellWindow(extension); 152 ShellWindow* window = CreateShellWindow(extension);
152 CloseShellWindow(window); 153 CloseShellWindow(window);
154 CloseShellWindowsAndWaitForAppToExit();
153 } 155 }
154 156
155 // Tests that platform apps can be launched in incognito mode without crashing. 157 // Tests that platform apps can be launched in incognito mode without crashing.
156 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchAppIncognito) { 158 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchAppIncognito) {
157 Browser* browser_incognito = ui_test_utils::OpenURLOffTheRecord( 159 Browser* browser_incognito = ui_test_utils::OpenURLOffTheRecord(
158 browser()->profile(), GURL("about:blank")); 160 browser()->profile(), GURL("about:blank"));
159 161
160 ExtensionTestMessageListener launched_listener("Launched", false); 162 ExtensionTestMessageListener launched_listener("Launched", false);
161 163
162 const Extension* extension = LoadExtensionIncognito( 164 const Extension* extension = LoadExtensionIncognito(
163 test_data_dir_.AppendASCII("platform_apps").AppendASCII("minimal")); 165 test_data_dir_.AppendASCII("platform_apps").AppendASCII("minimal"));
164 EXPECT_TRUE(extension); 166 EXPECT_TRUE(extension);
165 167
166 application_launch::OpenApplication(application_launch::LaunchParams( 168 application_launch::OpenApplication(application_launch::LaunchParams(
167 browser_incognito->profile(), extension, extension_misc::LAUNCH_NONE, 169 browser_incognito->profile(), extension, extension_misc::LAUNCH_NONE,
168 NEW_WINDOW)); 170 NEW_WINDOW));
169 171
170 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 172 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
173 CloseShellWindowsAndWaitForAppToExit();
171 } 174 }
172 175
173 // Tests that platform apps received the "launch" event when launched. 176 // Tests that platform apps received the "launch" event when launched.
174 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) { 177 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) {
175 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_; 178 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_;
176 } 179 }
177 180
178 // Tests that platform apps can reply to "launch" events that contain a Web 181 // Tests that platform apps can reply to "launch" events that contain a Web
179 // Intent. This test does not test the mechanics of invoking a Web Intent 182 // Intent. This test does not test the mechanics of invoking a Web Intent
180 // from a source page, and short-circuits to LaunchPlatformAppWithWebIntent. 183 // from a source page, and short-circuits to LaunchPlatformAppWithWebIntent.
(...skipping 14 matching lines...) Expand all
195 WebContents* web_contents = chrome::GetActiveWebContents(browser()); 198 WebContents* web_contents = chrome::GetActiveWebContents(browser());
196 ASSERT_TRUE(web_contents); 199 ASSERT_TRUE(web_contents);
197 200
198 extensions::LaunchPlatformAppWithWebIntent( 201 extensions::LaunchPlatformAppWithWebIntent(
199 browser()->profile(), 202 browser()->profile(),
200 extension, 203 extension,
201 handler.intents_dispatcher(), 204 handler.intents_dispatcher(),
202 web_contents); 205 web_contents);
203 206
204 ASSERT_TRUE(handler.WaitUntilReply()); 207 ASSERT_TRUE(handler.WaitUntilReply());
208 CloseShellWindowsAndWaitForAppToExit();
205 } 209 }
206 210
207 // Tests that platform apps cannot use certain disabled window properties, but 211 // Tests that platform apps cannot use certain disabled window properties, but
208 // can override them and then use them. 212 // can override them and then use them.
209 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisabledWindowProperties) { 213 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisabledWindowProperties) {
210 ASSERT_TRUE(RunPlatformAppTest("platform_apps/disabled_window_properties")) 214 ASSERT_TRUE(RunPlatformAppTest("platform_apps/disabled_window_properties"))
211 << message_; 215 << message_;
212 } 216 }
213 217
214 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { 218 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) {
215 ExtensionTestMessageListener launched_listener("Launched", false);
216 LoadAndLaunchPlatformApp("minimal"); 219 LoadAndLaunchPlatformApp("minimal");
217 220
218 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
219
220 // The empty app doesn't add any context menu items, so its menu should 221 // The empty app doesn't add any context menu items, so its menu should
221 // only include the developer tools. 222 // only include the developer tools.
222 WebContents* web_contents = GetFirstShellWindowWebContents(); 223 WebContents* web_contents = GetFirstShellWindowWebContents();
223 ASSERT_TRUE(web_contents); 224 ASSERT_TRUE(web_contents);
224 WebKit::WebContextMenuData data; 225 WebKit::WebContextMenuData data;
225 content::ContextMenuParams params(data); 226 content::ContextMenuParams params(data);
226 scoped_ptr<PlatformAppContextMenu> menu; 227 scoped_ptr<PlatformAppContextMenu> menu;
227 menu.reset(new PlatformAppContextMenu(web_contents, params)); 228 menu.reset(new PlatformAppContextMenu(web_contents, params));
228 menu->Init(); 229 menu->Init();
229 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); 230 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
230 ASSERT_TRUE( 231 ASSERT_TRUE(
231 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); 232 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE));
232 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); 233 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP));
233 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); 234 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
234 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); 235 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
236 CloseShellWindowsAndWaitForAppToExit();
235 } 237 }
236 238
237 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) { 239 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) {
238 ExtensionTestMessageListener launched_listener("Launched", false);
239 LoadAndLaunchPlatformApp("context_menu"); 240 LoadAndLaunchPlatformApp("context_menu");
240 241
241 // Wait for the extension to tell us it's initialized its context menus and
242 // launched a window.
243 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
244
245 // The context_menu app has two context menu items. These, along with a 242 // The context_menu app has two context menu items. These, along with a
246 // separator and the developer tools, is all that should be in the menu. 243 // separator and the developer tools, is all that should be in the menu.
247 WebContents* web_contents = GetFirstShellWindowWebContents(); 244 WebContents* web_contents = GetFirstShellWindowWebContents();
248 ASSERT_TRUE(web_contents); 245 ASSERT_TRUE(web_contents);
249 WebKit::WebContextMenuData data; 246 WebKit::WebContextMenuData data;
250 content::ContextMenuParams params(data); 247 content::ContextMenuParams params(data);
251 scoped_ptr<PlatformAppContextMenu> menu; 248 scoped_ptr<PlatformAppContextMenu> menu;
252 menu.reset(new PlatformAppContextMenu(web_contents, params)); 249 menu.reset(new PlatformAppContextMenu(web_contents, params));
253 menu->Init(); 250 menu->Init();
254 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); 251 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
255 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); 252 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1));
256 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); 253 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
257 ASSERT_TRUE( 254 ASSERT_TRUE(
258 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); 255 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE));
259 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); 256 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP));
260 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); 257 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
261 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); 258 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
262 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); 259 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO));
260 CloseShellWindowsAndWaitForAppToExit();
263 } 261 }
264 262
265 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, InstalledAppWithContextMenu) { 263 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, InstalledAppWithContextMenu) {
266 ExtensionTestMessageListener launched_listener("Launched", false);
267 InstallAndLaunchPlatformApp("context_menu"); 264 InstallAndLaunchPlatformApp("context_menu");
268 265
269 // Wait for the extension to tell us it's initialized its context menus and
270 // launched a window.
271 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
272
273 // The context_menu app has two context menu items. For an installed app 266 // The context_menu app has two context menu items. For an installed app
274 // these are all that should be in the menu. 267 // these are all that should be in the menu.
275 WebContents* web_contents = GetFirstShellWindowWebContents(); 268 WebContents* web_contents = GetFirstShellWindowWebContents();
276 ASSERT_TRUE(web_contents); 269 ASSERT_TRUE(web_contents);
277 WebKit::WebContextMenuData data; 270 WebKit::WebContextMenuData data;
278 content::ContextMenuParams params(data); 271 content::ContextMenuParams params(data);
279 scoped_ptr<PlatformAppContextMenu> menu; 272 scoped_ptr<PlatformAppContextMenu> menu;
280 menu.reset(new PlatformAppContextMenu(web_contents, params)); 273 menu.reset(new PlatformAppContextMenu(web_contents, params));
281 menu->Init(); 274 menu->Init();
282 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); 275 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
283 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); 276 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1));
284 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); 277 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
285 ASSERT_FALSE( 278 ASSERT_FALSE(
286 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); 279 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE));
287 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); 280 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP));
288 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); 281 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
289 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); 282 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
290 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); 283 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO));
284 CloseShellWindowsAndWaitForAppToExit();
291 } 285 }
292 286
293 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuTextField) { 287 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuTextField) {
294 ExtensionTestMessageListener launched_listener("Launched", false);
295 LoadAndLaunchPlatformApp("context_menu"); 288 LoadAndLaunchPlatformApp("context_menu");
296 289
297 // Wait for the extension to tell us it's initialized its context menus and
298 // launched a window.
299 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
300
301 // The context_menu app has one context menu item. This, along with a 290 // The context_menu app has one context menu item. This, along with a
302 // separator and the developer tools, is all that should be in the menu. 291 // separator and the developer tools, is all that should be in the menu.
303 WebContents* web_contents = GetFirstShellWindowWebContents(); 292 WebContents* web_contents = GetFirstShellWindowWebContents();
304 ASSERT_TRUE(web_contents); 293 ASSERT_TRUE(web_contents);
305 WebKit::WebContextMenuData data; 294 WebKit::WebContextMenuData data;
306 content::ContextMenuParams params(data); 295 content::ContextMenuParams params(data);
307 params.is_editable = true; 296 params.is_editable = true;
308 scoped_ptr<PlatformAppContextMenu> menu; 297 scoped_ptr<PlatformAppContextMenu> menu;
309 menu.reset(new PlatformAppContextMenu(web_contents, params)); 298 menu.reset(new PlatformAppContextMenu(web_contents, params));
310 menu->Init(); 299 menu->Init();
311 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); 300 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
312 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); 301 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
313 ASSERT_TRUE( 302 ASSERT_TRUE(
314 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); 303 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE));
315 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); 304 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP));
316 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); 305 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO));
317 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); 306 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY));
318 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); 307 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
319 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); 308 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
309 CloseShellWindowsAndWaitForAppToExit();
320 } 310 }
321 311
322 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuSelection) { 312 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuSelection) {
323 ExtensionTestMessageListener launched_listener("Launched", false);
324 LoadAndLaunchPlatformApp("context_menu"); 313 LoadAndLaunchPlatformApp("context_menu");
325 314
326 // Wait for the extension to tell us it's initialized its context menus and
327 // launched a window.
328 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
329
330 // The context_menu app has one context menu item. This, along with a 315 // The context_menu app has one context menu item. This, along with a
331 // separator and the developer tools, is all that should be in the menu. 316 // separator and the developer tools, is all that should be in the menu.
332 WebContents* web_contents = GetFirstShellWindowWebContents(); 317 WebContents* web_contents = GetFirstShellWindowWebContents();
333 ASSERT_TRUE(web_contents); 318 ASSERT_TRUE(web_contents);
334 WebKit::WebContextMenuData data; 319 WebKit::WebContextMenuData data;
335 content::ContextMenuParams params(data); 320 content::ContextMenuParams params(data);
336 params.selection_text = ASCIIToUTF16("Hello World"); 321 params.selection_text = ASCIIToUTF16("Hello World");
337 scoped_ptr<PlatformAppContextMenu> menu; 322 scoped_ptr<PlatformAppContextMenu> menu;
338 menu.reset(new PlatformAppContextMenu(web_contents, params)); 323 menu.reset(new PlatformAppContextMenu(web_contents, params));
339 menu->Init(); 324 menu->Init();
340 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); 325 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
341 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); 326 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
342 ASSERT_TRUE( 327 ASSERT_TRUE(
343 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); 328 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE));
344 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); 329 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP));
345 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); 330 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO));
346 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); 331 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY));
347 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); 332 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
348 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); 333 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
334 CloseShellWindowsAndWaitForAppToExit();
349 } 335 }
350 336
351 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuClicked) { 337 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuClicked) {
352 ExtensionTestMessageListener launched_listener("Launched", false);
353 LoadAndLaunchPlatformApp("context_menu_click"); 338 LoadAndLaunchPlatformApp("context_menu_click");
354 339
355 // Wait for the extension to tell us it's initialized its context menus and
356 // launched a window.
357 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
358
359 // Test that the menu item shows up 340 // Test that the menu item shows up
360 WebContents* web_contents = GetFirstShellWindowWebContents(); 341 WebContents* web_contents = GetFirstShellWindowWebContents();
361 ASSERT_TRUE(web_contents); 342 ASSERT_TRUE(web_contents);
362 WebKit::WebContextMenuData data; 343 WebKit::WebContextMenuData data;
363 content::ContextMenuParams params(data); 344 content::ContextMenuParams params(data);
364 params.page_url = GURL("http://foo.bar"); 345 params.page_url = GURL("http://foo.bar");
365 scoped_ptr<PlatformAppContextMenu> menu; 346 scoped_ptr<PlatformAppContextMenu> menu;
366 menu.reset(new PlatformAppContextMenu(web_contents, params)); 347 menu.reset(new PlatformAppContextMenu(web_contents, params));
367 menu->Init(); 348 menu->Init();
368 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); 349 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
369 350
370 // Execute the menu item 351 // Execute the menu item
371 ExtensionTestMessageListener onclicked_listener("onClicked fired for id1", 352 ExtensionTestMessageListener onclicked_listener("onClicked fired for id1",
372 false); 353 false);
373 menu->ExecuteCommand(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST); 354 menu->ExecuteCommand(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST);
374 355
375 ASSERT_TRUE(onclicked_listener.WaitUntilSatisfied()); 356 ASSERT_TRUE(onclicked_listener.WaitUntilSatisfied());
357 CloseShellWindowsAndWaitForAppToExit();
376 } 358 }
377 359
378 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowNavigation) { 360 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowNavigation) {
379 TabsAddedNotificationObserver observer(2); 361 TabsAddedNotificationObserver observer(2);
380 362
381 ASSERT_TRUE(StartTestServer()); 363 ASSERT_TRUE(StartTestServer());
382 ASSERT_TRUE(RunPlatformAppTest("platform_apps/navigation")) << message_; 364 ASSERT_TRUE(RunPlatformAppTestReturnImmediately("platform_apps/navigation"))
365 << message_;
383 366
384 observer.Wait(); 367 observer.Wait();
385 ASSERT_EQ(2U, observer.tabs().size()); 368 ASSERT_EQ(2U, observer.tabs().size());
386 EXPECT_EQ(std::string(chrome::kExtensionInvalidRequestURL), 369 EXPECT_EQ(std::string(chrome::kExtensionInvalidRequestURL),
387 observer.tabs()[0]->GetURL().spec()); 370 observer.tabs()[0]->GetURL().spec());
388 EXPECT_EQ("http://chromium.org/", 371 EXPECT_EQ("http://chromium.org/",
389 observer.tabs()[1]->GetURL().spec()); 372 observer.tabs()[1]->GetURL().spec());
373 browser()->window()->Close();
374 CloseShellWindowsAndWaitForAppToExit();
390 } 375 }
391 376
392 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Iframes) { 377 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Iframes) {
393 ASSERT_TRUE(StartTestServer()); 378 ASSERT_TRUE(StartTestServer());
394 ASSERT_TRUE(RunPlatformAppTest("platform_apps/iframes")) << message_; 379 ASSERT_TRUE(RunPlatformAppTest("platform_apps/iframes")) << message_;
395 } 380 }
396 381
397 // Tests that localStorage and WebSQL are disabled for platform apps. 382 // Tests that localStorage and WebSQL are disabled for platform apps.
398 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowStorage) { 383 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowStorage) {
399 ASSERT_TRUE(RunPlatformAppTest("platform_apps/storage")) << message_; 384 ASSERT_TRUE(RunPlatformAppTest("platform_apps/storage")) << message_;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 // Initially there should be just the one browser window visible to the 434 // Initially there should be just the one browser window visible to the
450 // extensions API. 435 // extensions API.
451 const Extension* extension = LoadExtension( 436 const Extension* extension = LoadExtension(
452 test_data_dir_.AppendASCII("common/background_page")); 437 test_data_dir_.AppendASCII("common/background_page"));
453 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension)); 438 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension));
454 439
455 // And no shell windows. 440 // And no shell windows.
456 ASSERT_EQ(0U, GetShellWindowCount()); 441 ASSERT_EQ(0U, GetShellWindowCount());
457 442
458 // Launch a platform app that shows a window. 443 // Launch a platform app that shows a window.
459 ExtensionTestMessageListener launched_listener("Launched", false);
460 LoadAndLaunchPlatformApp("minimal"); 444 LoadAndLaunchPlatformApp("minimal");
461 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
462 ASSERT_EQ(1U, GetShellWindowCount()); 445 ASSERT_EQ(1U, GetShellWindowCount());
463 ShellWindowRegistry::ShellWindowSet shell_windows = 446 ShellWindowRegistry::ShellWindowSet shell_windows =
464 ShellWindowRegistry::Get(browser()->profile())->shell_windows(); 447 ShellWindowRegistry::Get(browser()->profile())->shell_windows();
465 int shell_window_id = (*shell_windows.begin())->session_id().id(); 448 int shell_window_id = (*shell_windows.begin())->session_id().id();
466 449
467 // But it's not visible to the extensions API, it still thinks there's just 450 // But it's not visible to the extensions API, it still thinks there's just
468 // one browser window. 451 // one browser window.
469 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension)); 452 ASSERT_EQ(1U, RunGetWindowsFunctionForExtension(extension));
470 // It can't look it up by ID either 453 // It can't look it up by ID either
471 ASSERT_FALSE(RunGetWindowFunctionForExtension(shell_window_id, extension)); 454 ASSERT_FALSE(RunGetWindowFunctionForExtension(shell_window_id, extension));
472 455
473 // The app can also only see one window (its own). 456 // The app can also only see one window (its own).
474 // TODO(jeremya): add an extension function to get a shell window by ID, and 457 // TODO(jeremya): add an extension function to get a shell window by ID, and
475 // to get a list of all the shell windows, so we can test this. 458 // to get a list of all the shell windows, so we can test this.
476 459
477 // Launch another platform app that also shows a window. 460 // Launch another platform app that also shows a window.
478 ExtensionTestMessageListener launched_listener2("Launched", false);
479 LoadAndLaunchPlatformApp("context_menu"); 461 LoadAndLaunchPlatformApp("context_menu");
480 ASSERT_TRUE(launched_listener2.WaitUntilSatisfied());
481 462
482 // There are two total shell windows, but each app can only see its own. 463 // There are two total shell windows, but each app can only see its own.
483 ASSERT_EQ(2U, GetShellWindowCount()); 464 ASSERT_EQ(2U, GetShellWindowCount());
484 // TODO(jeremya): as above, this requires more extension functions. 465 // TODO(jeremya): as above, this requires more extension functions.
466 CloseShellWindowsAndWaitForAppToExit();
485 } 467 }
486 468
487 // ChromeOS does not support passing arguments on the command line, so the tests 469 // ChromeOS does not support passing arguments on the command line, so the tests
488 // that rely on this functionality are disabled. 470 // that rely on this functionality are disabled.
489 #if !defined(OS_CHROMEOS) 471 #if !defined(OS_CHROMEOS)
490 // Tests that command line parameters get passed through to platform apps 472 // Tests that command line parameters get passed through to platform apps
491 // via launchData correctly when launching with a file. 473 // via launchData correctly when launching with a file.
492 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithFile) { 474 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithFile) {
493 SetCommandLineArg(kTestFilePath); 475 SetCommandLineArg(kTestFilePath);
494 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_file")) 476 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_file"))
(...skipping 23 matching lines...) Expand all
518 extension_misc::LAUNCH_NONE, 500 extension_misc::LAUNCH_NONE,
519 NEW_WINDOW); 501 NEW_WINDOW);
520 params.command_line = CommandLine::ForCurrentProcess(); 502 params.command_line = CommandLine::ForCurrentProcess();
521 params.current_directory = test_data_dir_; 503 params.current_directory = test_data_dir_;
522 application_launch::OpenApplication(params); 504 application_launch::OpenApplication(params);
523 505
524 if (!catcher.GetNextResult()) { 506 if (!catcher.GetNextResult()) {
525 message_ = catcher.message(); 507 message_ = catcher.message();
526 ASSERT_TRUE(0); 508 ASSERT_TRUE(0);
527 } 509 }
510 CloseShellWindowsAndWaitForAppToExit();
528 } 511 }
529 512
530 // Tests that no launch data is sent through if the platform app provides 513 // Tests that no launch data is sent through if the platform app provides
531 // an intent with the wrong action. 514 // an intent with the wrong action.
532 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongIntent) { 515 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithWrongIntent) {
533 SetCommandLineArg(kTestFilePath); 516 SetCommandLineArg(kTestFilePath);
534 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_intent")) 517 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_wrong_intent"))
535 << message_; 518 << message_;
536 } 519 }
537 520
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 #endif // defined(OS_CHROMEOS) 575 #endif // defined(OS_CHROMEOS)
593 576
594 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OpenLink) { 577 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OpenLink) {
595 ASSERT_TRUE(StartTestServer()); 578 ASSERT_TRUE(StartTestServer());
596 content::WindowedNotificationObserver observer( 579 content::WindowedNotificationObserver observer(
597 chrome::NOTIFICATION_TAB_ADDED, 580 chrome::NOTIFICATION_TAB_ADDED,
598 content::Source<content::WebContentsDelegate>(browser())); 581 content::Source<content::WebContentsDelegate>(browser()));
599 LoadAndLaunchPlatformApp("open_link"); 582 LoadAndLaunchPlatformApp("open_link");
600 observer.Wait(); 583 observer.Wait();
601 ASSERT_EQ(2, browser()->tab_count()); 584 ASSERT_EQ(2, browser()->tab_count());
585 browser()->window()->Close();
586 CloseShellWindowsAndWaitForAppToExit();
602 } 587 }
603 588
604 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MutationEventsDisabled) { 589 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MutationEventsDisabled) {
605 ASSERT_TRUE(RunPlatformAppTest("platform_apps/mutation_events")) << message_; 590 ASSERT_TRUE(RunPlatformAppTest("platform_apps/mutation_events")) << message_;
606 } 591 }
607 592
608 // Test that windows created with an id will remember and restore their 593 // Test that windows created with an id will remember and restore their
609 // geometry when opening new windows. 594 // geometry when opening new windows.
610 // Flaky, see http://crbug.com/155459. 595 // Flaky, see http://crbug.com/155459.
611 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, 596 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 // Wait for javascript to verify that the second window got the updated 651 // Wait for javascript to verify that the second window got the updated
667 // coordinates, ignoring the default coordinates passed to the create method. 652 // coordinates, ignoring the default coordinates passed to the create method.
668 ASSERT_TRUE(done2_listener.WaitUntilSatisfied()); 653 ASSERT_TRUE(done2_listener.WaitUntilSatisfied());
669 654
670 // Tell javascript to open a third window. 655 // Tell javascript to open a third window.
671 page3_listener.Reply("continue"); 656 page3_listener.Reply("continue");
672 657
673 // Wait for javascript to verify that the third window got the restored size 658 // Wait for javascript to verify that the third window got the restored size
674 // and explicitly specified coordinates. 659 // and explicitly specified coordinates.
675 ASSERT_TRUE(done3_listener.WaitUntilSatisfied()); 660 ASSERT_TRUE(done3_listener.WaitUntilSatisfied());
661 CloseShellWindowsAndWaitForAppToExit();
676 } 662 }
677 663
678 // Tests that a running app is recorded in the preferences as such. 664 // Tests that a running app is recorded in the preferences as such.
679 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, RunningAppsAreRecorded) { 665 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, RunningAppsAreRecorded) {
680 content::WindowedNotificationObserver extension_suspended( 666 content::WindowedNotificationObserver extension_suspended(
681 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, 667 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
682 content::NotificationService::AllSources()); 668 content::NotificationService::AllSources());
683 669
684 const Extension* extension = LoadExtension( 670 const Extension* extension = LoadExtension(
685 test_data_dir_.AppendASCII("platform_apps/restart_test")); 671 test_data_dir_.AppendASCII("platform_apps/restart_test"));
(...skipping 11 matching lines...) Expand all
697 // App isn't running because it got suspended. 683 // App isn't running because it got suspended.
698 ASSERT_FALSE(extension_prefs->IsExtensionRunning(extension->id())); 684 ASSERT_FALSE(extension_prefs->IsExtensionRunning(extension->id()));
699 685
700 // Pretend that the app is supposed to be running. 686 // Pretend that the app is supposed to be running.
701 extension_prefs->SetExtensionRunning(extension->id(), true); 687 extension_prefs->SetExtensionRunning(extension->id(), true);
702 688
703 ExtensionTestMessageListener restart_listener("onRestarted", false); 689 ExtensionTestMessageListener restart_listener("onRestarted", false);
704 AppRestoreServiceFactory::GetForProfile(browser()->profile())-> 690 AppRestoreServiceFactory::GetForProfile(browser()->profile())->
705 HandleStartup(true); 691 HandleStartup(true);
706 restart_listener.WaitUntilSatisfied(); 692 restart_listener.WaitUntilSatisfied();
693 CloseShellWindowsAndWaitForAppToExit();
707 } 694 }
708 695
709 // Tests that relaunching an app with devtools open reopens devtools. 696 // Tests that relaunching an app with devtools open reopens devtools.
710 #ifdef NDEBUG 697 #ifdef NDEBUG
711 #define MAYBE_DevToolsOpenedWithReload DevToolsOpenedWithReload 698 #define MAYBE_DevToolsOpenedWithReload DevToolsOpenedWithReload
712 #else 699 #else
713 // This is currently expected to fail in debug builds due to a segfault in 700 // This is currently expected to fail in debug builds due to a segfault in
714 // WebKit triggered by a dereference between #ifndef NDEBUG guards see 701 // WebKit triggered by a dereference between #ifndef NDEBUG guards see
715 // http://crbug.com/157097 . 702 // http://crbug.com/157097 .
716 #define MAYBE_DevToolsOpenedWithReload FAILS_DevToolsOpenedWithReload 703 #define MAYBE_DevToolsOpenedWithReload FAILS_DevToolsOpenedWithReload
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 browser()->profile(), extension, extension_misc::LAUNCH_NONE, 737 browser()->profile(), extension, extension_misc::LAUNCH_NONE,
751 NEW_WINDOW)); 738 NEW_WINDOW));
752 app_loaded_observer.Wait(); 739 app_loaded_observer.Wait();
753 window = GetFirstShellWindow(); 740 window = GetFirstShellWindow();
754 ASSERT_TRUE(window); 741 ASSERT_TRUE(window);
755 742
756 // DevTools should have reopened with the relaunch. 743 // DevTools should have reopened with the relaunch.
757 rvh = window->web_contents()->GetRenderViewHost(); 744 rvh = window->web_contents()->GetRenderViewHost();
758 ASSERT_TRUE(rvh); 745 ASSERT_TRUE(rvh);
759 ASSERT_TRUE(DevToolsAgentHostRegistry::HasDevToolsAgentHost(rvh)); 746 ASSERT_TRUE(DevToolsAgentHostRegistry::HasDevToolsAgentHost(rvh));
747 CloseShellWindowsAndWaitForAppToExit();
760 } 748 }
761 749
762 } // namespace extensions 750 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698