chromium/chrome/browser/renderer_context_menu/render_view_context_menu_unittest.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/renderer_context_menu/render_view_context_menu.h"

#include <optional>

#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/companion/core/features.h"
#include "chrome/browser/download/chrome_download_manager_delegate.h"
#include "chrome/browser/download/download_core_service.h"
#include "chrome/browser/download/download_core_service_factory.h"
#include "chrome/browser/extensions/menu_manager.h"
#include "chrome/browser/extensions/menu_manager_factory.h"
#include "chrome/browser/extensions/test_extension_environment.h"
#include "chrome/browser/extensions/test_extension_prefs.h"
#include "chrome/browser/feed/web_feed_tab_helper.h"
#include "chrome/browser/navigation_predictor/navigation_predictor_keyed_service.h"
#include "chrome/browser/navigation_predictor/navigation_predictor_keyed_service_factory.h"
#include "chrome/browser/password_manager/chrome_password_manager_client.h"
#include "chrome/browser/password_manager/profile_password_store_factory.h"
#include "chrome/browser/predictors/loading_predictor.h"
#include "chrome/browser/predictors/loading_predictor_factory.h"
#include "chrome/browser/predictors/preconnect_manager.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/sync/sync_service_factory.h"
#include "chrome/browser/translate/chrome_translate_client.h"
#include "chrome/browser/ui/autofill/chrome_autofill_client.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/passwords/ui_utils.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/scoped_testing_local_state.h"
#include "chrome/test/base/search_test_utils.h"
#include "chrome/test/base/test_browser_window.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "components/autofill/content/browser/test_autofill_client_injector.h"
#include "components/autofill/content/browser/test_autofill_driver_injector.h"
#include "components/autofill/content/browser/test_content_autofill_client.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/test_autofill_driver.h"
#include "components/autofill/core/browser/ui/suggestion_hiding_reason.h"
#include "components/autofill/core/browser/ui/suggestion_type.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/custom_handlers/protocol_handler_registry.h"
#include "components/lens/buildflags.h"
#include "components/lens/lens_features.h"
#include "components/password_manager/core/browser/password_manager_test_utils.h"
#include "components/password_manager/core/browser/password_store/mock_password_store_interface.h"
#include "components/policy/core/common/policy_pref_names.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/proxy_config/proxy_config_pref_names.h"
#include "components/search_engines/template_url_service.h"
#include "components/sync/test/test_sync_service.h"
#include "components/translate/core/browser/language_state.h"
#include "components/translate/core/browser/translate_manager.h"
#include "content/public/browser/global_routing_id.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/web_contents_tester.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/common/url_pattern.h"
#include "services/network/test/test_shared_url_loader_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/navigation/impression.h"
#include "third_party/blink/public/mojom/context_menu/context_menu.mojom.h"
#include "ui/base/clipboard/clipboard.h"
#include "url/gurl.h"

#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/chromeos/policy/dlp/dlp_policy_constants.h"
#include "chrome/browser/chromeos/policy/dlp/dlp_rules_manager.h"
#include "chrome/browser/chromeos/policy/dlp/dlp_rules_manager_impl.h"
#include "chrome/browser/chromeos/policy/dlp/test/dlp_rules_manager_test_utils.h"
#endif

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ash/constants/ash_features.h"
#include "ash/constants/ash_switches.h"
#include "base/test/scoped_command_line.h"
#include "chrome/browser/ash/crosapi/browser_util.h"
#include "chrome/browser/ash/profiles/profile_helper.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "chromeos/ash/components/standalone_browser/feature_refs.h"
#include "components/account_id/account_id.h"
#include "components/user_manager/fake_user_manager.h"
#include "components/user_manager/scoped_user_manager.h"
#endif

Extension;
MenuItem;
MenuManager;
MenuManagerFactory;
URLPatternSet;

namespace {

// Generates a ContextMenuParams that matches the specified contexts.
static content::ContextMenuParams CreateParams(int contexts) {}

// Returns a test context menu.
std::unique_ptr<TestRenderViewContextMenu> CreateContextMenu(
    content::WebContents* web_contents,
    custom_handlers::ProtocolHandlerRegistry* registry) {}

class TestNavigationDelegate : public content::WebContentsDelegate {};

#if BUILDFLAG(IS_CHROMEOS)
class MockDlpRulesManager : public policy::DlpRulesManagerImpl {
 public:
  explicit MockDlpRulesManager(PrefService* local_state, Profile* profile)
      : DlpRulesManagerImpl(local_state, profile) {}
};
#endif

}  // namespace

class RenderViewContextMenuTest : public testing::Test {};

// Generates a URLPatternSet with a single pattern
static URLPatternSet CreatePatternSet(const std::string& pattern) {}

TEST_F(RenderViewContextMenuTest, TargetIgnoredForPage) {}

TEST_F(RenderViewContextMenuTest, TargetCheckedForLink) {}

TEST_F(RenderViewContextMenuTest, TargetCheckedForImage) {}

TEST_F(RenderViewContextMenuTest, TargetCheckedForVideo) {}

TEST_F(RenderViewContextMenuTest, TargetCheckedForAudio) {}

TEST_F(RenderViewContextMenuTest, MatchWhenLinkedImageMatchesTarget) {}

TEST_F(RenderViewContextMenuTest, MatchWhenLinkedImageMatchesSource) {}

TEST_F(RenderViewContextMenuTest, NoMatchWhenLinkedImageMatchesNeither) {}

TEST_F(RenderViewContextMenuTest, TargetIgnoredForFrame) {}

TEST_F(RenderViewContextMenuTest, TargetIgnoredForEditable) {}

TEST_F(RenderViewContextMenuTest, TargetIgnoredForSelection) {}

TEST_F(RenderViewContextMenuTest, TargetIgnoredForSelectionOnLink) {}

TEST_F(RenderViewContextMenuTest, TargetIgnoredForSelectionOnImage) {}

class RenderViewContextMenuExtensionsTest : public RenderViewContextMenuTest {};

TEST_F(RenderViewContextMenuExtensionsTest,
       ItemWithSameTitleFromTwoExtensions) {}

#if BUILDFLAG(IS_CHROMEOS_ASH)
using RenderViewContextMenuDeveloperItemsTest = ChromeRenderViewHostTestHarness;

