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

Side by Side Diff: chrome/browser/apps/app_browsertest.cc

Issue 130773004: Start moving context menu code to RenderFrame. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 6 years, 10 months 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 2013 The Chromium Authors. All rights reserved. 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 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 "apps/launcher.h" 5 #include "apps/launcher.h"
6 #include "apps/shell_window.h" 6 #include "apps/shell_window.h"
7 #include "apps/shell_window_registry.h" 7 #include "apps/shell_window_registry.h"
8 #include "apps/ui/native_app_window.h" 8 #include "apps/ui/native_app_window.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 namespace extensions { 64 namespace extensions {
65 65
66 namespace app_runtime = api::app_runtime; 66 namespace app_runtime = api::app_runtime;
67 67
68 namespace { 68 namespace {
69 69
70 // Non-abstract RenderViewContextMenu class. 70 // Non-abstract RenderViewContextMenu class.
71 class PlatformAppContextMenu : public RenderViewContextMenu { 71 class PlatformAppContextMenu : public RenderViewContextMenu {
72 public: 72 public:
73 PlatformAppContextMenu(WebContents* web_contents, 73 PlatformAppContextMenu(content::RenderFrameHost* render_frame_host,
74 const content::ContextMenuParams& params) 74 const content::ContextMenuParams& params)
75 : RenderViewContextMenu(web_contents, params) {} 75 : RenderViewContextMenu(render_frame_host, params) {}
76 76
77 bool HasCommandWithId(int command_id) { 77 bool HasCommandWithId(int command_id) {
78 return menu_model_.GetIndexOfCommandId(command_id) != -1; 78 return menu_model_.GetIndexOfCommandId(command_id) != -1;
79 } 79 }
80 80
81 protected: 81 protected:
82 // RenderViewContextMenu implementation. 82 // RenderViewContextMenu implementation.
83 virtual bool GetAcceleratorForCommandId( 83 virtual bool GetAcceleratorForCommandId(
84 int command_id, 84 int command_id,
85 ui::Accelerator* accelerator) OVERRIDE { 85 ui::Accelerator* accelerator) OVERRIDE {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 LoadAndLaunchPlatformApp("minimal"); 222 LoadAndLaunchPlatformApp("minimal");
223 223
224 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 224 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
225 225
226 // The empty app doesn't add any context menu items, so its menu should 226 // The empty app doesn't add any context menu items, so its menu should
227 // only include the developer tools. 227 // only include the developer tools.
228 WebContents* web_contents = GetFirstShellWindowWebContents(); 228 WebContents* web_contents = GetFirstShellWindowWebContents();
229 ASSERT_TRUE(web_contents); 229 ASSERT_TRUE(web_contents);
230 content::ContextMenuParams params; 230 content::ContextMenuParams params;
231 scoped_ptr<PlatformAppContextMenu> menu; 231 scoped_ptr<PlatformAppContextMenu> menu;
232 menu.reset(new PlatformAppContextMenu(web_contents, params)); 232 menu.reset(new PlatformAppContextMenu(web_contents->GetMainFrame(), params));
233 menu->Init(); 233 menu->Init();
234 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); 234 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
235 ASSERT_TRUE( 235 ASSERT_TRUE(
236 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); 236 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE));
237 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); 237 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP));
238 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); 238 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
239 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); 239 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
240 } 240 }
241 241
242 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) { 242 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) {
243 ExtensionTestMessageListener launched_listener("Launched", false); 243 ExtensionTestMessageListener launched_listener("Launched", false);
244 LoadAndLaunchPlatformApp("context_menu"); 244 LoadAndLaunchPlatformApp("context_menu");
245 245
246 // Wait for the extension to tell us it's initialized its context menus and 246 // Wait for the extension to tell us it's initialized its context menus and
247 // launched a window. 247 // launched a window.
248 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 248 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
249 249
250 // The context_menu app has two context menu items. These, along with a 250 // The context_menu app has two context menu items. These, along with a
251 // separator and the developer tools, is all that should be in the menu. 251 // separator and the developer tools, is all that should be in the menu.
252 WebContents* web_contents = GetFirstShellWindowWebContents(); 252 WebContents* web_contents = GetFirstShellWindowWebContents();
253 ASSERT_TRUE(web_contents); 253 ASSERT_TRUE(web_contents);
254 content::ContextMenuParams params; 254 content::ContextMenuParams params;
255 scoped_ptr<PlatformAppContextMenu> menu; 255 scoped_ptr<PlatformAppContextMenu> menu;
256 menu.reset(new PlatformAppContextMenu(web_contents, params)); 256 menu.reset(new PlatformAppContextMenu(web_contents->GetMainFrame(), params));
257 menu->Init(); 257 menu->Init();
258 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); 258 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
259 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); 259 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1));
260 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); 260 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
261 ASSERT_TRUE( 261 ASSERT_TRUE(
262 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); 262 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE));
263 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); 263 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP));
264 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); 264 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
265 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); 265 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
266 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); 266 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO));
267 } 267 }
268 268
269 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, InstalledAppWithContextMenu) { 269 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, InstalledAppWithContextMenu) {
270 ExtensionTestMessageListener launched_listener("Launched", false); 270 ExtensionTestMessageListener launched_listener("Launched", false);
271 InstallAndLaunchPlatformApp("context_menu"); 271 InstallAndLaunchPlatformApp("context_menu");
272 272
273 // Wait for the extension to tell us it's initialized its context menus and 273 // Wait for the extension to tell us it's initialized its context menus and
274 // launched a window. 274 // launched a window.
275 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 275 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
276 276
277 // The context_menu app has two context menu items. For an installed app 277 // The context_menu app has two context menu items. For an installed app
278 // these are all that should be in the menu. 278 // these are all that should be in the menu.
279 WebContents* web_contents = GetFirstShellWindowWebContents(); 279 WebContents* web_contents = GetFirstShellWindowWebContents();
280 ASSERT_TRUE(web_contents); 280 ASSERT_TRUE(web_contents);
281 content::ContextMenuParams params; 281 content::ContextMenuParams params;
282 scoped_ptr<PlatformAppContextMenu> menu; 282 scoped_ptr<PlatformAppContextMenu> menu;
283 menu.reset(new PlatformAppContextMenu(web_contents, params)); 283 menu.reset(new PlatformAppContextMenu(web_contents->GetMainFrame(), params));
284 menu->Init(); 284 menu->Init();
285 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); 285 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
286 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); 286 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1));
287 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); 287 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
288 ASSERT_FALSE( 288 ASSERT_FALSE(
289 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); 289 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE));
290 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); 290 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP));
291 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); 291 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
292 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); 292 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
293 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); 293 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO));
294 } 294 }
295 295
296 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuTextField) { 296 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuTextField) {
297 ExtensionTestMessageListener launched_listener("Launched", false); 297 ExtensionTestMessageListener launched_listener("Launched", false);
298 LoadAndLaunchPlatformApp("context_menu"); 298 LoadAndLaunchPlatformApp("context_menu");
299 299
300 // Wait for the extension to tell us it's initialized its context menus and 300 // Wait for the extension to tell us it's initialized its context menus and
301 // launched a window. 301 // launched a window.
302 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 302 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
303 303
304 // The context_menu app has one context menu item. This, along with a 304 // The context_menu app has one context menu item. This, along with a
305 // separator and the developer tools, is all that should be in the menu. 305 // separator and the developer tools, is all that should be in the menu.
306 WebContents* web_contents = GetFirstShellWindowWebContents(); 306 WebContents* web_contents = GetFirstShellWindowWebContents();
307 ASSERT_TRUE(web_contents); 307 ASSERT_TRUE(web_contents);
308 content::ContextMenuParams params; 308 content::ContextMenuParams params;
309 params.is_editable = true; 309 params.is_editable = true;
310 scoped_ptr<PlatformAppContextMenu> menu; 310 scoped_ptr<PlatformAppContextMenu> menu;
311 menu.reset(new PlatformAppContextMenu(web_contents, params)); 311 menu.reset(new PlatformAppContextMenu(web_contents->GetMainFrame(), params));
312 menu->Init(); 312 menu->Init();
313 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); 313 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
314 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); 314 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
315 ASSERT_TRUE( 315 ASSERT_TRUE(
316 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); 316 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE));
317 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); 317 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP));
318 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); 318 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO));
319 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); 319 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY));
320 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); 320 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
321 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); 321 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
322 } 322 }
323 323
324 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuSelection) { 324 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuSelection) {
325 ExtensionTestMessageListener launched_listener("Launched", false); 325 ExtensionTestMessageListener launched_listener("Launched", false);
326 LoadAndLaunchPlatformApp("context_menu"); 326 LoadAndLaunchPlatformApp("context_menu");
327 327
328 // Wait for the extension to tell us it's initialized its context menus and 328 // Wait for the extension to tell us it's initialized its context menus and
329 // launched a window. 329 // launched a window.
330 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 330 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
331 331
332 // The context_menu app has one context menu item. This, along with a 332 // The context_menu app has one context menu item. This, along with a
333 // separator and the developer tools, is all that should be in the menu. 333 // separator and the developer tools, is all that should be in the menu.
334 WebContents* web_contents = GetFirstShellWindowWebContents(); 334 WebContents* web_contents = GetFirstShellWindowWebContents();
335 ASSERT_TRUE(web_contents); 335 ASSERT_TRUE(web_contents);
336 content::ContextMenuParams params; 336 content::ContextMenuParams params;
337 params.selection_text = base::ASCIIToUTF16("Hello World"); 337 params.selection_text = base::ASCIIToUTF16("Hello World");
338 scoped_ptr<PlatformAppContextMenu> menu; 338 scoped_ptr<PlatformAppContextMenu> menu;
339 menu.reset(new PlatformAppContextMenu(web_contents, params)); 339 menu.reset(new PlatformAppContextMenu(web_contents->GetMainFrame(), params));
340 menu->Init(); 340 menu->Init();
341 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); 341 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
342 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); 342 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
343 ASSERT_TRUE( 343 ASSERT_TRUE(
344 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); 344 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE));
345 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); 345 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP));
346 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); 346 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO));
347 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); 347 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY));
348 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); 348 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
349 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); 349 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
350 } 350 }
351 351
352 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuClicked) { 352 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuClicked) {
353 ExtensionTestMessageListener launched_listener("Launched", false); 353 ExtensionTestMessageListener launched_listener("Launched", false);
354 LoadAndLaunchPlatformApp("context_menu_click"); 354 LoadAndLaunchPlatformApp("context_menu_click");
355 355
356 // Wait for the extension to tell us it's initialized its context menus and 356 // Wait for the extension to tell us it's initialized its context menus and
357 // launched a window. 357 // launched a window.
358 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 358 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
359 359
360 // Test that the menu item shows up 360 // Test that the menu item shows up
361 WebContents* web_contents = GetFirstShellWindowWebContents(); 361 WebContents* web_contents = GetFirstShellWindowWebContents();
362 ASSERT_TRUE(web_contents); 362 ASSERT_TRUE(web_contents);
363 content::ContextMenuParams params; 363 content::ContextMenuParams params;
364 params.page_url = GURL("http://foo.bar"); 364 params.page_url = GURL("http://foo.bar");
365 scoped_ptr<PlatformAppContextMenu> menu; 365 scoped_ptr<PlatformAppContextMenu> menu;
366 menu.reset(new PlatformAppContextMenu(web_contents, params)); 366 menu.reset(new PlatformAppContextMenu(web_contents->GetMainFrame(), params));
367 menu->Init(); 367 menu->Init();
368 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); 368 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
369 369
370 // Execute the menu item 370 // Execute the menu item
371 ExtensionTestMessageListener onclicked_listener("onClicked fired for id1", 371 ExtensionTestMessageListener onclicked_listener("onClicked fired for id1",
372 false); 372 false);
373 menu->ExecuteCommand(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST, 0); 373 menu->ExecuteCommand(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST, 0);
374 374
375 ASSERT_TRUE(onclicked_listener.WaitUntilSatisfied()); 375 ASSERT_TRUE(onclicked_listener.WaitUntilSatisfied());
376 } 376 }
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 1327
1328 ExtensionApiTest::ResultCatcher result_catcher; 1328 ExtensionApiTest::ResultCatcher result_catcher;
1329 1329
1330 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 1330 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
1331 1331
1332 EXPECT_TRUE(result_catcher.GetNextResult()); 1332 EXPECT_TRUE(result_catcher.GetNextResult());
1333 } 1333 }
1334 } 1334 }
1335 1335
1336 } // namespace extensions 1336 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698