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

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, 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
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/search_test_utils.h" 27 #include "chrome/test/base/search_test_utils.h"
25 #include "chrome/test/base/ui_test_utils.h" 28 #include "chrome/test/base/ui_test_utils.h"
(...skipping 11 matching lines...) Expand all
37 #include "content/public/browser/web_contents.h" 40 #include "content/public/browser/web_contents.h"
38 #include "content/public/test/browser_test_utils.h" 41 #include "content/public/test/browser_test_utils.h"
39 #include "content/public/test/test_utils.h" 42 #include "content/public/test/test_utils.h"
40 #include "net/base/load_flags.h" 43 #include "net/base/load_flags.h"
41 #include "net/url_request/url_request.h" 44 #include "net/url_request/url_request.h"
42 #include "net/url_request/url_request_filter.h" 45 #include "net/url_request/url_request_filter.h"
43 #include "net/url_request/url_request_interceptor.h" 46 #include "net/url_request/url_request_interceptor.h"
44 #include "third_party/WebKit/public/web/WebContextMenuData.h" 47 #include "third_party/WebKit/public/web/WebContextMenuData.h"
45 #include "third_party/WebKit/public/web/WebInputEvent.h" 48 #include "third_party/WebKit/public/web/WebInputEvent.h"
46 49
50 #if defined(OS_CHROMEOS)
51 #include "chrome/browser/chromeos/profiles/profile_helper.h"
52 #include "components/user_manager/user_manager.h"
53 #endif
54
47 using content::WebContents; 55 using content::WebContents;
48 56
49 namespace { 57 namespace {
50 58
51 class ContextMenuBrowserTest : public InProcessBrowserTest { 59 class ContextMenuBrowserTest : public InProcessBrowserTest {
52 public: 60 public:
53 ContextMenuBrowserTest() {} 61 ContextMenuBrowserTest() {}
54 62
55 protected: 63 protected:
56 scoped_ptr<TestRenderViewContextMenu> CreateContextMenuMediaTypeNone( 64 scoped_ptr<TestRenderViewContextMenu> CreateContextMenuMediaTypeNone(
(...skipping 30 matching lines...) Expand all
87 #if defined(OS_MACOSX) 95 #if defined(OS_MACOSX)
88 params.writing_direction_default = 0; 96 params.writing_direction_default = 0;
89 params.writing_direction_left_to_right = 0; 97 params.writing_direction_left_to_right = 0;
90 params.writing_direction_right_to_left = 0; 98 params.writing_direction_right_to_left = 0;
91 #endif // OS_MACOSX 99 #endif // OS_MACOSX
92 scoped_ptr<TestRenderViewContextMenu> menu( 100 scoped_ptr<TestRenderViewContextMenu> menu(
93 new TestRenderViewContextMenu(web_contents->GetMainFrame(), params)); 101 new TestRenderViewContextMenu(web_contents->GetMainFrame(), params));
94 menu->Init(); 102 menu->Init();
95 return menu; 103 return menu;
96 } 104 }
105
106 Profile* CreateSecondaryProfile(int profile_num) {
107 ProfileManager* profile_manager = g_browser_process->profile_manager();
108 base::FilePath profile_path = profile_manager->user_data_dir();
109 #if defined(OS_CHROMEOS)
110 std::string profile_name = base::StringPrintf("NewProfile%d", profile_num);
111 user_manager::UserManager::Get()->UserLoggedIn(
112 base::StringPrintf("user%d@test.com", profile_num), profile_name,
113 false);
114 profile_path = profile_path.Append(
115 chromeos::ProfileHelper::GetUserProfileDir(profile_name).BaseName());
116 #else
117 profile_path = profile_path.AppendASCII(
118 base::StringPrintf("New Profile %d", profile_num));
119 #endif
120 return profile_manager->GetProfile(profile_path);
121 }
97 }; 122 };
98 123
99 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, 124 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest,
100 OpenEntryPresentForNormalURLs) { 125 OpenEntryPresentForNormalURLs) {
101 scoped_ptr<TestRenderViewContextMenu> menu = CreateContextMenuMediaTypeNone( 126 scoped_ptr<TestRenderViewContextMenu> menu = CreateContextMenuMediaTypeNone(
102 GURL("http://www.google.com/"), GURL("http://www.google.com/")); 127 GURL("http://www.google.com/"), GURL("http://www.google.com/"));
103 128
104 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); 129 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB));
105 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); 130 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW));
106 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); 131 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION));
132 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE));
133 ASSERT_FALSE(menu->IsItemInRangePresent(IDC_OPEN_LINK_IN_PROFILE_FIRST,
134 IDC_OPEN_LINK_IN_PROFILE_LAST));
107 } 135 }
108 136
109 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, 137 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest,
110 OpenEntryAbsentForFilteredURLs) { 138 OpenEntryAbsentForFilteredURLs) {
111 scoped_ptr<TestRenderViewContextMenu> menu = 139 scoped_ptr<TestRenderViewContextMenu> menu =
112 CreateContextMenuMediaTypeNone(GURL("chrome://history"), GURL()); 140 CreateContextMenuMediaTypeNone(GURL("chrome://history"), GURL());
113 141
114 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); 142 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB));
115 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); 143 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW));
116 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); 144 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION));
145 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE));
146 ASSERT_FALSE(menu->IsItemInRangePresent(IDC_OPEN_LINK_IN_PROFILE_FIRST,
147 IDC_OPEN_LINK_IN_PROFILE_LAST));
117 } 148 }
118 149
119 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, ContextMenuForCanvas) { 150 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, ContextMenuForCanvas) {
120 content::ContextMenuParams params; 151 content::ContextMenuParams params;
121 params.media_type = blink::WebContextMenuData::MediaTypeCanvas; 152 params.media_type = blink::WebContextMenuData::MediaTypeCanvas;
122 153
123 TestRenderViewContextMenu menu( 154 TestRenderViewContextMenu menu(
124 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), 155 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(),
125 params); 156 params);
126 menu.Init(); 157 menu.Init();
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 } 421 }
391 422
392 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenImageInNewTab) { 423 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenImageInNewTab) {
393 scoped_ptr<TestRenderViewContextMenu> menu = 424 scoped_ptr<TestRenderViewContextMenu> menu =
394 CreateContextMenuMediaTypeImage(GURL("http://url.com/image.png")); 425 CreateContextMenuMediaTypeImage(GURL("http://url.com/image.png"));
395 ASSERT_FALSE( 426 ASSERT_FALSE(
396 menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB)); 427 menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB));
397 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB)); 428 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB));
398 } 429 }
399 430
431 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenLinkInProfileEntryPresent) {
432 {
433 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenuMediaTypeNone(
434 GURL("http://www.google.com/"), GURL("http://www.google.com/")));
435
436 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB));
437 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW));
438 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION));
439 // With only one profile exists, we don't add any items to the context menu
440 // for opening links in other profiles.
441 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE));
442 ASSERT_FALSE(menu->IsItemInRangePresent(IDC_OPEN_LINK_IN_PROFILE_FIRST,
443 IDC_OPEN_LINK_IN_PROFILE_LAST));
444 }
445
446 // Create one additional profile, but do not yet open windows in it.
447 CreateSecondaryProfile(1);
448
449 {
450 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenuMediaTypeNone(
451 GURL("http://www.google.com/"), GURL("http://www.google.com/")));
452
453 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB));
454 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW));
455 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION));
456 // With two profiles (the current and another profile), no submenu is
457 // created. Instead, a single item is added to the main context menu.
458 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE));
459 ASSERT_TRUE(menu->IsItemInRangePresent(IDC_OPEN_LINK_IN_PROFILE_FIRST,
460 IDC_OPEN_LINK_IN_PROFILE_LAST));
461 }
462
463 CreateSecondaryProfile(2);
464
465 {
466 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenuMediaTypeNone(
467 GURL("http://www.google.com/"), GURL("http://www.google.com/")));
468
469 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB));
470 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW));
471 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION));
472 // As soon as at least three profiles exist, we show all profiles in a
473 // submenu.
474 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE));
475 ASSERT_FALSE(menu->IsItemInRangePresent(IDC_OPEN_LINK_IN_PROFILE_FIRST,
476 IDC_OPEN_LINK_IN_PROFILE_LAST));
477 }
478 }
479
480 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenLinkInProfile) {
481 Profile* other_profile = CreateSecondaryProfile(1);
482 profiles::FindOrCreateNewWindowForProfile(
483 other_profile, chrome::startup::IS_NOT_PROCESS_STARTUP,
484 chrome::startup::IS_NOT_FIRST_RUN, chrome::GetActiveDesktop(), false);
485
486 ui_test_utils::WindowedTabAddedNotificationObserver tab_observer(
487 content::NotificationService::AllSources());
488
489 ASSERT_TRUE(test_server()->Start());
490 GURL url(test_server()->GetURL(std::string()));
491
492 scoped_ptr<TestRenderViewContextMenu> menu(
493 CreateContextMenuMediaTypeNone(url, url));
494
495 menu->ExecuteCommand(
496 IDC_OPEN_LINK_IN_PROFILE_FIRST +
497 g_browser_process->profile_manager()
498 ->GetProfileInfoCache()
499 .GetIndexOfProfileWithPath(other_profile->GetPath()),
500 0);
501
502 tab_observer.Wait();
503 content::WebContents* tab = tab_observer.GetTab();
504 content::WaitForLoadStop(tab);
505
506 // Verify that it's the correct tab and profile.
507 ASSERT_EQ(url, tab->GetURL());
508 ASSERT_EQ(other_profile,
509 Profile::FromBrowserContext(tab->GetBrowserContext()));
510 }
511
400 class ThumbnailResponseWatcher : public content::NotificationObserver { 512 class ThumbnailResponseWatcher : public content::NotificationObserver {
401 public: 513 public:
402 enum QuitReason { 514 enum QuitReason {
403 STILL_RUNNING = 0, 515 STILL_RUNNING = 0,
404 THUMBNAIL_RECEIVED, 516 THUMBNAIL_RECEIVED,
405 RENDER_PROCESS_GONE, 517 RENDER_PROCESS_GONE,
406 }; 518 };
407 519
408 class MessageFilter : public content::BrowserMessageFilter { 520 class MessageFilter : public content::BrowserMessageFilter {
409 public: 521 public:
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 IN_PROC_BROWSER_TEST_F(LoadImageBrowserTest, LoadImage) { 803 IN_PROC_BROWSER_TEST_F(LoadImageBrowserTest, LoadImage) {
692 static const char kValidImage[] = "files/load_image/image.png"; 804 static const char kValidImage[] = "files/load_image/image.png";
693 SetupAndLoadImagePage(kValidImage); 805 SetupAndLoadImagePage(kValidImage);
694 AddLoadImageInterceptor(kValidImage); 806 AddLoadImageInterceptor(kValidImage);
695 AttemptLoadImage(); 807 AttemptLoadImage();
696 interceptor_->WaitForRequests(1); 808 interceptor_->WaitForRequests(1);
697 EXPECT_EQ(1, interceptor_->num_requests()); 809 EXPECT_EQ(1, interceptor_->num_requests());
698 } 810 }
699 811
700 } // namespace 812 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698