// Verify that the "Inspect" item and the "View page source" item are not
// present in the context menu if the lacros is the only browser and the
// `kAllowDevtoolsInSystemUI` flag is not enabled.
TEST_F(RenderViewContextMenuDeveloperItemsTest,
       DeveloperItemsAreNotPresentByDefaultIfAshBrowserIsDisabled) {
  base::test::ScopedFeatureList features;
  features.InitWithFeatures(ash::standalone_browser::GetFeatureRefs(), {});
  base::test::ScopedCommandLine scoped_command_line;
  scoped_command_line.GetProcessCommandLine()->AppendSwitch(
      ash::switches::kEnableLacrosForTesting);

  auto fake_user_manager = std::make_unique<user_manager::FakeUserManager>();
  auto* primary_user =
      fake_user_manager->AddUser(AccountId::FromUserEmail("test@test"));
  fake_user_manager->UserLoggedIn(primary_user->GetAccountId(),
                                  primary_user->username_hash(),
                                  /*browser_restart=*/false,
                                  /*is_child=*/false);
  auto scoped_user_manager = std::make_unique<user_manager::ScopedUserManager>(
      std::move(fake_user_manager));

  ASSERT_FALSE(crosapi::browser_util::IsAshDevToolEnabled());

  content::ContextMenuParams params = CreateParams(MenuItem::PAGE);
  auto menu = std::make_unique<TestRenderViewContextMenu>(
      *web_contents()->GetPrimaryMainFrame(), params);
  menu->Init();

  EXPECT_FALSE(menu->IsItemPresent(IDC_VIEW_SOURCE));
  EXPECT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
}

// Verify that the "Inspect" item and the "View page source" are present in the
// context menu if the lacros is the only browser and the
// `kAllowDevtoolsInSystemUI` flag is enabled.
TEST_F(RenderViewContextMenuDeveloperItemsTest,
       DeveloperItemsArePresentIfAshBrowserIsDisabledAndFlagIsEnabled) {
  base::test::ScopedFeatureList features;
  std::vector<base::test::FeatureRef> enabled =
      ash::standalone_browser::GetFeatureRefs();
  enabled.push_back(ash::features::kAllowDevtoolsInSystemUI);
  features.InitWithFeatures(enabled, {});
  base::test::ScopedCommandLine scoped_command_line;
  scoped_command_line.GetProcessCommandLine()->AppendSwitch(
      ash::switches::kEnableLacrosForTesting);

  auto fake_user_manager = std::make_unique<user_manager::FakeUserManager>();
  auto* primary_user =
      fake_user_manager->AddUser(AccountId::FromUserEmail("test@test"));
  fake_user_manager->UserLoggedIn(primary_user->GetAccountId(),
                                  primary_user->username_hash(),
                                  /*browser_restart=*/false,
                                  /*is_child=*/false);
  auto scoped_user_manager = std::make_unique<user_manager::ScopedUserManager>(
      std::move(fake_user_manager));

  ASSERT_TRUE(crosapi::browser_util::IsAshDevToolEnabled());

  content::ContextMenuParams params = CreateParams(MenuItem::PAGE);
  auto menu = std::make_unique<TestRenderViewContextMenu>(
      *web_contents()->GetPrimaryMainFrame(), params);
  menu->Init();

  EXPECT_TRUE(menu->IsItemPresent(IDC_VIEW_SOURCE));
  EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

class RenderViewContextMenuPrefsTest
    : public ChromeRenderViewHostTestHarness,
      public predictors::PreconnectManager::Observer {};

// Verifies when Incognito Mode is not available (disabled by policy),
// Open Link in Incognito Window link in the context menu is disabled.
TEST_F(RenderViewContextMenuPrefsTest,
       DisableOpenInIncognitoWindowWhenIncognitoIsDisabled) {}

#if BUILDFLAG(IS_CHROMEOS)
class RenderViewContextMenuDlpPrefsTest
    : public RenderViewContextMenuPrefsTest {
 public:
  RenderViewContextMenuDlpPrefsTest() = default;

  RenderViewContextMenuDlpPrefsTest(const RenderViewContextMenuDlpPrefsTest&) =
      delete;
  RenderViewContextMenuDlpPrefsTest& operator=(
      const RenderViewContextMenuDlpPrefsTest&) = delete;

  void SetDlpClipboardRestriction() {
    policy::dlp_test_util::DlpRule rule("Rule #1", "Block", "testid1");
    rule.AddSrcUrl(PAGE_URL)
        .AddDstUrl(RESTRICTED_URL)
        .AddRestriction(data_controls::kRestrictionClipboard,
                        data_controls::kLevelBlock);

    base::Value::List rules;
    rules.Append(rule.Create());
    local_state()->SetList(policy::policy_prefs::kDlpRulesList,
                           std::move(rules));
  }

  static constexpr char PAGE_URL[] = "http://www.foo.com/";
  static constexpr char RESTRICTED_URL[] = "http://www.bar.com/";
  static constexpr char NOT_RESTRICTED_URL[] = "http://www.site.com/";
};

// Verifies that OpenLinkInNewTab field is enabled/disabled based on DLP rules.
TEST_F(RenderViewContextMenuDlpPrefsTest,
       DisableOpenLinkInNewTabWhenClipboardIsBlocked) {
  content::ContextMenuParams params = CreateParams(MenuItem::LINK);
  params.page_url = GURL(PAGE_URL);
  params.link_url = GURL(RESTRICTED_URL);
  auto menu = std::make_unique<TestRenderViewContextMenu>(
      *web_contents()->GetPrimaryMainFrame(), params);
  menu->set_dlp_rules_manager(nullptr);

  EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB));

  TestingProfile profile;
  MockDlpRulesManager mock_dlp_rules_manager(local_state(), &profile);
  menu->set_dlp_rules_manager(&mock_dlp_rules_manager);
  EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB));

  SetDlpClipboardRestriction();
  EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB));

  params.link_url = GURL(NOT_RESTRICTED_URL);
  menu = std::make_unique<TestRenderViewContextMenu>(
      *web_contents()->GetPrimaryMainFrame(), params);
  menu->set_dlp_rules_manager(&mock_dlp_rules_manager);
  EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB));
}

