diff options
| author | 2023-01-31 14:09:01 -0800 | |
|---|---|---|
| committer | 2023-02-03 14:34:42 -0800 | |
| commit | 150f8b476d622b592ce9192aed2e106076f2f67e (patch) | |
| tree | 463a6c4e3b34c0af1c7d61f1cb40a12e0f452da1 /java/tests/src | |
| parent | 3a9ca304f41a13c42f13f8f26eb9a714de24a267 (diff) | |
Enable scrollable image preview view
Enable scrollable image preview view under a feature flag.
Bug: 262280076
Test: manual test
Test: atest IntentResolverUnitTests with the both flag values
Change-Id: I86050f1e9193412d15fb35a162a0405cf8287401
Diffstat (limited to 'java/tests/src')
| -rw-r--r-- | java/tests/src/com/android/intentresolver/TestFeatureFlagRepository.kt | 30 | ||||
| -rw-r--r-- | java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java | 134 |
2 files changed, 116 insertions, 48 deletions
diff --git a/java/tests/src/com/android/intentresolver/TestFeatureFlagRepository.kt b/java/tests/src/com/android/intentresolver/TestFeatureFlagRepository.kt new file mode 100644 index 00000000..abc24efb --- /dev/null +++ b/java/tests/src/com/android/intentresolver/TestFeatureFlagRepository.kt @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.intentresolver + +import com.android.intentresolver.flags.FeatureFlagRepository +import com.android.systemui.flags.ReleasedFlag +import com.android.systemui.flags.UnreleasedFlag + +internal class TestFeatureFlagRepository( + private val overrides: Map<UnreleasedFlag, Boolean> +) : FeatureFlagRepository { + override fun isEnabled(flag: UnreleasedFlag): Boolean = + overrides.getOrDefault(flag, flag.default) + + override fun isEnabled(flag: ReleasedFlag): Boolean = flag.default +} diff --git a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java index 2d8a74b9..249dca62 100644 --- a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java +++ b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java @@ -90,24 +90,23 @@ import android.util.HashedStringCache; import android.util.Pair; import android.util.SparseArray; import android.view.View; +import android.view.ViewGroup; import androidx.annotation.CallSuper; import androidx.annotation.NonNull; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import androidx.test.espresso.contrib.RecyclerViewActions; import androidx.test.espresso.matcher.BoundedDiagnosingMatcher; import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.rule.ActivityTestRule; import com.android.intentresolver.ResolverActivity.ResolvedComponentInfo; import com.android.intentresolver.chooser.DisplayResolveInfo; -import com.android.intentresolver.flags.FeatureFlagRepository; import com.android.intentresolver.flags.Flags; import com.android.intentresolver.shortcuts.ShortcutLoader; import com.android.internal.config.sysui.SystemUiDeviceConfigFlags; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; -import com.android.systemui.flags.ReleasedFlag; -import com.android.systemui.flags.UnreleasedFlag; import org.hamcrest.Description; import org.hamcrest.Matcher; @@ -124,6 +123,7 @@ import org.mockito.Mockito; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -859,7 +859,7 @@ public class UnbundledChooserActivityTest { @Test - public void oneVisibleImagePreview() throws InterruptedException { + public void oneVisibleImagePreview() { Uri uri = Uri.parse("android.resource://com.android.frameworks.coretests/" + R.drawable.test320x240); @@ -884,18 +884,31 @@ public class UnbundledChooserActivityTest { .thenReturn(resolvedComponentInfos); mActivityRule.launchActivity(Intent.createChooser(sendIntent, null)); waitForIdle(); - onView(withId(com.android.internal.R.id.content_preview_image_1_large)) - .check(matches(isDisplayed())); - onView(withId(com.android.internal.R.id.content_preview_image_2_large)) - .check(matches(not(isDisplayed()))); - onView(withId(com.android.internal.R.id.content_preview_image_2_small)) - .check(matches(not(isDisplayed()))); - onView(withId(com.android.internal.R.id.content_preview_image_3_small)) - .check(matches(not(isDisplayed()))); + onView(withId(com.android.internal.R.id.content_preview_image_area)) + .check((view, exception) -> { + if (exception != null) { + throw exception; + } + ViewGroup parent = (ViewGroup) view; + ArrayList<View> visibleViews = new ArrayList<>(); + for (int i = 0, count = parent.getChildCount(); i < count; i++) { + View child = parent.getChildAt(i); + if (child.getVisibility() == View.VISIBLE) { + visibleViews.add(child); + } + } + assertThat(visibleViews.size(), is(1)); + assertThat( + "image preview view is fully visible", + isDisplayed().matches(visibleViews.get(0))); + }); } @Test - public void twoVisibleImagePreview() throws InterruptedException { + public void twoVisibleImagePreview() { + ChooserActivityOverrideData.getInstance().featureFlagRepository = + new TestFeatureFlagRepository( + Collections.singletonMap(Flags.SHARESHEET_SCROLLABLE_IMAGE_PREVIEW, false)); Uri uri = Uri.parse("android.resource://com.android.frameworks.coretests/" + R.drawable.test320x240); @@ -932,7 +945,11 @@ public class UnbundledChooserActivityTest { } @Test - public void threeOrMoreVisibleImagePreview() throws InterruptedException { + public void threeOrMoreVisibleImagePreview() { + ChooserActivityOverrideData.getInstance().featureFlagRepository = + new TestFeatureFlagRepository( + Collections.singletonMap( + Flags.SHARESHEET_SCROLLABLE_IMAGE_PREVIEW, false)); Uri uri = Uri.parse("android.resource://com.android.frameworks.coretests/" + R.drawable.test320x240); @@ -972,20 +989,60 @@ public class UnbundledChooserActivityTest { } @Test - public void testImageAndTextPreview() { + public void testManyVisibleImagePreview_ScrollableImagePreview() { ChooserActivityOverrideData.getInstance().featureFlagRepository = - new FeatureFlagRepository() { - @Override - public boolean isEnabled(@NonNull UnreleasedFlag flag) { - return Flags.SHARESHEET_IMAGE_AND_TEXT_PREVIEW.equals(flag) - || flag.getDefault(); - } + new TestFeatureFlagRepository( + Collections.singletonMap( + Flags.SHARESHEET_SCROLLABLE_IMAGE_PREVIEW, true)); + Uri uri = Uri.parse("android.resource://com.android.frameworks.coretests/" + + R.drawable.test320x240); + + ArrayList<Uri> uris = new ArrayList<>(); + uris.add(uri); + uris.add(uri); + uris.add(uri); + uris.add(uri); + uris.add(uri); + uris.add(uri); + uris.add(uri); + uris.add(uri); + uris.add(uri); + uris.add(uri); + + Intent sendIntent = createSendUriIntentWithPreview(uris); + ChooserActivityOverrideData.getInstance().previewThumbnail = createBitmap(); + ChooserActivityOverrideData.getInstance().isImageType = true; + + List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2); - @Override - public boolean isEnabled(@NonNull ReleasedFlag flag) { - return false; + when( + ChooserActivityOverrideData + .getInstance() + .resolverListController + .getResolversForIntent( + Mockito.anyBoolean(), + Mockito.anyBoolean(), + Mockito.anyBoolean(), + Mockito.isA(List.class))) + .thenReturn(resolvedComponentInfos); + mActivityRule.launchActivity(Intent.createChooser(sendIntent, null)); + waitForIdle(); + onView(withId(com.android.internal.R.id.content_preview_image_area)) + .perform(RecyclerViewActions.scrollToLastPosition()) + .check((view, exception) -> { + if (exception != null) { + throw exception; } - }; + RecyclerView recyclerView = (RecyclerView) view; + assertThat(recyclerView.getAdapter().getItemCount(), is(uris.size())); + }); + } + + @Test + public void testImageAndTextPreview() { + ChooserActivityOverrideData.getInstance().featureFlagRepository = + new TestFeatureFlagRepository( + Collections.singletonMap(Flags.SHARESHEET_IMAGE_AND_TEXT_PREVIEW, true)); final Uri uri = Uri.parse("android.resource://com.android.frameworks.coretests/" + R.drawable.test320x240); final String sharedText = "text-" + System.currentTimeMillis(); @@ -1723,17 +1780,8 @@ public class UnbundledChooserActivityTest { @Test public void testLaunchWithCustomAction() throws InterruptedException { ChooserActivityOverrideData.getInstance().featureFlagRepository = - new FeatureFlagRepository() { - @Override - public boolean isEnabled(@NonNull UnreleasedFlag flag) { - return Flags.SHARESHEET_CUSTOM_ACTIONS.equals(flag) || flag.getDefault(); - } - - @Override - public boolean isEnabled(@NonNull ReleasedFlag flag) { - return false; - } - }; + new TestFeatureFlagRepository( + Collections.singletonMap(Flags.SHARESHEET_CUSTOM_ACTIONS, true)); List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2); when( ChooserActivityOverrideData @@ -1787,18 +1835,8 @@ public class UnbundledChooserActivityTest { @Test public void testLaunchWithPayloadReselection() throws InterruptedException { ChooserActivityOverrideData.getInstance().featureFlagRepository = - new FeatureFlagRepository() { - @Override - public boolean isEnabled(@NonNull UnreleasedFlag flag) { - return Flags.SHARESHEET_RESELECTION_ACTION.equals(flag) - || flag.getDefault(); - } - - @Override - public boolean isEnabled(@NonNull ReleasedFlag flag) { - return false; - } - }; + new TestFeatureFlagRepository( + Collections.singletonMap(Flags.SHARESHEET_RESELECTION_ACTION, true)); List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2); when( ChooserActivityOverrideData |