Commit 589141da authored by Sophey Dong's avatar Sophey Dong Committed by Commit Bot

[Screenshot] Hide Screenshot option when in multi-window mode.

Bug: 1112281
Change-Id: I549d1cd20e78245c4df973b42bba3666c53881a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2383451
Commit-Queue: Sophey Dong <sophey@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarTanya Gupta <tgupta@chromium.org>
Reviewed-by: default avatarKyle Milka <kmilka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803975}
parent e7bc8b04
......@@ -452,9 +452,10 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
getLifecycleDispatcher().register(bottomContainer);
// Should be called after TabModels are initialized.
ShareDelegate shareDelegate = new ShareDelegateImpl(
mRootUiCoordinator.getBottomSheetController(), getActivityTabProvider(),
new ShareDelegateImpl.ShareSheetDelegate(), isCustomTab());
ShareDelegate shareDelegate =
new ShareDelegateImpl(mRootUiCoordinator.getBottomSheetController(),
getLifecycleDispatcher(), getActivityTabProvider(),
new ShareDelegateImpl.ShareSheetDelegate(), isCustomTab());
mShareDelegateSupplier.set(shareDelegate);
// If onStart was called before postLayoutInflation (because inflation was done in a
......
......@@ -17,6 +17,7 @@ import org.chromium.base.metrics.RecordUserAction;
import org.chromium.base.supplier.Supplier;
import org.chromium.chrome.browser.feature_engagement.ScreenshotTabObserver;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher;
import org.chromium.chrome.browser.offlinepages.OfflinePageUtils;
import org.chromium.chrome.browser.printing.PrintShareActivity;
import org.chromium.chrome.browser.printing.TabPrinter;
......@@ -48,10 +49,11 @@ public class ShareDelegateImpl implements ShareDelegate {
static final String CANONICAL_URL_RESULT_HISTOGRAM = "Mobile.CanonicalURLResult";
private final BottomSheetController mBottomSheetController;
private final ShareSheetDelegate mDelegate;
private final ActivityLifecycleDispatcher mLifecycleDispatcher;
private final Supplier<Tab> mTabProvider;
private final ShareSheetDelegate mDelegate;
private final boolean mIsCustomTab;
private long mShareStartTime;
private boolean mIsCustomTab;
private static boolean sScreenshotCaptureSkippedForTesting;
......@@ -59,15 +61,19 @@ public class ShareDelegateImpl implements ShareDelegate {
* Constructs a new {@link ShareDelegateImpl}.
*
* @param controller The BottomSheetController for the current activity.
* @param lifecycleDispatcher Dispatcher for activity lifecycle events, e.g. configuration
* changes.
* @param tabProvider Supplier for the current activity tab.
* @param delegate The ShareSheetDelegate for the current activity.
* @param isCustomTab This share delegate is associated with a CCT.
*/
public ShareDelegateImpl(BottomSheetController controller, Supplier<Tab> tabProvider,
public ShareDelegateImpl(BottomSheetController controller,
ActivityLifecycleDispatcher lifecycleDispatcher, Supplier<Tab> tabProvider,
ShareSheetDelegate delegate, boolean isCustomTab) {
mBottomSheetController = controller;
mDelegate = delegate;
mLifecycleDispatcher = lifecycleDispatcher;
mTabProvider = tabProvider;
mDelegate = delegate;
mIsCustomTab = isCustomTab;
}
......@@ -77,8 +83,8 @@ public class ShareDelegateImpl implements ShareDelegate {
if (mShareStartTime == 0L) {
mShareStartTime = System.currentTimeMillis();
}
mDelegate.share(params, chromeShareExtras, mBottomSheetController, mTabProvider,
this::printTab, mShareStartTime, isSharingHubV1Enabled());
mDelegate.share(params, chromeShareExtras, mBottomSheetController, mLifecycleDispatcher,
mTabProvider, this::printTab, mShareStartTime, isSharingHubV1Enabled());
mShareStartTime = 0;
}
......@@ -286,15 +292,16 @@ public class ShareDelegateImpl implements ShareDelegate {
* Trigger the share action for the specified params.
*/
void share(ShareParams params, ChromeShareExtras chromeShareExtras,
BottomSheetController controller, Supplier<Tab> tabProvider,
Callback<Tab> printCallback, long shareStartTime, boolean sharingHubEnabled) {
BottomSheetController controller, ActivityLifecycleDispatcher lifecycleDispatcher,
Supplier<Tab> tabProvider, Callback<Tab> printCallback, long shareStartTime,
boolean sharingHubEnabled) {
if (chromeShareExtras.shareDirectly()) {
ShareHelper.shareWithLastUsedComponent(params);
} else if (sharingHubEnabled && !chromeShareExtras.sharingTabGroup()) {
// TODO(crbug.com/1085078): Sharing hub is suppressed for tab group sharing.
// Re-enable it when tab group sharing is supported by sharing hub.
ShareSheetCoordinator coordinator =
new ShareSheetCoordinator(controller, tabProvider,
new ShareSheetCoordinator(controller, lifecycleDispatcher, tabProvider,
new ShareSheetPropertyModelBuilder(controller,
ContextUtils.getApplicationContext().getPackageManager()),
printCallback);
......
......@@ -21,6 +21,7 @@ import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.MetricsUtils.HistogramDelta;
import org.chromium.chrome.browser.app.ChromeActivity;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher;
import org.chromium.chrome.browser.share.ShareDelegateImpl.ShareSheetDelegate;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.test.ChromeActivityTestRule;
......@@ -118,7 +119,8 @@ public class ShareDelegateImplIntegrationTest {
ShareSheetDelegate delegate = new ShareSheetDelegate() {
@Override
void share(ShareParams params, ChromeShareExtras chromeShareParams,
BottomSheetController controller, Supplier<Tab> tabProvider,
BottomSheetController controller,
ActivityLifecycleDispatcher lifecycleDispatcher, Supplier<Tab> tabProvider,
Callback<Tab> printCallback, long shareStartTime,
boolean sharingHubEnabled) {
paramsRef.set(params);
......@@ -129,6 +131,7 @@ public class ShareDelegateImplIntegrationTest {
new ShareDelegateImpl(mActivityTestRule.getActivity()
.getRootUiCoordinatorForTesting()
.getBottomSheetController(),
mActivityTestRule.getActivity().getLifecycleDispatcher(),
mActivityTestRule.getActivity().getActivityTabProvider(), delegate, false)
.share(mActivityTestRule.getActivity().getActivityTab(), false);
});
......
......@@ -11,6 +11,7 @@ include_rules = [
"+chrome/android/java/src/org/chromium/chrome/browser/init/ChromeBrowserInitializer.java",
"+chrome/android/java/src/org/chromium/chrome/browser/media/MediaViewerUtils.java",
"+chrome/android/java/src/org/chromium/chrome/browser/modules/ModuleInstallUi.java",
"+chrome/android/java/src/org/chromium/chrome/browser/multiwindow/MultiWindowUtils.java",
"+chrome/android/java/src/org/chromium/chrome/browser/screenshot/EditorScreenshotTask.java",
"+chrome/android/java/src/org/chromium/chrome/browser/share",
"+chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java",
......
......@@ -97,9 +97,10 @@ class ChromeProvidedSharingOptionsProvider {
/**
* Encapsulates a {@link PropertyModel} and the {@link ContentType}s it should be shown for.
*/
private class FirstPartyOption {
private static class FirstPartyOption {
final Collection<Integer> mContentTypes;
final PropertyModel mPropertyModel;
final boolean mDisableForMultiWindow;
/**
* Should only be used when the default property model constructed in the builder does not
......@@ -107,10 +108,13 @@ class ChromeProvidedSharingOptionsProvider {
*
* @param model Property model for the first party option.
* @param contentTypes Content types to trigger for.
* @param disableForMultiWindow If the feature should be disabled if in multi-window mode.
*/
FirstPartyOption(PropertyModel model, Collection<Integer> contentTypes) {
FirstPartyOption(PropertyModel model, Collection<Integer> contentTypes,
boolean disableForMultiWindow) {
mPropertyModel = model;
mContentTypes = contentTypes;
mDisableForMultiWindow = disableForMultiWindow;
}
}
......@@ -119,6 +123,7 @@ class ChromeProvidedSharingOptionsProvider {
private int mIconLabel;
private String mFeatureNameForMetrics;
private Callback<View> mOnClickCallback;
private boolean mDisableForMultiWindow;
private final Integer[] mContentTypesInBuilder;
FirstPartyOptionBuilder(Integer... contentTypes) {
......@@ -141,6 +146,11 @@ class ChromeProvidedSharingOptionsProvider {
return this;
}
FirstPartyOptionBuilder setDisableForMultiWindow(boolean disableForMultiWindow) {
mDisableForMultiWindow = disableForMultiWindow;
return this;
}
FirstPartyOption build() {
PropertyModel model = ShareSheetPropertyModelBuilder.createPropertyModel(
AppCompatResources.getDrawable(mActivity, mIcon),
......@@ -150,7 +160,8 @@ class ChromeProvidedSharingOptionsProvider {
mBottomSheetController.hideContent(mBottomSheetContent, true);
mOnClickCallback.onResult(view);
});
return new FirstPartyOption(model, Arrays.asList(mContentTypesInBuilder));
return new FirstPartyOption(
model, Arrays.asList(mContentTypesInBuilder), mDisableForMultiWindow);
}
}
......@@ -159,12 +170,14 @@ class ChromeProvidedSharingOptionsProvider {
* 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) {
List<PropertyModel> getPropertyModels(Set<Integer> contentTypes, boolean isMultiWindow) {
List<PropertyModel> propertyModels = new ArrayList<>();
for (FirstPartyOption firstPartyOption : mOrderedFirstPartyOptions) {
if (!Collections.disjoint(contentTypes, firstPartyOption.mContentTypes)) {
if (!Collections.disjoint(contentTypes, firstPartyOption.mContentTypes)
&& !(isMultiWindow && firstPartyOption.mDisableForMultiWindow)) {
propertyModels.add(firstPartyOption.mPropertyModel);
}
}
......@@ -231,7 +244,8 @@ class ChromeProvidedSharingOptionsProvider {
});
return new FirstPartyOption(propertyModel,
Arrays.asList(ContentType.LINK_PAGE_VISIBLE, ContentType.TEXT,
ContentType.HIGHLIGHTED_TEXT, ContentType.IMAGE));
ContentType.HIGHLIGHTED_TEXT, ContentType.IMAGE),
/*disableForMultiWindow=*/true);
}
private FirstPartyOption createCopyLinkFirstPartyOption() {
......
......@@ -71,14 +71,7 @@ class ShareSheetBottomSheetContent implements BottomSheetContent, OnItemClickLis
messageView.setText(message);
}
RecyclerView topRow = this.getContentView().findViewById(R.id.share_sheet_chrome_apps);
if (topRowModels != null && topRowModels.size() > 0) {
View divider = this.getContentView().findViewById(R.id.share_sheet_divider);
divider.setVisibility(View.VISIBLE);
topRow.setVisibility(View.VISIBLE);
populateView(topRowModels, topRow);
topRow.addOnScrollListener(new ScrollEventReporter("SharingHubAndroid.TopRowScrolled"));
}
createChromeFeatureRecyclerViews(topRowModels);
RecyclerView bottomRow = this.getContentView().findViewById(R.id.share_sheet_other_apps);
populateView(
......@@ -87,6 +80,19 @@ class ShareSheetBottomSheetContent implements BottomSheetContent, OnItemClickLis
new ScrollEventReporter("SharingHubAndroid.BottomRowScrolled"));
}
void createChromeFeatureRecyclerViews(List<PropertyModel> chromeFeatureModels) {
RecyclerView chromeFeatureRow =
this.getContentView().findViewById(R.id.share_sheet_chrome_apps);
if (chromeFeatureModels != null && chromeFeatureModels.size() > 0) {
View divider = this.getContentView().findViewById(R.id.share_sheet_divider);
divider.setVisibility(View.VISIBLE);
chromeFeatureRow.setVisibility(View.VISIBLE);
populateView(chromeFeatureModels, chromeFeatureRow);
chromeFeatureRow.addOnScrollListener(
new ScrollEventReporter("SharingHubAndroid.TopRowScrolled"));
}
}
private void populateView(List<PropertyModel> models, RecyclerView view) {
ModelList modelList = new ModelList();
for (PropertyModel model : models) {
......
......@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.share.share_sheet;
import android.app.Activity;
import android.content.res.Configuration;
import android.view.View;
import androidx.annotation.VisibleForTesting;
......@@ -15,6 +16,9 @@ import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.base.supplier.Supplier;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher;
import org.chromium.chrome.browser.lifecycle.ConfigurationChangedObserver;
import org.chromium.chrome.browser.multiwindow.MultiWindowUtils;
import org.chromium.chrome.browser.share.ChromeShareExtras;
import org.chromium.chrome.browser.share.ShareHelper;
import org.chromium.chrome.browser.tab.Tab;
......@@ -35,8 +39,9 @@ import java.util.Set;
* Coordinator for displaying the share sheet.
*/
// TODO(crbug/1022172): Should be package-protected once modularization is complete.
public class ShareSheetCoordinator
implements ActivityStateObserver, ChromeOptionShareCallback, View.OnLayoutChangeListener {
public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptionShareCallback,
ConfigurationChangedObserver,
View.OnLayoutChangeListener {
private static final String NO_SHARE_SHEET_MESSAGE = "";
private final BottomSheetController mBottomSheetController;
private final Supplier<Tab> mTabProvider;
......@@ -44,25 +49,34 @@ public class ShareSheetCoordinator
private final Callback<Tab> mPrintTabCallback;
private long mShareStartTime;
private boolean mExcludeFirstParty;
private boolean mIsMultiWindow;
private Set<Integer> mContentTypes;
private Activity mActivity;
private ActivityLifecycleDispatcher mLifecycleDispatcher;
private ChromeProvidedSharingOptionsProvider mChromeProvidedSharingOptionsProvider;
private ShareSheetBottomSheetContent mBottomSheet;
private WindowAndroid mWindowAndroid;
private final BottomSheetObserver mBottomSheetObserver;
/**
* Constructs a new ShareSheetCoordinator.
*
* @param controller The {@link BottomSheetController} for the current activity.
* @param lifecycleDispatcher Dispatcher for activity lifecycle events, e.g. configuration
* changes.
* @param tabProvider Supplier for the current activity tab.
* @param modelBuilder The {@link ShareSheetPropertyModelBuilder} for the share sheet.
*/
// TODO(crbug/1022172): Should be package-protected once modularization is complete.
public ShareSheetCoordinator(BottomSheetController controller, Supplier<Tab> tabProvider,
public ShareSheetCoordinator(BottomSheetController controller,
ActivityLifecycleDispatcher lifecycleDispatcher, Supplier<Tab> tabProvider,
ShareSheetPropertyModelBuilder modelBuilder, Callback<Tab> printTab) {
mBottomSheetController = controller;
mLifecycleDispatcher = lifecycleDispatcher;
mLifecycleDispatcher.register(this);
mTabProvider = tabProvider;
mPropertyModelBuilder = modelBuilder;
mPrintTabCallback = printTab;
mBottomSheetObserver = new EmptyBottomSheetObserver() {
BottomSheetObserver bottomSheetObserver = new EmptyBottomSheetObserver() {
@Override
public void onSheetContentChanged(BottomSheetContent bottomSheet) {
super.onSheetContentChanged(bottomSheet);
......@@ -75,7 +89,7 @@ public class ShareSheetCoordinator
}
}
};
mBottomSheetController.addObserver(mBottomSheetObserver);
mBottomSheetController.addObserver(bottomSheetObserver);
}
protected void destroy() {
......@@ -83,6 +97,10 @@ public class ShareSheetCoordinator
mWindowAndroid.removeActivityStateObserver(this);
mWindowAndroid = null;
}
if (mLifecycleDispatcher != null) {
mLifecycleDispatcher.unregister(this);
mLifecycleDispatcher = null;
}
}
// TODO(crbug/1022172): Should be package-protected once modularization is complete.
......@@ -94,8 +112,8 @@ public class ShareSheetCoordinator
void showShareSheetWithMessage(String message, ShareParams params,
ChromeShareExtras chromeShareExtras, long shareStartTime) {
Activity activity = params.getWindow().getActivity().get();
if (activity == null) return;
mActivity = params.getWindow().getActivity().get();
if (mActivity == null) return;
if (mWindowAndroid == null) {
mWindowAndroid = params.getWindow();
......@@ -104,15 +122,14 @@ public class ShareSheetCoordinator
}
}
mBottomSheet = new ShareSheetBottomSheetContent(activity, this);
mBottomSheet = new ShareSheetBottomSheetContent(mActivity, this);
mShareStartTime = shareStartTime;
Set<Integer> contentTypes =
ShareSheetPropertyModelBuilder.getContentTypes(params, chromeShareExtras);
mContentTypes = ShareSheetPropertyModelBuilder.getContentTypes(params, chromeShareExtras);
List<PropertyModel> chromeFeatures =
createTopRowPropertyModels(activity, params, chromeShareExtras, contentTypes);
createTopRowPropertyModels(mActivity, params, chromeShareExtras, mContentTypes);
List<PropertyModel> thirdPartyApps = createBottomRowPropertyModels(
activity, params, contentTypes, chromeShareExtras.saveLastUsed());
mActivity, params, mContentTypes, chromeShareExtras.saveLastUsed());
mBottomSheet.createRecyclerViews(chromeFeatures, thirdPartyApps, message);
......@@ -145,12 +162,13 @@ public class ShareSheetCoordinator
if (mExcludeFirstParty) {
return new ArrayList<>();
}
ChromeProvidedSharingOptionsProvider chromeProvidedSharingOptionsProvider =
new ChromeProvidedSharingOptionsProvider(activity, mTabProvider,
mBottomSheetController, mBottomSheet, shareParams, chromeShareExtras,
mPrintTabCallback, mShareStartTime, this);
mChromeProvidedSharingOptionsProvider = new ChromeProvidedSharingOptionsProvider(activity,
mTabProvider, mBottomSheetController, mBottomSheet, shareParams, chromeShareExtras,
mPrintTabCallback, mShareStartTime, this);
mIsMultiWindow = MultiWindowUtils.getInstance().isInMultiWindowMode(activity);
return chromeProvidedSharingOptionsProvider.getPropertyModels(contentTypes);
return mChromeProvidedSharingOptionsProvider.getPropertyModels(
contentTypes, mIsMultiWindow);
}
@VisibleForTesting
......@@ -189,6 +207,25 @@ public class ShareSheetCoordinator
}
}
// ConfigurationChangedObserver
@Override
public void onConfigurationChanged(Configuration newConfig) {
if (mActivity == null) {
return;
}
boolean isMultiWindow = MultiWindowUtils.getInstance().isInMultiWindowMode(mActivity);
// mContentTypes is null if Chrome features should not be shown.
if (mIsMultiWindow == isMultiWindow || mContentTypes == null) {
return;
}
mIsMultiWindow = isMultiWindow;
mBottomSheet.createChromeFeatureRecyclerViews(
mChromeProvidedSharingOptionsProvider.getPropertyModels(
mContentTypes, mIsMultiWindow));
mBottomSheetController.requestShowContent(mBottomSheet, /*animate=*/false);
}
// View.OnLayoutChangeListener
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
......
......@@ -113,7 +113,7 @@ public class ChromeProvidedSharingOptionsProviderTest {
setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false);
List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.getPropertyModels(
ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES);
ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES, /*isMultiWindow=*/false);
Assert.assertEquals("Incorrect number of property models.", 4, propertyModels.size());
assertModelsAreInTheRightOrder(propertyModels,
......@@ -133,7 +133,7 @@ public class ChromeProvidedSharingOptionsProviderTest {
setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false);
List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.getPropertyModels(
ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES);
ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES, /*isMultiWindow=*/false);
Assert.assertEquals("Incorrect number of property models.", 2, propertyModels.size());
assertModelsAreInTheRightOrder(propertyModels,
......@@ -151,7 +151,7 @@ public class ChromeProvidedSharingOptionsProviderTest {
setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/true);
List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.getPropertyModels(
ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES);
ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES, /*isMultiWindow=*/false);
Assert.assertEquals("Incorrect number of property models.", 3, propertyModels.size());
assertModelsAreInTheRightOrder(propertyModels,
......@@ -163,8 +163,7 @@ public class ChromeProvidedSharingOptionsProviderTest {
@Test
@MediumTest
@Features.EnableFeatures({ChromeFeatureList.CHROME_SHARING_HUB_V15,
ChromeFeatureList.CHROME_SHARE_HIGHLIGHTS_ANDROID})
@Features.EnableFeatures({ChromeFeatureList.CHROME_SHARING_HUB_V15})
@Features.DisableFeatures(
{ChromeFeatureList.CHROME_SHARE_SCREENSHOT, ChromeFeatureList.CHROME_SHARE_QRCODE,
ChromeFeatureList.CHROME_SHARE_HIGHLIGHTS_ANDROID})
......@@ -173,13 +172,31 @@ public class ChromeProvidedSharingOptionsProviderTest {
setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false);
List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.getPropertyModels(
ImmutableSet.of(ContentType.TEXT));
ImmutableSet.of(ContentType.TEXT), /*isMultiWindow=*/false);
Assert.assertEquals("Incorrect number of property models.", 1, propertyModels.size());
assertModelsAreInTheRightOrder(propertyModels,
ImmutableList.of(mActivity.getResources().getString(R.string.sharing_copy_text)));
}
@Test
@MediumTest
@Features.EnableFeatures({ChromeFeatureList.CHROME_SHARE_SCREENSHOT})
public void createPropertyModels_multiWindow_doesNotIncludeScreenshot() {
setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false);
List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.getPropertyModels(
ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES, /*isMultiWindow=*/true);
Assert.assertEquals("Incorrect number of property models.", 3, propertyModels.size());
assertModelsAreInTheRightOrder(propertyModels,
ImmutableList.of(mActivity.getResources().getString(R.string.sharing_copy_url),
mActivity.getResources().getString(
R.string.send_tab_to_self_share_activity_title),
mActivity.getResources().getString(R.string.qr_code_share_icon_label)));
}
@Test
@MediumTest
@Features.EnableFeatures(
......@@ -190,7 +207,8 @@ public class ChromeProvidedSharingOptionsProviderTest {
setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/true);
List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.getPropertyModels(
ImmutableSet.of(ContentType.LINK_PAGE_NOT_VISIBLE));
ImmutableSet.of(ContentType.LINK_PAGE_NOT_VISIBLE),
/*isMultiWindow=*/false);
Assert.assertEquals("Incorrect number of property models.", 3, propertyModels.size());
assertModelsAreInTheRightOrder(propertyModels,
......@@ -210,7 +228,8 @@ public class ChromeProvidedSharingOptionsProviderTest {
setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/true);
List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.getPropertyModels(
ImmutableSet.of(ContentType.LINK_PAGE_NOT_VISIBLE, ContentType.IMAGE));
ImmutableSet.of(ContentType.LINK_PAGE_NOT_VISIBLE, ContentType.IMAGE),
/*isMultiWindow=*/false);
Assert.assertEquals("Incorrect number of property models.", 4, propertyModels.size());
assertModelsAreInTheRightOrder(propertyModels,
......@@ -229,7 +248,7 @@ public class ChromeProvidedSharingOptionsProviderTest {
setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false);
List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.getPropertyModels(
ImmutableSet.of(ContentType.TEXT));
ImmutableSet.of(ContentType.TEXT), /*isMultiWindow=*/false);
Assert.assertEquals("Incorrect number of property models.", 0, propertyModels.size());
}
......@@ -243,7 +262,7 @@ public class ChromeProvidedSharingOptionsProviderTest {
setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false);
List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.getPropertyModels(
ImmutableSet.of(ContentType.HIGHLIGHTED_TEXT));
ImmutableSet.of(ContentType.HIGHLIGHTED_TEXT), /*isMultiWindow=*/false);
Assert.assertEquals("Incorrect number of property models.", 2, propertyModels.size());
assertModelsAreInTheRightOrder(propertyModels,
......
......@@ -9,6 +9,7 @@ import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anySet;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.when;
import android.app.Activity;
import android.support.test.rule.ActivityTestRule;
......@@ -21,12 +22,12 @@ import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher;
import org.chromium.chrome.test.ChromeBrowserTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.Features;
......@@ -56,18 +57,21 @@ public final class ShareSheetCoordinatorTest {
public TestRule mFeatureProcessor = new Features.JUnitProcessor();
@Mock
private ShareSheetPropertyModelBuilder mPropertyModelBuilder;
private ActivityLifecycleDispatcher mLifecycleDispatcher;
@Mock
private ShareParams mParams;
private BottomSheetController mController;
@Mock
private BottomSheetController mController;
private ShareSheetPropertyModelBuilder mPropertyModelBuilder;
private Activity mActivity;
private ShareSheetCoordinator mShareSheetCoordinator;
@Before
public void setUp() {
mActivity = mActivityTestRule.getActivity();
MockitoAnnotations.initMocks(this);
PropertyModel testModel1 = new PropertyModel.Builder(ShareSheetItemViewProperties.ALL_KEYS)
.with(ShareSheetItemViewProperties.ICON, null)
......@@ -82,22 +86,21 @@ public final class ShareSheetCoordinatorTest {
ArrayList<PropertyModel> thirdPartyPropertyModels =
new ArrayList<>(Arrays.asList(testModel1, testModel2));
Mockito.when(mPropertyModelBuilder.selectThirdPartyApps(
any(), anySet(), any(), anyBoolean(), any(), anyLong()))
when(mPropertyModelBuilder.selectThirdPartyApps(
any(), anySet(), any(), anyBoolean(), any(), anyLong()))
.thenReturn(thirdPartyPropertyModels);
mShareSheetCoordinator =
new ShareSheetCoordinator(mController, null, mPropertyModelBuilder, null);
mShareSheetCoordinator = new ShareSheetCoordinator(
mController, mLifecycleDispatcher, null, mPropertyModelBuilder, null);
}
@Test
@MediumTest
public void disableFirstPartyFeatures() {
mShareSheetCoordinator.disableFirstPartyFeaturesForTesting();
Activity activity = mActivityTestRule.getActivity();
List<PropertyModel> propertyModels = mShareSheetCoordinator.createTopRowPropertyModels(
activity, mParams, /*chromeShareExtras=*/null,
mActivity, /*shareParams=*/null, /*chromeShareExtras=*/null,
ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES);
assertEquals("Property model list should be empty.", 0, propertyModels.size());
}
......@@ -105,18 +108,18 @@ public final class ShareSheetCoordinatorTest {
@Test
@MediumTest
public void testCreateBottomRowPropertyModels() {
Activity activity = mActivityTestRule.getActivity();
List<PropertyModel> propertyModels = mShareSheetCoordinator.createBottomRowPropertyModels(
activity, mParams, ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES,
mActivity, new ShareParams.Builder(null, "", "").build(),
ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES,
/*saveLastUsed=*/false);
assertEquals("Incorrect number of property models.", 3, propertyModels.size());
assertEquals("First property model isn't testModel1.", "testModel1",
propertyModels.get(0).get(ShareSheetItemViewProperties.LABEL));
assertEquals("Second property model isn't testModel2.", "testModel2",
propertyModels.get(1).get(ShareSheetItemViewProperties.LABEL));
assertEquals("Third property model isn't More.",
activity.getResources().getString(R.string.sharing_more_icon_label),
mActivity.getResources().getString(R.string.sharing_more_icon_label),
propertyModels.get(2).get(ShareSheetItemViewProperties.LABEL));
}
}
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