Commit be709442 authored by Rayan Kanso's avatar Rayan Kanso Committed by Commit Bot

Revert "[SharingHub] Changed the way firstPartyOptions are created."

This reverts commit 9593ee49.

Reason for revert: Breaking tests on Android.
Looks like Mockito is failing to mock 'WindowAndroid'
Sample build: https://ci.chromium.org/p/chromium/builders/ci/Lollipop%20Phone%20Tester/27576?

Bug: 1143640

Original change's description:
> [SharingHub] Changed the way firstPartyOptions are created.
>
> They will not be created on demand. This simplifies the logic to decide
> which options are relevant given the current state of the Chrome app.
>
> Change-Id: I9b3ebf3030cfaa48088d7c1d0082d659b47f28cd
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2485838
> Commit-Queue: Tanya Gupta <tgupta@chromium.org>
> Reviewed-by: Kyle Milka <kmilka@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#821914}

TBR=kmilka@chromium.org,tgupta@chromium.org,sophey@chromium.org

Change-Id: I904fb819d2fd37899faefb6c71140cd9c54ad419
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2506576Reviewed-by: default avatarRayan Kanso <rayankans@chromium.org>
Commit-Queue: Rayan Kanso <rayankans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822108}
parent 50cb1a54
...@@ -44,142 +44,132 @@ import java.util.Arrays; ...@@ -44,142 +44,132 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* Provides {@code PropertyModel}s of Chrome-provided sharing options. * Provides {@code PropertyModel}s of Chrome-provided sharing options.
*/ */
class ChromeProvidedSharingOptionsProvider { class ChromeProvidedSharingOptionsProvider {
private Activity mActivity; private final Activity mActivity;
private final Supplier<Tab> mTabProvider; private final Supplier<Tab> mTabProvider;
private final BottomSheetController mBottomSheetController; private final BottomSheetController mBottomSheetController;
private final ShareSheetBottomSheetContent mBottomSheetContent; private final ShareSheetBottomSheetContent mBottomSheetContent;
private ShareParams mShareParams; private final ShareParams mShareParams;
private ChromeShareExtras mChromeShareExtras; private final Callback<Tab> mPrintTabCallback;
private Callback<Tab> mPrintTabCallback; private final SettingsLauncher mSettingsLauncher;
private SettingsLauncher mSettingsLauncher; private final boolean mIsSyncEnabled;
private boolean mIsSyncEnabled; private final long mShareStartTime;
private long mShareStartTime; private final List<FirstPartyOption> mOrderedFirstPartyOptions;
private ChromeOptionShareCallback mChromeOptionShareCallback; private final ChromeOptionShareCallback mChromeOptionShareCallback;
private ScreenshotCoordinator mScreenshotCoordinator; private ScreenshotCoordinator mScreenshotCoordinator;
private String mUrl; private final String mUrl;
private boolean mIsMultiWindow;
private Collection<Integer> mContentTypes;
/** /**
* Constructs a new {@link ChromeProvidedSharingOptionsProvider}. * Constructs a new {@link ChromeProvidedSharingOptionsProvider}.
* *
* @param activity The current {@link Activity}.
* @param tabProvider Supplier for the current activity tab. * @param tabProvider Supplier for the current activity tab.
* @param bottomSheetController The {@link BottomSheetController} for the current activity. * @param bottomSheetController The {@link BottomSheetController} for the current activity.
* @param bottomSheetContent The {@link ShareSheetBottomSheetContent} for the current activity. * @param bottomSheetContent The {@link ShareSheetBottomSheetContent} for the current
* activity.
*/
ChromeProvidedSharingOptionsProvider(Supplier<Tab> tabProvider,
BottomSheetController bottomSheetController,
ShareSheetBottomSheetContent bottomSheetContent) {
mTabProvider = tabProvider;
mBottomSheetController = bottomSheetController;
mBottomSheetContent = bottomSheetContent;
}
/**
* Sets params related to the share itself.
*
* @param shareParams The {@link ShareParams} for the current share. * @param shareParams The {@link ShareParams} for the current share.
* @param chromeShareExtras The {@link ChromeShareExtras} for the current share. * @param chromeShareExtras The {@link ChromeShareExtras} for the current share.
* @param printTab A {@link Callback} that will print a given Tab.
* @param shareStartTime The start time of the current share. * @param shareStartTime The start time of the current share.
* @param chromeOptionShareCallback A ChromeOptionShareCallback that can be used by * @param chromeOptionShareCallback A ChromeOptionShareCallback that can be used by
* Chrome-provided sharing options. * Chrome-provided sharing options.
* @param contentTypes The contentTypes the share is comprised of.
*/ */
void setShareRelatedParams(ShareParams shareParams, ChromeShareExtras chromeShareExtras, ChromeProvidedSharingOptionsProvider(Activity activity, Supplier<Tab> tabProvider,
long shareStartTime, ChromeOptionShareCallback chromeOptionShareCallback, BottomSheetController bottomSheetController,
Collection<Integer> contentTypes) { ShareSheetBottomSheetContent bottomSheetContent, ShareParams shareParams,
ChromeShareExtras chromeShareExtras, Callback<Tab> printTab,
SettingsLauncher settingsLauncher, boolean isSyncEnabled, long shareStartTime,
ChromeOptionShareCallback chromeOptionShareCallback) {
mActivity = activity;
mTabProvider = tabProvider;
mBottomSheetController = bottomSheetController;
mBottomSheetContent = bottomSheetContent;
mShareParams = shareParams; mShareParams = shareParams;
mShareStartTime = shareStartTime;
mChromeShareExtras = chromeShareExtras;
mActivity = mShareParams.getWindow().getActivity().get();
mChromeOptionShareCallback = chromeOptionShareCallback;
mContentTypes = contentTypes;
}
/**
* Set params needed by the individual sharing features.
*
* @param printTab A {@link Callback} that will print a given Tab.
* @param settingsLauncher Launches Chrome settings.
* @param isSyncEnabled Whether the user has enabled sync.
*/
void setFeatureSpecificParams(
Callback<Tab> printTab, SettingsLauncher settingsLauncher, boolean isSyncEnabled) {
mPrintTabCallback = printTab; mPrintTabCallback = printTab;
mSettingsLauncher = settingsLauncher; mSettingsLauncher = settingsLauncher;
mIsSyncEnabled = isSyncEnabled; mIsSyncEnabled = isSyncEnabled;
mShareStartTime = shareStartTime;
mOrderedFirstPartyOptions = new ArrayList<>();
initializeFirstPartyOptionsInOrder();
mChromeOptionShareCallback = chromeOptionShareCallback;
mUrl = getUrlToShare(shareParams, chromeShareExtras,
mTabProvider.get().isInitialized() ? mTabProvider.get().getUrl().getSpec() : "");
} }
/** /**
* Set whether Chrome is in multiWindow mode. * Encapsulates a {@link PropertyModel} and the {@link ContentType}s it should be shown for.
*/
void setIsMultiWindow(boolean isMultiWindow) {
mIsMultiWindow = isMultiWindow;
}
/**
* Calculates the property models to display for the Share.
*
* <p>New share features should add a call to this function. The order of the functions
* determine the order in which they appear in the share sheet. Each feature is gated on the
* supported {@link ContentType}(s).
*
* @return the set of ChromeProvidedSharingOptions for the share.
*/ */
List<PropertyModel> calculatePropertyModels() { private static class FirstPartyOption {
mUrl = getUrlToShare(mShareParams, mChromeShareExtras, final Collection<Integer> mContentTypes;
mTabProvider.get().isInitialized() ? mTabProvider.get().getUrl().getSpec() : ""); final Collection<Integer> mContentTypesToDisableFor;
final PropertyModel mPropertyModel;
List<PropertyModel> propertyModels = new ArrayList<>(); final boolean mDisableForMultiWindow;
if (mContentTypes == null || mContentTypes.isEmpty()) { /**
return propertyModels; * Should only be used when the default property model constructed in the builder does not
* fit the feature's needs. This should be rare.
*
* @param model Property model for the first party option.
* @param contentTypes Content types to trigger for.
* @param contentTypesToDisableFor Content types to disable for.
* @param disableForMultiWindow If the feature should be disabled if in multi-window mode.
*/
FirstPartyOption(PropertyModel model, Collection<Integer> contentTypes,
Collection<Integer> contentTypesToDisableFor, boolean disableForMultiWindow) {
mPropertyModel = model;
mContentTypes = contentTypes;
mContentTypesToDisableFor = contentTypesToDisableFor;
mDisableForMultiWindow = disableForMultiWindow;
} }
maybeAddScreenshotOption(propertyModels);
maybeAddCopyLinkOption(propertyModels);
maybeCopyImageOption(propertyModels);
maybeAddCopyTextAndLinkOption(propertyModels);
maybeAddCopyTextOption(propertyModels);
maybeAddSendTabToSelfOption(propertyModels);
maybeAddHighlightsOption(propertyModels);
maybeAddQrCodeOption(propertyModels);
maybeAddPrintingOption(propertyModels);
return propertyModels;
} }
private class PropertyModelBuilder { private class FirstPartyOptionBuilder {
private int mIcon; private int mIcon;
private int mIconLabel; private int mIconLabel;
private String mFeatureNameForMetrics; private String mFeatureNameForMetrics;
private Callback<View> mOnClickCallback; private Callback<View> mOnClickCallback;
private boolean mDisableForMultiWindow;
private Integer[] mContentTypesToDisableFor;
private final Integer[] mContentTypesInBuilder;
PropertyModelBuilder setIcon(int icon, int iconLabel) { FirstPartyOptionBuilder(Integer... contentTypes) {
mContentTypesInBuilder = contentTypes;
mContentTypesToDisableFor = new Integer[] {};
}
FirstPartyOptionBuilder setIcon(int icon, int iconLabel) {
mIcon = icon; mIcon = icon;
mIconLabel = iconLabel; mIconLabel = iconLabel;
return this; return this;
} }
PropertyModelBuilder setFeatureNameForMetrics(String featureName) { FirstPartyOptionBuilder setFeatureNameForMetrics(String featureName) {
mFeatureNameForMetrics = featureName; mFeatureNameForMetrics = featureName;
return this; return this;
} }
PropertyModelBuilder setOnClickCallback(Callback<View> onClickCallback) { FirstPartyOptionBuilder setOnClickCallback(Callback<View> onClickCallback) {
mOnClickCallback = onClickCallback; mOnClickCallback = onClickCallback;
return this; return this;
} }
PropertyModel build() { FirstPartyOptionBuilder setContentTypesToDisableFor(Integer... contentTypesToDisableFor) {
return ShareSheetPropertyModelBuilder.createPropertyModel( mContentTypesToDisableFor = contentTypesToDisableFor;
return this;
}
FirstPartyOptionBuilder setDisableForMultiWindow(boolean disableForMultiWindow) {
mDisableForMultiWindow = disableForMultiWindow;
return this;
}
FirstPartyOption build() {
PropertyModel model = ShareSheetPropertyModelBuilder.createPropertyModel(
AppCompatResources.getDrawable(mActivity, mIcon), AppCompatResources.getDrawable(mActivity, mIcon),
mActivity.getResources().getString(mIconLabel), (view) -> { mActivity.getResources().getString(mIconLabel), (view) -> {
RecordUserAction.record(mFeatureNameForMetrics); RecordUserAction.record(mFeatureNameForMetrics);
...@@ -187,6 +177,57 @@ class ChromeProvidedSharingOptionsProvider { ...@@ -187,6 +177,57 @@ class ChromeProvidedSharingOptionsProvider {
mBottomSheetController.hideContent(mBottomSheetContent, true); mBottomSheetController.hideContent(mBottomSheetContent, true);
mOnClickCallback.onResult(view); mOnClickCallback.onResult(view);
}); });
return new FirstPartyOption(model, Arrays.asList(mContentTypesInBuilder),
Arrays.asList(mContentTypesToDisableFor), mDisableForMultiWindow);
}
}
/**
* Returns an ordered list of {@link PropertyModel}s that should be shown given the {@code
* contentTypes} being shared.
*
* @param contentTypes a {@link Set} of {@link ContentType}.
* @param isMultiWindow if in multi-window mode.
* @return a list of {@link PropertyModel}s.
*/
List<PropertyModel> getPropertyModels(Set<Integer> contentTypes, boolean isMultiWindow) {
List<PropertyModel> propertyModels = new ArrayList<>();
for (FirstPartyOption firstPartyOption : mOrderedFirstPartyOptions) {
if (!Collections.disjoint(contentTypes, firstPartyOption.mContentTypes)
&& Collections.disjoint(
contentTypes, firstPartyOption.mContentTypesToDisableFor)
&& !(isMultiWindow && firstPartyOption.mDisableForMultiWindow)) {
propertyModels.add(firstPartyOption.mPropertyModel);
}
}
return propertyModels;
}
/**
* Creates all enabled {@link FirstPartyOption}s and adds them to {@code
* mOrderedFirstPartyOptions} in the order they should appear.
*/
private void initializeFirstPartyOptionsInOrder() {
if (ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_SHARE_SCREENSHOT)) {
mOrderedFirstPartyOptions.add(createScreenshotFirstPartyOption());
}
mOrderedFirstPartyOptions.add(createCopyLinkFirstPartyOption());
if (ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_SHARING_HUB_V15)) {
mOrderedFirstPartyOptions.add(createCopyImageFirstPartyOption());
mOrderedFirstPartyOptions.add(createCopyFirstPartyOption());
mOrderedFirstPartyOptions.add(createCopyTextFirstPartyOption());
}
mOrderedFirstPartyOptions.add(createSendTabToSelfFirstPartyOption());
if (ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_SHARING_HUB_V15)
&& ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_SHARE_HIGHLIGHTS_ANDROID)) {
mOrderedFirstPartyOptions.add(createHighlightsFirstPartyOption());
}
if (ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_SHARE_QRCODE)
&& !mTabProvider.get().getWebContents().isIncognito()) {
mOrderedFirstPartyOptions.add(createQrCodeFirstPartyOption());
}
if (UserPrefs.get(Profile.getLastUsedRegularProfile()).getBoolean(Pref.PRINTING_ENABLED)) {
mOrderedFirstPartyOptions.add(createPrintingFirstPartyOption());
} }
} }
...@@ -206,18 +247,8 @@ class ChromeProvidedSharingOptionsProvider { ...@@ -206,18 +247,8 @@ class ChromeProvidedSharingOptionsProvider {
} }
}; };
private void maybeAddScreenshotOption(List<PropertyModel> propertyModels) { private FirstPartyOption createScreenshotFirstPartyOption() {
if (!ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_SHARE_SCREENSHOT) PropertyModel propertyModel = ShareSheetPropertyModelBuilder.createPropertyModel(
|| mIsMultiWindow) {
return;
}
if (Collections.disjoint(mContentTypes,
Arrays.asList(ContentType.LINK_PAGE_VISIBLE, ContentType.TEXT,
ContentType.HIGHLIGHTED_TEXT, ContentType.IMAGE))) {
return;
}
propertyModels.add(ShareSheetPropertyModelBuilder.createPropertyModel(
AppCompatResources.getDrawable(mActivity, R.drawable.screenshot), AppCompatResources.getDrawable(mActivity, R.drawable.screenshot),
mActivity.getResources().getString(R.string.sharing_screenshot), (view) -> { mActivity.getResources().getString(R.string.sharing_screenshot), (view) -> {
RecordUserAction.record("SharingHubAndroid.ScreenshotSelected"); RecordUserAction.record("SharingHubAndroid.ScreenshotSelected");
...@@ -228,181 +259,127 @@ class ChromeProvidedSharingOptionsProvider { ...@@ -228,181 +259,127 @@ class ChromeProvidedSharingOptionsProvider {
// observer will then remove itself. // observer will then remove itself.
mBottomSheetController.addObserver(mSheetObserver); mBottomSheetController.addObserver(mSheetObserver);
mBottomSheetController.hideContent(mBottomSheetContent, true); mBottomSheetController.hideContent(mBottomSheetContent, true);
})); });
return new FirstPartyOption(propertyModel,
Arrays.asList(ContentType.LINK_PAGE_VISIBLE, ContentType.TEXT,
ContentType.HIGHLIGHTED_TEXT, ContentType.IMAGE),
/*contentTypesToDisableFor=*/Collections.emptySet(),
/*disableForMultiWindow=*/true);
} }
private void maybeAddCopyLinkOption(List<PropertyModel> propertyModels) { private FirstPartyOption createCopyLinkFirstPartyOption() {
if (mContentTypes.contains(ContentType.LINK_AND_TEXT) return new FirstPartyOptionBuilder(
|| Collections.disjoint(mContentTypes, ContentType.LINK_PAGE_VISIBLE, ContentType.LINK_PAGE_NOT_VISIBLE)
Arrays.asList(ContentType.LINK_PAGE_VISIBLE, .setContentTypesToDisableFor(ContentType.LINK_AND_TEXT)
ContentType.LINK_PAGE_NOT_VISIBLE))) { .setIcon(R.drawable.ic_content_copy_black, R.string.sharing_copy_url)
return; .setFeatureNameForMetrics("SharingHubAndroid.CopyURLSelected")
} .setOnClickCallback((view) -> {
ClipboardManager clipboard = (ClipboardManager) mActivity.getSystemService(
propertyModels.add( Context.CLIPBOARD_SERVICE);
new PropertyModelBuilder() clipboard.setPrimaryClip(
.setIcon(R.drawable.ic_content_copy_black, R.string.sharing_copy_url) ClipData.newPlainText(mShareParams.getTitle(), mShareParams.getUrl()));
.setFeatureNameForMetrics("SharingHubAndroid.CopyURLSelected") Toast.makeText(mActivity, R.string.link_copied, Toast.LENGTH_SHORT).show();
.setOnClickCallback((view) -> { })
ClipboardManager clipboard = .build();
(ClipboardManager) mActivity.getSystemService(
Context.CLIPBOARD_SERVICE);
clipboard.setPrimaryClip(ClipData.newPlainText(
mShareParams.getTitle(), mShareParams.getUrl()));
Toast.makeText(mActivity, R.string.link_copied, Toast.LENGTH_SHORT)
.show();
})
.build());
} }
private void maybeCopyImageOption(List<PropertyModel> propertyModels) { private FirstPartyOption createCopyImageFirstPartyOption() {
if (!ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_SHARING_HUB_V15) return new FirstPartyOptionBuilder(ContentType.IMAGE)
|| !mContentTypes.contains(ContentType.IMAGE)) { .setIcon(R.drawable.ic_content_copy_black, R.string.sharing_copy_image)
return; .setFeatureNameForMetrics("SharingHubAndroid.CopyImageSelected")
} .setOnClickCallback((view) -> {
propertyModels.add( if (!mShareParams.getFileUris().isEmpty()) {
new PropertyModelBuilder() Clipboard.getInstance().setImageUri(mShareParams.getFileUris().get(0));
.setIcon(R.drawable.ic_content_copy_black, R.string.sharing_copy_image) Toast.makeText(mActivity, R.string.image_copied, Toast.LENGTH_SHORT).show();
.setFeatureNameForMetrics("SharingHubAndroid.CopyImageSelected") }
.setOnClickCallback((view) -> { })
if (!mShareParams.getFileUris().isEmpty()) { .build();
Clipboard.getInstance().setImageUri(
mShareParams.getFileUris().get(0));
Toast.makeText(mActivity, R.string.image_copied, Toast.LENGTH_SHORT)
.show();
}
})
.build());
} }
private void maybeAddCopyTextAndLinkOption(List<PropertyModel> propertyModels) { private FirstPartyOption createCopyFirstPartyOption() {
if (!ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_SHARING_HUB_V15) return new FirstPartyOptionBuilder(ContentType.LINK_AND_TEXT)
|| !mContentTypes.contains(ContentType.LINK_AND_TEXT)) { .setIcon(R.drawable.ic_content_copy_black, R.string.sharing_copy)
return; .setFeatureNameForMetrics("SharingHubAndroid.CopySelected")
} .setOnClickCallback((view) -> {
propertyModels.add( ClipboardManager clipboard = (ClipboardManager) mActivity.getSystemService(
new PropertyModelBuilder() Context.CLIPBOARD_SERVICE);
.setIcon(R.drawable.ic_content_copy_black, R.string.sharing_copy) clipboard.setPrimaryClip(ClipData.newPlainText(
.setFeatureNameForMetrics("SharingHubAndroid.CopySelected") mShareParams.getTitle(), mShareParams.getTextAndUrl()));
.setOnClickCallback((view) -> { Toast.makeText(mActivity, R.string.sharing_copied, Toast.LENGTH_SHORT).show();
ClipboardManager clipboard = })
(ClipboardManager) mActivity.getSystemService( .build();
Context.CLIPBOARD_SERVICE);
clipboard.setPrimaryClip(ClipData.newPlainText(
mShareParams.getTitle(), mShareParams.getTextAndUrl()));
Toast.makeText(mActivity, R.string.sharing_copied, Toast.LENGTH_SHORT)
.show();
})
.build());
} }
private void maybeAddCopyTextOption(List<PropertyModel> propertyModels) { private FirstPartyOption createCopyTextFirstPartyOption() {
if (!ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_SHARING_HUB_V15) return new FirstPartyOptionBuilder(ContentType.TEXT, ContentType.HIGHLIGHTED_TEXT)
|| mContentTypes.contains(ContentType.LINK_AND_TEXT)) { .setContentTypesToDisableFor(ContentType.LINK_AND_TEXT)
return; .setIcon(R.drawable.ic_content_copy_black, R.string.sharing_copy_text)
} .setFeatureNameForMetrics("SharingHubAndroid.CopyTextSelected")
if (Collections.disjoint( .setOnClickCallback((view) -> {
mContentTypes, Arrays.asList(ContentType.TEXT, ContentType.HIGHLIGHTED_TEXT))) { ClipboardManager clipboard = (ClipboardManager) mActivity.getSystemService(
return; Context.CLIPBOARD_SERVICE);
} clipboard.setPrimaryClip(
propertyModels.add( ClipData.newPlainText(mShareParams.getTitle(), mShareParams.getText()));
new PropertyModelBuilder() Toast.makeText(mActivity, R.string.text_copied, Toast.LENGTH_SHORT).show();
.setIcon(R.drawable.ic_content_copy_black, R.string.sharing_copy_text) })
.setFeatureNameForMetrics("SharingHubAndroid.CopyTextSelected") .build();
.setOnClickCallback((view) -> {
ClipboardManager clipboard =
(ClipboardManager) mActivity.getSystemService(
Context.CLIPBOARD_SERVICE);
clipboard.setPrimaryClip(ClipData.newPlainText(
mShareParams.getTitle(), mShareParams.getText()));
Toast.makeText(mActivity, R.string.text_copied, Toast.LENGTH_SHORT)
.show();
})
.build());
} }
private void maybeAddSendTabToSelfOption(List<PropertyModel> propertyModels) { private FirstPartyOption createSendTabToSelfFirstPartyOption() {
if (Collections.disjoint(mContentTypes, return new FirstPartyOptionBuilder(
Arrays.asList(ContentType.LINK_PAGE_VISIBLE, ContentType.LINK_PAGE_NOT_VISIBLE, ContentType.LINK_PAGE_VISIBLE, ContentType.LINK_PAGE_NOT_VISIBLE, ContentType.IMAGE)
ContentType.IMAGE))) { .setIcon(R.drawable.send_tab, R.string.send_tab_to_self_share_activity_title)
return; .setFeatureNameForMetrics("SharingHubAndroid.SendTabToSelfSelected")
} .setOnClickCallback((view) -> {
propertyModels.add( SendTabToSelfCoordinator sttsCoordinator =
new PropertyModelBuilder() new SendTabToSelfCoordinator(mActivity, mUrl, mShareParams.getTitle(),
.setIcon(
R.drawable.send_tab, R.string.send_tab_to_self_share_activity_title)
.setFeatureNameForMetrics("SharingHubAndroid.SendTabToSelfSelected")
.setOnClickCallback((view) -> {
SendTabToSelfCoordinator sttsCoordinator = new SendTabToSelfCoordinator(
mActivity, mUrl, mShareParams.getTitle(),
mBottomSheetController, mSettingsLauncher, mIsSyncEnabled, mBottomSheetController, mSettingsLauncher, mIsSyncEnabled,
mTabProvider.get() mTabProvider.get()
.getWebContents() .getWebContents()
.getNavigationController() .getNavigationController()
.getVisibleEntry() .getVisibleEntry()
.getTimestamp()); .getTimestamp());
sttsCoordinator.show(); sttsCoordinator.show();
}) })
.build()); .build();
} }
private void maybeAddQrCodeOption(List<PropertyModel> propertyModels) { private FirstPartyOption createQrCodeFirstPartyOption() {
if (!ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_SHARE_QRCODE) return new FirstPartyOptionBuilder(
|| mTabProvider.get().getWebContents().isIncognito()) { ContentType.LINK_PAGE_VISIBLE, ContentType.LINK_PAGE_NOT_VISIBLE, ContentType.IMAGE)
return; .setIcon(R.drawable.qr_code, R.string.qr_code_share_icon_label)
} .setFeatureNameForMetrics("SharingHubAndroid.QRCodeSelected")
if (Collections.disjoint(mContentTypes, .setOnClickCallback((view) -> {
Arrays.asList(ContentType.LINK_PAGE_VISIBLE, ContentType.LINK_PAGE_NOT_VISIBLE, QrCodeCoordinator qrCodeCoordinator = new QrCodeCoordinator(mActivity, mUrl);
ContentType.IMAGE))) { qrCodeCoordinator.show();
return; })
} .build();
propertyModels.add(new PropertyModelBuilder()
.setIcon(R.drawable.qr_code, R.string.qr_code_share_icon_label)
.setFeatureNameForMetrics("SharingHubAndroid.QRCodeSelected")
.setOnClickCallback((view) -> {
QrCodeCoordinator qrCodeCoordinator =
new QrCodeCoordinator(mActivity, mUrl);
qrCodeCoordinator.show();
})
.build());
} }
private void maybeAddPrintingOption(List<PropertyModel> propertyModels) { private FirstPartyOption createPrintingFirstPartyOption() {
if (!UserPrefs.get(Profile.getLastUsedRegularProfile()).getBoolean(Pref.PRINTING_ENABLED) return new FirstPartyOptionBuilder(ContentType.LINK_PAGE_VISIBLE)
|| !mContentTypes.contains(ContentType.LINK_PAGE_VISIBLE)) { .setIcon(R.drawable.sharing_print, R.string.print_share_activity_title)
return; .setFeatureNameForMetrics("SharingHubAndroid.PrintSelected")
} .setOnClickCallback((view) -> { mPrintTabCallback.onResult(mTabProvider.get()); })
propertyModels.add( .build();
new PropertyModelBuilder()
.setIcon(R.drawable.sharing_print, R.string.print_share_activity_title)
.setFeatureNameForMetrics("SharingHubAndroid.PrintSelected")
.setOnClickCallback(
(view) -> { mPrintTabCallback.onResult(mTabProvider.get()); })
.build());
} }
private void maybeAddHighlightsOption(List<PropertyModel> propertyModels) { private FirstPartyOption createHighlightsFirstPartyOption() {
if (!ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_SHARING_HUB_V15) return new FirstPartyOptionBuilder(ContentType.HIGHLIGHTED_TEXT)
|| !ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_SHARE_HIGHLIGHTS_ANDROID) .setIcon(R.drawable.link, R.string.sharing_highlights)
|| !mContentTypes.contains(ContentType.HIGHLIGHTED_TEXT)) { .setFeatureNameForMetrics("SharingHubAndroid.LinkToTextSelected")
return; .setOnClickCallback((view) -> {
} LinkToTextCoordinator linkToTextCoordinator =
propertyModels.add( new LinkToTextCoordinator(mActivity, mTabProvider.get(),
new PropertyModelBuilder() mChromeOptionShareCallback, mUrl, mShareParams.getText());
.setIcon(R.drawable.link, R.string.sharing_highlights) })
.setFeatureNameForMetrics("SharingHubAndroid.LinkToTextSelected") .build();
.setOnClickCallback((view) -> {
LinkToTextCoordinator linkToTextCoordinator = new LinkToTextCoordinator(
mActivity, mTabProvider.get(), mChromeOptionShareCallback, mUrl,
mShareParams.getText());
})
.build());
} }
/** /**
* Returns the url to share. * Returns the url to share.
* *
* <p> This prioritizes the URL in {@link ShareParams}, but if it does not exist, we look for an * <p>This prioritizes the URL in {@link ShareParams}, but if it does not exist, we look for an
* image source URL from {@link ChromeShareExtras}. The image source URL is not contained in * image source URL from {@link ChromeShareExtras}. The image source URL is not contained in
* {@link ShareParams#getUrl()} because we do not want to share the image URL with the image * {@link ShareParams#getUrl()} because we do not want to share the image URL with the image
* file in third-party app shares. If both are empty then current tab URL is used. This is * file in third-party app shares. If both are empty then current tab URL is used. This is
......
...@@ -47,6 +47,10 @@ public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptio ...@@ -47,6 +47,10 @@ public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptio
private final BottomSheetController mBottomSheetController; private final BottomSheetController mBottomSheetController;
private final Supplier<Tab> mTabProvider; private final Supplier<Tab> mTabProvider;
private final ShareSheetPropertyModelBuilder mPropertyModelBuilder; private final ShareSheetPropertyModelBuilder mPropertyModelBuilder;
private final Callback<Tab> mPrintTabCallback;
private final SettingsLauncher mSettingsLauncher;
private final boolean mIsSyncEnabled;
private long mShareStartTime;
private boolean mExcludeFirstParty; private boolean mExcludeFirstParty;
private boolean mIsMultiWindow; private boolean mIsMultiWindow;
private Set<Integer> mContentTypes; private Set<Integer> mContentTypes;
...@@ -64,7 +68,7 @@ public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptio ...@@ -64,7 +68,7 @@ public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptio
* *
* @param controller The {@link BottomSheetController} for the current activity. * @param controller The {@link BottomSheetController} for the current activity.
* @param lifecycleDispatcher Dispatcher for activity lifecycle events, e.g. configuration * @param lifecycleDispatcher Dispatcher for activity lifecycle events, e.g. configuration
* changes. * changes.
* @param tabProvider Supplier for the current activity tab. * @param tabProvider Supplier for the current activity tab.
* @param modelBuilder The {@link ShareSheetPropertyModelBuilder} for the share sheet. * @param modelBuilder The {@link ShareSheetPropertyModelBuilder} for the share sheet.
*/ */
...@@ -78,6 +82,9 @@ public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptio ...@@ -78,6 +82,9 @@ public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptio
mLifecycleDispatcher.register(this); mLifecycleDispatcher.register(this);
mTabProvider = tabProvider; mTabProvider = tabProvider;
mPropertyModelBuilder = modelBuilder; mPropertyModelBuilder = modelBuilder;
mPrintTabCallback = printTab;
mSettingsLauncher = settingsLauncher;
mIsSyncEnabled = isSyncEnabled;
mBottomSheetObserver = new EmptyBottomSheetObserver() { mBottomSheetObserver = new EmptyBottomSheetObserver() {
@Override @Override
public void onSheetContentChanged(BottomSheetContent bottomSheet) { public void onSheetContentChanged(BottomSheetContent bottomSheet) {
...@@ -93,11 +100,6 @@ public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptio ...@@ -93,11 +100,6 @@ public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptio
}; };
mBottomSheetController.addObserver(mBottomSheetObserver); mBottomSheetController.addObserver(mBottomSheetObserver);
mIconBridge = iconBridge; mIconBridge = iconBridge;
mChromeProvidedSharingOptionsProvider =
new ChromeProvidedSharingOptionsProvider(tabProvider, controller, mBottomSheet);
mChromeProvidedSharingOptionsProvider.setFeatureSpecificParams(
printTab, settingsLauncher, isSyncEnabled);
} }
protected void destroy() { protected void destroy() {
...@@ -115,7 +117,6 @@ public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptio ...@@ -115,7 +117,6 @@ public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptio
mLifecycleDispatcher.unregister(this); mLifecycleDispatcher.unregister(this);
mLifecycleDispatcher = null; mLifecycleDispatcher = null;
} }
mChromeProvidedSharingOptionsProvider = null;
} }
// TODO(crbug/1022172): Should be package-protected once modularization is complete. // TODO(crbug/1022172): Should be package-protected once modularization is complete.
...@@ -134,11 +135,12 @@ public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptio ...@@ -134,11 +135,12 @@ public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptio
mBottomSheet = new ShareSheetBottomSheetContent(mActivity, mIconBridge, this, params); mBottomSheet = new ShareSheetBottomSheetContent(mActivity, mIconBridge, this, params);
mShareStartTime = shareStartTime;
mContentTypes = ShareSheetPropertyModelBuilder.getContentTypes(params, chromeShareExtras); mContentTypes = ShareSheetPropertyModelBuilder.getContentTypes(params, chromeShareExtras);
List<PropertyModel> firstPartyApps = createFirstPartyPropertyModels( List<PropertyModel> firstPartyApps =
mActivity, params, chromeShareExtras, mContentTypes, shareStartTime); createFirstPartyPropertyModels(mActivity, params, chromeShareExtras, mContentTypes);
List<PropertyModel> thirdPartyApps = createThirdPartyPropertyModels( List<PropertyModel> thirdPartyApps = createThirdPartyPropertyModels(
mActivity, params, mContentTypes, chromeShareExtras.saveLastUsed(), shareStartTime); mActivity, params, mContentTypes, chromeShareExtras.saveLastUsed());
mBottomSheet.createRecyclerViews( mBottomSheet.createRecyclerViews(
firstPartyApps, thirdPartyApps, mContentTypes, params.getFileContentType()); firstPartyApps, thirdPartyApps, mContentTypes, params.getFileContentType());
...@@ -160,24 +162,25 @@ public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptio ...@@ -160,24 +162,25 @@ public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptio
} }
List<PropertyModel> createFirstPartyPropertyModels(Activity activity, ShareParams shareParams, List<PropertyModel> createFirstPartyPropertyModels(Activity activity, ShareParams shareParams,
ChromeShareExtras chromeShareExtras, Set<Integer> contentTypes, long shareStartTime) { ChromeShareExtras chromeShareExtras, Set<Integer> contentTypes) {
if (mExcludeFirstParty) { if (mExcludeFirstParty) {
return new ArrayList<>(); return new ArrayList<>();
} }
mChromeProvidedSharingOptionsProvider = new ChromeProvidedSharingOptionsProvider(activity,
mTabProvider, mBottomSheetController, mBottomSheet, shareParams, chromeShareExtras,
mPrintTabCallback, mSettingsLauncher, mIsSyncEnabled, mShareStartTime, this);
mIsMultiWindow = ApiCompatibilityUtils.isInMultiWindowMode(activity); mIsMultiWindow = ApiCompatibilityUtils.isInMultiWindowMode(activity);
mChromeProvidedSharingOptionsProvider.setShareRelatedParams( return mChromeProvidedSharingOptionsProvider.getPropertyModels(
shareParams, chromeShareExtras, shareStartTime, this, contentTypes); contentTypes, mIsMultiWindow);
mChromeProvidedSharingOptionsProvider.setIsMultiWindow(mIsMultiWindow);
return mChromeProvidedSharingOptionsProvider.calculatePropertyModels();
} }
@VisibleForTesting @VisibleForTesting
List<PropertyModel> createThirdPartyPropertyModels(Activity activity, ShareParams params, List<PropertyModel> createThirdPartyPropertyModels(Activity activity, ShareParams params,
Set<Integer> contentTypes, boolean saveLastUsed, long shareStartTime) { Set<Integer> contentTypes, boolean saveLastUsed) {
if (params == null) return null; if (params == null) return null;
List<PropertyModel> models = mPropertyModelBuilder.selectThirdPartyApps(mBottomSheet, List<PropertyModel> models = mPropertyModelBuilder.selectThirdPartyApps(mBottomSheet,
contentTypes, params, saveLastUsed, params.getWindow(), shareStartTime); contentTypes, params, saveLastUsed, params.getWindow(), mShareStartTime);
// More... // More...
PropertyModel morePropertyModel = ShareSheetPropertyModelBuilder.createPropertyModel( PropertyModel morePropertyModel = ShareSheetPropertyModelBuilder.createPropertyModel(
AppCompatResources.getDrawable(activity, R.drawable.sharing_more), AppCompatResources.getDrawable(activity, R.drawable.sharing_more),
...@@ -215,22 +218,16 @@ public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptio ...@@ -215,22 +218,16 @@ public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptio
return; return;
} }
boolean isMultiWindow = ApiCompatibilityUtils.isInMultiWindowMode(mActivity); boolean isMultiWindow = ApiCompatibilityUtils.isInMultiWindowMode(mActivity);
if (mIsMultiWindow == isMultiWindow) { // mContentTypes is null if Chrome features should not be shown.
if (mIsMultiWindow == isMultiWindow || mContentTypes == null) {
return; return;
} }
mIsMultiWindow = isMultiWindow; mIsMultiWindow = isMultiWindow;
mChromeProvidedSharingOptionsProvider.setIsMultiWindow(mIsMultiWindow); mBottomSheet.createFirstPartyRecyclerViews(
List<PropertyModel> firstPartyOptions = mChromeProvidedSharingOptionsProvider.getPropertyModels(
mChromeProvidedSharingOptionsProvider.calculatePropertyModels(); mContentTypes, mIsMultiWindow));
mBottomSheetController.requestShowContent(mBottomSheet, /*animate=*/false);
// firstPartyOptions is empty if Chrome features should not be shown.
if (firstPartyOptions == null || firstPartyOptions.isEmpty()) {
return;
}
mBottomSheet.createFirstPartyRecyclerViews(firstPartyOptions);
mBottomSheetController.requestShowContent(mBottomSheet, /* animate= */ false);
} }
// View.OnLayoutChangeListener // View.OnLayoutChangeListener
...@@ -245,4 +242,5 @@ public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptio ...@@ -245,4 +242,5 @@ public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptio
mBottomSheet.getThirdPartyView().invalidate(); mBottomSheet.getThirdPartyView().invalidate();
mBottomSheet.getThirdPartyView().requestLayout(); mBottomSheet.getThirdPartyView().requestLayout();
} }
} }
...@@ -40,13 +40,10 @@ import org.chromium.components.prefs.PrefService; ...@@ -40,13 +40,10 @@ import org.chromium.components.prefs.PrefService;
import org.chromium.components.user_prefs.UserPrefs; import org.chromium.components.user_prefs.UserPrefs;
import org.chromium.components.user_prefs.UserPrefsJni; import org.chromium.components.user_prefs.UserPrefsJni;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.ImmutableWeakReference;
import org.chromium.ui.base.WindowAndroid;
import org.chromium.ui.modelutil.PropertyModel; import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.test.util.DummyUiActivity; import org.chromium.ui.test.util.DummyUiActivity;
import org.chromium.url.GURL; import org.chromium.url.GURL;
import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
...@@ -80,9 +77,6 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -80,9 +77,6 @@ public class ChromeProvidedSharingOptionsProviderTest {
@Mock @Mock
private ShareSheetCoordinator mShareSheetCoordinator; private ShareSheetCoordinator mShareSheetCoordinator;
@Mock
private WindowAndroid mWindow;
private Activity mActivity; private Activity mActivity;
private ChromeProvidedSharingOptionsProvider mChromeProvidedSharingOptionsProvider; private ChromeProvidedSharingOptionsProvider mChromeProvidedSharingOptionsProvider;
...@@ -106,7 +100,6 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -106,7 +100,6 @@ public class ChromeProvidedSharingOptionsProviderTest {
Mockito.when(mTab.getUrl()).thenReturn(new GURL(URL)); Mockito.when(mTab.getUrl()).thenReturn(new GURL(URL));
Mockito.when(mWebContents.isIncognito()).thenReturn(false); Mockito.when(mWebContents.isIncognito()).thenReturn(false);
mActivity = mActivityTestRule.getActivity(); mActivity = mActivityTestRule.getActivity();
Mockito.when(mWindow.getActivity()).thenReturn(new ImmutableWeakReference<>(mActivity));
} }
@Test @Test
...@@ -116,11 +109,10 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -116,11 +109,10 @@ public class ChromeProvidedSharingOptionsProviderTest {
@Features.DisableFeatures({ChromeFeatureList.CHROME_SHARING_HUB_V15}) @Features.DisableFeatures({ChromeFeatureList.CHROME_SHARING_HUB_V15})
public void public void
getPropertyModels_screenshotQrCodeEnabled_includesBoth() { getPropertyModels_screenshotQrCodeEnabled_includesBoth() {
setUpChromeProvidedSharingOptionsProviderTest(/* printingEnabled= */ false, setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false);
ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES,
/* isMultiWindow= */ false);
List<PropertyModel> propertyModels = List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.calculatePropertyModels(); mChromeProvidedSharingOptionsProvider.getPropertyModels(
ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES, /*isMultiWindow=*/false);
assertCorrectModelsAreInTheRightOrder(propertyModels, assertCorrectModelsAreInTheRightOrder(propertyModels,
ImmutableList.of(mActivity.getResources().getString(R.string.sharing_screenshot), ImmutableList.of(mActivity.getResources().getString(R.string.sharing_screenshot),
...@@ -135,11 +127,10 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -135,11 +127,10 @@ public class ChromeProvidedSharingOptionsProviderTest {
ChromeFeatureList.CHROME_SHARE_QRCODE, ChromeFeatureList.CHROME_SHARING_HUB_V15}) ChromeFeatureList.CHROME_SHARE_QRCODE, ChromeFeatureList.CHROME_SHARING_HUB_V15})
public void public void
getPropertyModels_screenshotQrCodeDisabled_doesNotIncludeEither() { getPropertyModels_screenshotQrCodeDisabled_doesNotIncludeEither() {
setUpChromeProvidedSharingOptionsProviderTest(/* printingEnabled= */ false, setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false);
ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES,
/* isMultiWindow= */ false);
List<PropertyModel> propertyModels = List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.calculatePropertyModels(); mChromeProvidedSharingOptionsProvider.getPropertyModels(
ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES, /*isMultiWindow=*/false);
assertCorrectModelsAreInTheRightOrder(propertyModels, assertCorrectModelsAreInTheRightOrder(propertyModels,
ImmutableList.of(mActivity.getResources().getString( ImmutableList.of(mActivity.getResources().getString(
...@@ -152,11 +143,10 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -152,11 +143,10 @@ public class ChromeProvidedSharingOptionsProviderTest {
ChromeFeatureList.CHROME_SHARE_QRCODE, ChromeFeatureList.CHROME_SHARING_HUB_V15}) ChromeFeatureList.CHROME_SHARE_QRCODE, ChromeFeatureList.CHROME_SHARING_HUB_V15})
public void public void
getPropertyModels_printingEnabled_includesPrinting() { getPropertyModels_printingEnabled_includesPrinting() {
setUpChromeProvidedSharingOptionsProviderTest(/* printingEnabled= */ true, setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/true);
ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES,
/* isMultiWindow= */ false);
List<PropertyModel> propertyModels = List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.calculatePropertyModels(); mChromeProvidedSharingOptionsProvider.getPropertyModels(
ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES, /*isMultiWindow=*/false);
assertCorrectModelsAreInTheRightOrder(propertyModels, assertCorrectModelsAreInTheRightOrder(propertyModels,
ImmutableList.of(mActivity.getResources().getString( ImmutableList.of(mActivity.getResources().getString(
...@@ -172,10 +162,10 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -172,10 +162,10 @@ public class ChromeProvidedSharingOptionsProviderTest {
ChromeFeatureList.CHROME_SHARE_HIGHLIGHTS_ANDROID}) ChromeFeatureList.CHROME_SHARE_HIGHLIGHTS_ANDROID})
public void public void
getPropertyModels_sharingHub15Enabled_includesCopyText() { getPropertyModels_sharingHub15Enabled_includesCopyText() {
setUpChromeProvidedSharingOptionsProviderTest(/* printingEnabled= */ false, setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false);
ImmutableSet.of(ContentType.TEXT), /* isMultiWindow= */ false);
List<PropertyModel> propertyModels = List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.calculatePropertyModels(); mChromeProvidedSharingOptionsProvider.getPropertyModels(
ImmutableSet.of(ContentType.TEXT), /*isMultiWindow=*/false);
assertCorrectModelsAreInTheRightOrder(propertyModels, assertCorrectModelsAreInTheRightOrder(propertyModels,
ImmutableList.of(mActivity.getResources().getString(R.string.sharing_copy_text))); ImmutableList.of(mActivity.getResources().getString(R.string.sharing_copy_text)));
...@@ -189,13 +179,13 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -189,13 +179,13 @@ public class ChromeProvidedSharingOptionsProviderTest {
ChromeFeatureList.CHROME_SHARE_HIGHLIGHTS_ANDROID}) ChromeFeatureList.CHROME_SHARE_HIGHLIGHTS_ANDROID})
public void public void
getPropertyModels_linkAndTextShare() { getPropertyModels_linkAndTextShare() {
setUpChromeProvidedSharingOptionsProviderTest(/* printingEnabled= */ false, setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false);
ImmutableSet.of(ContentType.LINK_AND_TEXT, ContentType.LINK_PAGE_NOT_VISIBLE,
ContentType.TEXT),
/* isMultiWindow= */ true);
List<PropertyModel> propertyModels = List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.calculatePropertyModels(); mChromeProvidedSharingOptionsProvider.getPropertyModels(
ImmutableSet.of(ContentType.LINK_AND_TEXT,
ContentType.LINK_PAGE_NOT_VISIBLE, ContentType.TEXT),
/*isMultiWindow=*/true);
assertCorrectModelsAreInTheRightOrder(propertyModels, assertCorrectModelsAreInTheRightOrder(propertyModels,
ImmutableList.of(mActivity.getResources().getString(R.string.sharing_copy), ImmutableList.of(mActivity.getResources().getString(R.string.sharing_copy),
...@@ -211,12 +201,12 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -211,12 +201,12 @@ public class ChromeProvidedSharingOptionsProviderTest {
ChromeFeatureList.CHROME_SHARE_HIGHLIGHTS_ANDROID}) ChromeFeatureList.CHROME_SHARE_HIGHLIGHTS_ANDROID})
public void public void
getPropertyModels_linkShare() { getPropertyModels_linkShare() {
setUpChromeProvidedSharingOptionsProviderTest(/* printingEnabled= */ false, setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false);
ImmutableSet.of(ContentType.LINK_PAGE_NOT_VISIBLE),
/* isMultiWindow= */ true);
List<PropertyModel> propertyModels = List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.calculatePropertyModels(); mChromeProvidedSharingOptionsProvider.getPropertyModels(
ImmutableSet.of(ContentType.LINK_PAGE_NOT_VISIBLE),
/*isMultiWindow=*/true);
assertCorrectModelsAreInTheRightOrder(propertyModels, assertCorrectModelsAreInTheRightOrder(propertyModels,
ImmutableList.of(mActivity.getResources().getString(R.string.sharing_copy_url), ImmutableList.of(mActivity.getResources().getString(R.string.sharing_copy_url),
...@@ -232,12 +222,12 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -232,12 +222,12 @@ public class ChromeProvidedSharingOptionsProviderTest {
ChromeFeatureList.CHROME_SHARE_HIGHLIGHTS_ANDROID}) ChromeFeatureList.CHROME_SHARE_HIGHLIGHTS_ANDROID})
public void public void
getPropertyModels_textShare() { getPropertyModels_textShare() {
setUpChromeProvidedSharingOptionsProviderTest(/* printingEnabled= */ false, setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false);
ImmutableSet.of(ContentType.TEXT),
/* isMultiWindow= */ true);
List<PropertyModel> propertyModels = List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.calculatePropertyModels(); mChromeProvidedSharingOptionsProvider.getPropertyModels(
ImmutableSet.of(ContentType.TEXT),
/*isMultiWindow=*/true);
assertCorrectModelsAreInTheRightOrder(propertyModels, assertCorrectModelsAreInTheRightOrder(propertyModels,
ImmutableList.of(mActivity.getResources().getString(R.string.sharing_copy_text))); ImmutableList.of(mActivity.getResources().getString(R.string.sharing_copy_text)));
...@@ -251,11 +241,11 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -251,11 +241,11 @@ public class ChromeProvidedSharingOptionsProviderTest {
ChromeFeatureList.CHROME_SHARING_HUB_V15}) ChromeFeatureList.CHROME_SHARING_HUB_V15})
public void public void
getPropertyModels_multiWindow_doesNotIncludeScreenshot() { getPropertyModels_multiWindow_doesNotIncludeScreenshot() {
setUpChromeProvidedSharingOptionsProviderTest(/* printingEnabled= */ false, setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false);
ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES, /* isMultiWindow= */ true);
List<PropertyModel> propertyModels = List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.calculatePropertyModels(); mChromeProvidedSharingOptionsProvider.getPropertyModels(
ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES, /*isMultiWindow=*/true);
assertCorrectModelsAreInTheRightOrder(propertyModels, assertCorrectModelsAreInTheRightOrder(propertyModels,
ImmutableList.of(mActivity.getResources().getString( ImmutableList.of(mActivity.getResources().getString(
...@@ -269,11 +259,11 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -269,11 +259,11 @@ public class ChromeProvidedSharingOptionsProviderTest {
@Features.DisableFeatures({ChromeFeatureList.CHROME_SHARING_HUB_V15}) @Features.DisableFeatures({ChromeFeatureList.CHROME_SHARING_HUB_V15})
public void public void
getPropertyModels_filtersByContentType() { getPropertyModels_filtersByContentType() {
setUpChromeProvidedSharingOptionsProviderTest(/* printingEnabled= */ true, setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/true);
ImmutableSet.of(ContentType.LINK_PAGE_NOT_VISIBLE),
/* isMultiWindow= */ false);
List<PropertyModel> propertyModels = List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.calculatePropertyModels(); mChromeProvidedSharingOptionsProvider.getPropertyModels(
ImmutableSet.of(ContentType.LINK_PAGE_NOT_VISIBLE),
/*isMultiWindow=*/false);
assertCorrectModelsAreInTheRightOrder(propertyModels, assertCorrectModelsAreInTheRightOrder(propertyModels,
ImmutableList.of(mActivity.getResources().getString(R.string.sharing_copy_url), ImmutableList.of(mActivity.getResources().getString(R.string.sharing_copy_url),
...@@ -289,11 +279,11 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -289,11 +279,11 @@ public class ChromeProvidedSharingOptionsProviderTest {
@Features.DisableFeatures({ChromeFeatureList.CHROME_SHARING_HUB_V15}) @Features.DisableFeatures({ChromeFeatureList.CHROME_SHARING_HUB_V15})
public void public void
getPropertyModels_multipleTypes_filtersByContentType() { getPropertyModels_multipleTypes_filtersByContentType() {
setUpChromeProvidedSharingOptionsProviderTest(/* printingEnabled= */ true, setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/true);
ImmutableSet.of(ContentType.LINK_PAGE_NOT_VISIBLE, ContentType.IMAGE),
/* isMultiWindow= */ false);
List<PropertyModel> propertyModels = List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.calculatePropertyModels(); mChromeProvidedSharingOptionsProvider.getPropertyModels(
ImmutableSet.of(ContentType.LINK_PAGE_NOT_VISIBLE, ContentType.IMAGE),
/*isMultiWindow=*/false);
assertCorrectModelsAreInTheRightOrder(propertyModels, assertCorrectModelsAreInTheRightOrder(propertyModels,
ImmutableList.of(mActivity.getResources().getString(R.string.sharing_screenshot), ImmutableList.of(mActivity.getResources().getString(R.string.sharing_screenshot),
...@@ -310,10 +300,10 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -310,10 +300,10 @@ public class ChromeProvidedSharingOptionsProviderTest {
@Features.EnableFeatures({ChromeFeatureList.CHROME_SHARE_HIGHLIGHTS_ANDROID}) @Features.EnableFeatures({ChromeFeatureList.CHROME_SHARE_HIGHLIGHTS_ANDROID})
public void public void
getPropertyModels_sharingHub15Disabled_noHighlights() { getPropertyModels_sharingHub15Disabled_noHighlights() {
setUpChromeProvidedSharingOptionsProviderTest(/* printingEnabled= */ false, setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false);
ImmutableSet.of(ContentType.TEXT), /* isMultiWindow= */ false);
List<PropertyModel> propertyModels = List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.calculatePropertyModels(); mChromeProvidedSharingOptionsProvider.getPropertyModels(
ImmutableSet.of(ContentType.TEXT), /*isMultiWindow=*/false);
assertEquals("Incorrect number of property models.", 0, propertyModels.size()); assertEquals("Incorrect number of property models.", 0, propertyModels.size());
} }
...@@ -325,10 +315,10 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -325,10 +315,10 @@ public class ChromeProvidedSharingOptionsProviderTest {
@Features.DisableFeatures({ChromeFeatureList.CHROME_SHARE_SCREENSHOT}) @Features.DisableFeatures({ChromeFeatureList.CHROME_SHARE_SCREENSHOT})
public void public void
getPropertyModels_sharingHub15HighlightsEnabled() { getPropertyModels_sharingHub15HighlightsEnabled() {
setUpChromeProvidedSharingOptionsProviderTest(/* printingEnabled= */ false, setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false);
ImmutableSet.of(ContentType.HIGHLIGHTED_TEXT), /* isMultiWindow= */ false);
List<PropertyModel> propertyModels = List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.calculatePropertyModels(); mChromeProvidedSharingOptionsProvider.getPropertyModels(
ImmutableSet.of(ContentType.HIGHLIGHTED_TEXT), /*isMultiWindow=*/false);
assertCorrectModelsAreInTheRightOrder(propertyModels, assertCorrectModelsAreInTheRightOrder(propertyModels,
ImmutableList.of(mActivity.getResources().getString(R.string.sharing_copy_text), ImmutableList.of(mActivity.getResources().getString(R.string.sharing_copy_text),
...@@ -338,8 +328,7 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -338,8 +328,7 @@ public class ChromeProvidedSharingOptionsProviderTest {
@Test @Test
@MediumTest @MediumTest
public void getUrlToShare_noShareParamsUrl_returnsImageUrl() { public void getUrlToShare_noShareParamsUrl_returnsImageUrl() {
ShareParams shareParams = ShareParams shareParams = new ShareParams.Builder(null, /*title=*/"", /*url=*/"").build();
new ShareParams.Builder(null, /* title= */ "", /* url= */ "").build();
ChromeShareExtras chromeShareExtras = ChromeShareExtras chromeShareExtras =
new ChromeShareExtras.Builder().setImageSrcUrl(URL).build(); new ChromeShareExtras.Builder().setImageSrcUrl(URL).build();
...@@ -352,7 +341,7 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -352,7 +341,7 @@ public class ChromeProvidedSharingOptionsProviderTest {
@Test @Test
@MediumTest @MediumTest
public void getUrlToShare_shareParamsUrlExists_returnsShareParamsUrl() { public void getUrlToShare_shareParamsUrlExists_returnsShareParamsUrl() {
ShareParams shareParams = new ShareParams.Builder(null, /* title= */ "", URL).build(); ShareParams shareParams = new ShareParams.Builder(null, /*title=*/"", URL).build();
ChromeShareExtras chromeShareExtras = ChromeShareExtras chromeShareExtras =
new ChromeShareExtras.Builder().setImageSrcUrl("").build(); new ChromeShareExtras.Builder().setImageSrcUrl("").build();
...@@ -365,8 +354,7 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -365,8 +354,7 @@ public class ChromeProvidedSharingOptionsProviderTest {
@Test @Test
@MediumTest @MediumTest
public void getUrlToShare_noShareParamsUrl_noImageUrl() { public void getUrlToShare_noShareParamsUrl_noImageUrl() {
ShareParams shareParams = ShareParams shareParams = new ShareParams.Builder(null, /*title=*/"", /*url=*/"").build();
new ShareParams.Builder(null, /* title= */ "", /* url= */ "").build();
ChromeShareExtras chromeShareExtras = ChromeShareExtras chromeShareExtras =
new ChromeShareExtras.Builder().setImageSrcUrl("").build(); new ChromeShareExtras.Builder().setImageSrcUrl("").build();
...@@ -376,24 +364,21 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -376,24 +364,21 @@ public class ChromeProvidedSharingOptionsProviderTest {
URL); URL);
} }
private void setUpChromeProvidedSharingOptionsProviderTest( private void setUpChromeProvidedSharingOptionsProviderTest(boolean printingEnabled) {
boolean printingEnabled, Collection<Integer> contentTypes, boolean isMultiWindow) {
Mockito.when(mPrefService.getBoolean(anyString())).thenReturn(printingEnabled); Mockito.when(mPrefService.getBoolean(anyString())).thenReturn(printingEnabled);
ShareParams shareParams = ShareParams shareParams = new ShareParams.Builder(null, /*title=*/"", /*url=*/"").build();
new ShareParams.Builder(mWindow, /* title= */ "", /* url= */ "").build();
mChromeProvidedSharingOptionsProvider = mChromeProvidedSharingOptionsProvider =
new ChromeProvidedSharingOptionsProvider(mTabProvider, new ChromeProvidedSharingOptionsProvider(mActivity, mTabProvider,
/* bottomSheetController= */ null, /*bottomSheetController=*/null,
new ShareSheetBottomSheetContent( new ShareSheetBottomSheetContent(
mActivity, null, mShareSheetCoordinator, shareParams)); mActivity, null, mShareSheetCoordinator, shareParams),
mChromeProvidedSharingOptionsProvider.setShareRelatedParams(shareParams, new ShareParams.Builder(null, "", "").build(),
new ChromeShareExtras.Builder().build(), /* shareStartTime= */ 0, new ChromeShareExtras.Builder().build(),
mShareSheetCoordinator, contentTypes); /*TabPrinterDelegate=*/null,
mChromeProvidedSharingOptionsProvider.setFeatureSpecificParams( /*settingsLauncher=*/null,
/* TabPrinterDelegate= */ null, /* settingsLauncher= */ null, /*syncState=*/false,
/* syncState= */ false); /*shareStartTime=*/0, mShareSheetCoordinator);
mChromeProvidedSharingOptionsProvider.setIsMultiWindow(isMultiWindow);
} }
private void assertCorrectModelsAreInTheRightOrder( private void assertCorrectModelsAreInTheRightOrder(
......
...@@ -22,7 +22,6 @@ import org.junit.Test; ...@@ -22,7 +22,6 @@ import org.junit.Test;
import org.junit.rules.TestRule; import org.junit.rules.TestRule;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
...@@ -34,8 +33,6 @@ import org.chromium.chrome.test.ChromeJUnit4ClassRunner; ...@@ -34,8 +33,6 @@ import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.Features; import org.chromium.chrome.test.util.browser.Features;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetController; import org.chromium.components.browser_ui.bottomsheet.BottomSheetController;
import org.chromium.components.browser_ui.share.ShareParams; import org.chromium.components.browser_ui.share.ShareParams;
import org.chromium.ui.base.ImmutableWeakReference;
import org.chromium.ui.base.WindowAndroid;
import org.chromium.ui.modelutil.PropertyModel; import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.test.util.DummyUiActivity; import org.chromium.ui.test.util.DummyUiActivity;
...@@ -71,9 +68,6 @@ public final class ShareSheetCoordinatorTest { ...@@ -71,9 +68,6 @@ public final class ShareSheetCoordinatorTest {
@Mock @Mock
private ShareParams mParams; private ShareParams mParams;
@Mock
private WindowAndroid mWindow;
private Activity mActivity; private Activity mActivity;
private ShareSheetCoordinator mShareSheetCoordinator; private ShareSheetCoordinator mShareSheetCoordinator;
...@@ -101,9 +95,6 @@ public final class ShareSheetCoordinatorTest { ...@@ -101,9 +95,6 @@ public final class ShareSheetCoordinatorTest {
mShareSheetCoordinator = new ShareSheetCoordinator(mController, mLifecycleDispatcher, null, mShareSheetCoordinator = new ShareSheetCoordinator(mController, mLifecycleDispatcher, null,
mPropertyModelBuilder, null, null, null, false); mPropertyModelBuilder, null, null, null, false);
Mockito.when(mParams.getWindow()).thenReturn(mWindow);
Mockito.when(mWindow.getActivity()).thenReturn(new ImmutableWeakReference<>(mActivity));
} }
@Test @Test
...@@ -113,7 +104,7 @@ public final class ShareSheetCoordinatorTest { ...@@ -113,7 +104,7 @@ public final class ShareSheetCoordinatorTest {
List<PropertyModel> propertyModels = mShareSheetCoordinator.createFirstPartyPropertyModels( List<PropertyModel> propertyModels = mShareSheetCoordinator.createFirstPartyPropertyModels(
mActivity, mParams, /*chromeShareExtras=*/null, mActivity, mParams, /*chromeShareExtras=*/null,
ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES, /*shareStartTime=*/0); ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES);
assertEquals("Property model list should be empty.", 0, propertyModels.size()); assertEquals("Property model list should be empty.", 0, propertyModels.size());
} }
...@@ -122,7 +113,7 @@ public final class ShareSheetCoordinatorTest { ...@@ -122,7 +113,7 @@ public final class ShareSheetCoordinatorTest {
public void testCreateThirdPartyPropertyModels() { public void testCreateThirdPartyPropertyModels() {
List<PropertyModel> propertyModels = mShareSheetCoordinator.createThirdPartyPropertyModels( List<PropertyModel> propertyModels = mShareSheetCoordinator.createThirdPartyPropertyModels(
mActivity, mParams, ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES, mActivity, mParams, ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES,
/*saveLastUsed=*/false, /*shareStartTime=*/0); /*saveLastUsed=*/false);
assertEquals("Incorrect number of property models.", 3, propertyModels.size()); assertEquals("Incorrect number of property models.", 3, propertyModels.size());
assertEquals("First property model isn't testModel1.", "testModel1", assertEquals("First property model isn't testModel1.", "testModel1",
......
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