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

Side by Side Diff: chrome/browser/renderer_context_menu/render_view_context_menu_browsertest.cc

Issue 1191453002: Implement "open link as user" context menu entry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updates Created 5 years, 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
13 #include "base/strings/stringprintf.h"
13 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/app/chrome_command_ids.h" 15 #include "chrome/app/chrome_command_ids.h"
16 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/chrome_notification_types.h" 17 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/profiles/profile_window.h"
16 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" 19 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
17 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert est_util.h" 20 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert est_util.h"
18 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" 21 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h"
19 #include "chrome/browser/search_engines/template_url_service_factory.h" 22 #include "chrome/browser/search_engines/template_url_service_factory.h"
20 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" 24 #include "chrome/browser/ui/tabs/tab_strip_model.h"
22 #include "chrome/common/render_messages.h" 25 #include "chrome/common/render_messages.h"
23 #include "chrome/test/base/in_process_browser_test.h" 26 #include "chrome/test/base/in_process_browser_test.h"
24 #include "chrome/test/base/ui_test_utils.h" 27 #include "chrome/test/base/ui_test_utils.h"
25 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h" 28 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h"
26 #include "components/search_engines/template_url_data.h" 29 #include "components/search_engines/template_url_data.h"
27 #include "components/search_engines/template_url_service.h" 30 #include "components/search_engines/template_url_service.h"
28 #include "content/public/browser/browser_message_filter.h" 31 #include "content/public/browser/browser_message_filter.h"
29 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
30 #include "content/public/browser/navigation_controller.h" 33 #include "content/public/browser/navigation_controller.h"
31 #include "content/public/browser/navigation_entry.h" 34 #include "content/public/browser/navigation_entry.h"
32 #include "content/public/browser/notification_service.h" 35 #include "content/public/browser/notification_service.h"
33 #include "content/public/browser/render_process_host.h" 36 #include "content/public/browser/render_process_host.h"
34 #include "content/public/browser/render_view_host.h" 37 #include "content/public/browser/render_view_host.h"
35 #include "content/public/browser/web_contents.h" 38 #include "content/public/browser/web_contents.h"
36 #include "content/public/test/browser_test_utils.h" 39 #include "content/public/test/browser_test_utils.h"
37 #include "content/public/test/test_utils.h" 40 #include "content/public/test/test_utils.h"
38 #include "net/base/load_flags.h" 41 #include "net/base/load_flags.h"
39 #include "net/url_request/url_request.h" 42 #include "net/url_request/url_request.h"
40 #include "net/url_request/url_request_filter.h" 43 #include "net/url_request/url_request_filter.h"
41 #include "net/url_request/url_request_interceptor.h" 44 #include "net/url_request/url_request_interceptor.h"
42 #include "third_party/WebKit/public/web/WebContextMenuData.h" 45 #include "third_party/WebKit/public/web/WebContextMenuData.h"
43 #include "third_party/WebKit/public/web/WebInputEvent.h" 46 #include "third_party/WebKit/public/web/WebInputEvent.h"
44 47
48 #if defined(OS_CHROMEOS)
49 #include "chrome/browser/chromeos/profiles/profile_helper.h"
50 #include "components/user_manager/user_manager.h"
51 #endif
52
45 using content::WebContents; 53 using content::WebContents;
46 54
47 namespace { 55 namespace {
48 56
49 class ContextMenuBrowserTest : public InProcessBrowserTest { 57 class ContextMenuBrowserTest : public InProcessBrowserTest {
50 public: 58 public:
51 ContextMenuBrowserTest() {} 59 ContextMenuBrowserTest() {}
52 60
53 TestRenderViewContextMenu* CreateContextMenu( 61 TestRenderViewContextMenu* CreateContextMenu(
54 const GURL& unfiltered_url, 62 const GURL& unfiltered_url,
(...skipping 18 matching lines...) Expand all
73 menu->Init(); 81 menu->Init();
74 return menu; 82 return menu;
75 } 83 }
76 84
77 TestRenderViewContextMenu* CreateContextMenuMediaTypeNone( 85 TestRenderViewContextMenu* CreateContextMenuMediaTypeNone(
78 const GURL& unfiltered_url, 86 const GURL& unfiltered_url,
79 const GURL& url) { 87 const GURL& url) {
80 return CreateContextMenu(unfiltered_url, url, 88 return CreateContextMenu(unfiltered_url, url,
81 blink::WebContextMenuData::MediaTypeNone); 89 blink::WebContextMenuData::MediaTypeNone);
82 } 90 }
91
92 Profile* CreateSecondaryProfile(int profile_num) {
93 ProfileManager* profile_manager = g_browser_process->profile_manager();
94 base::FilePath profile_path = profile_manager->user_data_dir();
95 #if defined(OS_CHROMEOS)
96 std::string profile_name = base::StringPrintf("NewProfile%d", profile_num);
97 user_manager::UserManager::Get()->UserLoggedIn(
98 base::StringPrintf("user%d@test.com", profile_num), profile_name,
99 false);
100 profile_path = profile_path.Append(
101 chromeos::ProfileHelper::GetUserProfileDir(profile_name).BaseName());
102 #else
103 profile_path = profile_path.AppendASCII(
104 base::StringPrintf("New Profile %d", profile_num));
105 #endif
106 return profile_manager->GetProfile(profile_path);
107 }
83 }; 108 };
84 109
85 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, 110 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest,
86 OpenEntryPresentForNormalURLs) { 111 OpenEntryPresentForNormalURLs) {
87 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenuMediaTypeNone( 112 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenuMediaTypeNone(
88 GURL("http://www.google.com/"), GURL("http://www.google.com/"))); 113 GURL("http://www.google.com/"), GURL("http://www.google.com/")));
89 114
90 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); 115 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB));
91 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); 116 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW));
92 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); 117 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION));
118 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE));
119 ASSERT_FALSE(menu->IsItemInRangePresent(IDC_OPEN_LINK_IN_PROFILE_FIRST,
120 IDC_OPEN_LINK_IN_PROFILE_LAST));
93 } 121 }
94 122
95 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, 123 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest,
96 OpenEntryAbsentForFilteredURLs) { 124 OpenEntryAbsentForFilteredURLs) {
97 scoped_ptr<TestRenderViewContextMenu> menu( 125 scoped_ptr<TestRenderViewContextMenu> menu(
98 CreateContextMenuMediaTypeNone(GURL("chrome://history"), GURL())); 126 CreateContextMenuMediaTypeNone(GURL("chrome://history"), GURL()));
99 127
100 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); 128 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB));
101 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); 129 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW));
102 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); 130 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION));
131 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE));
132 ASSERT_FALSE(menu->IsItemInRangePresent(IDC_OPEN_LINK_IN_PROFILE_FIRST,
133 IDC_OPEN_LINK_IN_PROFILE_LAST));
103 } 134 }
104 135
105 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, 136 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest,
106 ContextMenuForCanvas) { 137 ContextMenuForCanvas) {
107 content::ContextMenuParams params; 138 content::ContextMenuParams params;
108 params.media_type = blink::WebContextMenuData::MediaTypeCanvas; 139 params.media_type = blink::WebContextMenuData::MediaTypeCanvas;
109 140
110 TestRenderViewContextMenu menu( 141 TestRenderViewContextMenu menu(
111 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), 142 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(),
112 params); 143 params);
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 375
345 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenImageInNewTab) { 376 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenImageInNewTab) {
346 scoped_ptr<TestRenderViewContextMenu> menu( 377 scoped_ptr<TestRenderViewContextMenu> menu(
347 CreateContextMenu(GURL(), GURL("http://url.com/image.png"), 378 CreateContextMenu(GURL(), GURL("http://url.com/image.png"),
348 blink::WebContextMenuData::MediaTypeImage)); 379 blink::WebContextMenuData::MediaTypeImage));
349 ASSERT_FALSE( 380 ASSERT_FALSE(
350 menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB)); 381 menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB));
351 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB)); 382 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB));
352 } 383 }
353 384
385 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenLinkInProfileEntryPresent) {
386 // Create two additional profiles, but do not yep open windows in them.
Peter Kasting 2015/06/16 22:01:47 Nit: yep -> yet
387 Profile* profile1 = CreateSecondaryProfile(1);
388 Profile* profile2 = CreateSecondaryProfile(2);
389 {
390 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenuMediaTypeNone(
391 GURL("http://www.google.com/"), GURL("http://www.google.com/")));
392
393 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB));
394 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW));
395 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION));
396 // We only show the menu if the profiles actually have an active browser.
Peter Kasting 2015/06/16 22:01:47 Nit: Maybe: "With only the current profile open, w
397 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE));
398 ASSERT_FALSE(menu->IsItemInRangePresent(IDC_OPEN_LINK_IN_PROFILE_FIRST,
399 IDC_OPEN_LINK_IN_PROFILE_LAST));
400 }
401
402 profiles::FindOrCreateNewWindowForProfile(
403 profile1, chrome::startup::IS_NOT_PROCESS_STARTUP,
404 chrome::startup::IS_NOT_FIRST_RUN, chrome::GetActiveDesktop(), false);
405 {
406 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenuMediaTypeNone(
407 GURL("http://www.google.com/"), GURL("http://www.google.com/")));
408
409 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB));
410 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW));
411 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION));
412 // With two profiles (the current and another profile), no submenu is
413 // created. Instead, a single item is added to the main context menu.
414 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE));
415 ASSERT_TRUE(menu->IsItemInRangePresent(IDC_OPEN_LINK_IN_PROFILE_FIRST,
416 IDC_OPEN_LINK_IN_PROFILE_LAST));
417 }
418
419 profiles::FindOrCreateNewWindowForProfile(
420 profile2, chrome::startup::IS_NOT_PROCESS_STARTUP,
421 chrome::startup::IS_NOT_FIRST_RUN, chrome::GetActiveDesktop(), false);
422 {
423 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenuMediaTypeNone(
424 GURL("http://www.google.com/"), GURL("http://www.google.com/")));
425
426 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB));
427 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW));
428 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION));
429 // With three or more profiles (the current profile and at least two
430 // others), we show a submenu.
431 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE));
432 ASSERT_FALSE(menu->IsItemInRangePresent(IDC_OPEN_LINK_IN_PROFILE_FIRST,
433 IDC_OPEN_LINK_IN_PROFILE_LAST));
434 }
435 }
436
437 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenLinkInProfile) {
438 Profile* other_profile = CreateSecondaryProfile(1);
439 profiles::FindOrCreateNewWindowForProfile(
440 other_profile, chrome::startup::IS_NOT_PROCESS_STARTUP,
441 chrome::startup::IS_NOT_FIRST_RUN, chrome::GetActiveDesktop(), false);
442
443 ui_test_utils::WindowedTabAddedNotificationObserver tab_observer(
444 content::NotificationService::AllSources());
445
446 ASSERT_TRUE(test_server()->Start());
447 GURL url(test_server()->GetURL(std::string()));
448
449 scoped_ptr<TestRenderViewContextMenu> menu(
450 CreateContextMenuMediaTypeNone(url, url));
451
452 menu->ExecuteCommand(
453 IDC_OPEN_LINK_IN_PROFILE_FIRST +
454 g_browser_process->profile_manager()
455 ->GetProfileInfoCache()
456 .GetIndexOfProfileWithPath(other_profile->GetPath()),
457 0);
458
459 tab_observer.Wait();
460 content::WebContents* tab = tab_observer.GetTab();
461 content::WaitForLoadStop(tab);
462
463 // Verify that it's the correct tab and profile.
464 ASSERT_EQ(url, tab->GetURL());
465 ASSERT_EQ(other_profile,
466 Profile::FromBrowserContext(tab->GetBrowserContext()));
467 }
468
354 class ThumbnailResponseWatcher : public content::NotificationObserver { 469 class ThumbnailResponseWatcher : public content::NotificationObserver {
355 public: 470 public:
356 enum QuitReason { 471 enum QuitReason {
357 STILL_RUNNING = 0, 472 STILL_RUNNING = 0,
358 THUMBNAIL_RECEIVED, 473 THUMBNAIL_RECEIVED,
359 RENDER_PROCESS_GONE, 474 RENDER_PROCESS_GONE,
360 }; 475 };
361 476
362 class MessageFilter : public content::BrowserMessageFilter { 477 class MessageFilter : public content::BrowserMessageFilter {
363 public: 478 public:
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 IN_PROC_BROWSER_TEST_F(LoadImageBrowserTest, LoadImage) { 760 IN_PROC_BROWSER_TEST_F(LoadImageBrowserTest, LoadImage) {
646 static const char kValidImage[] = "files/load_image/image.png"; 761 static const char kValidImage[] = "files/load_image/image.png";
647 SetupAndLoadImagePage(kValidImage); 762 SetupAndLoadImagePage(kValidImage);
648 AddLoadImageInterceptor(kValidImage); 763 AddLoadImageInterceptor(kValidImage);
649 AttemptLoadImage(); 764 AttemptLoadImage();
650 interceptor_->WaitForRequests(1); 765 interceptor_->WaitForRequests(1);
651 EXPECT_EQ(1, interceptor_->num_requests()); 766 EXPECT_EQ(1, interceptor_->num_requests());
652 } 767 }
653 768
654 } // namespace 769 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698