// Verifies that OpenLinkInNewWindow field is enabled/disabled based on DLP
// rules.
TEST_F(RenderViewContextMenuDlpPrefsTest,
       DisableOpenLinkInNewWindowWhenClipboardIsBlocked) {
  content::ContextMenuParams params = CreateParams(MenuItem::LINK);
  params.page_url = GURL(PAGE_URL);
  params.link_url = GURL(RESTRICTED_URL);
  auto menu = std::make_unique<TestRenderViewContextMenu>(
      *web_contents()->GetPrimaryMainFrame(), params);
  menu->set_dlp_rules_manager(nullptr);

  EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW));

  TestingProfile profile;
  MockDlpRulesManager mock_dlp_rules_manager(local_state(), &profile);
  menu->set_dlp_rules_manager(&mock_dlp_rules_manager);
  EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW));

  SetDlpClipboardRestriction();
  EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW));

  params.link_url = GURL(NOT_RESTRICTED_URL);
  menu = std::make_unique<TestRenderViewContextMenu>(
      *web_contents()->GetPrimaryMainFrame(), params);
  menu->set_dlp_rules_manager(&mock_dlp_rules_manager);
  EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW));
}

// Verifies that OpenLinkInProfileTab field is enabled/disabled based on DLP
// rules.
TEST_F(RenderViewContextMenuDlpPrefsTest,
       DisableOpenLinkInProfileTabWhenClipboardIsBlocked) {
  content::ContextMenuParams params = CreateParams(MenuItem::LINK);
  params.page_url = GURL(PAGE_URL);
  params.link_url = GURL(RESTRICTED_URL);
  auto menu = std::make_unique<TestRenderViewContextMenu>(
      *web_contents()->GetPrimaryMainFrame(), params);
  menu->set_dlp_rules_manager(nullptr);

  EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE));

  TestingProfile profile;
  MockDlpRulesManager mock_dlp_rules_manager(local_state(), &profile);
  menu->set_dlp_rules_manager(&mock_dlp_rules_manager);
  EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE));

  SetDlpClipboardRestriction();
  EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE));

  params.link_url = GURL(NOT_RESTRICTED_URL);
  menu = std::make_unique<TestRenderViewContextMenu>(
      *web_contents()->GetPrimaryMainFrame(), params);
  menu->set_dlp_rules_manager(&mock_dlp_rules_manager);
  EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE));
}

// Verifies that OpenLinkInWebApp field is enabled/disabled based on DLP rules.
TEST_F(RenderViewContextMenuDlpPrefsTest,
       DisableOpenLinkInWebAppWhenClipboardIsBlocked) {
  content::ContextMenuParams params = CreateParams(MenuItem::LINK);
  params.page_url = GURL(PAGE_URL);
  params.link_url = GURL(RESTRICTED_URL);
  auto menu = std::make_unique<TestRenderViewContextMenu>(
      *web_contents()->GetPrimaryMainFrame(), params);
  menu->set_dlp_rules_manager(nullptr);

  EXPECT_TRUE(
      menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKBOOKMARKAPP));

  TestingProfile profile;
  MockDlpRulesManager mock_dlp_rules_manager(local_state(), &profile);
  menu->set_dlp_rules_manager(&mock_dlp_rules_manager);
  EXPECT_TRUE(
      menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKBOOKMARKAPP));

  SetDlpClipboardRestriction();
  EXPECT_FALSE(
      menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKBOOKMARKAPP));

  params.link_url = GURL(NOT_RESTRICTED_URL);
  menu = std::make_unique<TestRenderViewContextMenu>(
      *web_contents()->GetPrimaryMainFrame(), params);
  menu->set_dlp_rules_manager(&mock_dlp_rules_manager);
  EXPECT_TRUE(
      menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKBOOKMARKAPP));
}

// Verifies that GoToURL field is enabled/disabled based on DLP rules.
TEST_F(RenderViewContextMenuDlpPrefsTest,
       DisableGoToURLWhenClipboardIsBlocked) {
  content::ContextMenuParams params = CreateParams(MenuItem::SELECTION);
  params.page_url = GURL(PAGE_URL);
  auto menu = std::make_unique<TestRenderViewContextMenu>(
      *web_contents()->GetPrimaryMainFrame(), params);
  menu->set_dlp_rules_manager(nullptr);
  menu->set_selection_navigation_url(GURL(RESTRICTED_URL));

  EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_GOTOURL));

  TestingProfile profile;
  MockDlpRulesManager mock_dlp_rules_manager(local_state(), &profile);
  menu->set_dlp_rules_manager(&mock_dlp_rules_manager);
  EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_GOTOURL));

  SetDlpClipboardRestriction();
  EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_GOTOURL));

  menu->set_selection_navigation_url(GURL(NOT_RESTRICTED_URL));
  EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_GOTOURL));
}

// Verifies that SearchWebFor field is enabled/disabled based on DLP rules.
TEST_F(RenderViewContextMenuDlpPrefsTest,
       DisableSearchWebForWhenClipboardIsBlocked) {
  content::ContextMenuParams params = CreateParams(MenuItem::SELECTION);
  params.page_url = GURL(PAGE_URL);
  auto menu = std::make_unique<TestRenderViewContextMenu>(
      *web_contents()->GetPrimaryMainFrame(), params);
  menu->set_dlp_rules_manager(nullptr);
  menu->set_selection_navigation_url(GURL(RESTRICTED_URL));

  EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_SEARCHWEBFOR));

  TestingProfile profile;
  MockDlpRulesManager mock_dlp_rules_manager(local_state(), &profile);
  menu->set_dlp_rules_manager(&mock_dlp_rules_manager);
  EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_SEARCHWEBFOR));

  SetDlpClipboardRestriction();
  EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_SEARCHWEBFOR));

  menu->set_selection_navigation_url(GURL(NOT_RESTRICTED_URL));
  EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_SEARCHWEBFOR));
}

// Verifies that SearchWebForNewTab field is enabled/disabled based on DLP
// rules.
TEST_F(RenderViewContextMenuDlpPrefsTest,
       DisableSearchWebForNewTabWhenClipboardIsBlocked) {
  content::ContextMenuParams params = CreateParams(MenuItem::SELECTION);
  params.page_url = GURL(PAGE_URL);
  auto menu = std::make_unique<TestRenderViewContextMenu>(
      *web_contents()->GetPrimaryMainFrame(), params);
  menu->set_dlp_rules_manager(nullptr);
  menu->set_selection_navigation_url(GURL(RESTRICTED_URL));

  EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_SEARCHWEBFORNEWTAB));

  TestingProfile profile;
  MockDlpRulesManager mock_dlp_rules_manager(local_state(), &profile);
  menu->set_dlp_rules_manager(&mock_dlp_rules_manager);
  EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_SEARCHWEBFORNEWTAB));

  SetDlpClipboardRestriction();
  EXPECT_FALSE(
      menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_SEARCHWEBFORNEWTAB));

  menu->set_selection_navigation_url(GURL(NOT_RESTRICTED_URL));
  EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_SEARCHWEBFORNEWTAB));
}
#endif

