summaryrefslogtreecommitdiff
path: root/tests/src/com/android/providers/media/photopicker/espresso/SpecialFormatMultiSelectTest.java
blob: 5897164153bbd79808f2edb2fdbde40fb52436ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
 * Copyright (C) 2021 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.providers.media.photopicker.espresso;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;

import static com.android.providers.media.photopicker.espresso.CustomSwipeAction.swipeLeftAndWait;
import static com.android.providers.media.photopicker.espresso.CustomSwipeAction.swipeRightAndWait;
import static com.android.providers.media.photopicker.espresso.OverflowMenuUtils.assertOverflowMenuNotShown;
import static com.android.providers.media.photopicker.espresso.RecyclerViewTestUtils.clickItem;
import static com.android.providers.media.photopicker.espresso.RecyclerViewTestUtils.longClickItem;

import androidx.test.ext.junit.rules.ActivityScenarioRule;

import com.android.providers.media.R;
import com.android.providers.media.library.RunOnlyOnPostsubmit;

import org.junit.Rule;
import org.junit.Test;

@RunOnlyOnPostsubmit
public class SpecialFormatMultiSelectTest extends SpecialFormatBaseTest {

    @Rule
    public ActivityScenarioRule<PhotoPickerTestActivity> mRule
            = new ActivityScenarioRule<>(PhotoPickerBaseTest.getMultiSelectionIntent());

    @Test
    public void testPreview_multiSelect_longPress_gif() throws Exception {
        onView(withId(PICKER_TAB_RECYCLERVIEW_ID)).check(matches(isDisplayed()));

        // Navigate to preview
        longClickItem(PICKER_TAB_RECYCLERVIEW_ID, GIF_POSITION, ICON_THUMBNAIL_ID);

        try (ViewPager2IdlingResource idlingResource =
                ViewPager2IdlingResource.register(mRule.getScenario(), PREVIEW_VIEW_PAGER_ID)) {
            // Verify imageView is displayed for gif preview
            onView(withId(PREVIEW_GIF_ID)).check(matches(isDisplayed()));
            onView(withId(R.id.preview_imageView)).check(matches(isDisplayed()));
            onView(withId(PREVIEW_MOTION_PHOTO_ID)).check(doesNotExist());
        }
    }

    @Test
    public void testPreview_multiSelect_longPress_animatedWebp() throws Exception {
        onView(withId(PICKER_TAB_RECYCLERVIEW_ID)).check(matches(isDisplayed()));

        // Navigate to preview
        longClickItem(PICKER_TAB_RECYCLERVIEW_ID, ANIMATED_WEBP_POSITION, ICON_THUMBNAIL_ID);

        try (ViewPager2IdlingResource idlingResource =
                ViewPager2IdlingResource.register(mRule.getScenario(), PREVIEW_VIEW_PAGER_ID)) {
            // Verify imageView is displayed for animated webp preview
            onView(withId(R.id.preview_imageView)).check(matches(isDisplayed()));

            // Verify GIF icon is shown for animated webp preview
            onView(withId(PREVIEW_GIF_ID)).check(matches(isDisplayed()));

            // Verify Motion Photo icon is not shown for animated webp preview
            onView(withId(PREVIEW_MOTION_PHOTO_ID)).check(doesNotExist());

            // Verify the overflow menu is not shown for PICK_IMAGES intent
            assertOverflowMenuNotShown();
        }
    }

    @Test
    public void testPreview_multiSelect_longPress_nonAnimatedWebp() throws Exception {
        onView(withId(PICKER_TAB_RECYCLERVIEW_ID)).check(matches(isDisplayed()));

        // Navigate to preview
        longClickItem(PICKER_TAB_RECYCLERVIEW_ID, NON_ANIMATED_WEBP_POSITION, ICON_THUMBNAIL_ID);

        try (ViewPager2IdlingResource idlingResource =
                ViewPager2IdlingResource.register(mRule.getScenario(), PREVIEW_VIEW_PAGER_ID)) {
            // Verify imageView is displayed for non-animated webp preview
            onView(withId(R.id.preview_imageView)).check(matches(isDisplayed()));

            // Verify GIF icon is not shown for non-animated webp preview
            onView(withId(PREVIEW_GIF_ID)).check(doesNotExist());

            // Verify Motion Photo icon is not shown for non-animated webp preview
            onView(withId(PREVIEW_MOTION_PHOTO_ID)).check(doesNotExist());

            // Verify the overflow menu is not shown for PICK_IMAGES intent
            assertOverflowMenuNotShown();
        }
    }

