Commit ea45d4f3 authored by Yu Su's avatar Yu Su Committed by Commit Bot

Add supports to Lens Shopping experiments for google.com

- enable lens shopping experiments variants for google.com
- add unit tests to LensUtilsTest for shopping intent

Bug: 158099013
Change-Id: Ib605afcfe069320a0b2a52d4ea045759a39e3592
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2261093
Commit-Queue: Yu Su <yusuyoutube@google.com>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#782024}
parent 4b3ea7a9
......@@ -1019,7 +1019,7 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator {
// In Lens Shopping Menu Item experiment, fallback to search image with google lens
// When the url is not in domain allowlist.
if (LensUtils.enableGoogleLensShoppingFeature()) {
if (LensUtils.isInDomainAllowlist(pageUrl)) {
if (LensUtils.isInShoppingAllowlist(pageUrl)) {
// Hide Search With Google Lens menu item when experiment only with Lens Shopping
// menu items.
if (!LensUtils.showBothSearchAndShopImageWithLens()) {
......
......@@ -45,7 +45,9 @@ public class LensUtils {
private static final String USE_SEARCH_BY_IMAGE_TEXT_FEATURE_PARAM_NAME =
"useSearchByImageText";
private static final String LENS_SHOPPING_ALLOWLIST_ENTRIES_FEATURE_PARAM_NAME =
"AllowlistEntries";
"allowlistEntries";
private static final String LENS_SHOPPING_URL_PATTERNS_FEATURE_PARAM_NAME =
"shoppingUrlPatterns";
private static final String LOG_UKM_PARAM_NAME = "logUkm";
private static final String SEND_SRC_PARAM_NAME = "sendSrc";
private static final String SEND_ALT_PARAM_NAME = "sendAlt";
......@@ -54,12 +56,14 @@ public class LensUtils {
private static final String MIN_AGSA_VERSION_NAME_FOR_LENS_CHROME_SHOPPING_INTENT = "11.16";
private static final String LENS_INTENT_TYPE_LENS_CHROME_SHOPPING = "18";
private static final String LENS_SHOPPING_FEATURE_FLAG_VARIANT_NAME = "lensShopVariation";
private static final String LENS_DEFAULT_SHOPPING_URL_PATTERNS =
"^https://www.google.com/shopping/.*|^https://www.google.com/.*tbm=shop.*";
/**
* See function for details.
*/
private static boolean sFakePassableLensEnvironmentForTesting;
private static boolean sFakeImageSrcUrlInAllowlist;
private static boolean sFakeImageUrlInShoppingAllowlistForTesting;
private static String sFakeVariationsForTesting;
/** Supported Lens intent types. */
@IntDef({
......@@ -81,8 +85,9 @@ public class LensUtils {
sFakePassableLensEnvironmentForTesting = shouldFake;
}
public static void setFakeImageSrlUrlInAllowlist(final boolean shouldFake) {
sFakeImageSrcUrlInAllowlist = shouldFake;
@VisibleForTesting
public static void setFakeImageUrlInShoppingAllowlistForTesting(final boolean shouldFake) {
sFakeImageUrlInShoppingAllowlistForTesting = shouldFake;
}
/*
......@@ -362,17 +367,27 @@ public class LensUtils {
* list of Entry names (as strings).
*/
public static String getAllowlistEntries() {
// TODO(yusuyoutube): Create a default allowlist to support QA testing.
return ChromeFeatureList.getFieldTrialParamByFeature(
ChromeFeatureList.CONTEXT_MENU_SHOP_WITH_GOOGLE_LENS,
LENS_SHOPPING_ALLOWLIST_ENTRIES_FEATURE_PARAM_NAME);
}
/**
* Check if the uri domain is in the Lens shopping domain Allowlist.
* Gets the list of shopping url patterns(regex) as String. Format is a "||" separated
* list of regex strings.
*/
public static String getShoppingUrlPatterns() {
return ChromeFeatureList.getFieldTrialParamByFeature(
ChromeFeatureList.CONTEXT_MENU_SHOP_WITH_GOOGLE_LENS,
LENS_SHOPPING_URL_PATTERNS_FEATURE_PARAM_NAME);
}
/**
* Check if the page uri to determine whether the image is shoppable.
* @return true if the image is shoppable.
*/
public static boolean isInDomainAllowlist(final String url) {
if (sFakeImageSrcUrlInAllowlist) {
public static boolean isInShoppingAllowlist(final String url) {
if (sFakeImageUrlInShoppingAllowlistForTesting) {
return true;
}
......@@ -380,19 +395,7 @@ public class LensUtils {
return false;
}
final String allowlistEntries = getAllowlistEntries();
if (allowlistEntries == null || allowlistEntries.isEmpty()) {
return false;
}
final String[] allowlist = allowlistEntries.split(",");
for (final String allowlistEntry : allowlist) {
if (url.contains(allowlistEntry)) {
return true;
}
}
return false;
return hasShoppingUrlPattern(url) || isInDomainAllowList(url);
}
/*
......@@ -414,4 +417,33 @@ public class LensUtils {
return false;
}
/**
* Check if the uri matches any shopping url patterns.
*/
private static boolean hasShoppingUrlPattern(final String url) {
String shoppingUrlPatterns = getShoppingUrlPatterns();
if (shoppingUrlPatterns == null || shoppingUrlPatterns.isEmpty()) {
// Fallback to default shopping url patterns.
shoppingUrlPatterns = LENS_DEFAULT_SHOPPING_URL_PATTERNS;
}
return url.matches(shoppingUrlPatterns);
}
/**
* Check if the uri domain is in the Lens shopping domain Allowlist.
*/
private static boolean isInDomainAllowList(final String url) {
final String allowlistEntries = getAllowlistEntries();
final String[] allowlist = allowlistEntries.split(",");
for (final String allowlistEntry : allowlist) {
if (allowlistEntry.length() > 0 && url.contains(allowlistEntry)) {
return true;
}
}
return false;
}
}
......@@ -176,7 +176,7 @@ public class ContextMenuTest implements CustomMainActivityStart {
public void
testShopSimilarProductsFiresIntent() throws Throwable {
LensUtils.setFakePassableLensEnvironmentForTesting(true);
LensUtils.setFakeImageSrlUrlInAllowlist(true);
LensUtils.setFakeImageUrlInShoppingAllowlistForTesting(true);
Tab tab = mDownloadTestRule.getActivity().getActivityTab();
ShareHelper.setIgnoreActivityNotFoundExceptionForTesting(true);
hardcodeTestImageForSharing(TEST_JPG_IMAGE_FILE_EXTENSION);
......@@ -187,6 +187,8 @@ public class ContextMenuTest implements CustomMainActivityStart {
"com.google.android.googlequicksearchbox");
}
@Test
@MediumTest
@Feature({"Browser"})
......@@ -199,7 +201,7 @@ public class ContextMenuTest implements CustomMainActivityStart {
public void
testShopImageWithGoogleLensFiresIntent() throws Throwable {
LensUtils.setFakePassableLensEnvironmentForTesting(true);
LensUtils.setFakeImageSrlUrlInAllowlist(true);
LensUtils.setFakeImageUrlInShoppingAllowlistForTesting(true);
Tab tab = mDownloadTestRule.getActivity().getActivityTab();
ShareHelper.setIgnoreActivityNotFoundExceptionForTesting(true);
hardcodeTestImageForSharing(TEST_JPG_IMAGE_FILE_EXTENSION);
......@@ -222,7 +224,7 @@ public class ContextMenuTest implements CustomMainActivityStart {
public void
testSearchSimilarProductsFiresIntent() throws Throwable {
LensUtils.setFakePassableLensEnvironmentForTesting(true);
LensUtils.setFakeImageSrlUrlInAllowlist(true);
LensUtils.setFakeImageUrlInShoppingAllowlistForTesting(true);
Tab tab = mDownloadTestRule.getActivity().getActivityTab();
ShareHelper.setIgnoreActivityNotFoundExceptionForTesting(true);
hardcodeTestImageForSharing(TEST_JPG_IMAGE_FILE_EXTENSION);
......@@ -543,7 +545,7 @@ public class ContextMenuTest implements CustomMainActivityStart {
public void
testContextMenuLensEnabledShopSimilarProducts() throws TimeoutException {
LensUtils.setFakePassableLensEnvironmentForTesting(true);
LensUtils.setFakeImageSrlUrlInAllowlist(true);
LensUtils.setFakeImageUrlInShoppingAllowlistForTesting(true);
Tab tab = mDownloadTestRule.getActivity().getActivityTab();
ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testImage");
......@@ -568,7 +570,7 @@ public class ContextMenuTest implements CustomMainActivityStart {
public void
testContextMenuLensEnabledShopImageWithGoogleLens() throws TimeoutException {
LensUtils.setFakePassableLensEnvironmentForTesting(true);
LensUtils.setFakeImageSrlUrlInAllowlist(true);
LensUtils.setFakeImageUrlInShoppingAllowlistForTesting(true);
Tab tab = mDownloadTestRule.getActivity().getActivityTab();
ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testImage");
......@@ -593,7 +595,7 @@ public class ContextMenuTest implements CustomMainActivityStart {
public void
testContextMenuLensEnabledSeachSimilarProducts() throws TimeoutException {
LensUtils.setFakePassableLensEnvironmentForTesting(true);
LensUtils.setFakeImageSrlUrlInAllowlist(true);
LensUtils.setFakeImageUrlInShoppingAllowlistForTesting(true);
Tab tab = mDownloadTestRule.getActivity().getActivityTab();
ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testImage");
......@@ -618,7 +620,7 @@ public class ContextMenuTest implements CustomMainActivityStart {
public void
testContextMenuLensEnabledSearchAndShopSimilarProducts() throws TimeoutException {
LensUtils.setFakePassableLensEnvironmentForTesting(true);
LensUtils.setFakeImageSrlUrlInAllowlist(true);
LensUtils.setFakeImageUrlInShoppingAllowlistForTesting(true);
Tab tab = mDownloadTestRule.getActivity().getActivityTab();
ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testImage");
......
......@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.share;
import static org.junit.Assert.assertTrue;
import android.content.Intent;
import android.net.Uri;
......@@ -17,6 +19,7 @@ import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.share.LensUtils.IntentType;
import org.chromium.chrome.test.ChromeBrowserTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
......@@ -41,7 +44,9 @@ public class LensUtilsTest {
mBrowserTestRule.addAndSignInTestAccount();
Intent intentNoUri = getShareWithGoogleLensIntentOnUiThread(Uri.EMPTY,
/* isIncognito= */ false, 1234L, /* srcUrl */ "", /* titleOrAltText */ "");
/* isIncognito= */ false, 1234L, /* srcUrl */ "", /* titleOrAltText */ "",
/* intentType= */ IntentType.DEFAULT,
/* requiresConfirmation= */ false);
Assert.assertEquals("Intent without image has incorrect URI", "googleapp://lens",
intentNoUri.getData().toString());
Assert.assertEquals("Intent without image has incorrect action", Intent.ACTION_VIEW,
......@@ -49,7 +54,9 @@ public class LensUtilsTest {
final String contentUrl = "content://image-url";
Intent intentWithContentUri = getShareWithGoogleLensIntentOnUiThread(Uri.parse(contentUrl),
/* isIncognito= */ false, 1234L, /* srcUrl */ "", /* titleOrAltText */ "");
/* isIncognito= */ false, 1234L, /* srcUrl */ "", /* titleOrAltText */ "",
/* intentType= */ IntentType.DEFAULT,
/* requiresConfirmation= */ false);
Assert.assertEquals("Intent with image has incorrect URI",
"googleapp://lens?LensBitmapUriKey=content%3A%2F%2Fimage-url&AccountNameUriKey="
+ "test%40gmail.com&IncognitoUriKey=false&ActivityLaunchTimestampNanos=1234",
......@@ -100,7 +107,9 @@ public class LensUtilsTest {
public void getShareWithGoogleLensIntentIncognitoTest() {
mBrowserTestRule.addAndSignInTestAccount();
Intent intentNoUri = getShareWithGoogleLensIntentOnUiThread(Uri.EMPTY,
/* isIncognito= */ true, 1234L, /* srcUrl */ "", /* titleOrAltText */ "");
/* isIncognito= */ true, 1234L, /* srcUrl */ "", /* titleOrAltText */ "",
/* intentType= */ IntentType.DEFAULT,
/* requiresConfirmation= */ false);
Assert.assertEquals("Intent without image has incorrect URI", "googleapp://lens",
intentNoUri.getData().toString());
Assert.assertEquals("Intent without image has incorrect action", Intent.ACTION_VIEW,
......@@ -108,7 +117,9 @@ public class LensUtilsTest {
final String contentUrl = "content://image-url";
Intent intentWithContentUri = getShareWithGoogleLensIntentOnUiThread(Uri.parse(contentUrl),
/* isIncognito= */ true, 1234L, /* srcUrl */ "", /* titleOrAltText */ "");
/* isIncognito= */ true, 1234L, /* srcUrl */ "", /* titleOrAltText */ "",
/* intentType= */ IntentType.DEFAULT,
/* requiresConfirmation= */ false);
// The account name should not be included in the intent because the uesr is incognito.
Assert.assertEquals("Intent with image has incorrect URI",
"googleapp://lens?LensBitmapUriKey=content%3A%2F%2Fimage-url&AccountNameUriKey="
......@@ -131,7 +142,8 @@ public class LensUtilsTest {
final String contentUrl = "content://image-url";
Intent intentWithContentUri = getShareWithGoogleLensIntentOnUiThread(Uri.parse(contentUrl),
/* isIncognito= */ false, 1234L, /* srcUrl */ "",
/* titleOrAltText */ "");
/* titleOrAltText */ "", /* intentType= */ IntentType.DEFAULT,
/* requiresConfirmation= */ false);
// The account name should not be included in the intent because the uesr is incognito.
Assert.assertEquals("Intent with image has incorrect URI",
"googleapp://lens?LensBitmapUriKey=content%3A%2F%2Fimage-url&AccountNameUriKey="
......@@ -155,7 +167,8 @@ public class LensUtilsTest {
final String contentUrl = "content://image-url";
Intent intentWithContentUri = getShareWithGoogleLensIntentOnUiThread(Uri.parse(contentUrl),
/* isIncognito= */ true, 1234L, /* srcUrl */ "",
/* titleOrAltText */ "");
/* titleOrAltText */ "", /* intentType= */ IntentType.DEFAULT,
/* requiresConfirmation= */ false);
// The account name should not be included in the intent because the uesr is incognito.
Assert.assertEquals("Intent with image has incorrect URI",
"googleapp://lens?LensBitmapUriKey=content%3A%2F%2Fimage-url&AccountNameUriKey="
......@@ -173,7 +186,9 @@ public class LensUtilsTest {
@SmallTest
public void getShareWithGoogleLensIntentNotSignedInTest() {
Intent intentNoUri = getShareWithGoogleLensIntentOnUiThread(Uri.EMPTY,
/* isIncognito= */ false, 1234L, /* srcUrl */ "", /* titleOrAltText */ "");
/* isIncognito= */ false, 1234L, /* srcUrl */ "", /* titleOrAltText */ "",
/* intentType= */ IntentType.DEFAULT,
/* requiresConfirmation= */ false);
Assert.assertEquals("Intent without image has incorrect URI", "googleapp://lens",
intentNoUri.getData().toString());
Assert.assertEquals("Intent without image has incorrect action", Intent.ACTION_VIEW,
......@@ -181,7 +196,9 @@ public class LensUtilsTest {
final String contentUrl = "content://image-url";
Intent intentWithContentUri = getShareWithGoogleLensIntentOnUiThread(Uri.parse(contentUrl),
/* isIncognito= */ false, 1234L, /* srcUrl */ "", /* titleOrAltText */ "");
/* isIncognito= */ false, 1234L, /* srcUrl */ "", /* titleOrAltText */ "",
/* intentType= */ IntentType.DEFAULT,
/* requiresConfirmation= */ false);
Assert.assertEquals("Intent with image has incorrect URI",
"googleapp://lens?LensBitmapUriKey=content%3A%2F%2Fimage-url&AccountNameUriKey="
+ "&IncognitoUriKey=false&ActivityLaunchTimestampNanos=1234",
......@@ -200,21 +217,22 @@ public class LensUtilsTest {
final String contentUrl = "content://image-url";
Intent intentWithContentUriZeroTimestamp =
getShareWithGoogleLensIntentOnUiThread(Uri.parse(contentUrl),
/* isIncognito= */ false, 0L, /* srcUrl */ "", /* titleOrAltText */ "");
/* isIncognito= */ false, 0L, /* srcUrl */ "", /* titleOrAltText */ "",
/* intentType= */ IntentType.DEFAULT,
/* requiresConfirmation= */ false);
Assert.assertEquals("Intent with image has incorrect URI",
"googleapp://lens?LensBitmapUriKey=content%3A%2F%2Fimage-url&AccountNameUriKey="
+ "&IncognitoUriKey=false&ActivityLaunchTimestampNanos=0",
intentWithContentUriZeroTimestamp.getData().toString());
}
// TODO(yusuyoutube): Add unit tests for the intent type and requires confirmation.
private Intent getShareWithGoogleLensIntentOnUiThread(Uri imageUri, boolean isIncognito,
long currentTimeNanos, String srcUrl, String titleOrAltText) {
long currentTimeNanos, String srcUrl, String titleOrAltText,
@IntentType final int intentType, boolean requiresConfirmation) {
return TestThreadUtils.runOnUiThreadBlockingNoException(
() -> LensUtils.getShareWithGoogleLensIntent(
imageUri, isIncognito, currentTimeNanos, srcUrl, titleOrAltText,
/* intentType */ LensUtils.IntentType.DEFAULT,
/* requiresConfirmation */ false));
imageUri, isIncognito, currentTimeNanos, srcUrl, titleOrAltText,
intentType, requiresConfirmation));
}
/**
......@@ -227,7 +245,9 @@ public class LensUtilsTest {
final String contentUrl = "content://image-url";
Intent intentWithContentUri = getShareWithGoogleLensIntentOnUiThread(Uri.parse(contentUrl),
/* isIncognito= */ false, 1234L, /* srcUrl */ "",
/* titleOrAltText */ "An image description.");
/* titleOrAltText */ "An image description.",
/* intentType= */ IntentType.DEFAULT,
/* requiresConfirmation= */ false);
// The account name should not be included in the intent because the uesr is incognito.
Assert.assertEquals("Intent with image has incorrect URI",
"googleapp://lens?LensBitmapUriKey=content%3A%2F%2Fimage-url&AccountNameUriKey="
......@@ -252,7 +272,9 @@ public class LensUtilsTest {
final String contentUrl = "content://image-url";
Intent intentWithContentUri = getShareWithGoogleLensIntentOnUiThread(Uri.parse(contentUrl),
/* isIncognito= */ true, 1234L, /* srcUrl */ "",
/* titleOrAltText */ "An image description.");
/* titleOrAltText */ "An image description.",
/* intentType= */ IntentType.DEFAULT,
/* requiresConfirmation= */ false);
// The account name should not be included in the intent because the uesr is incognito.
Assert.assertEquals("Intent with image has incorrect URI",
"googleapp://lens?LensBitmapUriKey=content%3A%2F%2Fimage-url&AccountNameUriKey="
......@@ -262,6 +284,49 @@ public class LensUtilsTest {
intentWithContentUri.getAction());
}
/**
* Test {@link LensUtils#getShareWithGoogleLensIntent()} method when the intent type is
* shopping.
*/
@Test
@SmallTest
public void getShareWithGoogleLensIntentWithShoppingIntentTest() {
final String contentUrl = "content://image-url";
Intent intentWithContentUri = getShareWithGoogleLensIntentOnUiThread(Uri.parse(contentUrl),
/* isIncognito= */ false, 1234L, /* srcUrl */ "",
/* titleOrAltText */ "", /* intentType= */ IntentType.SHOPPING,
/* requiresConfirmation= */ false);
// The account name should not be included in the intent because the uesr is incognito.
Assert.assertEquals("Intent with image has incorrect URI",
"googleapp://lens?LensBitmapUriKey=content%3A%2F%2Fimage-url&AccountNameUriKey="
+ "&IncognitoUriKey=false&ActivityLaunchTimestampNanos=1234&"
+ "lens_intent_type=18",
intentWithContentUri.getData().toString());
Assert.assertEquals("Intent with image has incorrect action", Intent.ACTION_VIEW,
intentWithContentUri.getAction());
}
/**
* Test {@link LensUtils#getShareWithGoogleLensIntent()} method when requires confirmation.
*/
@Test
@SmallTest
public void getShareWithGoogleLensIntentWithConfirmationTest() {
final String contentUrl = "content://image-url";
Intent intentWithContentUri = getShareWithGoogleLensIntentOnUiThread(Uri.parse(contentUrl),
/* isIncognito= */ false, 1234L, /* srcUrl */ "",
/* titleOrAltText */ "", /* intentType= */ IntentType.DEFAULT,
/* requiresConfirmation= */ true);
// The account name should not be included in the intent because the uesr is incognito.
Assert.assertEquals("Intent with image has incorrect URI",
"googleapp://lens?LensBitmapUriKey=content%3A%2F%2Fimage-url&AccountNameUriKey="
+ "&IncognitoUriKey=false&ActivityLaunchTimestampNanos=1234&"
+ "requiresConfirmation=true",
intentWithContentUri.getData().toString());
Assert.assertEquals("Intent with image has incorrect action", Intent.ACTION_VIEW,
intentWithContentUri.getAction());
}
/**
* Test {@link LensUtils#getShareWithGoogleLensIntent()} method when alt text is available and
* enabled by finch.
......@@ -277,7 +342,9 @@ public class LensUtilsTest {
final String contentUrl = "content://image-url";
Intent intentWithContentUri = getShareWithGoogleLensIntentOnUiThread(Uri.parse(contentUrl),
/* isIncognito= */ false, 1234L, /* srcUrl */ "",
/* titleOrAltText */ "An image description.");
/* titleOrAltText */ "An image description.",
/* intentType= */ IntentType.DEFAULT,
/* requiresConfirmation= */ false);
// The account name should not be included in the intent because the uesr is incognito.
Assert.assertEquals("Intent with image has incorrect URI",
"googleapp://lens?LensBitmapUriKey=content%3A%2F%2Fimage-url&AccountNameUriKey="
......@@ -298,7 +365,8 @@ public class LensUtilsTest {
final String contentUrl = "content://image-url";
Intent intentWithContentUri = getShareWithGoogleLensIntentOnUiThread(Uri.parse(contentUrl),
/* isIncognito= */ false, 1234L, /* srcUrl */ "http://www.google.com?key=val",
/* titleOrAltText */ "");
/* titleOrAltText */ "", /* intentType= */ IntentType.DEFAULT,
/* requiresConfirmation= */ false);
// The account name should not be included in the intent because the uesr is incognito.
Assert.assertEquals("Intent with image has incorrect URI",
"googleapp://lens?LensBitmapUriKey=content%3A%2F%2Fimage-url&AccountNameUriKey="
......@@ -323,7 +391,8 @@ public class LensUtilsTest {
final String contentUrl = "content://image-url";
Intent intentWithContentUri = getShareWithGoogleLensIntentOnUiThread(Uri.parse(contentUrl),
/* isIncognito= */ false, 1234L, /* srcUrl */ "http://www.google.com?key=val",
/* titleOrAltText */ "");
/* titleOrAltText */ "", /* intentType= */ IntentType.DEFAULT,
/* requiresConfirmation= */ false);
// The account name should not be included in the intent because the uesr is incognito.
Assert.assertEquals("Intent with image has incorrect URI",
"googleapp://lens?LensBitmapUriKey=content%3A%2F%2Fimage-url&AccountNameUriKey="
......@@ -349,7 +418,8 @@ public class LensUtilsTest {
final String contentUrl = "content://image-url";
Intent intentWithContentUri = getShareWithGoogleLensIntentOnUiThread(Uri.parse(contentUrl),
/* isIncognito= */ true, 1234L, /* srcUrl */ "http://www.google.com?key=val",
/* titleOrAltText */ "");
/* titleOrAltText */ "", /* intentType= */ IntentType.DEFAULT,
/* requiresConfirmation= */ false);
// The account name should not be included in the intent because the uesr is incognito.
Assert.assertEquals("Intent with image has incorrect URI",
"googleapp://lens?LensBitmapUriKey=content%3A%2F%2Fimage-url&AccountNameUriKey="
......@@ -358,4 +428,52 @@ public class LensUtilsTest {
Assert.assertEquals("Intent with image has incorrect action", Intent.ACTION_VIEW,
intentWithContentUri.getAction());
}
/**
* Test {@link LensUtils#isInShoppingAllowlist(url)} method for url in domain allowlist.
*/
@CommandLineFlags.Add({"enable-features=" + ChromeFeatureList.CONTEXT_MENU_SHOP_WITH_GOOGLE_LENS
+ "<FakeStudyName",
"force-fieldtrials=FakeStudyName/Enabled",
"force-fieldtrial-params=FakeStudyName.Enabled:allowlistEntries/shopping-site-2"})
@Test
@SmallTest
public void
isInShoppingAllowlistWithDomainAllowlistTest() {
final String pageUrl = "shopping-site-2.com/product_1";
assertTrue(isInShoppingAllowlistOnUiThread(pageUrl));
}
/**
* Test {@link LensUtils#isInShoppingAllowlist(url)} method for url with shopping url patterns.
*/
@CommandLineFlags.Add({"enable-features=" + ChromeFeatureList.CONTEXT_MENU_SHOP_WITH_GOOGLE_LENS
+ "<FakeStudyName",
"force-fieldtrials=FakeStudyName/Enabled",
"force-fieldtrial-params=FakeStudyName.Enabled:shoppingUrlPatterns/^shopping-site.*"})
@Test
@SmallTest
public void
isInShoppingAllowlistWithShoppingUrlPatternsTest() {
final String pageUrl = "shopping-site-2.com/product_1";
assertTrue(isInShoppingAllowlistOnUiThread(pageUrl));
}
/**
* Test {@link LensUtils#isInShoppingAllowlist(url)} method for url with default shopping url
* patterns.
*/
@Test
@SmallTest
public void isInShoppingAllowlistWithDefaultShoppingUrlPatternTest() {
final String googleShoppingItemUrl = "https://www.google.com/shopping/product_1";
final String googleShoppingPageUrl = "https://www.google.com/search?=8893t5/tbm=shop/dress";
assertTrue(isInShoppingAllowlistOnUiThread(googleShoppingPageUrl));
assertTrue(isInShoppingAllowlistOnUiThread(googleShoppingItemUrl));
}
private boolean isInShoppingAllowlistOnUiThread(String imageUri) {
return TestThreadUtils.runOnUiThreadBlockingNoException(
() -> LensUtils.isInShoppingAllowlist(imageUri));
}
}
\ No newline at end of file
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