// Verifies Incognito Mode is not enabled for links disallowed in Incognito.
TEST_F(RenderViewContextMenuPrefsTest,
       DisableOpenInIncognitoWindowForDisallowedUrls) {}

// Make sure the checking custom command id that is not enabled will not
// cause DCHECK failure.
TEST_F(RenderViewContextMenuPrefsTest, IsCustomCommandIdEnabled) {}

// Check that if image is broken "Load image" menu item is present.
TEST_F(RenderViewContextMenuPrefsTest, LoadBrokenImage) {}

// Verify that the suggested file name is propagated to web contents when save a
// media file in context menu.
TEST_F(RenderViewContextMenuPrefsTest, SaveMediaSuggestedFileName) {}

// Verify ContextMenu navigations properly set the initiator frame token for a
// frame.
TEST_F(RenderViewContextMenuPrefsTest, OpenLinkNavigationParamsSet) {}

// Verify ContextMenu navigations properly set the initiating origin.
TEST_F(RenderViewContextMenuPrefsTest, OpenLinkNavigationInitiatorSet) {}

// Verify that "Show all passwords" is displayed on a password field.
TEST_F(RenderViewContextMenuPrefsTest, ShowAllPasswords) {}

// Verify that "Show all passwords" is displayed on a password field in
// Incognito.
TEST_F(RenderViewContextMenuPrefsTest, ShowAllPasswordsIncognito) {}

TEST_F(RenderViewContextMenuPrefsTest,
       SaveAsDisabledByDownloadRestrictionsPolicy) {}

TEST_F(RenderViewContextMenuPrefsTest,
       SaveAsDisabledByAllowFileSelectionDialogsPolicy) {}

// Verify that item "Search web for" on password Manager - passwords is not
// present
TEST_F(RenderViewContextMenuPrefsTest,
       SearchWebForOptionOnPasswordsManagerSubPageIsDisabled) {}

// Verify that item "Search web for" on password check is not present
TEST_F(RenderViewContextMenuPrefsTest,
       SearchWebForOptionOnPasswordManagerCheckIsDisabled) {}

// Verify that item "Search web for" on password settings is not present
TEST_F(RenderViewContextMenuPrefsTest,
       SearchWebForOptionOnPasswordManagerSettingsIsDisabled) {}

class RenderViewContextMenuHideAutofillSuggestionsTest
    : public RenderViewContextMenuPrefsTest {};

// Always hide the autofill popup when the context menu opens.
TEST_F(RenderViewContextMenuHideAutofillSuggestionsTest,
       HideAutofillSuggestions) {}

// Verify that the Lens Image Search menu item is disabled on non-image content
TEST_F(RenderViewContextMenuPrefsTest, LensImageSearchNonImage) {}

// Verify that the Lens Image Search menu item is disabled when there is the
// Browser is NULL (b/266624865).
TEST_F(RenderViewContextMenuPrefsTest, LensImageSearchNoBrowser) {}

// Verify that the Lens Image Search menu item is enabled on image content
TEST_F(RenderViewContextMenuPrefsTest, LensImageSearchEnabled) {}

#if BUILDFLAG(IS_CHROMEOS_ASH)
// Verify that the Lens Image Search menu item is disabled on image content in
// Ash, if Lacros is the only browser.
TEST_F(RenderViewContextMenuPrefsTest,
       LensImageSearchDisabledIfAshBrowserIsDisabled) {
  base::test::ScopedFeatureList features;
  std::vector<base::test::FeatureRef> enabled =
      ash::standalone_browser::GetFeatureRefs();
  enabled.push_back(lens::features::kLensStandalone);
  enabled.push_back(lens::features::kEnableImageTranslate);
  features.InitWithFeatures(enabled, {lens::features::kLensOverlay});
  base::test::ScopedCommandLine scoped_command_line;
  scoped_command_line.GetProcessCommandLine()->AppendSwitch(
      ash::switches::kEnableLacrosForTesting);

  auto fake_user_manager = std::make_unique<user_manager::FakeUserManager>();
  auto* primary_user =
      fake_user_manager->AddUser(AccountId::FromUserEmail("test@test"));
  fake_user_manager->UserLoggedIn(primary_user->GetAccountId(),
                                  primary_user->username_hash(),
                                  /*browser_restart=*/false,
                                  /*is_child=*/false);
  auto scoped_user_manager = std::make_unique<user_manager::ScopedUserManager>(
      std::move(fake_user_manager));
  ASSERT_FALSE(crosapi::browser_util::IsAshWebBrowserEnabled());
  ash::ProfileHelper::Get();

  TestingProfileManager testing_profile_manager(
      TestingBrowserProcess::GetGlobal(), testing_local_state());
  ASSERT_TRUE(testing_profile_manager.SetUp());

  SetUserSelectedDefaultSearchProvider("https://www.google.com",
                                       /*supports_image_search=*/true);
  content::ContextMenuParams params = CreateParams(MenuItem::IMAGE);
  params.has_image_contents = true;
  TestRenderViewContextMenu menu(*web_contents()->GetPrimaryMainFrame(),
                                 params);
  menu.SetBrowser(GetBrowser());
  menu.Init();

  EXPECT_FALSE(menu.IsItemPresent(IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE));
  EXPECT_FALSE(menu.IsItemPresent(IDC_CONTENT_CONTEXT_SEARCHLENSFORIMAGE));
  EXPECT_FALSE(menu.IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATEIMAGEWITHWEB));
  EXPECT_FALSE(menu.IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATEIMAGEWITHLENS));
}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

// Verify that the Lens Image Search menu item is enabled for Progressive Web
// Apps
TEST_F(RenderViewContextMenuPrefsTest, LensImageSearchForProgressiveWebApp) {}

// Verify that the Lens Image Search menu item is enabled for third-party
// default search engines that support image search.
TEST_F(RenderViewContextMenuPrefsTest, LensImageSearchEnabledFor3pDse) {}

// Verify that the Lens Image Search menu item is disabled for third-part
// default search engines that do not support image search.
TEST_F(RenderViewContextMenuPrefsTest, LensImageSearchDisabledFor3pDse) {}

// Verify that the Translate image menu item is enabled on image content when
// the page is translated
TEST_F(RenderViewContextMenuPrefsTest, LensTranslateImageEnabled) {}

// Verify that the Translate image menu item is enabled for third-party
// default search engines that support image translate.
TEST_F(RenderViewContextMenuPrefsTest, LensTranslateImageEnabledFor3pDse) {}