    @Test
    public void testPreview_multiSelect_longPress_motionPhoto() throws Exception {
        onView(withId(PICKER_TAB_RECYCLERVIEW_ID)).check(matches(isDisplayed()));

        // Navigate to preview
        longClickItem(PICKER_TAB_RECYCLERVIEW_ID, MOTION_PHOTO_POSITION, ICON_THUMBNAIL_ID);

        try (ViewPager2IdlingResource idlingResource =
                ViewPager2IdlingResource.register(mRule.getScenario(), PREVIEW_VIEW_PAGER_ID)) {
            // Verify imageView is displayed for motion photo preview
            onView(withId(PREVIEW_MOTION_PHOTO_ID)).check(matches(isDisplayed()));
            onView(withId(R.id.preview_imageView)).check(matches(isDisplayed()));
            onView(withId(PREVIEW_GIF_ID)).check(doesNotExist());
            // Verify the overflow menu is not shown for PICK_IMAGES intent
            assertOverflowMenuNotShown();
        }
    }

    @Test
    public void testPreview_multiSelect_navigation() throws Exception {
        onView(withId(PICKER_TAB_RECYCLERVIEW_ID)).check(matches(isDisplayed()));

        // Select items
        clickItem(PICKER_TAB_RECYCLERVIEW_ID, GIF_POSITION, ICON_THUMBNAIL_ID);
        clickItem(PICKER_TAB_RECYCLERVIEW_ID, ANIMATED_WEBP_POSITION, ICON_THUMBNAIL_ID);
        clickItem(PICKER_TAB_RECYCLERVIEW_ID, MOTION_PHOTO_POSITION, ICON_THUMBNAIL_ID);
        clickItem(PICKER_TAB_RECYCLERVIEW_ID, NON_ANIMATED_WEBP_POSITION, ICON_THUMBNAIL_ID);
        // Navigate to preview
        onView(withId(VIEW_SELECTED_BUTTON_ID)).perform(click());

        try (ViewPager2IdlingResource idlingResource =
                ViewPager2IdlingResource.register(mRule.getScenario(), PREVIEW_VIEW_PAGER_ID)) {
            // Preview Order
            // 1 - Gif
            // 2 - Animated Webp
            // 3 - MotionPhoto
            // 4 - Non-Animated Webp
            // Navigate from Gif -> Motion Photo -> Animated Webp -> Non-Animated Webp ->
            // Animated Webp -> Gif and verify the layout matches.
            // This test does not check for common layout as that is already covered in
            // other tests.

            // 1. Gif
            onView(withId(PREVIEW_GIF_ID)).check(matches(isDisplayed()));
            onView(withId(PREVIEW_MOTION_PHOTO_ID)).check(doesNotExist());

            swipeLeftAndWait(PREVIEW_VIEW_PAGER_ID);
            // 2. Animated Webp
            onView(withId(PREVIEW_GIF_ID)).check(matches(isDisplayed()));
            onView(withId(PREVIEW_MOTION_PHOTO_ID)).check(doesNotExist());

            swipeLeftAndWait(PREVIEW_VIEW_PAGER_ID);
            // 3. Motion Photo
            onView(withId(PREVIEW_MOTION_PHOTO_ID)).check(matches(isDisplayed()));
            onView(withId(PREVIEW_GIF_ID)).check(doesNotExist());

            swipeLeftAndWait(PREVIEW_VIEW_PAGER_ID);
            // 4. Non-Animated Webp
            onView(withId(PREVIEW_GIF_ID)).check(doesNotExist());
            onView(withId(PREVIEW_MOTION_PHOTO_ID)).check(doesNotExist());

            swipeRightAndWait(PREVIEW_VIEW_PAGER_ID);
            // 3. Motion Photo
            onView(withId(PREVIEW_MOTION_PHOTO_ID)).check(matches(isDisplayed()));
            onView(withId(PREVIEW_GIF_ID)).check(doesNotExist());

            swipeRightAndWait(PREVIEW_VIEW_PAGER_ID);
            // 2. Animated Webp
            onView(withId(PREVIEW_GIF_ID)).check(matches(isDisplayed()));
            onView(withId(PREVIEW_MOTION_PHOTO_ID)).check(doesNotExist());

            swipeRightAndWait(PREVIEW_VIEW_PAGER_ID);
            // 1. Gif
            onView(withId(PREVIEW_GIF_ID)).check(matches(isDisplayed()));
            onView(withId(PREVIEW_MOTION_PHOTO_ID)).check(doesNotExist());
        }
    }
}