| OLD | NEW |
| 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 10 matching lines...) Expand all Loading... |
| 36 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
| 37 #include "content/public/test/browser_test_utils.h" | 40 #include "content/public/test/browser_test_utils.h" |
| 38 #include "content/public/test/test_utils.h" | 41 #include "content/public/test/test_utils.h" |
| 39 #include "net/base/load_flags.h" | 42 #include "net/base/load_flags.h" |
| 40 #include "net/url_request/url_request.h" | 43 #include "net/url_request/url_request.h" |
| 41 #include "net/url_request/url_request_filter.h" | 44 #include "net/url_request/url_request_filter.h" |
| 42 #include "net/url_request/url_request_interceptor.h" | 45 #include "net/url_request/url_request_interceptor.h" |
| 43 #include "third_party/WebKit/public/web/WebContextMenuData.h" | 46 #include "third_party/WebKit/public/web/WebContextMenuData.h" |
| 44 #include "third_party/WebKit/public/web/WebInputEvent.h" | 47 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 45 | 48 |
| 49 #if defined(OS_CHROMEOS) |
| 50 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 51 #include "components/user_manager/user_manager.h" |
| 52 #endif |
| 53 |
| 46 using content::WebContents; | 54 using content::WebContents; |
| 47 | 55 |
| 48 namespace { | 56 namespace { |
| 49 | 57 |
| 50 class ContextMenuBrowserTest : public InProcessBrowserTest { | 58 class ContextMenuBrowserTest : public InProcessBrowserTest { |
| 51 public: | 59 public: |
| 52 ContextMenuBrowserTest() {} | 60 ContextMenuBrowserTest() {} |
| 53 | 61 |
| 54 TestRenderViewContextMenu* CreateContextMenu( | 62 TestRenderViewContextMenu* CreateContextMenu( |
| 55 const GURL& unfiltered_url, | 63 const GURL& unfiltered_url, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 74 menu->Init(); | 82 menu->Init(); |
| 75 return menu; | 83 return menu; |
| 76 } | 84 } |
| 77 | 85 |
| 78 TestRenderViewContextMenu* CreateContextMenuMediaTypeNone( | 86 TestRenderViewContextMenu* CreateContextMenuMediaTypeNone( |
| 79 const GURL& unfiltered_url, | 87 const GURL& unfiltered_url, |
| 80 const GURL& url) { | 88 const GURL& url) { |
| 81 return CreateContextMenu(unfiltered_url, url, | 89 return CreateContextMenu(unfiltered_url, url, |
| 82 blink::WebContextMenuData::MediaTypeNone); | 90 blink::WebContextMenuData::MediaTypeNone); |
| 83 } | 91 } |
| 92 |
| 93 Profile* CreateSecondaryProfile(int profile_num) { |
| 94 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 95 base::FilePath profile_path = profile_manager->user_data_dir(); |
| 96 #if defined(OS_CHROMEOS) |
| 97 std::string profile_name = base::StringPrintf("NewProfile%d", profile_num); |
| 98 user_manager::UserManager::Get()->UserLoggedIn( |
| 99 base::StringPrintf("user%d@test.com", profile_num), profile_name, |
| 100 false); |
| 101 profile_path = profile_path.Append( |
| 102 chromeos::ProfileHelper::GetUserProfileDir(profile_name).BaseName()); |
| 103 #else |
| 104 profile_path = profile_path.AppendASCII( |
| 105 base::StringPrintf("New Profile %d", profile_num)); |
| 106 #endif |
| 107 return profile_manager->GetProfile(profile_path); |
| 108 } |
| 84 }; | 109 }; |
| 85 | 110 |
| 86 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, | 111 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, |
| 87 OpenEntryPresentForNormalURLs) { | 112 OpenEntryPresentForNormalURLs) { |
| 88 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenuMediaTypeNone( | 113 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenuMediaTypeNone( |
| 89 GURL("http://www.google.com/"), GURL("http://www.google.com/"))); | 114 GURL("http://www.google.com/"), GURL("http://www.google.com/"))); |
| 90 | 115 |
| 91 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); | 116 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); |
| 92 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); | 117 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); |
| 93 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); | 118 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); |
| 119 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE)); |
| 120 ASSERT_FALSE(menu->IsItemInRangePresent(IDC_OPEN_LINK_IN_PROFILE_FIRST, |
| 121 IDC_OPEN_LINK_IN_PROFILE_LAST)); |
| 94 } | 122 } |
| 95 | 123 |
| 96 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, | 124 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, |
| 97 OpenEntryAbsentForFilteredURLs) { | 125 OpenEntryAbsentForFilteredURLs) { |
| 98 scoped_ptr<TestRenderViewContextMenu> menu( | 126 scoped_ptr<TestRenderViewContextMenu> menu( |
| 99 CreateContextMenuMediaTypeNone(GURL("chrome://history"), GURL())); | 127 CreateContextMenuMediaTypeNone(GURL("chrome://history"), GURL())); |
| 100 | 128 |
| 101 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); | 129 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); |
| 102 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); | 130 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); |
| 103 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)); |
| 104 } | 135 } |
| 105 | 136 |
| 106 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, | 137 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, |
| 107 ContextMenuForCanvas) { | 138 ContextMenuForCanvas) { |
| 108 content::ContextMenuParams params; | 139 content::ContextMenuParams params; |
| 109 params.media_type = blink::WebContextMenuData::MediaTypeCanvas; | 140 params.media_type = blink::WebContextMenuData::MediaTypeCanvas; |
| 110 | 141 |
| 111 TestRenderViewContextMenu menu( | 142 TestRenderViewContextMenu menu( |
| 112 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), | 143 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), |
| 113 params); | 144 params); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 | 376 |
| 346 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenImageInNewTab) { | 377 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenImageInNewTab) { |
| 347 scoped_ptr<TestRenderViewContextMenu> menu( | 378 scoped_ptr<TestRenderViewContextMenu> menu( |
| 348 CreateContextMenu(GURL(), GURL("http://url.com/image.png"), | 379 CreateContextMenu(GURL(), GURL("http://url.com/image.png"), |
| 349 blink::WebContextMenuData::MediaTypeImage)); | 380 blink::WebContextMenuData::MediaTypeImage)); |
| 350 ASSERT_FALSE( | 381 ASSERT_FALSE( |
| 351 menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB)); | 382 menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB)); |
| 352 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB)); | 383 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB)); |
| 353 } | 384 } |
| 354 | 385 |
| 386 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenLinkInProfileEntryPresent) { |
| 387 // Create two additional profiles, but do not yet open windows in them. |
| 388 Profile* profile1 = CreateSecondaryProfile(1); |
| 389 Profile* profile2 = CreateSecondaryProfile(2); |
| 390 { |
| 391 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenuMediaTypeNone( |
| 392 GURL("http://www.google.com/"), GURL("http://www.google.com/"))); |
| 393 |
| 394 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); |
| 395 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); |
| 396 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); |
| 397 // With only the current profile open, we don't add any items to the |
| 398 // context menu for opening links in other profiles. |
| 399 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE)); |
| 400 ASSERT_FALSE(menu->IsItemInRangePresent(IDC_OPEN_LINK_IN_PROFILE_FIRST, |
| 401 IDC_OPEN_LINK_IN_PROFILE_LAST)); |
| 402 } |
| 403 |
| 404 profiles::FindOrCreateNewWindowForProfile( |
| 405 profile1, chrome::startup::IS_NOT_PROCESS_STARTUP, |
| 406 chrome::startup::IS_NOT_FIRST_RUN, chrome::GetActiveDesktop(), false); |
| 407 { |
| 408 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenuMediaTypeNone( |
| 409 GURL("http://www.google.com/"), GURL("http://www.google.com/"))); |
| 410 |
| 411 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); |
| 412 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); |
| 413 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); |
| 414 // With two profiles (the current and another profile), no submenu is |
| 415 // created. Instead, a single item is added to the main context menu. |
| 416 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE)); |
| 417 ASSERT_TRUE(menu->IsItemInRangePresent(IDC_OPEN_LINK_IN_PROFILE_FIRST, |
| 418 IDC_OPEN_LINK_IN_PROFILE_LAST)); |
| 419 } |
| 420 |
| 421 profiles::FindOrCreateNewWindowForProfile( |
| 422 profile2, chrome::startup::IS_NOT_PROCESS_STARTUP, |
| 423 chrome::startup::IS_NOT_FIRST_RUN, chrome::GetActiveDesktop(), false); |
| 424 { |
| 425 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenuMediaTypeNone( |
| 426 GURL("http://www.google.com/"), GURL("http://www.google.com/"))); |
| 427 |
| 428 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); |
| 429 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); |
| 430 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); |
| 431 // With three profiles (the current profile and exactly two others), we |
| 432 // show two inline items. |
| 433 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE)); |
| 434 ASSERT_TRUE(menu->IsItemInRangePresent(IDC_OPEN_LINK_IN_PROFILE_FIRST, |
| 435 IDC_OPEN_LINK_IN_PROFILE_LAST)); |
| 436 } |
| 437 |
| 438 // Create a third additional profile, but don't create any windows in it. |
| 439 CreateSecondaryProfile(3); |
| 440 |
| 441 { |
| 442 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenuMediaTypeNone( |
| 443 GURL("http://www.google.com/"), GURL("http://www.google.com/"))); |
| 444 |
| 445 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); |
| 446 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); |
| 447 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); |
| 448 // As soon as a third additional profile is present, we show all profiles |
| 449 // in a submenu. |
| 450 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE)); |
| 451 ASSERT_FALSE(menu->IsItemInRangePresent(IDC_OPEN_LINK_IN_PROFILE_FIRST, |
| 452 IDC_OPEN_LINK_IN_PROFILE_LAST)); |
| 453 } |
| 454 } |
| 455 |
| 456 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenLinkInProfile) { |
| 457 Profile* other_profile = CreateSecondaryProfile(1); |
| 458 profiles::FindOrCreateNewWindowForProfile( |
| 459 other_profile, chrome::startup::IS_NOT_PROCESS_STARTUP, |
| 460 chrome::startup::IS_NOT_FIRST_RUN, chrome::GetActiveDesktop(), false); |
| 461 |
| 462 ui_test_utils::WindowedTabAddedNotificationObserver tab_observer( |
| 463 content::NotificationService::AllSources()); |
| 464 |
| 465 ASSERT_TRUE(test_server()->Start()); |
| 466 GURL url(test_server()->GetURL(std::string())); |
| 467 |
| 468 scoped_ptr<TestRenderViewContextMenu> menu( |
| 469 CreateContextMenuMediaTypeNone(url, url)); |
| 470 |
| 471 menu->ExecuteCommand( |
| 472 IDC_OPEN_LINK_IN_PROFILE_FIRST + |
| 473 g_browser_process->profile_manager() |
| 474 ->GetProfileInfoCache() |
| 475 .GetIndexOfProfileWithPath(other_profile->GetPath()), |
| 476 0); |
| 477 |
| 478 tab_observer.Wait(); |
| 479 content::WebContents* tab = tab_observer.GetTab(); |
| 480 content::WaitForLoadStop(tab); |
| 481 |
| 482 // Verify that it's the correct tab and profile. |
| 483 ASSERT_EQ(url, tab->GetURL()); |
| 484 ASSERT_EQ(other_profile, |
| 485 Profile::FromBrowserContext(tab->GetBrowserContext())); |
| 486 } |
| 487 |
| 355 class ThumbnailResponseWatcher : public content::NotificationObserver { | 488 class ThumbnailResponseWatcher : public content::NotificationObserver { |
| 356 public: | 489 public: |
| 357 enum QuitReason { | 490 enum QuitReason { |
| 358 STILL_RUNNING = 0, | 491 STILL_RUNNING = 0, |
| 359 THUMBNAIL_RECEIVED, | 492 THUMBNAIL_RECEIVED, |
| 360 RENDER_PROCESS_GONE, | 493 RENDER_PROCESS_GONE, |
| 361 }; | 494 }; |
| 362 | 495 |
| 363 class MessageFilter : public content::BrowserMessageFilter { | 496 class MessageFilter : public content::BrowserMessageFilter { |
| 364 public: | 497 public: |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 IN_PROC_BROWSER_TEST_F(LoadImageBrowserTest, LoadImage) { | 779 IN_PROC_BROWSER_TEST_F(LoadImageBrowserTest, LoadImage) { |
| 647 static const char kValidImage[] = "files/load_image/image.png"; | 780 static const char kValidImage[] = "files/load_image/image.png"; |
| 648 SetupAndLoadImagePage(kValidImage); | 781 SetupAndLoadImagePage(kValidImage); |
| 649 AddLoadImageInterceptor(kValidImage); | 782 AddLoadImageInterceptor(kValidImage); |
| 650 AttemptLoadImage(); | 783 AttemptLoadImage(); |
| 651 interceptor_->WaitForRequests(1); | 784 interceptor_->WaitForRequests(1); |
| 652 EXPECT_EQ(1, interceptor_->num_requests()); | 785 EXPECT_EQ(1, interceptor_->num_requests()); |
| 653 } | 786 } |
| 654 | 787 |
| 655 } // namespace | 788 } // namespace |
| OLD | NEW |