// Verify that the Translate image menu item is disabled for third-party
// default search engines that do not support image translate.
TEST_F(RenderViewContextMenuPrefsTest, LensTranslateImageDisabledFor3pDse) {}

#if BUILDFLAG(ENABLE_LENS_DESKTOP_GOOGLE_BRANDED_FEATURES)
// Verify that the Lens Region Search menu item is displayed when the feature
// is enabled.
TEST_F(RenderViewContextMenuPrefsTest, LensRegionSearch) {
  base::test::ScopedFeatureList features;
  features.InitWithFeatures({lens::features::kLensStandalone},
                            {lens::features::kLensOverlay});
  SetUserSelectedDefaultSearchProvider("https://www.google.com",
                                       /*supports_image_search=*/true);
  content::ContextMenuParams params = CreateParams(MenuItem::PAGE);
  TestRenderViewContextMenu menu(*web_contents()->GetPrimaryMainFrame(),
                                 params);
  menu.SetBrowser(GetBrowser());
  menu.Init();

  EXPECT_TRUE(menu.IsItemPresent(IDC_CONTENT_CONTEXT_LENS_REGION_SEARCH));
}

#if BUILDFLAG(IS_CHROMEOS_ASH)
// Verify that the Lens Region Search menu item is not displayed even when the
// feature is enabled if Lacros is the only browser.
TEST_F(RenderViewContextMenuPrefsTest,
       LensRegionSearchDisabledIfAshBrowserIsDisabled) {
  base::test::ScopedFeatureList features;
  std::vector<base::test::FeatureRef> enabled =
      ash::standalone_browser::GetFeatureRefs();
  enabled.push_back(lens::features::kLensStandalone);
  features.InitWithFeatures(enabled, {lens::features::kLensOverlay});
  base::test::ScopedCommandLine scoped_command_line;
  scoped_command_line.GetProcessCommandLine()->AppendSwitch(
      ash::switches::kEnableLacrosForTesting);

  auto fake_user_manager = std::make_unique<user_manager::FakeUserManager>();
  auto* primary_user =
      fake_user_manager->AddUser(AccountId::FromUserEmail("test@test"));
  fake_user_manager->UserLoggedIn(primary_user->GetAccountId(),
                                  primary_user->username_hash(),
                                  /*browser_restart=*/false,
                                  /*is_child=*/false);
  auto scoped_user_manager = std::make_unique<user_manager::ScopedUserManager>(
      std::move(fake_user_manager));
  ASSERT_FALSE(crosapi::browser_util::IsAshWebBrowserEnabled());
  ash::ProfileHelper::Get();

  TestingProfileManager testing_profile_manager(
      TestingBrowserProcess::GetGlobal(), testing_local_state());
  ASSERT_TRUE(testing_profile_manager.SetUp());

  SetUserSelectedDefaultSearchProvider("https://www.google.com",
                                       /*supports_image_search=*/true);
  content::ContextMenuParams params = CreateParams(MenuItem::PAGE);
  TestRenderViewContextMenu menu(*web_contents()->GetPrimaryMainFrame(),
                                 params);
  menu.SetBrowser(GetBrowser());
  menu.Init();

  EXPECT_FALSE(menu.IsItemPresent(IDC_CONTENT_CONTEXT_LENS_REGION_SEARCH));
}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

TEST_F(RenderViewContextMenuPrefsTest, LensRegionSearchPdfEnabled) {
  base::test::ScopedFeatureList features;
  features.InitWithFeatures({lens::features::kLensStandalone},
                            {lens::features::kLensOverlay});
  SetUserSelectedDefaultSearchProvider("https://www.google.com",
                                       /*supports_image_search=*/true);
  content::RenderFrameHost* render_frame_host =
      web_contents()->GetPrimaryMainFrame();
  OverrideLastCommittedOrigin(
      render_frame_host,
      url::Origin::Create(
          GURL("chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai")));
  content::ContextMenuParams params = CreateParams(MenuItem::PAGE);
  TestRenderViewContextMenu menu(*render_frame_host, params);
  menu.SetBrowser(GetBrowser());
  menu.Init();

  EXPECT_TRUE(menu.IsItemPresent(IDC_CONTENT_CONTEXT_LENS_REGION_SEARCH));
}

// Verify that the Lens Region Search menu item is disabled when the user's
// enterprise policy for Lens Region Search is disabled.
TEST_F(RenderViewContextMenuPrefsTest,
       LensRegionSearchEnterprisePoicyDisabled) {
  base::test::ScopedFeatureList features;
  features.InitWithFeatures({lens::features::kLensStandalone},
                            {lens::features::kLensOverlay});
  SetUserSelectedDefaultSearchProvider("https://www.google.com",
                                       /*supports_image_search=*/true);
  // Set enterprise policy to false.
  profile()->GetPrefs()->SetBoolean(prefs::kLensRegionSearchEnabled, false);
  content::ContextMenuParams params = CreateParams(MenuItem::PAGE);
  TestRenderViewContextMenu menu(*web_contents()->GetPrimaryMainFrame(),
                                 params);
  menu.SetBrowser(GetBrowser());
  menu.Init();

  EXPECT_FALSE(menu.IsItemPresent(IDC_CONTENT_CONTEXT_LENS_REGION_SEARCH));
}

// Verify that the Lens Region Search menu item is disabled when the user
// clicks on an image.
TEST_F(RenderViewContextMenuPrefsTest, LensRegionSearchDisabledOnImage) {
  base::test::ScopedFeatureList features;
  features.InitWithFeatures({lens::features::kLensStandalone},
                            {lens::features::kLensOverlay});
  SetUserSelectedDefaultSearchProvider("https://www.google.com",
                                       /*supports_image_search=*/true);
  content::ContextMenuParams params = CreateParams(MenuItem::IMAGE);
  params.has_image_contents = true;
  TestRenderViewContextMenu menu(*web_contents()->GetPrimaryMainFrame(),
                                 params);
  menu.SetBrowser(GetBrowser());
  AppendImageItems(&menu);

  EXPECT_FALSE(menu.IsItemPresent(IDC_CONTENT_CONTEXT_LENS_REGION_SEARCH));
  EXPECT_FALSE(menu.IsItemPresent(IDC_CONTENT_CONTEXT_WEB_REGION_SEARCH));
}

