Chromium Code Reviews| 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/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 Loading... | |
| 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 Loading... | |
| 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 Profile* profile1 = CreateSecondaryProfile(1); | |
| 387 Profile* profile2 = CreateSecondaryProfile(2); | |
| 388 { | |
| 389 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenuMediaTypeNone( | |
| 390 GURL("http://www.google.com/"), GURL("http://www.google.com/"))); | |
| 391 | |
| 392 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); | |
| 393 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); | |
| 394 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); | |
| 395 // We only show the menu if the profiles actually have an active browser. | |
| 396 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE)); | |
| 397 ASSERT_FALSE(menu->IsItemInRangePresent(IDC_OPEN_LINK_IN_PROFILE_FIRST, | |
| 398 IDC_OPEN_LINK_IN_PROFILE_LAST)); | |
| 399 } | |
| 400 | |
| 401 profiles::FindOrCreateNewWindowForProfile( | |
| 402 profile1, chrome::startup::IS_NOT_PROCESS_STARTUP, | |
| 403 chrome::startup::IS_NOT_FIRST_RUN, chrome::GetActiveDesktop(), false); | |
| 404 { | |
| 405 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenuMediaTypeNone( | |
| 406 GURL("http://www.google.com/"), GURL("http://www.google.com/"))); | |
| 407 | |
| 408 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); | |
| 409 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); | |
| 410 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); | |
| 411 // With two profiles, we don't show a submenu. | |
|
Peter Kasting
2015/06/15 23:45:15
This comment is the same as the one below, but the
jochen (gone - plz use gerrit)
2015/06/16 08:00:14
done
Peter Kasting
2015/06/16 08:20:24
I'm still confused. Now the two comments both men
jochen (gone - plz use gerrit)
2015/06/16 09:01:50
I shouldn't try to write comments in the early mor
| |
| 412 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE)); | |
| 413 ASSERT_TRUE(menu->IsItemInRangePresent(IDC_OPEN_LINK_IN_PROFILE_FIRST, | |
| 414 IDC_OPEN_LINK_IN_PROFILE_LAST)); | |
| 415 } | |
| 416 | |
| 417 profiles::FindOrCreateNewWindowForProfile( | |
| 418 profile2, chrome::startup::IS_NOT_PROCESS_STARTUP, | |
| 419 chrome::startup::IS_NOT_FIRST_RUN, chrome::GetActiveDesktop(), false); | |
| 420 { | |
| 421 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenuMediaTypeNone( | |
| 422 GURL("http://www.google.com/"), GURL("http://www.google.com/"))); | |
| 423 | |
| 424 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); | |
| 425 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); | |
| 426 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); | |
| 427 // With three or more profiles, we don't show a submenu. | |
| 428 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE)); | |
| 429 ASSERT_FALSE(menu->IsItemInRangePresent(IDC_OPEN_LINK_IN_PROFILE_FIRST, | |
| 430 IDC_OPEN_LINK_IN_PROFILE_LAST)); | |
| 431 } | |
| 432 } | |
| 433 | |
| 434 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenLinkInProfile) { | |
| 435 Profile* other_profile = CreateSecondaryProfile(1); | |
| 436 profiles::FindOrCreateNewWindowForProfile( | |
| 437 other_profile, chrome::startup::IS_NOT_PROCESS_STARTUP, | |
| 438 chrome::startup::IS_NOT_FIRST_RUN, chrome::GetActiveDesktop(), false); | |
| 439 | |
| 440 ui_test_utils::WindowedTabAddedNotificationObserver tab_observer( | |
| 441 content::NotificationService::AllSources()); | |
| 442 | |
| 443 ASSERT_TRUE(test_server()->Start()); | |
| 444 GURL url(test_server()->GetURL(std::string())); | |
| 445 | |
| 446 scoped_ptr<TestRenderViewContextMenu> menu( | |
| 447 CreateContextMenuMediaTypeNone(url, url)); | |
| 448 | |
| 449 menu->ExecuteCommand( | |
| 450 IDC_OPEN_LINK_IN_PROFILE_FIRST + | |
| 451 g_browser_process->profile_manager() | |
| 452 ->GetProfileInfoCache() | |
| 453 .GetIndexOfProfileWithPath(other_profile->GetPath()), | |
| 454 0); | |
| 455 | |
| 456 tab_observer.Wait(); | |
| 457 content::WebContents* tab = tab_observer.GetTab(); | |
| 458 content::WaitForLoadStop(tab); | |
| 459 | |
| 460 // Verify that it's the correct tab and profile. | |
| 461 ASSERT_EQ(url, tab->GetURL()); | |
| 462 ASSERT_EQ(other_profile, | |
| 463 Profile::FromBrowserContext(tab->GetBrowserContext())); | |
| 464 } | |
| 465 | |
| 354 class ThumbnailResponseWatcher : public content::NotificationObserver { | 466 class ThumbnailResponseWatcher : public content::NotificationObserver { |
| 355 public: | 467 public: |
| 356 enum QuitReason { | 468 enum QuitReason { |
| 357 STILL_RUNNING = 0, | 469 STILL_RUNNING = 0, |
| 358 THUMBNAIL_RECEIVED, | 470 THUMBNAIL_RECEIVED, |
| 359 RENDER_PROCESS_GONE, | 471 RENDER_PROCESS_GONE, |
| 360 }; | 472 }; |
| 361 | 473 |
| 362 class MessageFilter : public content::BrowserMessageFilter { | 474 class MessageFilter : public content::BrowserMessageFilter { |
| 363 public: | 475 public: |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 645 IN_PROC_BROWSER_TEST_F(ShowImageBrowserTest, ShowImage) { | 757 IN_PROC_BROWSER_TEST_F(ShowImageBrowserTest, ShowImage) { |
| 646 static const char kValidImage[] = "files/show_image/image.png"; | 758 static const char kValidImage[] = "files/show_image/image.png"; |
| 647 SetupAndLoadImagePage(kValidImage); | 759 SetupAndLoadImagePage(kValidImage); |
| 648 AddShowImageInterceptor(kValidImage); | 760 AddShowImageInterceptor(kValidImage); |
| 649 AttemptShowImage(); | 761 AttemptShowImage(); |
| 650 interceptor_->WaitForRequests(1); | 762 interceptor_->WaitForRequests(1); |
| 651 EXPECT_EQ(1, interceptor_->num_requests()); | 763 EXPECT_EQ(1, interceptor_->num_requests()); |
| 652 } | 764 } |
| 653 | 765 |
| 654 } // namespace | 766 } // namespace |
| OLD | NEW |