Commit 8f694dfb authored by Sophey Dong's avatar Sophey Dong Committed by Commit Bot

[SharingHub] Add other cases to the preview.

Screenshots: http://dr/corp/drive/folders/1k1L-fXN_nxOTtJR8OOcB8zdhSIqx6ibb

Bug: 1120093
Change-Id: Ifb3dd75cdb25ba6eaa8f9d38639073b030b372d3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2404393
Commit-Queue: Sophey Dong <sophey@chromium.org>
Reviewed-by: default avatarSinan Sahin <sinansahin@google.com>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarTanya Gupta <tgupta@chromium.org>
Reviewed-by: default avatarKyle Milka <kmilka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806818}
parent 712f26f3
...@@ -351,6 +351,7 @@ chrome_java_sources = [ ...@@ -351,6 +351,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulator.java", "java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulator.java",
"java/src/org/chromium/chrome/browser/contextmenu/ContextMenuHelper.java", "java/src/org/chromium/chrome/browser/contextmenu/ContextMenuHelper.java",
"java/src/org/chromium/chrome/browser/contextmenu/ContextMenuUi.java", "java/src/org/chromium/chrome/browser/contextmenu/ContextMenuUi.java",
"java/src/org/chromium/chrome/browser/contextmenu/ContextMenuUtils.java",
"java/src/org/chromium/chrome/browser/contextmenu/LensAsyncManager.java", "java/src/org/chromium/chrome/browser/contextmenu/LensAsyncManager.java",
"java/src/org/chromium/chrome/browser/contextmenu/RevampedContextMenuChipController.java", "java/src/org/chromium/chrome/browser/contextmenu/RevampedContextMenuChipController.java",
"java/src/org/chromium/chrome/browser/contextmenu/RevampedContextMenuCoordinator.java", "java/src/org/chromium/chrome/browser/contextmenu/RevampedContextMenuCoordinator.java",
......
...@@ -104,6 +104,7 @@ chrome_test_java_sources = [ ...@@ -104,6 +104,7 @@ chrome_test_java_sources = [
"javatests/src/org/chromium/chrome/browser/compositor/layouts/MockResourcesForLayout.java", "javatests/src/org/chromium/chrome/browser/compositor/layouts/MockResourcesForLayout.java",
"javatests/src/org/chromium/chrome/browser/compositor/overlays/strip/TabStripTest.java", "javatests/src/org/chromium/chrome/browser/compositor/overlays/strip/TabStripTest.java",
"javatests/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulatorTest.java", "javatests/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulatorTest.java",
"javatests/src/org/chromium/chrome/browser/contextmenu/ContextMenuUtilsTest.java",
"javatests/src/org/chromium/chrome/browser/contextmenu/RevampedContextMenuChipControllerTest.java", "javatests/src/org/chromium/chrome/browser/contextmenu/RevampedContextMenuChipControllerTest.java",
"javatests/src/org/chromium/chrome/browser/contextmenu/RevampedContextMenuHeaderViewTest.java", "javatests/src/org/chromium/chrome/browser/contextmenu/RevampedContextMenuHeaderViewTest.java",
"javatests/src/org/chromium/chrome/browser/contextmenu/RevampedContextMenuItemViewTest.java", "javatests/src/org/chromium/chrome/browser/contextmenu/RevampedContextMenuItemViewTest.java",
......
...@@ -45,32 +45,30 @@ ...@@ -45,32 +45,30 @@
<TextView <TextView
android:id="@+id/title_preview" android:id="@+id/title_preview"
android:ellipsize="end" android:ellipsize="end"
android:layout_width="fill_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_toEndOf="@id/image_preview" android:layout_toEndOf="@id/image_preview"
android:maxLines="1" android:maxLines="1"
android:minHeight="18dp" android:minHeight="18dp"
android:paddingEnd="16dp" android:paddingEnd="16dp"
android:paddingStart="12dp" android:paddingStart="12dp"
android:gravity="center_vertical" android:paddingBottom="4dp"
android:textAlignment="viewStart" android:textAlignment="viewStart"/>
android:textAppearance="@style/TextAppearance.TextMediumThick.Primary"/>
<TextView <TextView
android:id="@+id/url_preview" android:id="@+id/subtitle_preview"
android:ellipsize="end" android:ellipsize="end"
android:layout_below="@id/title_preview" android:layout_below="@id/title_preview"
android:layout_width="fill_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_toEndOf="@id/image_preview" android:layout_toEndOf="@id/image_preview"
android:layout_centerVertical="true"
android:maxLines="1" android:maxLines="1"
android:minHeight="18dp" android:minHeight="18dp"
android:paddingEnd="16dp" android:paddingEnd="16dp"
android:paddingStart="12dp" android:paddingStart="12dp"
android:paddingTop="4dp"
android:gravity="center_vertical"
android:textAlignment="viewStart" android:textAlignment="viewStart"
android:textAppearance="@style/TextAppearance.TextMedium.Secondary"/> android:textAppearance="@style/TextAppearance.TextMedium.Primary"/>
</RelativeLayout> </RelativeLayout>
<View <View
......
...@@ -695,7 +695,10 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { ...@@ -695,7 +695,10 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator {
} else if (itemId == R.id.contextmenu_share_link) { } else if (itemId == R.id.contextmenu_share_link) {
recordContextMenuSelection(params, ContextMenuUma.Action.SHARE_LINK); recordContextMenuSelection(params, ContextMenuUma.Action.SHARE_LINK);
ShareParams linkShareParams = ShareParams linkShareParams =
new ShareParams.Builder(getWindow(), params.getUrl(), params.getUrl()).build(); new ShareParams
.Builder(
getWindow(), ContextMenuUtils.getTitle(params), params.getUrl())
.build();
mShareDelegateSupplier.get().share( mShareDelegateSupplier.get().share(
linkShareParams, new ChromeShareExtras.Builder().setSaveLastUsed(true).build()); linkShareParams, new ChromeShareExtras.Builder().setSaveLastUsed(true).build());
} else if (itemId == R.id.contextmenu_search_with_google_lens) { } else if (itemId == R.id.contextmenu_search_with_google_lens) {
...@@ -735,7 +738,7 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { ...@@ -735,7 +738,7 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator {
ChromePreferenceKeys.CONTEXT_MENU_SEARCH_SIMILAR_PRODUCTS_CLICKED, true); ChromePreferenceKeys.CONTEXT_MENU_SEARCH_SIMILAR_PRODUCTS_CLICKED, true);
} else if (itemId == R.id.contextmenu_share_image) { } else if (itemId == R.id.contextmenu_share_image) {
recordContextMenuSelection(params, ContextMenuUma.Action.SHARE_IMAGE); recordContextMenuSelection(params, ContextMenuUma.Action.SHARE_IMAGE);
shareImage(renderFrameHost, params.getSrcUrl()); shareImage(renderFrameHost, params);
} else if (itemId == R.id.contextmenu_open_in_chrome) { } else if (itemId == R.id.contextmenu_open_in_chrome) {
recordContextMenuSelection(params, ContextMenuUma.Action.OPEN_IN_CHROME); recordContextMenuSelection(params, ContextMenuUma.Action.OPEN_IN_CHROME);
mDelegate.onOpenInChrome(params.getUrl(), params.getPageUrl()); mDelegate.onOpenInChrome(params.getUrl(), params.getPageUrl());
...@@ -820,9 +823,9 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { ...@@ -820,9 +823,9 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator {
* Package-private, allowing access only from the context menu item to ensure that * Package-private, allowing access only from the context menu item to ensure that
* it will use the right activity set when the menu was displayed. * it will use the right activity set when the menu was displayed.
* @param renderFrameHost {@link RenderFrameHost} to get the encoded images from. * @param renderFrameHost {@link RenderFrameHost} to get the encoded images from.
* @param srcUrl url of the image. * @param params The {@link ContextMenuParams} for the image.
*/ */
private void shareImage(RenderFrameHost renderFrameHost, String srcUrl) { private void shareImage(RenderFrameHost renderFrameHost, ContextMenuParams params) {
retrieveImage(renderFrameHost, ContextMenuImageFormat.ORIGINAL, (Uri imageUri) -> { retrieveImage(renderFrameHost, ContextMenuImageFormat.ORIGINAL, (Uri imageUri) -> {
if (!mShareDelegateSupplier.get().isSharingHubV15Enabled()) { if (!mShareDelegateSupplier.get().isSharingHubV15Enabled()) {
ShareHelper.shareImage(getWindow(), null, imageUri); ShareHelper.shareImage(getWindow(), null, imageUri);
...@@ -831,14 +834,15 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { ...@@ -831,14 +834,15 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator {
ContentResolver contentResolver = ContentResolver contentResolver =
ContextUtils.getApplicationContext().getContentResolver(); ContextUtils.getApplicationContext().getContentResolver();
ShareParams imageShareParams = ShareParams imageShareParams =
new ShareParams.Builder(getWindow(), /*title=*/"", /*url=*/"") new ShareParams
.Builder(getWindow(), ContextMenuUtils.getTitle(params), /*url=*/"")
.setFileUris(new ArrayList<>(Collections.singletonList(imageUri))) .setFileUris(new ArrayList<>(Collections.singletonList(imageUri)))
.setFileContentType(contentResolver.getType(imageUri)) .setFileContentType(contentResolver.getType(imageUri))
.build(); .build();
mShareDelegateSupplier.get().share(imageShareParams, mShareDelegateSupplier.get().share(imageShareParams,
new ChromeShareExtras.Builder() new ChromeShareExtras.Builder()
.setSaveLastUsed(true) .setSaveLastUsed(true)
.setImageSrcUrl(srcUrl) .setImageSrcUrl(params.getSrcUrl())
.build()); .build());
}); });
} }
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.contextmenu;
import android.text.TextUtils;
import android.webkit.URLUtil;
import org.chromium.components.embedder_support.contextmenu.ContextMenuParams;
/**
* Provides utility methods for generating context menus.
*/
public final class ContextMenuUtils {
private ContextMenuUtils() {}
/**
* Returns the title for the given {@link ContextMenuParams}.
*/
static String getTitle(ContextMenuParams params) {
if (!TextUtils.isEmpty(params.getTitleText())) {
return params.getTitleText();
}
if (!TextUtils.isEmpty(params.getLinkText())) {
return params.getLinkText();
}
if (params.isImage() || params.isVideo() || params.isFile()) {
return URLUtil.guessFileName(params.getSrcUrl(), null, null);
}
return "";
}
}
...@@ -5,11 +5,9 @@ ...@@ -5,11 +5,9 @@
package org.chromium.chrome.browser.contextmenu; package org.chromium.chrome.browser.contextmenu;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.TextUtils; import android.text.TextUtils;
import android.webkit.URLUtil;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.chrome.browser.ChromeBaseAppCompatActivity; import org.chromium.chrome.browser.ChromeBaseAppCompatActivity;
...@@ -26,12 +24,9 @@ class RevampedContextMenuHeaderCoordinator { ...@@ -26,12 +24,9 @@ class RevampedContextMenuHeaderCoordinator {
private PropertyModel mModel; private PropertyModel mModel;
private RevampedContextMenuHeaderMediator mMediator; private RevampedContextMenuHeaderMediator mMediator;
private Context mContext;
RevampedContextMenuHeaderCoordinator(Activity activity, @PerformanceClass int performanceClass, RevampedContextMenuHeaderCoordinator(Activity activity, @PerformanceClass int performanceClass,
ContextMenuParams params, Profile profile) { ContextMenuParams params, Profile profile) {
mContext = activity; mModel = buildModel(ContextMenuUtils.getTitle(params), getUrl(activity, params, profile));
mModel = buildModel(getTitle(params), getUrl(activity, params, profile));
mMediator = new RevampedContextMenuHeaderMediator( mMediator = new RevampedContextMenuHeaderMediator(
activity, mModel, performanceClass, params, profile); activity, mModel, performanceClass, params, profile);
} }
...@@ -51,19 +46,6 @@ class RevampedContextMenuHeaderCoordinator { ...@@ -51,19 +46,6 @@ class RevampedContextMenuHeaderCoordinator {
.build(); .build();
} }
private String getTitle(ContextMenuParams params) {
if (!TextUtils.isEmpty(params.getTitleText())) {
return params.getTitleText();
}
if (!TextUtils.isEmpty(params.getLinkText())) {
return params.getLinkText();
}
if (params.isImage() || params.isVideo() || params.isFile()) {
return URLUtil.guessFileName(params.getSrcUrl(), null, null);
}
return "";
}
private CharSequence getUrl(Activity activity, ContextMenuParams params, Profile profile) { private CharSequence getUrl(Activity activity, ContextMenuParams params, Profile profile) {
CharSequence url = params.getUrl(); CharSequence url = params.getUrl();
if (!TextUtils.isEmpty(url)) { if (!TextUtils.isEmpty(url)) {
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.contextmenu;
import static org.junit.Assert.assertEquals;
import android.webkit.URLUtil;
import androidx.test.filters.SmallTest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.blink_public.common.ContextMenuDataMediaType;
import org.chromium.components.embedder_support.contextmenu.ContextMenuParams;
/**
* Unit tests for {@link ContextMenuUtils}.
*/
@RunWith(BaseJUnit4ClassRunner.class)
public class ContextMenuUtilsTest {
private static final String sTitleText = "titleText";
private static final String sLinkText = "linkText";
private static final String sSrcUrl = "https://www.google.com/";
@Test
@SmallTest
public void getTitle_hasTitleText() {
ContextMenuParams params = new ContextMenuParams(0,
org.chromium.blink_public.common.ContextMenuDataMediaType.IMAGE, "", "", sLinkText,
"", sSrcUrl, sTitleText, null, false, 0, 0, 0);
assertEquals(sTitleText, ContextMenuUtils.getTitle(params));
}
@Test
@SmallTest
public void getTitle_noTitleTextHasLinkText() {
ContextMenuParams params = new ContextMenuParams(0, ContextMenuDataMediaType.IMAGE, "", "",
sLinkText, "", sSrcUrl, "", null, false, 0, 0, 0);
assertEquals(sLinkText, ContextMenuUtils.getTitle(params));
}
@Test
@SmallTest
public void getTitle_noTitleTextOrLinkText() {
ContextMenuParams params = new ContextMenuParams(0, ContextMenuDataMediaType.IMAGE, "", "",
"", "", sSrcUrl, "", null, false, 0, 0, 0);
assertEquals(URLUtil.guessFileName(sSrcUrl, null, null), ContextMenuUtils.getTitle(params));
}
@Test
@SmallTest
public void getTitle_noShareParams() {
ContextMenuParams params = new ContextMenuParams(
0, ContextMenuDataMediaType.NONE, "", "", "", "", "", "", null, false, 0, 0, 0);
assertEquals("", ContextMenuUtils.getTitle(params));
}
}
...@@ -6,12 +6,9 @@ package org.chromium.chrome.browser.share.share_sheet; ...@@ -6,12 +6,9 @@ package org.chromium.chrome.browser.share.share_sheet;
import android.app.Activity; import android.app.Activity;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.view.View; import android.view.View;
import androidx.annotation.ColorInt;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.content.res.AppCompatResources;
...@@ -27,14 +24,12 @@ import org.chromium.chrome.browser.settings.SettingsLauncher; ...@@ -27,14 +24,12 @@ import org.chromium.chrome.browser.settings.SettingsLauncher;
import org.chromium.chrome.browser.share.ChromeShareExtras; import org.chromium.chrome.browser.share.ChromeShareExtras;
import org.chromium.chrome.browser.share.ShareHelper; import org.chromium.chrome.browser.share.ShareHelper;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.ui.favicon.IconType;
import org.chromium.chrome.browser.ui.favicon.LargeIconBridge; import org.chromium.chrome.browser.ui.favicon.LargeIconBridge;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetContent; import org.chromium.components.browser_ui.bottomsheet.BottomSheetContent;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetController; import org.chromium.components.browser_ui.bottomsheet.BottomSheetController;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetObserver; import org.chromium.components.browser_ui.bottomsheet.BottomSheetObserver;
import org.chromium.components.browser_ui.bottomsheet.EmptyBottomSheetObserver; import org.chromium.components.browser_ui.bottomsheet.EmptyBottomSheetObserver;
import org.chromium.components.browser_ui.share.ShareParams; import org.chromium.components.browser_ui.share.ShareParams;
import org.chromium.components.browser_ui.widget.RoundedIconGenerator;
import org.chromium.ui.base.WindowAndroid; import org.chromium.ui.base.WindowAndroid;
import org.chromium.ui.base.WindowAndroid.ActivityStateObserver; import org.chromium.ui.base.WindowAndroid.ActivityStateObserver;
import org.chromium.ui.modelutil.PropertyModel; import org.chromium.ui.modelutil.PropertyModel;
...@@ -140,8 +135,7 @@ public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptio ...@@ -140,8 +135,7 @@ public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptio
} }
} }
mBottomSheet = new ShareSheetBottomSheetContent(mActivity, this, params); mBottomSheet = new ShareSheetBottomSheetContent(mActivity, mIconBridge, this, params);
fetchFavicon(mActivity, params.getUrl());
mShareStartTime = shareStartTime; mShareStartTime = shareStartTime;
mContentTypes = ShareSheetPropertyModelBuilder.getContentTypes(params, chromeShareExtras); mContentTypes = ShareSheetPropertyModelBuilder.getContentTypes(params, chromeShareExtras);
...@@ -150,7 +144,7 @@ public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptio ...@@ -150,7 +144,7 @@ public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptio
List<PropertyModel> thirdPartyApps = createThirdPartyPropertyModels( List<PropertyModel> thirdPartyApps = createThirdPartyPropertyModels(
mActivity, params, mContentTypes, chromeShareExtras.saveLastUsed()); mActivity, params, mContentTypes, chromeShareExtras.saveLastUsed());
mBottomSheet.createRecyclerViews(firstPartyApps, thirdPartyApps, message); mBottomSheet.createRecyclerViews(firstPartyApps, thirdPartyApps, mContentTypes, message);
boolean shown = mBottomSheetController.requestShowContent(mBottomSheet, true); boolean shown = mBottomSheetController.requestShowContent(mBottomSheet, true);
if (shown) { if (shown) {
...@@ -258,58 +252,4 @@ public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptio ...@@ -258,58 +252,4 @@ public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptio
mBottomSheet.getThirdPartyView().requestLayout(); mBottomSheet.getThirdPartyView().requestLayout();
} }
/** Fetches the favicon for the given url. **/
void fetchFavicon(Activity activity, String url) {
if (!url.isEmpty()) {
// Update mActivity so it's non-null in onFaviconAvailable in tests.
mActivity = activity;
mUrl = url;
mIconBridge.getLargeIconForStringUrl(url,
activity.getResources().getDimensionPixelSize(R.dimen.default_favicon_min_size),
this::onFaviconAvailable);
}
}
/**
* Passed as the callback to {@link LargeIconBridge#getLargeIconForStringUrl}
* by showShareSheetWithMessage.
*/
void onFaviconAvailable(@Nullable Bitmap icon, @ColorInt int fallbackColor,
boolean isColorDefault, @IconType int iconType) {
// If we didn't get a favicon, generate a monogram instead
if (icon == null) {
RoundedIconGenerator iconGenerator = createRoundedIconGenerator(fallbackColor);
icon = iconGenerator.generateIconForUrl(mUrl);
// generateIconForUrl might return null if the URL is empty or the domain cannot be
// resolved. See https://crbug.com/987101
// TODO(1120093): Handle the case where generating an icon fails.
if (icon == null) {
return;
}
}
int size = mActivity.getResources().getDimensionPixelSize(
R.dimen.sharing_hub_preview_monogram_size);
mIconForPreview = Bitmap.createScaledBitmap(icon, size, size, true);
if (mBottomSheet != null) {
mBottomSheet.setFaviconForPreview(mIconForPreview);
}
}
private RoundedIconGenerator createRoundedIconGenerator(@ColorInt int iconColor) {
Resources resources = mActivity.getResources();
int iconSize = resources.getDimensionPixelSize(R.dimen.sharing_hub_preview_monogram_size);
int cornerRadius = iconSize / 2;
int textSize =
resources.getDimensionPixelSize(R.dimen.sharing_hub_preview_monogram_text_size);
return new RoundedIconGenerator(iconSize, iconSize, cornerRadius, iconColor, textSize);
}
@VisibleForTesting
Bitmap getIconForPreview() {
return mIconForPreview;
}
} }
...@@ -307,10 +307,11 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -307,10 +307,11 @@ public class ChromeProvidedSharingOptionsProviderTest {
Mockito.when(mPrefService.getBoolean(anyString())).thenReturn(printingEnabled); Mockito.when(mPrefService.getBoolean(anyString())).thenReturn(printingEnabled);
ShareParams shareParams = new ShareParams.Builder(null, /*title=*/"", /*url=*/"").build(); ShareParams shareParams = new ShareParams.Builder(null, /*title=*/"", /*url=*/"").build();
mChromeProvidedSharingOptionsProvider = new ChromeProvidedSharingOptionsProvider(mActivity, mChromeProvidedSharingOptionsProvider =
mTabProvider, new ChromeProvidedSharingOptionsProvider(mActivity, mTabProvider,
/*bottomSheetController=*/null, /*bottomSheetController=*/null,
new ShareSheetBottomSheetContent(mActivity, mShareSheetCoordinator, shareParams), new ShareSheetBottomSheetContent(
mActivity, null, mShareSheetCoordinator, shareParams),
new ShareParams.Builder(null, "", "").build(), new ShareParams.Builder(null, "", "").build(),
new ChromeShareExtras.Builder().build(), new ChromeShareExtras.Builder().build(),
/*TabPrinterDelegate=*/null, /*TabPrinterDelegate=*/null,
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.share.share_sheet;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.support.test.rule.ActivityTestRule;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.test.filters.MediumTest;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.share.share_sheet.ShareSheetPropertyModelBuilder.ContentType;
import org.chromium.chrome.browser.ui.favicon.IconType;
import org.chromium.chrome.browser.ui.favicon.LargeIconBridge;
import org.chromium.chrome.test.ChromeBrowserTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.components.browser_ui.share.ShareParams;
import org.chromium.ui.test.util.DummyUiActivity;
import org.chromium.url.GURL;
import java.util.ArrayList;
/**
* Tests {@link ShareSheetBottomSheetContent}.
*/
@RunWith(ChromeJUnit4ClassRunner.class)
@Features.EnableFeatures({ChromeFeatureList.CHROME_SHARING_HUB_V15})
public final class ShareSheetBottomSheetContentTest {
@Rule
public final ChromeBrowserTestRule mBrowserTestRule = new ChromeBrowserTestRule();
@Rule
public ActivityTestRule<DummyUiActivity> mActivityTestRule =
new ActivityTestRule<>(DummyUiActivity.class);
private static final Bitmap.Config sConfig = Bitmap.Config.ALPHA_8;
private static final Uri sImageUri = Uri.parse("content://testImage.png");
private static final String sText = "Text";
private static final String sTitle = "Title";
private static final String sUrl = "https://www.example.com";
private Activity mActivity;
private ShareParams mShareParams;
private ShareSheetBottomSheetContent mShareSheetBottomSheetContent;
@Before
public void setUp() {
mActivity = mActivityTestRule.getActivity();
mShareParams = new ShareParams.Builder(/*window=*/null, sTitle, sUrl)
.setText(sText)
.setFileUris(new ArrayList<>(ImmutableList.of(sImageUri)))
.build();
mShareSheetBottomSheetContent = new ShareSheetBottomSheetContent(
mActivity, new MockLargeIconBridge(), null, mShareParams);
}
@Test
@MediumTest
public void createRecyclerViews_hasMessage_doesNotShowPreview() {
mShareSheetBottomSheetContent.createRecyclerViews(
ImmutableList.of(), ImmutableList.of(), ImmutableSet.of(), "message");
TextView titleView =
mShareSheetBottomSheetContent.getContentView().findViewById(R.id.title_preview);
TextView subtitleView =
mShareSheetBottomSheetContent.getContentView().findViewById(R.id.subtitle_preview);
ImageView imageView =
mShareSheetBottomSheetContent.getContentView().findViewById(R.id.image_preview);
assertEquals("", titleView.getText());
assertEquals("", subtitleView.getText());
assertNull(imageView.getDrawable());
}
@Test
@MediumTest
public void createRecyclerViews_imageOnlyShare() {
ShareSheetBottomSheetContent shareSheetBottomSheetContent =
new ShareSheetBottomSheetContent(mActivity, new MockLargeIconBridge(), null,
new ShareParams.Builder(/*window=*/null, /*title=*/"", /*url=*/"")
.setFileUris(new ArrayList<>(ImmutableList.of(sImageUri)))
.build());
shareSheetBottomSheetContent.createRecyclerViews(
ImmutableList.of(), ImmutableList.of(), ImmutableSet.of(ContentType.IMAGE), "");
TextView titleView =
shareSheetBottomSheetContent.getContentView().findViewById(R.id.title_preview);
TextView subtitleView =
shareSheetBottomSheetContent.getContentView().findViewById(R.id.subtitle_preview);
assertEquals("", titleView.getText());
assertEquals(mActivity.getString(R.string.sharing_hub_image_preview_subtitle),
subtitleView.getText());
}
@Test
@MediumTest
public void createRecyclerViews_highlightedTextShare() {
mShareSheetBottomSheetContent.createRecyclerViews(ImmutableList.of(), ImmutableList.of(),
ImmutableSet.of(ContentType.HIGHLIGHTED_TEXT), "");
TextView titleView =
mShareSheetBottomSheetContent.getContentView().findViewById(R.id.title_preview);
TextView subtitleView =
mShareSheetBottomSheetContent.getContentView().findViewById(R.id.subtitle_preview);
assertEquals(View.GONE, titleView.getVisibility());
assertEquals(mShareParams.getText(), subtitleView.getText());
}
@Test
@MediumTest
public void createRecyclerViews_textOnlyShare() {
mShareSheetBottomSheetContent.createRecyclerViews(
ImmutableList.of(), ImmutableList.of(), ImmutableSet.of(ContentType.TEXT), "");
TextView titleView =
mShareSheetBottomSheetContent.getContentView().findViewById(R.id.title_preview);
TextView subtitleView =
mShareSheetBottomSheetContent.getContentView().findViewById(R.id.subtitle_preview);
assertEquals(View.GONE, titleView.getVisibility());
assertEquals(mShareParams.getText(), subtitleView.getText());
}
@Test
@MediumTest
public void createRecyclerViews_producesCorrectFavicon() {
mShareSheetBottomSheetContent.createRecyclerViews(ImmutableList.of(), ImmutableList.of(),
ImmutableSet.of(ContentType.LINK_PAGE_VISIBLE), "");
ImageView imageView =
mShareSheetBottomSheetContent.getContentView().findViewById(R.id.image_preview);
assertNotNull(imageView.getDrawable());
Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
int size = mActivity.getResources().getDimensionPixelSize(
R.dimen.sharing_hub_preview_monogram_size);
assertEquals(size, bitmap.getWidth());
assertEquals(size, bitmap.getHeight());
assertEquals(sConfig, bitmap.getConfig());
}
@Test
@MediumTest
public void createRecyclerViews_tabShare() {
mShareSheetBottomSheetContent.createRecyclerViews(ImmutableList.of(), ImmutableList.of(),
ImmutableSet.of(ContentType.LINK_PAGE_VISIBLE), "");
TextView titleView =
mShareSheetBottomSheetContent.getContentView().findViewById(R.id.title_preview);
TextView subtitleView =
mShareSheetBottomSheetContent.getContentView().findViewById(R.id.subtitle_preview);
ImageView imageView =
mShareSheetBottomSheetContent.getContentView().findViewById(R.id.image_preview);
assertEquals(mShareParams.getTitle(), titleView.getText());
assertEquals(mShareParams.getUrl(), subtitleView.getText());
assertNotNull(imageView.getDrawable());
}
@Test
@MediumTest
public void createRecyclerViews_webShareTextAndUrl() {
mShareSheetBottomSheetContent.createRecyclerViews(ImmutableList.of(), ImmutableList.of(),
ImmutableSet.of(ContentType.LINK_PAGE_NOT_VISIBLE, ContentType.TEXT), "");
TextView titleView =
mShareSheetBottomSheetContent.getContentView().findViewById(R.id.title_preview);
TextView subtitleView =
mShareSheetBottomSheetContent.getContentView().findViewById(R.id.subtitle_preview);
ImageView imageView =
mShareSheetBottomSheetContent.getContentView().findViewById(R.id.image_preview);
assertEquals(mShareParams.getText(), titleView.getText());
assertEquals(mShareParams.getUrl(), subtitleView.getText());
assertNotNull(imageView.getDrawable());
}
@Test
@MediumTest
public void createRecyclerViews_webShareUrl() {
ShareSheetBottomSheetContent shareSheetBottomSheetContent =
new ShareSheetBottomSheetContent(mActivity, new MockLargeIconBridge(), null,
new ShareParams.Builder(/*window=*/null, /*title=*/"", sUrl).build());
shareSheetBottomSheetContent.createRecyclerViews(ImmutableList.of(), ImmutableList.of(),
ImmutableSet.of(ContentType.LINK_PAGE_NOT_VISIBLE), "");
TextView titleView =
shareSheetBottomSheetContent.getContentView().findViewById(R.id.title_preview);
TextView subtitleView =
shareSheetBottomSheetContent.getContentView().findViewById(R.id.subtitle_preview);
ImageView imageView =
shareSheetBottomSheetContent.getContentView().findViewById(R.id.image_preview);
assertEquals(View.GONE, titleView.getVisibility());
assertEquals(mShareParams.getUrl(), subtitleView.getText());
assertNotNull(imageView.getDrawable());
}
private static class MockLargeIconBridge extends LargeIconBridge {
@Override
public boolean getLargeIconForUrl(
GURL pageUrl, int desiredSizePx, final LargeIconBridge.LargeIconCallback callback) {
callback.onLargeIconAvailable(
Bitmap.createBitmap(48, 84, sConfig), 0, false, IconType.INVALID);
return true;
}
}
}
...@@ -12,7 +12,6 @@ import static org.mockito.Matchers.any; ...@@ -12,7 +12,6 @@ import static org.mockito.Matchers.any;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.app.Activity; import android.app.Activity;
import android.graphics.Bitmap;
import android.support.test.rule.ActivityTestRule; import android.support.test.rule.ActivityTestRule;
import androidx.test.filters.MediumTest; import androidx.test.filters.MediumTest;
...@@ -29,8 +28,6 @@ import org.chromium.base.test.util.CommandLineFlags; ...@@ -29,8 +28,6 @@ import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.flags.ChromeSwitches; import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher; import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher;
import org.chromium.chrome.browser.ui.favicon.IconType;
import org.chromium.chrome.browser.ui.favicon.LargeIconBridge;
import org.chromium.chrome.test.ChromeBrowserTestRule; import org.chromium.chrome.test.ChromeBrowserTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.Features; import org.chromium.chrome.test.util.browser.Features;
...@@ -74,8 +71,6 @@ public final class ShareSheetCoordinatorTest { ...@@ -74,8 +71,6 @@ public final class ShareSheetCoordinatorTest {
private Activity mActivity; private Activity mActivity;
private ShareSheetCoordinator mShareSheetCoordinator; private ShareSheetCoordinator mShareSheetCoordinator;
private static Bitmap.Config sConfig = Bitmap.Config.ALPHA_8;
@Before @Before
public void setUp() { public void setUp() {
mActivity = mActivityTestRule.getActivity(); mActivity = mActivityTestRule.getActivity();
...@@ -99,7 +94,7 @@ public final class ShareSheetCoordinatorTest { ...@@ -99,7 +94,7 @@ public final class ShareSheetCoordinatorTest {
.thenReturn(thirdPartyPropertyModels); .thenReturn(thirdPartyPropertyModels);
mShareSheetCoordinator = new ShareSheetCoordinator(mController, mLifecycleDispatcher, null, mShareSheetCoordinator = new ShareSheetCoordinator(mController, mLifecycleDispatcher, null,
mPropertyModelBuilder, null, new MockLargeIconBridge(), null, false); mPropertyModelBuilder, null, null, null, false);
} }
@Test @Test
...@@ -129,28 +124,4 @@ public final class ShareSheetCoordinatorTest { ...@@ -129,28 +124,4 @@ public final class ShareSheetCoordinatorTest {
mActivity.getResources().getString(R.string.sharing_more_icon_label), mActivity.getResources().getString(R.string.sharing_more_icon_label),
propertyModels.get(2).get(ShareSheetItemViewProperties.LABEL)); propertyModels.get(2).get(ShareSheetItemViewProperties.LABEL));
} }
@Test
@MediumTest
public void testFetchFavicon() {
Activity activity = mActivityTestRule.getActivity();
mShareSheetCoordinator.fetchFavicon(activity, "https://www.example.com");
Bitmap bitmap = mShareSheetCoordinator.getIconForPreview();
int size = activity.getResources().getDimensionPixelSize(
R.dimen.sharing_hub_preview_monogram_size);
assertEquals(size, bitmap.getWidth());
assertEquals(size, bitmap.getHeight());
assertEquals(sConfig, bitmap.getConfig());
}
private static class MockLargeIconBridge extends LargeIconBridge {
@Override
public boolean getLargeIconForStringUrl(String pageUrl, int desiredSizePx,
final LargeIconBridge.LargeIconCallback callback) {
callback.onLargeIconAvailable(
Bitmap.createBitmap(48, 84, sConfig), 0, false, IconType.INVALID);
return true;
}
}
} }
...@@ -9,6 +9,7 @@ share_test_java_sources = [ ...@@ -9,6 +9,7 @@ share_test_java_sources = [
"//chrome/browser/share/android/javatests/src/org/chromium/chrome/browser/share/screenshot/ScreenshotShareSheetViewTest.java", "//chrome/browser/share/android/javatests/src/org/chromium/chrome/browser/share/screenshot/ScreenshotShareSheetViewTest.java",
"//chrome/browser/share/android/javatests/src/org/chromium/chrome/browser/share/send_tab_to_self/SendTabToSelfCoordinatorTest.java", "//chrome/browser/share/android/javatests/src/org/chromium/chrome/browser/share/send_tab_to_self/SendTabToSelfCoordinatorTest.java",
"//chrome/browser/share/android/javatests/src/org/chromium/chrome/browser/share/share_sheet/ChromeProvidedSharingOptionsProviderTest.java", "//chrome/browser/share/android/javatests/src/org/chromium/chrome/browser/share/share_sheet/ChromeProvidedSharingOptionsProviderTest.java",
"//chrome/browser/share/android/javatests/src/org/chromium/chrome/browser/share/share_sheet/ShareSheetBottomSheetContentTest.java",
"//chrome/browser/share/android/javatests/src/org/chromium/chrome/browser/share/share_sheet/ShareSheetCoordinatorTest.java", "//chrome/browser/share/android/javatests/src/org/chromium/chrome/browser/share/share_sheet/ShareSheetCoordinatorTest.java",
"//chrome/browser/share/android/javatests/src/org/chromium/chrome/browser/share/share_sheet/ShareSheetPropertyModelBuilderTest.java", "//chrome/browser/share/android/javatests/src/org/chromium/chrome/browser/share/share_sheet/ShareSheetPropertyModelBuilderTest.java",
] ]
......
...@@ -3590,6 +3590,9 @@ To change this setting, <ph name="BEGIN_LINK">&lt;resetlink&gt;</ph>reset sync<p ...@@ -3590,6 +3590,9 @@ To change this setting, <ph name="BEGIN_LINK">&lt;resetlink&gt;</ph>reset sync<p
<message name="IDS_SHARING_HUB_OPEN_SETTINGS_LABEL" desc="Label for the open settings button."> <message name="IDS_SHARING_HUB_OPEN_SETTINGS_LABEL" desc="Label for the open settings button.">
Open Settings Open Settings
</message> </message>
<message name="IDS_SHARING_HUB_IMAGE_PREVIEW_SUBTITLE" desc="Subtitle shown in the preview of Sharing Hub image shares.">
image
</message>
<!-- ClickToCall --> <!-- ClickToCall -->
<message name="IDS_CLICK_TO_CALL_NOTIFICATION_TEXT" desc="Text displayed in a click to call notification to call on a number."> <message name="IDS_CLICK_TO_CALL_NOTIFICATION_TEXT" desc="Text displayed in a click to call notification to call on a number.">
......
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