Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.internal.app; |
| 18 | |
Matt Pietal | 2603840 | 2019-01-08 07:29:34 -0500 | [diff] [blame] | 19 | import static androidx.test.espresso.Espresso.onView; |
| 20 | import static androidx.test.espresso.action.ViewActions.click; |
| 21 | import static androidx.test.espresso.assertion.ViewAssertions.matches; |
| 22 | import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; |
| 23 | import static androidx.test.espresso.matcher.ViewMatchers.withId; |
| 24 | import static androidx.test.espresso.matcher.ViewMatchers.withText; |
Tadashi G. Takaoka | b4470f2 | 2019-01-15 18:29:15 +0900 | [diff] [blame] | 25 | |
| 26 | import static com.android.internal.app.ChooserWrapperActivity.sOverrides; |
| 27 | |
| 28 | import static org.hamcrest.CoreMatchers.is; |
| 29 | import static org.hamcrest.CoreMatchers.not; |
Susi Kharraz-Post | 7e2115d | 2019-02-01 16:51:22 -0500 | [diff] [blame] | 30 | import static org.hamcrest.CoreMatchers.notNullValue; |
Tadashi G. Takaoka | b4470f2 | 2019-01-15 18:29:15 +0900 | [diff] [blame] | 31 | import static org.hamcrest.MatcherAssert.assertThat; |
Susi Kharraz-Post | 7e2115d | 2019-02-01 16:51:22 -0500 | [diff] [blame] | 32 | import static org.mockito.Mockito.atLeastOnce; |
Matt Pietal | f38e9d2 | 2019-02-15 10:01:03 -0500 | [diff] [blame] | 33 | import static org.mockito.Mockito.mock; |
Tadashi G. Takaoka | b4470f2 | 2019-01-15 18:29:15 +0900 | [diff] [blame] | 34 | import static org.mockito.Mockito.times; |
| 35 | import static org.mockito.Mockito.verify; |
| 36 | import static org.mockito.Mockito.when; |
| 37 | |
| 38 | import android.app.usage.UsageStatsManager; |
Matt Pietal | 2603840 | 2019-01-08 07:29:34 -0500 | [diff] [blame] | 39 | import android.content.ClipData; |
Matt Pietal | 1fa7d80 | 2019-01-30 10:44:15 -0500 | [diff] [blame] | 40 | import android.content.ClipDescription; |
| 41 | import android.content.ClipboardManager; |
| 42 | import android.content.Context; |
Tadashi G. Takaoka | b4470f2 | 2019-01-15 18:29:15 +0900 | [diff] [blame] | 43 | import android.content.Intent; |
| 44 | import android.content.pm.ResolveInfo; |
Matt Pietal | f38e9d2 | 2019-02-15 10:01:03 -0500 | [diff] [blame] | 45 | import android.database.Cursor; |
Matt Pietal | 2603840 | 2019-01-08 07:29:34 -0500 | [diff] [blame] | 46 | import android.graphics.Bitmap; |
| 47 | import android.graphics.Canvas; |
| 48 | import android.graphics.Color; |
| 49 | import android.graphics.Paint; |
Susi Kharraz-Post | 7e2115d | 2019-02-01 16:51:22 -0500 | [diff] [blame] | 50 | import android.metrics.LogMaker; |
Matt Pietal | 2603840 | 2019-01-08 07:29:34 -0500 | [diff] [blame] | 51 | import android.net.Uri; |
Tadashi G. Takaoka | b4470f2 | 2019-01-15 18:29:15 +0900 | [diff] [blame] | 52 | |
Matt Pietal | 2603840 | 2019-01-08 07:29:34 -0500 | [diff] [blame] | 53 | import androidx.test.ext.junit.runners.AndroidJUnit4; |
| 54 | import androidx.test.platform.app.InstrumentationRegistry; |
Tadashi G. Takaoka | b4470f2 | 2019-01-15 18:29:15 +0900 | [diff] [blame] | 55 | import androidx.test.rule.ActivityTestRule; |
Tadashi G. Takaoka | b4470f2 | 2019-01-15 18:29:15 +0900 | [diff] [blame] | 56 | |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 57 | import com.android.internal.R; |
| 58 | import com.android.internal.app.ResolverActivity.ResolvedComponentInfo; |
Susi Kharraz-Post | 7e2115d | 2019-02-01 16:51:22 -0500 | [diff] [blame] | 59 | import com.android.internal.logging.MetricsLogger; |
Susi Kharraz-Post | 0446fab | 2019-02-21 09:42:31 -0500 | [diff] [blame] | 60 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 61 | |
| 62 | import org.junit.Before; |
| 63 | import org.junit.Rule; |
| 64 | import org.junit.Test; |
| 65 | import org.junit.runner.RunWith; |
Susi Kharraz-Post | 7e2115d | 2019-02-01 16:51:22 -0500 | [diff] [blame] | 66 | import org.mockito.ArgumentCaptor; |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 67 | import org.mockito.Mockito; |
| 68 | |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 69 | import java.util.ArrayList; |
| 70 | import java.util.List; |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 71 | |
| 72 | /** |
| 73 | * Chooser activity instrumentation tests |
| 74 | */ |
| 75 | @RunWith(AndroidJUnit4.class) |
| 76 | public class ChooserActivityTest { |
Susi Kharraz-Post | 7e2115d | 2019-02-01 16:51:22 -0500 | [diff] [blame] | 77 | |
| 78 | private static final int CONTENT_PREVIEW_IMAGE = 1; |
| 79 | private static final int CONTENT_PREVIEW_FILE = 2; |
| 80 | private static final int CONTENT_PREVIEW_TEXT = 3; |
| 81 | |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 82 | @Rule |
| 83 | public ActivityTestRule<ChooserWrapperActivity> mActivityRule = |
| 84 | new ActivityTestRule<>(ChooserWrapperActivity.class, false, |
| 85 | false); |
| 86 | |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 87 | @Before |
| 88 | public void cleanOverrideData() { |
| 89 | sOverrides.reset(); |
| 90 | } |
| 91 | |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 92 | @Test |
| 93 | public void customTitle() throws InterruptedException { |
Matt Pietal | 2603840 | 2019-01-08 07:29:34 -0500 | [diff] [blame] | 94 | Intent viewIntent = createViewTextIntent(); |
| 95 | List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2); |
| 96 | |
| 97 | when(sOverrides.resolverListController.getResolversForIntent(Mockito.anyBoolean(), |
| 98 | Mockito.anyBoolean(), |
| 99 | Mockito.isA(List.class))).thenReturn(resolvedComponentInfos); |
| 100 | mActivityRule.launchActivity(Intent.createChooser(viewIntent, "chooser test")); |
| 101 | |
| 102 | waitForIdle(); |
| 103 | onView(withId(R.id.title)).check(matches(withText("chooser test"))); |
| 104 | } |
| 105 | |
| 106 | @Test |
| 107 | public void customTitleIgnoredForSendIntents() throws InterruptedException { |
| 108 | Intent sendIntent = createSendTextIntent(); |
Hakan Seyalioglu | 79b69f0 | 2017-01-12 17:08:02 -0800 | [diff] [blame] | 109 | List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2); |
| 110 | |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 111 | when(sOverrides.resolverListController.getResolversForIntent(Mockito.anyBoolean(), |
| 112 | Mockito.anyBoolean(), |
Hakan Seyalioglu | 79b69f0 | 2017-01-12 17:08:02 -0800 | [diff] [blame] | 113 | Mockito.isA(List.class))).thenReturn(resolvedComponentInfos); |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 114 | mActivityRule.launchActivity(Intent.createChooser(sendIntent, "chooser test")); |
| 115 | waitForIdle(); |
Matt Pietal | 2603840 | 2019-01-08 07:29:34 -0500 | [diff] [blame] | 116 | onView(withId(R.id.title)).check(matches(withText(R.string.whichSendApplication))); |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | @Test |
| 120 | public void emptyTitle() throws InterruptedException { |
Matt Pietal | 2603840 | 2019-01-08 07:29:34 -0500 | [diff] [blame] | 121 | Intent sendIntent = createSendTextIntent(); |
Hakan Seyalioglu | 79b69f0 | 2017-01-12 17:08:02 -0800 | [diff] [blame] | 122 | List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2); |
| 123 | |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 124 | when(sOverrides.resolverListController.getResolversForIntent(Mockito.anyBoolean(), |
| 125 | Mockito.anyBoolean(), |
Hakan Seyalioglu | 79b69f0 | 2017-01-12 17:08:02 -0800 | [diff] [blame] | 126 | Mockito.isA(List.class))).thenReturn(resolvedComponentInfos); |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 127 | mActivityRule.launchActivity(Intent.createChooser(sendIntent, null)); |
| 128 | waitForIdle(); |
| 129 | onView(withId(R.id.title)) |
| 130 | .check(matches(withText(R.string.whichSendApplication))); |
| 131 | } |
| 132 | |
| 133 | @Test |
Matt Pietal | 2603840 | 2019-01-08 07:29:34 -0500 | [diff] [blame] | 134 | public void emptyPreviewTitleAndThumbnail() throws InterruptedException { |
| 135 | Intent sendIntent = createSendTextIntentWithPreview(null, null); |
| 136 | List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2); |
| 137 | |
| 138 | when(sOverrides.resolverListController.getResolversForIntent(Mockito.anyBoolean(), |
| 139 | Mockito.anyBoolean(), |
| 140 | Mockito.isA(List.class))).thenReturn(resolvedComponentInfos); |
| 141 | mActivityRule.launchActivity(Intent.createChooser(sendIntent, null)); |
| 142 | waitForIdle(); |
| 143 | onView(withId(R.id.content_preview_title)).check(matches(not(isDisplayed()))); |
| 144 | onView(withId(R.id.content_preview_thumbnail)).check(matches(not(isDisplayed()))); |
| 145 | } |
| 146 | |
| 147 | @Test |
| 148 | public void visiblePreviewTitleWithoutThumbnail() throws InterruptedException { |
| 149 | String previewTitle = "My Content Preview Title"; |
| 150 | Intent sendIntent = createSendTextIntentWithPreview(previewTitle, null); |
| 151 | List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2); |
| 152 | |
| 153 | when(sOverrides.resolverListController.getResolversForIntent(Mockito.anyBoolean(), |
| 154 | Mockito.anyBoolean(), |
| 155 | Mockito.isA(List.class))).thenReturn(resolvedComponentInfos); |
| 156 | mActivityRule.launchActivity(Intent.createChooser(sendIntent, null)); |
| 157 | waitForIdle(); |
| 158 | onView(withId(R.id.content_preview_title)).check(matches(isDisplayed())); |
| 159 | onView(withId(R.id.content_preview_title)).check(matches(withText(previewTitle))); |
| 160 | onView(withId(R.id.content_preview_thumbnail)).check(matches(not(isDisplayed()))); |
| 161 | } |
| 162 | |
| 163 | @Test |
| 164 | public void visiblePreviewTitleWithInvalidThumbnail() throws InterruptedException { |
| 165 | String previewTitle = "My Content Preview Title"; |
| 166 | Intent sendIntent = createSendTextIntentWithPreview(previewTitle, |
| 167 | Uri.parse("tel:(+49)12345789")); |
| 168 | List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2); |
| 169 | |
| 170 | when(sOverrides.resolverListController.getResolversForIntent(Mockito.anyBoolean(), |
| 171 | Mockito.anyBoolean(), |
| 172 | Mockito.isA(List.class))).thenReturn(resolvedComponentInfos); |
| 173 | mActivityRule.launchActivity(Intent.createChooser(sendIntent, null)); |
| 174 | waitForIdle(); |
| 175 | onView(withId(R.id.content_preview_title)).check(matches(isDisplayed())); |
| 176 | onView(withId(R.id.content_preview_thumbnail)).check(matches(not(isDisplayed()))); |
| 177 | } |
| 178 | |
| 179 | @Test |
| 180 | public void visiblePreviewTitleAndThumbnail() throws InterruptedException { |
| 181 | String previewTitle = "My Content Preview Title"; |
| 182 | Intent sendIntent = createSendTextIntentWithPreview(previewTitle, |
| 183 | Uri.parse("android.resource://com.android.frameworks.coretests/" |
| 184 | + com.android.frameworks.coretests.R.drawable.test320x240)); |
| 185 | sOverrides.previewThumbnail = createBitmap(); |
| 186 | List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2); |
| 187 | |
| 188 | when(sOverrides.resolverListController.getResolversForIntent(Mockito.anyBoolean(), |
| 189 | Mockito.anyBoolean(), |
| 190 | Mockito.isA(List.class))).thenReturn(resolvedComponentInfos); |
| 191 | mActivityRule.launchActivity(Intent.createChooser(sendIntent, null)); |
| 192 | waitForIdle(); |
| 193 | onView(withId(R.id.content_preview_title)).check(matches(isDisplayed())); |
| 194 | onView(withId(R.id.content_preview_thumbnail)).check(matches(isDisplayed())); |
| 195 | } |
| 196 | |
| 197 | @Test |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 198 | public void twoOptionsAndUserSelectsOne() throws InterruptedException { |
Matt Pietal | 2603840 | 2019-01-08 07:29:34 -0500 | [diff] [blame] | 199 | Intent sendIntent = createSendTextIntent(); |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 200 | List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2); |
| 201 | |
| 202 | when(sOverrides.resolverListController.getResolversForIntent(Mockito.anyBoolean(), |
| 203 | Mockito.anyBoolean(), |
| 204 | Mockito.isA(List.class))).thenReturn(resolvedComponentInfos); |
| 205 | |
| 206 | final ChooserWrapperActivity activity = mActivityRule |
| 207 | .launchActivity(Intent.createChooser(sendIntent, null)); |
| 208 | waitForIdle(); |
| 209 | |
| 210 | assertThat(activity.getAdapter().getCount(), is(2)); |
| 211 | onView(withId(R.id.profile_button)).check(matches(not(isDisplayed()))); |
| 212 | |
| 213 | ResolveInfo[] chosen = new ResolveInfo[1]; |
| 214 | sOverrides.onSafelyStartCallback = targetInfo -> { |
| 215 | chosen[0] = targetInfo.getResolveInfo(); |
| 216 | return true; |
| 217 | }; |
| 218 | |
| 219 | ResolveInfo toChoose = resolvedComponentInfos.get(0).getResolveInfoAt(0); |
| 220 | onView(withText(toChoose.activityInfo.name)) |
| 221 | .perform(click()); |
| 222 | waitForIdle(); |
| 223 | assertThat(chosen[0], is(toChoose)); |
| 224 | } |
| 225 | |
| 226 | @Test |
Kang Li | 9fa2a2c | 2017-01-06 13:33:24 -0800 | [diff] [blame] | 227 | public void updateChooserCountsAndModelAfterUserSelection() throws InterruptedException { |
Matt Pietal | 2603840 | 2019-01-08 07:29:34 -0500 | [diff] [blame] | 228 | Intent sendIntent = createSendTextIntent(); |
Kang Li | 64b018e | 2017-01-05 17:30:06 -0800 | [diff] [blame] | 229 | List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2); |
| 230 | |
| 231 | when(sOverrides.resolverListController.getResolversForIntent(Mockito.anyBoolean(), |
| 232 | Mockito.anyBoolean(), |
| 233 | Mockito.isA(List.class))).thenReturn(resolvedComponentInfos); |
| 234 | |
| 235 | final ChooserWrapperActivity activity = mActivityRule |
| 236 | .launchActivity(Intent.createChooser(sendIntent, null)); |
| 237 | waitForIdle(); |
| 238 | UsageStatsManager usm = activity.getUsageStatsManager(); |
| 239 | verify(sOverrides.resolverListController, times(1)) |
| 240 | .sort(Mockito.any(List.class)); |
| 241 | assertThat(activity.getIsSelected(), is(false)); |
| 242 | sOverrides.onSafelyStartCallback = targetInfo -> { |
| 243 | return true; |
| 244 | }; |
Kang Li | 64b018e | 2017-01-05 17:30:06 -0800 | [diff] [blame] | 245 | ResolveInfo toChoose = resolvedComponentInfos.get(0).getResolveInfoAt(0); |
Kang Li | 64b018e | 2017-01-05 17:30:06 -0800 | [diff] [blame] | 246 | onView(withText(toChoose.activityInfo.name)) |
| 247 | .perform(click()); |
| 248 | waitForIdle(); |
| 249 | verify(sOverrides.resolverListController, times(1)) |
Kang Li | 9fa2a2c | 2017-01-06 13:33:24 -0800 | [diff] [blame] | 250 | .updateChooserCounts(Mockito.anyString(), Mockito.anyInt(), Mockito.anyString()); |
| 251 | verify(sOverrides.resolverListController, times(1)) |
Kang Li | 64b018e | 2017-01-05 17:30:06 -0800 | [diff] [blame] | 252 | .updateModel(toChoose.activityInfo.getComponentName()); |
| 253 | assertThat(activity.getIsSelected(), is(true)); |
Kang Li | 64b018e | 2017-01-05 17:30:06 -0800 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | @Test |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 257 | public void noResultsFromPackageManager() { |
| 258 | when(sOverrides.resolverListController.getResolversForIntent(Mockito.anyBoolean(), |
| 259 | Mockito.anyBoolean(), |
| 260 | Mockito.isA(List.class))).thenReturn(null); |
Matt Pietal | 2603840 | 2019-01-08 07:29:34 -0500 | [diff] [blame] | 261 | Intent sendIntent = createSendTextIntent(); |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 262 | final ChooserWrapperActivity activity = mActivityRule |
| 263 | .launchActivity(Intent.createChooser(sendIntent, null)); |
| 264 | waitForIdle(); |
| 265 | assertThat(activity.isFinishing(), is(false)); |
| 266 | |
| 267 | onView(withId(R.id.empty)).check(matches(isDisplayed())); |
| 268 | onView(withId(R.id.resolver_list)).check(matches(not(isDisplayed()))); |
| 269 | InstrumentationRegistry.getInstrumentation().runOnMainSync( |
| 270 | () -> activity.getAdapter().handlePackagesChanged() |
| 271 | ); |
| 272 | // backward compatibility. looks like we finish when data is empty after package change |
| 273 | assertThat(activity.isFinishing(), is(true)); |
| 274 | } |
| 275 | |
| 276 | @Test |
| 277 | public void autoLaunchSingleResult() throws InterruptedException { |
| 278 | ResolveInfo[] chosen = new ResolveInfo[1]; |
| 279 | sOverrides.onSafelyStartCallback = targetInfo -> { |
| 280 | chosen[0] = targetInfo.getResolveInfo(); |
| 281 | return true; |
| 282 | }; |
| 283 | |
| 284 | List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(1); |
| 285 | when(sOverrides.resolverListController.getResolversForIntent(Mockito.anyBoolean(), |
| 286 | Mockito.anyBoolean(), |
| 287 | Mockito.isA(List.class))).thenReturn(resolvedComponentInfos); |
| 288 | |
Matt Pietal | 2603840 | 2019-01-08 07:29:34 -0500 | [diff] [blame] | 289 | Intent sendIntent = createSendTextIntent(); |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 290 | final ChooserWrapperActivity activity = mActivityRule |
| 291 | .launchActivity(Intent.createChooser(sendIntent, null)); |
| 292 | waitForIdle(); |
| 293 | |
| 294 | assertThat(chosen[0], is(resolvedComponentInfos.get(0).getResolveInfoAt(0))); |
| 295 | assertThat(activity.isFinishing(), is(true)); |
| 296 | } |
| 297 | |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 298 | @Test |
| 299 | public void hasOtherProfileOneOption() throws Exception { |
Matt Pietal | 2603840 | 2019-01-08 07:29:34 -0500 | [diff] [blame] | 300 | Intent sendIntent = createSendTextIntent(); |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 301 | List<ResolvedComponentInfo> resolvedComponentInfos = |
| 302 | createResolvedComponentsForTestWithOtherProfile(2); |
| 303 | ResolveInfo toChoose = resolvedComponentInfos.get(1).getResolveInfoAt(0); |
| 304 | |
| 305 | when(ChooserWrapperActivity.sOverrides.resolverListController.getResolversForIntent( |
| 306 | Mockito.anyBoolean(), |
| 307 | Mockito.anyBoolean(), |
| 308 | Mockito.isA(List.class))).thenReturn(resolvedComponentInfos); |
| 309 | |
| 310 | final ChooserWrapperActivity activity = mActivityRule |
| 311 | .launchActivity(Intent.createChooser(sendIntent, null)); |
| 312 | waitForIdle(); |
| 313 | |
| 314 | // The other entry is filtered to the other profile slot |
| 315 | assertThat(activity.getAdapter().getCount(), is(1)); |
| 316 | |
| 317 | ResolveInfo[] chosen = new ResolveInfo[1]; |
| 318 | ChooserWrapperActivity.sOverrides.onSafelyStartCallback = targetInfo -> { |
| 319 | chosen[0] = targetInfo.getResolveInfo(); |
| 320 | return true; |
| 321 | }; |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 322 | |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 323 | // Make a stable copy of the components as the original list may be modified |
| 324 | List<ResolvedComponentInfo> stableCopy = |
| 325 | createResolvedComponentsForTestWithOtherProfile(2); |
| 326 | // Check that the "Other Profile" activity is put in the right spot |
| 327 | onView(withId(R.id.profile_button)).check(matches( |
| 328 | withText(stableCopy.get(0).getResolveInfoAt(0).activityInfo.name))); |
| 329 | onView(withText(stableCopy.get(1).getResolveInfoAt(0).activityInfo.name)) |
| 330 | .perform(click()); |
| 331 | waitForIdle(); |
| 332 | assertThat(chosen[0], is(toChoose)); |
| 333 | } |
| 334 | |
| 335 | @Test |
| 336 | public void hasOtherProfileTwoOptionsAndUserSelectsOne() throws Exception { |
Matt Pietal | 2603840 | 2019-01-08 07:29:34 -0500 | [diff] [blame] | 337 | Intent sendIntent = createSendTextIntent(); |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 338 | List<ResolvedComponentInfo> resolvedComponentInfos = |
| 339 | createResolvedComponentsForTestWithOtherProfile(3); |
| 340 | ResolveInfo toChoose = resolvedComponentInfos.get(1).getResolveInfoAt(0); |
| 341 | |
| 342 | when(ChooserWrapperActivity.sOverrides.resolverListController.getResolversForIntent( |
| 343 | Mockito.anyBoolean(), |
| 344 | Mockito.anyBoolean(), |
| 345 | Mockito.isA(List.class))).thenReturn(resolvedComponentInfos); |
| 346 | when(ChooserWrapperActivity.sOverrides.resolverListController.getLastChosen()) |
| 347 | .thenReturn(resolvedComponentInfos.get(0).getResolveInfoAt(0)); |
| 348 | |
| 349 | final ChooserWrapperActivity activity = mActivityRule |
| 350 | .launchActivity(Intent.createChooser(sendIntent, null)); |
| 351 | waitForIdle(); |
| 352 | |
| 353 | // The other entry is filtered to the other profile slot |
| 354 | assertThat(activity.getAdapter().getCount(), is(2)); |
| 355 | |
| 356 | ResolveInfo[] chosen = new ResolveInfo[1]; |
| 357 | ChooserWrapperActivity.sOverrides.onSafelyStartCallback = targetInfo -> { |
| 358 | chosen[0] = targetInfo.getResolveInfo(); |
| 359 | return true; |
| 360 | }; |
| 361 | |
| 362 | // Make a stable copy of the components as the original list may be modified |
| 363 | List<ResolvedComponentInfo> stableCopy = |
| 364 | createResolvedComponentsForTestWithOtherProfile(3); |
| 365 | // Check that the "Other Profile" activity is put in the right spot |
| 366 | onView(withId(R.id.profile_button)).check(matches( |
| 367 | withText(stableCopy.get(0).getResolveInfoAt(0).activityInfo.name))); |
| 368 | onView(withText(stableCopy.get(1).getResolveInfoAt(0).activityInfo.name)) |
| 369 | .perform(click()); |
| 370 | waitForIdle(); |
| 371 | assertThat(chosen[0], is(toChoose)); |
| 372 | } |
| 373 | |
| 374 | @Test |
| 375 | public void hasLastChosenActivityAndOtherProfile() throws Exception { |
Matt Pietal | 2603840 | 2019-01-08 07:29:34 -0500 | [diff] [blame] | 376 | Intent sendIntent = createSendTextIntent(); |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 377 | List<ResolvedComponentInfo> resolvedComponentInfos = |
| 378 | createResolvedComponentsForTestWithOtherProfile(3); |
| 379 | ResolveInfo toChoose = resolvedComponentInfos.get(1).getResolveInfoAt(0); |
| 380 | |
| 381 | when(ChooserWrapperActivity.sOverrides.resolverListController.getResolversForIntent( |
| 382 | Mockito.anyBoolean(), |
| 383 | Mockito.anyBoolean(), |
| 384 | Mockito.isA(List.class))).thenReturn(resolvedComponentInfos); |
| 385 | |
| 386 | final ChooserWrapperActivity activity = mActivityRule |
| 387 | .launchActivity(Intent.createChooser(sendIntent, null)); |
| 388 | waitForIdle(); |
| 389 | |
| 390 | // The other entry is filtered to the last used slot |
| 391 | assertThat(activity.getAdapter().getCount(), is(2)); |
| 392 | |
| 393 | ResolveInfo[] chosen = new ResolveInfo[1]; |
| 394 | ChooserWrapperActivity.sOverrides.onSafelyStartCallback = targetInfo -> { |
| 395 | chosen[0] = targetInfo.getResolveInfo(); |
| 396 | return true; |
| 397 | }; |
| 398 | |
| 399 | // Make a stable copy of the components as the original list may be modified |
| 400 | List<ResolvedComponentInfo> stableCopy = |
| 401 | createResolvedComponentsForTestWithOtherProfile(3); |
| 402 | // Check that the "Other Profile" activity is put in the right spot |
| 403 | onView(withId(R.id.profile_button)).check(matches( |
| 404 | withText(stableCopy.get(0).getResolveInfoAt(0).activityInfo.name))); |
| 405 | onView(withText(stableCopy.get(1).getResolveInfoAt(0).activityInfo.name)) |
| 406 | .perform(click()); |
| 407 | waitForIdle(); |
| 408 | assertThat(chosen[0], is(toChoose)); |
| 409 | } |
| 410 | |
Matt Pietal | 1fa7d80 | 2019-01-30 10:44:15 -0500 | [diff] [blame] | 411 | @Test |
| 412 | public void copyTextToClipboard() throws Exception { |
| 413 | Intent sendIntent = createSendTextIntent(); |
Matt Pietal | 46d828c | 2019-02-05 08:07:07 -0500 | [diff] [blame] | 414 | List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2); |
Matt Pietal | 1fa7d80 | 2019-01-30 10:44:15 -0500 | [diff] [blame] | 415 | |
| 416 | when(ChooserWrapperActivity.sOverrides.resolverListController.getResolversForIntent( |
Susi Kharraz-Post | 7e2115d | 2019-02-01 16:51:22 -0500 | [diff] [blame] | 417 | Mockito.anyBoolean(), |
| 418 | Mockito.anyBoolean(), |
| 419 | Mockito.isA(List.class))).thenReturn(resolvedComponentInfos); |
Matt Pietal | 1fa7d80 | 2019-01-30 10:44:15 -0500 | [diff] [blame] | 420 | |
| 421 | final ChooserWrapperActivity activity = mActivityRule |
| 422 | .launchActivity(Intent.createChooser(sendIntent, null)); |
| 423 | waitForIdle(); |
| 424 | |
Matt Pietal | 46d828c | 2019-02-05 08:07:07 -0500 | [diff] [blame] | 425 | onView(withId(R.id.copy_button)).check(matches(isDisplayed())); |
Matt Pietal | 1fa7d80 | 2019-01-30 10:44:15 -0500 | [diff] [blame] | 426 | onView(withId(R.id.copy_button)).perform(click()); |
Matt Pietal | 1fa7d80 | 2019-01-30 10:44:15 -0500 | [diff] [blame] | 427 | ClipboardManager clipboard = (ClipboardManager) activity.getSystemService( |
| 428 | Context.CLIPBOARD_SERVICE); |
| 429 | ClipData clipData = clipboard.getPrimaryClip(); |
| 430 | assertThat("testing intent sending", is(clipData.getItemAt(0).getText())); |
| 431 | |
| 432 | ClipDescription clipDescription = clipData.getDescription(); |
| 433 | assertThat("text/plain", is(clipDescription.getMimeType(0))); |
| 434 | } |
| 435 | |
Matt Pietal | 0ea391b | 2019-01-30 10:44:15 -0500 | [diff] [blame] | 436 | @Test |
| 437 | public void oneVisibleImagePreview() throws InterruptedException { |
| 438 | Uri uri = Uri.parse("android.resource://com.android.frameworks.coretests/" |
| 439 | + com.android.frameworks.coretests.R.drawable.test320x240); |
| 440 | |
| 441 | ArrayList<Uri> uris = new ArrayList<>(); |
| 442 | uris.add(uri); |
| 443 | |
Matt Pietal | 46d828c | 2019-02-05 08:07:07 -0500 | [diff] [blame] | 444 | Intent sendIntent = createSendUriIntentWithPreview(uris); |
Matt Pietal | 0ea391b | 2019-01-30 10:44:15 -0500 | [diff] [blame] | 445 | sOverrides.previewThumbnail = createBitmap(); |
Matt Pietal | 46d828c | 2019-02-05 08:07:07 -0500 | [diff] [blame] | 446 | sOverrides.isImageType = true; |
Matt Pietal | 0ea391b | 2019-01-30 10:44:15 -0500 | [diff] [blame] | 447 | |
| 448 | List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2); |
| 449 | |
| 450 | when(sOverrides.resolverListController.getResolversForIntent(Mockito.anyBoolean(), |
| 451 | Mockito.anyBoolean(), |
| 452 | Mockito.isA(List.class))).thenReturn(resolvedComponentInfos); |
| 453 | mActivityRule.launchActivity(Intent.createChooser(sendIntent, null)); |
| 454 | waitForIdle(); |
| 455 | onView(withId(R.id.content_preview_image_1_large)).check(matches(isDisplayed())); |
| 456 | onView(withId(R.id.content_preview_image_2_large)).check(matches(not(isDisplayed()))); |
| 457 | onView(withId(R.id.content_preview_image_2_small)).check(matches(not(isDisplayed()))); |
| 458 | onView(withId(R.id.content_preview_image_3_small)).check(matches(not(isDisplayed()))); |
| 459 | } |
| 460 | |
| 461 | @Test |
| 462 | public void twoVisibleImagePreview() throws InterruptedException { |
| 463 | Uri uri = Uri.parse("android.resource://com.android.frameworks.coretests/" |
| 464 | + com.android.frameworks.coretests.R.drawable.test320x240); |
| 465 | |
| 466 | ArrayList<Uri> uris = new ArrayList<>(); |
| 467 | uris.add(uri); |
| 468 | uris.add(uri); |
| 469 | |
Matt Pietal | 46d828c | 2019-02-05 08:07:07 -0500 | [diff] [blame] | 470 | Intent sendIntent = createSendUriIntentWithPreview(uris); |
Matt Pietal | 0ea391b | 2019-01-30 10:44:15 -0500 | [diff] [blame] | 471 | sOverrides.previewThumbnail = createBitmap(); |
Matt Pietal | 46d828c | 2019-02-05 08:07:07 -0500 | [diff] [blame] | 472 | sOverrides.isImageType = true; |
Matt Pietal | 0ea391b | 2019-01-30 10:44:15 -0500 | [diff] [blame] | 473 | |
| 474 | List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2); |
| 475 | |
| 476 | when(sOverrides.resolverListController.getResolversForIntent(Mockito.anyBoolean(), |
| 477 | Mockito.anyBoolean(), |
| 478 | Mockito.isA(List.class))).thenReturn(resolvedComponentInfos); |
| 479 | mActivityRule.launchActivity(Intent.createChooser(sendIntent, null)); |
| 480 | waitForIdle(); |
| 481 | onView(withId(R.id.content_preview_image_1_large)).check(matches(isDisplayed())); |
| 482 | onView(withId(R.id.content_preview_image_2_large)).check(matches(isDisplayed())); |
| 483 | onView(withId(R.id.content_preview_image_2_small)).check(matches(not(isDisplayed()))); |
| 484 | onView(withId(R.id.content_preview_image_3_small)).check(matches(not(isDisplayed()))); |
| 485 | } |
| 486 | |
| 487 | @Test |
| 488 | public void threeOrMoreVisibleImagePreview() throws InterruptedException { |
| 489 | Uri uri = Uri.parse("android.resource://com.android.frameworks.coretests/" |
| 490 | + com.android.frameworks.coretests.R.drawable.test320x240); |
| 491 | |
| 492 | ArrayList<Uri> uris = new ArrayList<>(); |
| 493 | uris.add(uri); |
| 494 | uris.add(uri); |
| 495 | uris.add(uri); |
| 496 | uris.add(uri); |
| 497 | uris.add(uri); |
| 498 | |
Matt Pietal | 46d828c | 2019-02-05 08:07:07 -0500 | [diff] [blame] | 499 | Intent sendIntent = createSendUriIntentWithPreview(uris); |
Matt Pietal | 0ea391b | 2019-01-30 10:44:15 -0500 | [diff] [blame] | 500 | sOverrides.previewThumbnail = createBitmap(); |
Matt Pietal | 46d828c | 2019-02-05 08:07:07 -0500 | [diff] [blame] | 501 | sOverrides.isImageType = true; |
Matt Pietal | 0ea391b | 2019-01-30 10:44:15 -0500 | [diff] [blame] | 502 | |
| 503 | List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2); |
| 504 | |
| 505 | when(sOverrides.resolverListController.getResolversForIntent(Mockito.anyBoolean(), |
Susi Kharraz-Post | 7e2115d | 2019-02-01 16:51:22 -0500 | [diff] [blame] | 506 | Mockito.anyBoolean(), |
| 507 | Mockito.isA(List.class))).thenReturn(resolvedComponentInfos); |
Matt Pietal | 0ea391b | 2019-01-30 10:44:15 -0500 | [diff] [blame] | 508 | mActivityRule.launchActivity(Intent.createChooser(sendIntent, null)); |
| 509 | waitForIdle(); |
| 510 | onView(withId(R.id.content_preview_image_1_large)).check(matches(isDisplayed())); |
| 511 | onView(withId(R.id.content_preview_image_2_large)).check(matches(not(isDisplayed()))); |
| 512 | onView(withId(R.id.content_preview_image_2_small)).check(matches(isDisplayed())); |
| 513 | onView(withId(R.id.content_preview_image_3_small)).check(matches(isDisplayed())); |
| 514 | } |
| 515 | |
Susi Kharraz-Post | 7e2115d | 2019-02-01 16:51:22 -0500 | [diff] [blame] | 516 | @Test |
| 517 | public void testOnCreateLogging() { |
| 518 | Intent sendIntent = createSendTextIntent(); |
| 519 | sendIntent.setType("TestType"); |
| 520 | |
| 521 | MetricsLogger mockLogger = sOverrides.metricsLogger; |
| 522 | ArgumentCaptor<LogMaker> logMakerCaptor = ArgumentCaptor.forClass(LogMaker.class); |
| 523 | mActivityRule.launchActivity(Intent.createChooser(sendIntent, "logger test")); |
| 524 | waitForIdle(); |
| 525 | verify(mockLogger, atLeastOnce()).write(logMakerCaptor.capture()); |
| 526 | assertThat(logMakerCaptor.getAllValues().get(0).getCategory(), |
Susi Kharraz-Post | 0446fab | 2019-02-21 09:42:31 -0500 | [diff] [blame] | 527 | is(MetricsEvent.ACTION_ACTIVITY_CHOOSER_SHOWN)); |
Susi Kharraz-Post | 7e2115d | 2019-02-01 16:51:22 -0500 | [diff] [blame] | 528 | assertThat(logMakerCaptor |
| 529 | .getAllValues().get(0) |
Susi Kharraz-Post | 0446fab | 2019-02-21 09:42:31 -0500 | [diff] [blame] | 530 | .getTaggedData(MetricsEvent.FIELD_TIME_TO_APP_TARGETS), |
Susi Kharraz-Post | 7e2115d | 2019-02-01 16:51:22 -0500 | [diff] [blame] | 531 | is(notNullValue())); |
| 532 | assertThat(logMakerCaptor |
| 533 | .getAllValues().get(0) |
Susi Kharraz-Post | 0446fab | 2019-02-21 09:42:31 -0500 | [diff] [blame] | 534 | .getTaggedData(MetricsEvent.FIELD_SHARESHEET_MIMETYPE), |
Susi Kharraz-Post | 7e2115d | 2019-02-01 16:51:22 -0500 | [diff] [blame] | 535 | is("TestType")); |
Susi Kharraz-Post | 0446fab | 2019-02-21 09:42:31 -0500 | [diff] [blame] | 536 | assertThat(logMakerCaptor |
| 537 | .getAllValues().get(0) |
| 538 | .getSubtype(), |
| 539 | is(MetricsEvent.PARENT_PROFILE)); |
| 540 | } |
| 541 | |
| 542 | @Test |
| 543 | public void testOnCreateLoggingFromWorkProfile() { |
| 544 | Intent sendIntent = createSendTextIntent(); |
| 545 | sendIntent.setType("TestType"); |
| 546 | sOverrides.alternateProfileSetting = MetricsEvent.MANAGED_PROFILE; |
| 547 | MetricsLogger mockLogger = sOverrides.metricsLogger; |
| 548 | ArgumentCaptor<LogMaker> logMakerCaptor = ArgumentCaptor.forClass(LogMaker.class); |
| 549 | mActivityRule.launchActivity(Intent.createChooser(sendIntent, "logger test")); |
| 550 | waitForIdle(); |
| 551 | verify(mockLogger, atLeastOnce()).write(logMakerCaptor.capture()); |
| 552 | assertThat(logMakerCaptor.getAllValues().get(0).getCategory(), |
| 553 | is(MetricsEvent.ACTION_ACTIVITY_CHOOSER_SHOWN)); |
| 554 | assertThat(logMakerCaptor |
| 555 | .getAllValues().get(0) |
| 556 | .getTaggedData(MetricsEvent.FIELD_TIME_TO_APP_TARGETS), |
| 557 | is(notNullValue())); |
| 558 | assertThat(logMakerCaptor |
| 559 | .getAllValues().get(0) |
| 560 | .getTaggedData(MetricsEvent.FIELD_SHARESHEET_MIMETYPE), |
| 561 | is("TestType")); |
| 562 | assertThat(logMakerCaptor |
| 563 | .getAllValues().get(0) |
| 564 | .getSubtype(), |
| 565 | is(MetricsEvent.MANAGED_PROFILE)); |
Susi Kharraz-Post | 7e2115d | 2019-02-01 16:51:22 -0500 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | @Test |
| 569 | public void testEmptyPreviewLogging() { |
| 570 | Intent sendIntent = createSendTextIntentWithPreview(null, null); |
| 571 | |
| 572 | MetricsLogger mockLogger = sOverrides.metricsLogger; |
| 573 | ArgumentCaptor<LogMaker> logMakerCaptor = ArgumentCaptor.forClass(LogMaker.class); |
| 574 | mActivityRule.launchActivity(Intent.createChooser(sendIntent, "empty preview logger test")); |
| 575 | waitForIdle(); |
Matt Pietal | 46d828c | 2019-02-05 08:07:07 -0500 | [diff] [blame] | 576 | |
| 577 | verify(mockLogger, Mockito.times(1)).write(logMakerCaptor.capture()); |
Susi Kharraz-Post | 7e2115d | 2019-02-01 16:51:22 -0500 | [diff] [blame] | 578 | // First invocation is from onCreate |
Matt Pietal | 46d828c | 2019-02-05 08:07:07 -0500 | [diff] [blame] | 579 | assertThat(logMakerCaptor.getAllValues().get(0).getCategory(), |
Susi Kharraz-Post | 0446fab | 2019-02-21 09:42:31 -0500 | [diff] [blame] | 580 | is(MetricsEvent.ACTION_ACTIVITY_CHOOSER_SHOWN)); |
Susi Kharraz-Post | 7e2115d | 2019-02-01 16:51:22 -0500 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | @Test |
| 584 | public void testTitlePreviewLogging() { |
| 585 | Intent sendIntent = createSendTextIntentWithPreview("TestTitle", null); |
| 586 | |
| 587 | MetricsLogger mockLogger = sOverrides.metricsLogger; |
| 588 | ArgumentCaptor<LogMaker> logMakerCaptor = ArgumentCaptor.forClass(LogMaker.class); |
Matt Pietal | 46d828c | 2019-02-05 08:07:07 -0500 | [diff] [blame] | 589 | |
| 590 | List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2); |
| 591 | |
| 592 | when(ChooserWrapperActivity.sOverrides.resolverListController.getResolversForIntent( |
| 593 | Mockito.anyBoolean(), |
| 594 | Mockito.anyBoolean(), |
| 595 | Mockito.isA(List.class))).thenReturn(resolvedComponentInfos); |
| 596 | |
Susi Kharraz-Post | 7e2115d | 2019-02-01 16:51:22 -0500 | [diff] [blame] | 597 | mActivityRule.launchActivity(Intent.createChooser(sendIntent, null)); |
| 598 | waitForIdle(); |
Matt Pietal | 46d828c | 2019-02-05 08:07:07 -0500 | [diff] [blame] | 599 | verify(mockLogger, Mockito.times(3)).write(logMakerCaptor.capture()); |
Susi Kharraz-Post | 7e2115d | 2019-02-01 16:51:22 -0500 | [diff] [blame] | 600 | // First invocation is from onCreate |
| 601 | assertThat(logMakerCaptor.getAllValues().get(1).getCategory(), |
Susi Kharraz-Post | 0446fab | 2019-02-21 09:42:31 -0500 | [diff] [blame] | 602 | is(MetricsEvent.ACTION_SHARE_WITH_PREVIEW)); |
Susi Kharraz-Post | 7e2115d | 2019-02-01 16:51:22 -0500 | [diff] [blame] | 603 | assertThat(logMakerCaptor.getAllValues().get(1).getSubtype(), |
| 604 | is(CONTENT_PREVIEW_TEXT)); |
| 605 | } |
| 606 | |
| 607 | @Test |
| 608 | public void testImagePreviewLogging() { |
| 609 | Uri uri = Uri.parse("android.resource://com.android.frameworks.coretests/" |
| 610 | + com.android.frameworks.coretests.R.drawable.test320x240); |
| 611 | |
| 612 | ArrayList<Uri> uris = new ArrayList<>(); |
| 613 | uris.add(uri); |
| 614 | |
Matt Pietal | 46d828c | 2019-02-05 08:07:07 -0500 | [diff] [blame] | 615 | Intent sendIntent = createSendUriIntentWithPreview(uris); |
Susi Kharraz-Post | 7e2115d | 2019-02-01 16:51:22 -0500 | [diff] [blame] | 616 | sOverrides.previewThumbnail = createBitmap(); |
Matt Pietal | 46d828c | 2019-02-05 08:07:07 -0500 | [diff] [blame] | 617 | sOverrides.isImageType = true; |
Susi Kharraz-Post | 7e2115d | 2019-02-01 16:51:22 -0500 | [diff] [blame] | 618 | |
| 619 | List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2); |
| 620 | |
| 621 | when(sOverrides.resolverListController.getResolversForIntent(Mockito.anyBoolean(), |
| 622 | Mockito.anyBoolean(), |
| 623 | Mockito.isA(List.class))).thenReturn(resolvedComponentInfos); |
| 624 | |
| 625 | MetricsLogger mockLogger = sOverrides.metricsLogger; |
| 626 | ArgumentCaptor<LogMaker> logMakerCaptor = ArgumentCaptor.forClass(LogMaker.class); |
| 627 | mActivityRule.launchActivity(Intent.createChooser(sendIntent, null)); |
| 628 | waitForIdle(); |
| 629 | verify(mockLogger, Mockito.times(3)).write(logMakerCaptor.capture()); |
| 630 | // First invocation is from onCreate |
| 631 | assertThat(logMakerCaptor.getAllValues().get(1).getCategory(), |
Susi Kharraz-Post | 0446fab | 2019-02-21 09:42:31 -0500 | [diff] [blame] | 632 | is(MetricsEvent.ACTION_SHARE_WITH_PREVIEW)); |
Susi Kharraz-Post | 7e2115d | 2019-02-01 16:51:22 -0500 | [diff] [blame] | 633 | assertThat(logMakerCaptor.getAllValues().get(1).getSubtype(), |
| 634 | is(CONTENT_PREVIEW_IMAGE)); |
| 635 | assertThat(logMakerCaptor.getAllValues().get(2).getCategory(), |
Susi Kharraz-Post | 0446fab | 2019-02-21 09:42:31 -0500 | [diff] [blame] | 636 | is(MetricsEvent.ACTION_SHARE_WITH_PREVIEW)); |
Susi Kharraz-Post | 7e2115d | 2019-02-01 16:51:22 -0500 | [diff] [blame] | 637 | assertThat(logMakerCaptor.getAllValues().get(2).getSubtype(), |
| 638 | is(CONTENT_PREVIEW_IMAGE)); |
| 639 | } |
| 640 | |
Matt Pietal | 46d828c | 2019-02-05 08:07:07 -0500 | [diff] [blame] | 641 | @Test |
| 642 | public void oneVisibleFilePreview() throws InterruptedException { |
| 643 | Uri uri = Uri.parse("content://com.android.frameworks.coretests/app.pdf"); |
| 644 | |
| 645 | ArrayList<Uri> uris = new ArrayList<>(); |
| 646 | uris.add(uri); |
| 647 | |
| 648 | Intent sendIntent = createSendUriIntentWithPreview(uris); |
| 649 | |
| 650 | List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2); |
| 651 | |
| 652 | when(sOverrides.resolverListController.getResolversForIntent(Mockito.anyBoolean(), |
| 653 | Mockito.anyBoolean(), |
| 654 | Mockito.isA(List.class))).thenReturn(resolvedComponentInfos); |
| 655 | mActivityRule.launchActivity(Intent.createChooser(sendIntent, null)); |
| 656 | waitForIdle(); |
| 657 | onView(withId(R.id.content_preview_filename)).check(matches(isDisplayed())); |
| 658 | onView(withId(R.id.content_preview_filename)).check(matches(withText("app.pdf"))); |
| 659 | onView(withId(R.id.content_preview_file_icon)).check(matches(isDisplayed())); |
| 660 | } |
| 661 | |
| 662 | |
| 663 | @Test |
| 664 | public void moreThanOneVisibleFilePreview() throws InterruptedException { |
| 665 | Uri uri = Uri.parse("content://com.android.frameworks.coretests/app.pdf"); |
| 666 | |
| 667 | ArrayList<Uri> uris = new ArrayList<>(); |
| 668 | uris.add(uri); |
| 669 | uris.add(uri); |
| 670 | uris.add(uri); |
| 671 | |
| 672 | Intent sendIntent = createSendUriIntentWithPreview(uris); |
| 673 | |
| 674 | List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2); |
| 675 | |
| 676 | when(sOverrides.resolverListController.getResolversForIntent(Mockito.anyBoolean(), |
| 677 | Mockito.anyBoolean(), |
| 678 | Mockito.isA(List.class))).thenReturn(resolvedComponentInfos); |
| 679 | mActivityRule.launchActivity(Intent.createChooser(sendIntent, null)); |
| 680 | waitForIdle(); |
| 681 | onView(withId(R.id.content_preview_filename)).check(matches(isDisplayed())); |
| 682 | onView(withId(R.id.content_preview_filename)).check(matches(withText("app.pdf + 2 files"))); |
| 683 | onView(withId(R.id.content_preview_file_icon)).check(matches(isDisplayed())); |
| 684 | } |
| 685 | |
Matt Pietal | f38e9d2 | 2019-02-15 10:01:03 -0500 | [diff] [blame] | 686 | @Test |
| 687 | public void contentProviderThrowSecurityException() throws InterruptedException { |
| 688 | Uri uri = Uri.parse("content://com.android.frameworks.coretests/app.pdf"); |
| 689 | |
| 690 | ArrayList<Uri> uris = new ArrayList<>(); |
| 691 | uris.add(uri); |
| 692 | |
| 693 | Intent sendIntent = createSendUriIntentWithPreview(uris); |
| 694 | |
| 695 | List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2); |
| 696 | when(sOverrides.resolverListController.getResolversForIntent(Mockito.anyBoolean(), |
| 697 | Mockito.anyBoolean(), |
| 698 | Mockito.isA(List.class))).thenReturn(resolvedComponentInfos); |
| 699 | |
| 700 | sOverrides.resolverForceException = true; |
| 701 | |
| 702 | mActivityRule.launchActivity(Intent.createChooser(sendIntent, null)); |
| 703 | waitForIdle(); |
| 704 | onView(withId(R.id.content_preview_filename)).check(matches(isDisplayed())); |
| 705 | onView(withId(R.id.content_preview_filename)).check(matches(withText("app.pdf"))); |
| 706 | onView(withId(R.id.content_preview_file_icon)).check(matches(isDisplayed())); |
| 707 | } |
| 708 | |
| 709 | @Test |
| 710 | public void contentProviderReturnsNoColumns() throws InterruptedException { |
| 711 | Uri uri = Uri.parse("content://com.android.frameworks.coretests/app.pdf"); |
| 712 | |
| 713 | ArrayList<Uri> uris = new ArrayList<>(); |
| 714 | uris.add(uri); |
| 715 | uris.add(uri); |
| 716 | |
| 717 | Intent sendIntent = createSendUriIntentWithPreview(uris); |
| 718 | |
| 719 | List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2); |
| 720 | when(sOverrides.resolverListController.getResolversForIntent(Mockito.anyBoolean(), |
| 721 | Mockito.anyBoolean(), |
| 722 | Mockito.isA(List.class))).thenReturn(resolvedComponentInfos); |
| 723 | |
| 724 | Cursor cursor = mock(Cursor.class); |
| 725 | when(cursor.getCount()).thenReturn(1); |
| 726 | Mockito.doNothing().when(cursor).close(); |
| 727 | when(cursor.moveToFirst()).thenReturn(true); |
| 728 | when(cursor.getColumnIndex(Mockito.anyString())).thenReturn(-1); |
| 729 | |
| 730 | sOverrides.resolverCursor = cursor; |
| 731 | |
| 732 | mActivityRule.launchActivity(Intent.createChooser(sendIntent, null)); |
| 733 | waitForIdle(); |
| 734 | onView(withId(R.id.content_preview_filename)).check(matches(isDisplayed())); |
| 735 | onView(withId(R.id.content_preview_filename)).check(matches(withText("app.pdf + 1 file"))); |
| 736 | onView(withId(R.id.content_preview_file_icon)).check(matches(isDisplayed())); |
| 737 | } |
| 738 | |
Matt Pietal | 2603840 | 2019-01-08 07:29:34 -0500 | [diff] [blame] | 739 | private Intent createSendTextIntent() { |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 740 | Intent sendIntent = new Intent(); |
| 741 | sendIntent.setAction(Intent.ACTION_SEND); |
| 742 | sendIntent.putExtra(Intent.EXTRA_TEXT, "testing intent sending"); |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 743 | return sendIntent; |
| 744 | } |
| 745 | |
Matt Pietal | 2603840 | 2019-01-08 07:29:34 -0500 | [diff] [blame] | 746 | private Intent createSendTextIntentWithPreview(String title, Uri imageThumbnail) { |
| 747 | Intent sendIntent = new Intent(); |
| 748 | sendIntent.setAction(Intent.ACTION_SEND); |
| 749 | sendIntent.putExtra(Intent.EXTRA_TEXT, "testing intent sending"); |
| 750 | sendIntent.putExtra(Intent.EXTRA_TITLE, title); |
| 751 | if (imageThumbnail != null) { |
| 752 | ClipData.Item clipItem = new ClipData.Item(imageThumbnail); |
| 753 | sendIntent.setClipData(new ClipData("Clip Label", new String[]{"image/png"}, clipItem)); |
| 754 | } |
| 755 | |
| 756 | return sendIntent; |
| 757 | } |
| 758 | |
Matt Pietal | 46d828c | 2019-02-05 08:07:07 -0500 | [diff] [blame] | 759 | private Intent createSendUriIntentWithPreview(ArrayList<Uri> uris) { |
Matt Pietal | 0ea391b | 2019-01-30 10:44:15 -0500 | [diff] [blame] | 760 | Intent sendIntent = new Intent(); |
| 761 | |
| 762 | if (uris.size() > 1) { |
| 763 | sendIntent.setAction(Intent.ACTION_SEND_MULTIPLE); |
| 764 | sendIntent.putExtra(Intent.EXTRA_STREAM, uris); |
| 765 | } else { |
| 766 | sendIntent.setAction(Intent.ACTION_SEND); |
| 767 | sendIntent.putExtra(Intent.EXTRA_STREAM, uris.get(0)); |
| 768 | } |
| 769 | |
| 770 | return sendIntent; |
| 771 | } |
| 772 | |
Matt Pietal | 2603840 | 2019-01-08 07:29:34 -0500 | [diff] [blame] | 773 | private Intent createViewTextIntent() { |
| 774 | Intent viewIntent = new Intent(); |
| 775 | viewIntent.setAction(Intent.ACTION_VIEW); |
| 776 | viewIntent.putExtra(Intent.EXTRA_TEXT, "testing intent viewing"); |
| 777 | return viewIntent; |
| 778 | } |
| 779 | |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 780 | private List<ResolvedComponentInfo> createResolvedComponentsForTest(int numberOfResults) { |
| 781 | List<ResolvedComponentInfo> infoList = new ArrayList<>(numberOfResults); |
| 782 | for (int i = 0; i < numberOfResults; i++) { |
Hakan Seyalioglu | 9149dca | 2017-01-17 12:20:01 -0800 | [diff] [blame] | 783 | infoList.add(ResolverDataProvider.createResolvedComponentInfo(i)); |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 784 | } |
| 785 | return infoList; |
| 786 | } |
| 787 | |
Hakan Seyalioglu | 13405c5 | 2017-01-31 19:01:31 -0800 | [diff] [blame] | 788 | private List<ResolvedComponentInfo> createResolvedComponentsForTestWithOtherProfile( |
| 789 | int numberOfResults) { |
| 790 | List<ResolvedComponentInfo> infoList = new ArrayList<>(numberOfResults); |
| 791 | for (int i = 0; i < numberOfResults; i++) { |
| 792 | if (i == 0) { |
| 793 | infoList.add(ResolverDataProvider.createResolvedComponentInfoWithOtherId(i)); |
| 794 | } else { |
| 795 | infoList.add(ResolverDataProvider.createResolvedComponentInfo(i)); |
| 796 | } |
| 797 | } |
| 798 | return infoList; |
| 799 | } |
| 800 | |
Hakan Seyalioglu | e1276bf | 2016-12-07 16:38:57 -0800 | [diff] [blame] | 801 | private void waitForIdle() { |
| 802 | InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
| 803 | } |
Matt Pietal | 2603840 | 2019-01-08 07:29:34 -0500 | [diff] [blame] | 804 | |
| 805 | private Bitmap createBitmap() { |
| 806 | int width = 200; |
| 807 | int height = 200; |
| 808 | Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); |
| 809 | Canvas canvas = new Canvas(bitmap); |
| 810 | |
| 811 | Paint paint = new Paint(); |
| 812 | paint.setColor(Color.RED); |
| 813 | paint.setStyle(Paint.Style.FILL); |
| 814 | canvas.drawPaint(paint); |
| 815 | |
| 816 | paint.setColor(Color.WHITE); |
| 817 | paint.setAntiAlias(true); |
| 818 | paint.setTextSize(14.f); |
| 819 | paint.setTextAlign(Paint.Align.CENTER); |
| 820 | canvas.drawText("Hi!", (width / 2.f), (height / 2.f), paint); |
| 821 | |
| 822 | return bitmap; |
| 823 | } |
| 824 | } |