// Verify that the Lens Region Search menu item is disabled when there is no
// browser.
TEST_F(RenderViewContextMenuPrefsTest, LensRegionSearchPdfDisabledNoBrowser) {
  base::test::ScopedFeatureList features;
  features.InitWithFeatures({lens::features::kLensStandalone},
                            {lens::features::kLensOverlay});
  SetUserSelectedDefaultSearchProvider("https://www.google.com",
                                       /*supports_image_search=*/true);
  content::RenderFrameHost* render_frame_host =
      web_contents()->GetPrimaryMainFrame();
  OverrideLastCommittedOrigin(
      render_frame_host,
      url::Origin::Create(
          GURL("chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai")));
  content::ContextMenuParams params = CreateParams(MenuItem::PAGE);
  TestRenderViewContextMenu menu(*render_frame_host, params);
  menu.Init();

  EXPECT_FALSE(menu.IsItemPresent(IDC_CONTENT_CONTEXT_LENS_REGION_SEARCH));
  EXPECT_FALSE(menu.IsItemPresent(IDC_CONTENT_CONTEXT_WEB_REGION_SEARCH));
}

// Verify that the web region search menu item is enabled for a non-Google
// search engine that supports visual search.
TEST_F(RenderViewContextMenuPrefsTest,
       LensRegionSearchNonGoogleDefaultSearchEngineSupportsImageSearch) {
  base::test::ScopedFeatureList features;
  features.InitWithFeatures({lens::features::kLensStandalone},
                            {lens::features::kLensOverlay});
  SetUserSelectedDefaultSearchProvider("https://www.search.com",
                                       /*supports_image_search=*/true);
  content::ContextMenuParams params = CreateParams(MenuItem::PAGE);
  TestRenderViewContextMenu menu(*web_contents()->GetPrimaryMainFrame(),
                                 params);
  menu.SetBrowser(GetBrowser());
  menu.Init();

  EXPECT_TRUE(menu.IsItemPresent(IDC_CONTENT_CONTEXT_WEB_REGION_SEARCH));
  EXPECT_FALSE(menu.IsItemPresent(IDC_CONTENT_CONTEXT_LENS_REGION_SEARCH));
}

// Verify that region search menu items are disabled for a search engine that
// does not support visual search.
TEST_F(RenderViewContextMenuPrefsTest,
       LensRegionSearchDefaultSearchEngineDoesNotSupportImageSearch) {
  base::test::ScopedFeatureList features;
  features.InitWithFeatures({lens::features::kLensStandalone},
                            {lens::features::kLensOverlay});
  SetUserSelectedDefaultSearchProvider("https://www.search.com",
                                       /*supports_image_search=*/false);
  content::ContextMenuParams params = CreateParams(MenuItem::PAGE);
  TestRenderViewContextMenu menu(*web_contents()->GetPrimaryMainFrame(),
                                 params);
  menu.SetBrowser(GetBrowser());
  menu.Init();

  EXPECT_FALSE(menu.IsItemPresent(IDC_CONTENT_CONTEXT_WEB_REGION_SEARCH));
  EXPECT_FALSE(menu.IsItemPresent(IDC_CONTENT_CONTEXT_LENS_REGION_SEARCH));
}

// Verify that the Lens Region Search menu item is disabled for any page with a
// Chrome UI Scheme.
TEST_F(RenderViewContextMenuPrefsTest, LensRegionSearchChromeUIScheme) {
  base::test::ScopedFeatureList features;
  features.InitWithFeatures({lens::features::kLensStandalone},
                            {lens::features::kLensOverlay});
  SetUserSelectedDefaultSearchProvider("https://www.google.com",
                                       /*supports_image_search=*/true);
  content::ContextMenuParams params = CreateParams(MenuItem::PAGE);
  params.page_url = GURL(chrome::kChromeUISettingsURL);
  params.frame_url = params.page_url;
  TestRenderViewContextMenu menu(*web_contents()->GetPrimaryMainFrame(),
                                 params);
  menu.SetBrowser(GetBrowser());
  menu.Init();

  EXPECT_FALSE(menu.IsItemPresent(IDC_CONTENT_CONTEXT_LENS_REGION_SEARCH));
}

// Verify that the adding the companion image search option to the menu
// issues a preconnection request to lens.google.com.
TEST_F(RenderViewContextMenuPrefsTest,
       CompanionImageSearchIssuesGoogleLensPreconnect) {
  BeginPreresolveListening();
  base::test::ScopedFeatureList features;
  features.InitWithFeaturesAndParameters(
      {{companion::features::internal::kSidePanelCompanion,
        {{"open-companion-for-image-search", "true"}}}},
      {lens::features::kLensOverlay});
  SetUserSelectedDefaultSearchProvider("https://www.google.com",
                                       /*supports_image_search=*/true);
  content::ContextMenuParams params = CreateParams(MenuItem::IMAGE);
  params.has_image_contents = true;
  TestRenderViewContextMenu menu(*web_contents()->GetPrimaryMainFrame(),
                                 params);
  menu.SetBrowser(GetBrowser());
  menu.Init();

  size_t index = 0;
  raw_ptr<ui::MenuModel> model = nullptr;

  ASSERT_TRUE(menu.GetMenuModelAndItemIndex(
      IDC_CONTENT_CONTEXT_SEARCHLENSFORIMAGE, &model, &index));

  base::RunLoop run_loop;
  preresolved_finished_closure() = run_loop.QuitClosure();
  run_loop.Run();
  ASSERT_EQ(last_preresolved_url().spec(), "https://lens.google.com/");
}

// Verify that the adding the companion region search option to the menu
// issues a preconnection request to lens.google.com.
TEST_F(RenderViewContextMenuPrefsTest,
       CompanionRegionSearchIssuesGoogleLensPreconnect) {
  BeginPreresolveListening();
  base::test::ScopedFeatureList features;
  features.InitWithFeaturesAndParameters(
      {{companion::features::internal::kSidePanelCompanion,
        {{"open-companion-for-image-search", "true"}}}},
      {lens::features::kLensOverlay});
  SetUserSelectedDefaultSearchProvider("https://www.google.com",
                                       /*supports_image_search=*/true);
  content::ContextMenuParams params = CreateParams(MenuItem::PAGE);

  TestRenderViewContextMenu menu(*web_contents()->GetPrimaryMainFrame(),
                                 params);
  menu.SetBrowser(GetBrowser());
  menu.Init();

  size_t index = 0;
  raw_ptr<ui::MenuModel> model = nullptr;

  ASSERT_TRUE(menu.GetMenuModelAndItemIndex(
      IDC_CONTENT_CONTEXT_LENS_REGION_SEARCH, &model, &index));
  EXPECT_TRUE(menu.IsItemPresent(IDC_CONTENT_CONTEXT_LENS_REGION_SEARCH));

  base::RunLoop run_loop;
  preresolved_finished_closure() = run_loop.QuitClosure();
  run_loop.Run();
  ASSERT_EQ(last_preresolved_url().spec(), "https://lens.google.com/");
}

