Commit 36451543 authored by Ben Goldberger's avatar Ben Goldberger Committed by Commit Bot

Add finch-triggered behavior to activate lens behavior without changing image search menu text.

Bug: 1027273
Change-Id: I86bd7a8ea15197bf31ebbc163897c5455f8823de
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1929648
Commit-Queue: Ben Goldberger <benwgold@google.com>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718891}
parent 41c70260
...@@ -49,6 +49,7 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { ...@@ -49,6 +49,7 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator {
private final ContextMenuItemDelegate mDelegate; private final ContextMenuItemDelegate mDelegate;
private final @ContextMenuMode int mMode; private final @ContextMenuMode int mMode;
private final ShareDelegate mShareDelegate; private final ShareDelegate mShareDelegate;
private boolean mEnableLensWithSearchByImageText;
/** /**
* Defines the Groups of each Context Menu Item * Defines the Groups of each Context Menu Item
...@@ -393,7 +394,13 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { ...@@ -393,7 +394,13 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator {
if (enableGoogleLensFeature if (enableGoogleLensFeature
&& shouldShowLensMenuItemAndRecordMetrics( && shouldShowLensMenuItemAndRecordMetrics(
context, templateUrlServiceInstance)) { context, templateUrlServiceInstance)) {
imageTab.add(new ChromeContextMenuItem(Item.SEARCH_WITH_GOOGLE_LENS)); if (LensUtils.useLensWithSearchByImageText()) {
mEnableLensWithSearchByImageText = true;
imageTab.add(new ChromeContextMenuItem(Item.SEARCH_BY_IMAGE));
} else {
imageTab.add(
new ChromeContextMenuItem(Item.SEARCH_WITH_GOOGLE_LENS));
}
} else { } else {
imageTab.add(new ChromeContextMenuItem(Item.SEARCH_BY_IMAGE)); imageTab.add(new ChromeContextMenuItem(Item.SEARCH_BY_IMAGE));
} }
...@@ -554,8 +561,13 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { ...@@ -554,8 +561,13 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator {
ContextMenuUma.record(params, ContextMenuUma.Action.SEARCH_WITH_GOOGLE_LENS); ContextMenuUma.record(params, ContextMenuUma.Action.SEARCH_WITH_GOOGLE_LENS);
helper.searchWithGoogleLens(mDelegate.isIncognito()); helper.searchWithGoogleLens(mDelegate.isIncognito());
} else if (itemId == R.id.contextmenu_search_by_image) { } else if (itemId == R.id.contextmenu_search_by_image) {
ContextMenuUma.record(params, ContextMenuUma.Action.SEARCH_BY_IMAGE); if (mEnableLensWithSearchByImageText) {
helper.searchForImage(); ContextMenuUma.record(params, ContextMenuUma.Action.SEARCH_WITH_GOOGLE_LENS);
helper.searchWithGoogleLens(mDelegate.isIncognito());
} else {
ContextMenuUma.record(params, ContextMenuUma.Action.SEARCH_BY_IMAGE);
helper.searchForImage();
}
} else if (itemId == R.id.contextmenu_share_image) { } else if (itemId == R.id.contextmenu_share_image) {
ContextMenuUma.record(params, ContextMenuUma.Action.SHARE_IMAGE); ContextMenuUma.record(params, ContextMenuUma.Action.SHARE_IMAGE);
helper.shareImage(); helper.shareImage();
......
...@@ -27,6 +27,8 @@ public class LensUtils { ...@@ -27,6 +27,8 @@ public class LensUtils {
private static final String ACCOUNT_NAME_URI_KEY = "AccountNameUriKey"; private static final String ACCOUNT_NAME_URI_KEY = "AccountNameUriKey";
private static final String INCOGNITO_URI_KEY = "IncognitoUriKey"; private static final String INCOGNITO_URI_KEY = "IncognitoUriKey";
private static final String MIN_AGSA_VERSION_FEATURE_PARAM_NAME = "minAgsaVersionName"; private static final String MIN_AGSA_VERSION_FEATURE_PARAM_NAME = "minAgsaVersionName";
private static final String USE_SEARCH_BY_IMAGE_TEXT_FEATURE_PARAM_NAME =
"useSearchByImageText";
private static final String MIN_AGSA_VERSION_NAME_FOR_LENS_POSTCAPTURE = "8.19"; private static final String MIN_AGSA_VERSION_NAME_FOR_LENS_POSTCAPTURE = "8.19";
/** /**
...@@ -178,4 +180,10 @@ public class LensUtils { ...@@ -178,4 +180,10 @@ public class LensUtils {
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
return intent; return intent;
} }
public static boolean useLensWithSearchByImageText() {
return ChromeFeatureList.getFieldTrialParamByFeatureAsBoolean(
ChromeFeatureList.CONTEXT_MENU_SEARCH_WITH_GOOGLE_LENS,
USE_SEARCH_BY_IMAGE_TEXT_FEATURE_PARAM_NAME, false);
}
} }
...@@ -153,6 +153,27 @@ public class ContextMenuTest implements CustomMainActivityStart { ...@@ -153,6 +153,27 @@ public class ContextMenuTest implements CustomMainActivityStart {
"com.google.android.googlequicksearchbox"); "com.google.android.googlequicksearchbox");
} }
@Test
@MediumTest
@Feature({"Browser"})
@CommandLineFlags.Add({"enable-features="
+ ChromeFeatureList.CONTEXT_MENU_SEARCH_WITH_GOOGLE_LENS + "<FakeStudyName",
"force-fieldtrials=FakeStudyName/Enabled",
"force-fieldtrial-params=FakeStudyName.Enabled:useSearchByImageText/true"})
public void
testSearchWithGoogleLensWithSearchByImageTextFiresIntent() throws Throwable {
Tab tab = mDownloadTestRule.getActivity().getActivityTab();
LensUtils.setFakePassableLensEnvironmentForTesting(true);
ShareHelper.setIgnoreActivityNotFoundExceptionForTesting(true);
hardcodeTestImageForSharing();
ContextMenuUtils.selectContextMenuItemWithExpectedIntent(
InstrumentationRegistry.getInstrumentation(), mDownloadTestRule.getActivity(), tab,
"testImage", R.id.contextmenu_search_by_image,
"com.google.android.googlequicksearchbox");
}
@Test @Test
@MediumTest @MediumTest
@Feature({"Browser"}) @Feature({"Browser"})
...@@ -427,6 +448,26 @@ public class ContextMenuTest implements CustomMainActivityStart { ...@@ -427,6 +448,26 @@ public class ContextMenuTest implements CustomMainActivityStart {
assertMenuItemsAreEqual(menu, expectedItems); assertMenuItemsAreEqual(menu, expectedItems);
} }
@Test
@SmallTest
@Feature({"Browser", "ContextMenu"})
@CommandLineFlags.Add({"enable-features="
+ ChromeFeatureList.CONTEXT_MENU_SEARCH_WITH_GOOGLE_LENS + "<FakeStudyName",
"force-fieldtrials=FakeStudyName/Enabled",
"force-fieldtrial-params=FakeStudyName.Enabled:useSearchByImageText/true"})
public void
testContextMenuRetrievesImageOptionsLensEnabledSearchByImageText() throws TimeoutException {
Tab tab = mDownloadTestRule.getActivity().getActivityTab();
ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testImage");
Integer[] expectedItems = {R.id.contextmenu_save_image,
R.id.contextmenu_open_image_in_new_tab, R.id.contextmenu_search_by_image,
R.id.contextmenu_share_image};
Integer[] featureItems = {R.id.contextmenu_open_image_in_ephemeral_tab};
expectedItems = addItemsIf(EphemeralTabPanel.isSupported(), expectedItems, featureItems);
assertMenuItemsAreEqual(menu, expectedItems);
}
@Test @Test
@SmallTest @SmallTest
@Feature({"Browser", "ContextMenu"}) @Feature({"Browser", "ContextMenu"})
...@@ -506,6 +547,32 @@ public class ContextMenuTest implements CustomMainActivityStart { ...@@ -506,6 +547,32 @@ public class ContextMenuTest implements CustomMainActivityStart {
assertMenuItemsAreEqual(menu, expectedItems); assertMenuItemsAreEqual(menu, expectedItems);
} }
@Test
@SmallTest
@Feature({"Browser", "ContextMenu"})
@CommandLineFlags.Add({"enable-features="
+ ChromeFeatureList.CONTEXT_MENU_SEARCH_WITH_GOOGLE_LENS + "<FakeStudyName",
"force-fieldtrials=FakeStudyName/Enabled",
"force-fieldtrial-params=FakeStudyName.Enabled:useSearchByImageText/true"})
public void
testContextMenuRetrievesImageLinkOptionsSearchLensEnabledSearchByImageText()
throws TimeoutException {
LensUtils.setFakePassableLensEnvironmentForTesting(true);
Tab tab = mDownloadTestRule.getActivity().getActivityTab();
ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testImageLink");
Integer[] expectedItems = {R.id.contextmenu_open_in_new_tab,
R.id.contextmenu_open_in_incognito_tab, R.id.contextmenu_copy_link_address,
R.id.contextmenu_save_link_as, R.id.contextmenu_save_image,
R.id.contextmenu_open_image_in_new_tab, R.id.contextmenu_search_by_image,
R.id.contextmenu_share_image, R.id.contextmenu_share_link};
Integer[] featureItems = {R.id.contextmenu_open_in_ephemeral_tab,
R.id.contextmenu_open_image_in_ephemeral_tab};
expectedItems = addItemsIf(EphemeralTabPanel.isSupported(), expectedItems, featureItems);
assertMenuItemsAreEqual(menu, expectedItems);
}
@Test @Test
@SmallTest @SmallTest
@Feature({"Browser", "ContextMenu"}) @Feature({"Browser", "ContextMenu"})
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment