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

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

Issue 1754393002: Fix current profile is unnecessary added to "Open link as" context menu. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix implicit conversion of signed and unsigned integers Created 4 years, 9 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 "chrome/browser/renderer_context_menu/render_view_context_menu.h" 5 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "content/public/browser/web_contents.h" 47 #include "content/public/browser/web_contents.h"
48 #include "content/public/test/browser_test_utils.h" 48 #include "content/public/test/browser_test_utils.h"
49 #include "content/public/test/test_utils.h" 49 #include "content/public/test/test_utils.h"
50 #include "net/base/load_flags.h" 50 #include "net/base/load_flags.h"
51 #include "net/test/embedded_test_server/embedded_test_server.h" 51 #include "net/test/embedded_test_server/embedded_test_server.h"
52 #include "net/url_request/url_request.h" 52 #include "net/url_request/url_request.h"
53 #include "net/url_request/url_request_filter.h" 53 #include "net/url_request/url_request_filter.h"
54 #include "net/url_request/url_request_interceptor.h" 54 #include "net/url_request/url_request_interceptor.h"
55 #include "third_party/WebKit/public/web/WebContextMenuData.h" 55 #include "third_party/WebKit/public/web/WebContextMenuData.h"
56 #include "third_party/WebKit/public/web/WebInputEvent.h" 56 #include "third_party/WebKit/public/web/WebInputEvent.h"
57 #include "ui/base/models/menu_model.h"
57 58
58 using content::WebContents; 59 using content::WebContents;
59 60
60 namespace { 61 namespace {
61 62
62 class ContextMenuBrowserTest : public InProcessBrowserTest { 63 class ContextMenuBrowserTest : public InProcessBrowserTest {
63 public: 64 public:
64 ContextMenuBrowserTest() {} 65 ContextMenuBrowserTest() {}
65 66
66 protected: 67 protected:
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 { 447 {
447 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenuMediaTypeNone( 448 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenuMediaTypeNone(
448 GURL("http://www.google.com/"), GURL("http://www.google.com/"))); 449 GURL("http://www.google.com/"), GURL("http://www.google.com/")));
449 450
450 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); 451 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB));
451 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); 452 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW));
452 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); 453 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION));
453 // With two profiles (the current and another profile), no submenu is 454 // With two profiles (the current and another profile), no submenu is
454 // created. Instead, a single item is added to the main context menu. 455 // created. Instead, a single item is added to the main context menu.
455 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE)); 456 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE));
456 ASSERT_TRUE(menu->IsItemInRangePresent(IDC_OPEN_LINK_IN_PROFILE_FIRST, 457 ASSERT_TRUE(menu->IsItemPresent(IDC_OPEN_LINK_IN_PROFILE_FIRST));
457 IDC_OPEN_LINK_IN_PROFILE_LAST));
458 } 458 }
459 459
460 CreateSecondaryProfile(2); 460 CreateSecondaryProfile(2);
461 461
462 { 462 {
463 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenuMediaTypeNone( 463 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenuMediaTypeNone(
464 GURL("http://www.google.com/"), GURL("http://www.google.com/"))); 464 GURL("http://www.google.com/"), GURL("http://www.google.com/")));
465 465
466 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); 466 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB));
467 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); 467 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW));
468 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); 468 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION));
469 // As soon as at least three profiles exist, we show all profiles in a 469 // As soon as at least three profiles exist, we show all profiles in a
470 // submenu. 470 // submenu.
471 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE)); 471 ui::MenuModel* model = NULL;
472 int index = -1;
473 ASSERT_TRUE(menu->GetMenuModelAndItemIndex(IDC_OPEN_LINK_IN_PROFILE_FIRST,
474 &model, &index));
475 ASSERT_EQ(2, model->GetItemCount());
472 ASSERT_FALSE(menu->IsItemInRangePresent(IDC_OPEN_LINK_IN_PROFILE_FIRST, 476 ASSERT_FALSE(menu->IsItemInRangePresent(IDC_OPEN_LINK_IN_PROFILE_FIRST,
473 IDC_OPEN_LINK_IN_PROFILE_LAST)); 477 IDC_OPEN_LINK_IN_PROFILE_LAST));
474 } 478 }
475 } 479 }
476 480
477 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenLinkInProfile) { 481 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenLinkInProfile) {
478 // Create |num_profiles| extra profiles for testing. 482 // Create |num_profiles| extra profiles for testing.
479 const int num_profiles = 8; 483 const int num_profiles = 8;
480 // The following are the profile numbers that are omitted and need signin. 484 // The following are the profile numbers that are omitted and need signin.
481 // These profiles are not added to the menu. 485 // These profiles are not added to the menu. Omitted profiles refers to
482 const std::vector<int> profiles_omit{1, 4}; 486 // supervised profiles in the process of creation. Adding more than one
483 const std::vector<int> profiles_signin_required{3, 6}; 487 // omitted profile may result in DCHECK errors.
488 int profile_omit = 4;
489 const std::vector<int> profiles_signin_required{1, 3, 6};
484 490
485 // Create the profiles. 491 // Create the profiles.
486 ProfileAttributesStorage& storage = 492 ProfileAttributesStorage& storage =
487 g_browser_process->profile_manager()->GetProfileAttributesStorage(); 493 g_browser_process->profile_manager()->GetProfileAttributesStorage();
488 std::vector<Profile*> profiles_in_menu; 494 std::vector<Profile*> profiles_in_menu;
489 for (int i = 0; i < num_profiles; ++i) { 495 for (int i = 0; i < num_profiles; ++i) {
490 Profile* profile = CreateSecondaryProfile(i); 496 Profile* profile = CreateSecondaryProfile(i);
491 ProfileAttributesEntry* entry; 497 ProfileAttributesEntry* entry;
492 ASSERT_TRUE(storage.GetProfileAttributesWithPath(profile->GetPath(), 498 ASSERT_TRUE(storage.GetProfileAttributesWithPath(profile->GetPath(),
493 &entry)); 499 &entry));
494 // Open a browser window for the profile if and only if the profile is not 500 // Open a browser window for the profile if and only if the profile is not
495 // omitted nor needing signin. 501 // omitted nor needing signin.
496 if (std::binary_search(profiles_omit.begin(), profiles_omit.end(), i)) { 502 if (i == profile_omit) {
497 entry->SetIsOmitted(true); 503 entry->SetIsOmitted(true);
498 } else if (std::binary_search(profiles_signin_required.begin(), 504 } else if (std::binary_search(profiles_signin_required.begin(),
499 profiles_signin_required.end(), i)) { 505 profiles_signin_required.end(), i)) {
500 entry->SetIsSigninRequired(true); 506 entry->SetIsSigninRequired(true);
501 } else { 507 } else {
502 profiles::FindOrCreateNewWindowForProfile( 508 profiles::FindOrCreateNewWindowForProfile(
503 profile, chrome::startup::IS_NOT_PROCESS_STARTUP, 509 profile, chrome::startup::IS_NOT_PROCESS_STARTUP,
504 chrome::startup::IS_NOT_FIRST_RUN, false); 510 chrome::startup::IS_NOT_FIRST_RUN, false);
505 profiles_in_menu.push_back(profile); 511 profiles_in_menu.push_back(profile);
506 } 512 }
507 } 513 }
508 514
509 ui_test_utils::WindowedTabAddedNotificationObserver tab_observer( 515 ui_test_utils::WindowedTabAddedNotificationObserver tab_observer(
510 content::NotificationService::AllSources()); 516 content::NotificationService::AllSources());
511 517
512 ASSERT_TRUE(embedded_test_server()->Start()); 518 ASSERT_TRUE(embedded_test_server()->Start());
513 GURL url(embedded_test_server()->GetURL("/")); 519 GURL url(embedded_test_server()->GetURL("/"));
514 520
515 scoped_ptr<TestRenderViewContextMenu> menu( 521 scoped_ptr<TestRenderViewContextMenu> menu(
516 CreateContextMenuMediaTypeNone(url, url)); 522 CreateContextMenuMediaTypeNone(url, url));
517 523
524 // Verify that the size of the menu is correct.
525 ui::MenuModel* model = NULL;
526 int index = -1;
527 ASSERT_TRUE(menu->GetMenuModelAndItemIndex(IDC_OPEN_LINK_IN_PROFILE_FIRST,
528 &model, &index));
529 ASSERT_EQ(static_cast<int>(profiles_in_menu.size()), model->GetItemCount());
530
518 // Open the menu items. They should match their corresponding profiles in 531 // Open the menu items. They should match their corresponding profiles in
519 // |profiles_in_menu|. 532 // |profiles_in_menu|.
520 for (Profile* profile : profiles_in_menu) { 533 for (Profile* profile : profiles_in_menu) {
521 size_t menu_index = 534 int command_id = menu->GetCommandIDByProfilePath(profile->GetPath());
522 menu->GetItemIndexByProfilePath(profile->GetPath()); 535 ASSERT_NE(-1, command_id);
523 ASSERT_NE(std::string::npos, menu_index); 536 menu->ExecuteCommand(command_id, 0);
524 menu->ExecuteCommand(
525 IDC_OPEN_LINK_IN_PROFILE_FIRST + static_cast<int>(menu_index), 0);
526 537
527 tab_observer.Wait(); 538 tab_observer.Wait();
528 content::WebContents* tab = tab_observer.GetTab(); 539 content::WebContents* tab = tab_observer.GetTab();
529 content::WaitForLoadStop(tab); 540 content::WaitForLoadStop(tab);
530 541
531 // Verify that it's the correct tab and profile. 542 // Verify that it's the correct tab and profile.
532 EXPECT_EQ(url, tab->GetURL()); 543 EXPECT_EQ(url, tab->GetURL());
533 EXPECT_EQ(profile, Profile::FromBrowserContext(tab->GetBrowserContext())); 544 EXPECT_EQ(profile, Profile::FromBrowserContext(tab->GetBrowserContext()));
534 } 545 }
535 } 546 }
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 IN_PROC_BROWSER_TEST_F(LoadImageBrowserTest, LoadImage) { 841 IN_PROC_BROWSER_TEST_F(LoadImageBrowserTest, LoadImage) {
831 static const char kValidImage[] = "/load_image/image.png"; 842 static const char kValidImage[] = "/load_image/image.png";
832 SetupAndLoadImagePage(kValidImage); 843 SetupAndLoadImagePage(kValidImage);
833 AddLoadImageInterceptor(kValidImage); 844 AddLoadImageInterceptor(kValidImage);
834 AttemptLoadImage(); 845 AttemptLoadImage();
835 interceptor_->WaitForRequests(1); 846 interceptor_->WaitForRequests(1);
836 EXPECT_EQ(1, interceptor_->num_requests()); 847 EXPECT_EQ(1, interceptor_->num_requests());
837 } 848 }
838 849
839 } // namespace 850 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698