// Verify that the adding the Lens image search option to the menu
// issues a preconnection request to lens.google.com.
TEST_F(RenderViewContextMenuPrefsTest,
       LensImageSearchIssuesGoogleLensPreconnect) {
  BeginPreresolveListening();
  base::test::ScopedFeatureList features;
  features.InitWithFeatures({lens::features::kLensStandalone},
                            {lens::features::kLensOverlay});
  SetUserSelectedDefaultSearchProvider("https://www.google.com",
                                       /*supports_image_search=*/true);
  content::ContextMenuParams params = CreateParams(MenuItem::IMAGE);
  params.has_image_contents = true;
  TestRenderViewContextMenu menu(*web_contents()->GetPrimaryMainFrame(),
                                 params);
  menu.SetBrowser(GetBrowser());
  menu.Init();

  size_t index = 0;
  raw_ptr<ui::MenuModel> model = nullptr;

  ASSERT_TRUE(menu.GetMenuModelAndItemIndex(
      IDC_CONTENT_CONTEXT_SEARCHLENSFORIMAGE, &model, &index));

  base::RunLoop run_loop;
  preresolved_finished_closure() = run_loop.QuitClosure();
  run_loop.Run();
  ASSERT_EQ(last_preresolved_url().spec(), "https://lens.google.com/");
}

// Verify that the adding the Lens region search option to the menu
// issues a preconnection request to lens.google.com.
TEST_F(RenderViewContextMenuPrefsTest,
       LensRegionSearchIssuesGoogleLensPreconnect) {
  BeginPreresolveListening();
  base::test::ScopedFeatureList features;
  features.InitWithFeatures({lens::features::kLensStandalone},
                            {lens::features::kLensOverlay});
  SetUserSelectedDefaultSearchProvider("https://www.google.com",
                                       /*supports_image_search=*/true);
  content::ContextMenuParams params = CreateParams(MenuItem::PAGE);

  TestRenderViewContextMenu menu(*web_contents()->GetPrimaryMainFrame(),
                                 params);
  menu.SetBrowser(GetBrowser());
  menu.Init();

  size_t index = 0;
  raw_ptr<ui::MenuModel> model = nullptr;

  ASSERT_TRUE(menu.GetMenuModelAndItemIndex(
      IDC_CONTENT_CONTEXT_LENS_REGION_SEARCH, &model, &index));
  EXPECT_TRUE(menu.IsItemPresent(IDC_CONTENT_CONTEXT_LENS_REGION_SEARCH));

  base::RunLoop run_loop;
  preresolved_finished_closure() = run_loop.QuitClosure();
  run_loop.Run();
  ASSERT_EQ(last_preresolved_url().spec(), "https://lens.google.com/");
}

TEST_F(RenderViewContextMenuPrefsTest,
       CompanionImageSearchIssuesProcessPrewarming) {
  base::test::ScopedFeatureList features;
  features.InitWithFeaturesAndParameters(
      {{companion::features::internal::kSidePanelCompanion,
        {{"open-companion-for-image-search", "true"}}}},
      {lens::features::kLensOverlay});
  SetUserSelectedDefaultSearchProvider("https://www.google.com",
                                       /*supports_image_search=*/true);
  content::ContextMenuParams params = CreateParams(MenuItem::IMAGE);
  params.has_image_contents = true;

  unsigned int initial_num_processes =
      mock_rph_factory().GetProcesses()->size();

  TestRenderViewContextMenu menu(*web_contents()->GetPrimaryMainFrame(),
                                 params);
  menu.SetBrowser(GetBrowser());
  menu.Init();

  size_t index = 0;
  raw_ptr<ui::MenuModel> model = nullptr;
  ASSERT_TRUE(menu.GetMenuModelAndItemIndex(
      IDC_CONTENT_CONTEXT_SEARCHLENSFORIMAGE, &model, &index));

  ASSERT_EQ(initial_num_processes + 1,
            mock_rph_factory().GetProcesses()->size());
}

TEST_F(RenderViewContextMenuPrefsTest,
       CompanionRegionSearchIssuesProcessPrewarming) {
  base::test::ScopedFeatureList features;
  features.InitWithFeaturesAndParameters(
      {{companion::features::internal::kSidePanelCompanion,
        {{"open-companion-for-image-search", "true"}}}},
      {lens::features::kLensOverlay});
  SetUserSelectedDefaultSearchProvider("https://www.google.com",
                                       /*supports_image_search=*/true);
  content::ContextMenuParams params = CreateParams(MenuItem::PAGE);

  unsigned int initial_num_processes =
      mock_rph_factory().GetProcesses()->size();

  TestRenderViewContextMenu menu(*web_contents()->GetPrimaryMainFrame(),
                                 params);
  menu.SetBrowser(GetBrowser());
  menu.Init();

  size_t index = 0;
  raw_ptr<ui::MenuModel> model = nullptr;
  ASSERT_TRUE(menu.GetMenuModelAndItemIndex(
      IDC_CONTENT_CONTEXT_LENS_REGION_SEARCH, &model, &index));

  ASSERT_EQ(initial_num_processes + 1,
            mock_rph_factory().GetProcesses()->size());
}

TEST_F(RenderViewContextMenuPrefsTest, LensImageSearchIssuesProcessPrewarming) {
  base::test::ScopedFeatureList features;
  features.InitWithFeatures({lens::features::kLensStandalone},
                            {lens::features::kLensOverlay});
  SetUserSelectedDefaultSearchProvider("https://www.google.com",
                                       /*supports_image_search=*/true);
  content::ContextMenuParams params = CreateParams(MenuItem::IMAGE);
  params.has_image_contents = true;

  unsigned int initial_num_processes =
      mock_rph_factory().GetProcesses()->size();

  TestRenderViewContextMenu menu(*web_contents()->GetPrimaryMainFrame(),
                                 params);
  menu.SetBrowser(GetBrowser());
  menu.Init();

  size_t index = 0;
  raw_ptr<ui::MenuModel> model = nullptr;
  ASSERT_TRUE(menu.GetMenuModelAndItemIndex(
      IDC_CONTENT_CONTEXT_SEARCHLENSFORIMAGE, &model, &index));

  ASSERT_EQ(initial_num_processes + 1,
            mock_rph_factory().GetProcesses()->size());
}

TEST_F(RenderViewContextMenuPrefsTest,
       LensRegionSearchIssuesProcessPrewarming) {
  base::test::ScopedFeatureList features;
  features.InitWithFeatures({lens::features::kLensStandalone},
                            {lens::features::kLensOverlay});
  SetUserSelectedDefaultSearchProvider("https://www.google.com",
                                       /*supports_image_search=*/true);
  content::ContextMenuParams params = CreateParams(MenuItem::PAGE);

  unsigned int initial_num_processes =
      mock_rph_factory().GetProcesses()->size();

  TestRenderViewContextMenu menu(*web_contents()->GetPrimaryMainFrame(),
                                 params);
  menu.SetBrowser(GetBrowser());
  menu.Init();

  size_t index = 0;
  raw_ptr<ui::MenuModel> model = nullptr;
  ASSERT_TRUE(menu.GetMenuModelAndItemIndex(
      IDC_CONTENT_CONTEXT_LENS_REGION_SEARCH, &model, &index));

  ASSERT_EQ(initial_num_processes + 1,
            mock_rph_factory().GetProcesses()->size());
}

TEST_F(RenderViewContextMenuPrefsTest,
       WithoutLensOrCompanionDoesNotIssueProcessPrewarming) {
  SetUserSelectedDefaultSearchProvider("https://www.google.com",
                                       /*supports_image_search=*/true);
  content::ContextMenuParams params = CreateParams(MenuItem::IMAGE);

  unsigned int initial_num_processes =
      mock_rph_factory().GetProcesses()->size();

  TestRenderViewContextMenu menu(*web_contents()->GetPrimaryMainFrame(),
                                 params);
  menu.SetBrowser(GetBrowser());
  menu.Init();

  ASSERT_EQ(initial_num_processes, mock_rph_factory().GetProcesses()->size());
}

TEST_F(RenderViewContextMenuPrefsTest,
       CompanionPrewarmingFlagDisablesProcessPrewarming) {
  base::test::ScopedFeatureList features;
  features.InitWithFeaturesAndParameters(
      {{companion::features::internal::kSidePanelCompanion,
        {{"open-companion-for-image-search", "true"},
         {"companion-issue-process-prewarming", "false"}}}},
      {lens::features::kLensOverlay});
  SetUserSelectedDefaultSearchProvider("https://www.google.com",
                                       /*supports_image_search=*/true);
  content::ContextMenuParams params = CreateParams(MenuItem::IMAGE);
  params.has_image_contents = true;

  unsigned int initial_num_processes =
      mock_rph_factory().GetProcesses()->size();

  TestRenderViewContextMenu menu(*web_contents()->GetPrimaryMainFrame(),
                                 params);
  menu.SetBrowser(GetBrowser());
  menu.Init();

  size_t index = 0;
  raw_ptr<ui::MenuModel> model = nullptr;
  ASSERT_TRUE(menu.GetMenuModelAndItemIndex(
      IDC_CONTENT_CONTEXT_SEARCHLENSFORIMAGE, &model, &index));

#if BUILDFLAG(IS_CHROMEOS)
  // Companion feature is force disabled on ChromeOS.
  ASSERT_EQ(initial_num_processes + 1,
            mock_rph_factory().GetProcesses()->size());
#else
  ASSERT_EQ(initial_num_processes, mock_rph_factory().GetProcesses()->size());
#endif  // BUILDFLAG(IS_CHROMEOS)
}

TEST_F(RenderViewContextMenuPrefsTest,
       LensPrewarmingFlagDisablesProcessPrewarming) {
  base::test::ScopedFeatureList features;
  features.InitWithFeaturesAndParameters(
      {{lens::features::kLensStandalone,
        {{"lens-issue-process-prewarming", "false"}}}},
      {lens::features::kLensOverlay});
  SetUserSelectedDefaultSearchProvider("https://www.google.com",
                                       /*supports_image_search=*/true);
  content::ContextMenuParams params = CreateParams(MenuItem::IMAGE);
  params.has_image_contents = true;

  unsigned int initial_num_processes =
      mock_rph_factory().GetProcesses()->size();

  TestRenderViewContextMenu menu(*web_contents()->GetPrimaryMainFrame(),
                                 params);
  menu.SetBrowser(GetBrowser());
  menu.Init();

  size_t index = 0;
  raw_ptr<ui::MenuModel> model = nullptr;
  ASSERT_TRUE(menu.GetMenuModelAndItemIndex(
      IDC_CONTENT_CONTEXT_SEARCHLENSFORIMAGE, &model, &index));

  ASSERT_EQ(initial_num_processes, mock_rph_factory().GetProcesses()->size());
}

// Verify that the Lens Region Search menu item is enabled for Progressive Web
// Apps. Region Search on PWAs is currently broken and therefore disabled on
// Mac. b/250074889
#if BUILDFLAG(IS_MAC)
#define MAYBE_LensRegionSearchProgressiveWebApp
#else
#define MAYBE_LensRegionSearchProgressiveWebApp
#endif
TEST_F(RenderViewContextMenuPrefsTest,
       MAYBE_LensRegionSearchProgressiveWebApp) {
  base::test::ScopedFeatureList features;
  features.InitWithFeatures({lens::features::kLensStandalone},
                            {lens::features::kLensOverlay});
  SetUserSelectedDefaultSearchProvider("https://www.google.com",
                                       /*supports_image_search=*/true);
  content::ContextMenuParams params = CreateParams(MenuItem::PAGE);
  TestRenderViewContextMenu menu(*web_contents()->GetPrimaryMainFrame(),
                                 params);
  menu.SetBrowser(GetPwaBrowser());
  menu.Init();

  EXPECT_TRUE(menu.IsItemPresent(IDC_CONTENT_CONTEXT_LENS_REGION_SEARCH));
}

#endif  // BUILDFLAG(ENABLE_LENS_DESKTOP_GOOGLE_BRANDED_FEATURES)

// Test FormatUrlForClipboard behavior
// -------------------------------------------

struct FormatUrlForClipboardTestData {};

class FormatUrlForClipboardTest
    : public testing::TestWithParam<FormatUrlForClipboardTestData> {};

const FormatUrlForClipboardTestData kFormatUrlForClipboardTestData[]{};

INSTANTIATE_TEST_SUITE_P();

TEST_P(FormatUrlForClipboardTest, FormatUrlForClipboard) {}