Merge "Add test for tapping Work share tab when work profile is off" into rvc-dev am: 8f27cd8e55
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11734120 Change-Id: I1cc5c0029d53a7c1b7a6ef6e86d8c1b4d25ff4bf
This commit is contained in:
@@ -1809,7 +1809,8 @@ public class ChooserActivity extends ResolverActivity implements
|
||||
}
|
||||
}
|
||||
|
||||
void queryTargetServices(ChooserListAdapter adapter) {
|
||||
@VisibleForTesting
|
||||
protected void queryTargetServices(ChooserListAdapter adapter) {
|
||||
mQueriedTargetServicesTimeMs = System.currentTimeMillis();
|
||||
|
||||
Context selectedProfileContext = createContextAsUser(
|
||||
@@ -1962,7 +1963,8 @@ public class ChooserActivity extends ResolverActivity implements
|
||||
return driList;
|
||||
}
|
||||
|
||||
private void queryDirectShareTargets(
|
||||
@VisibleForTesting
|
||||
protected void queryDirectShareTargets(
|
||||
ChooserListAdapter adapter, boolean skipAppPredictionService) {
|
||||
mQueriedSharingShortcutsTimeMs = System.currentTimeMillis();
|
||||
UserHandle userHandle = adapter.getUserHandle();
|
||||
|
||||
@@ -34,9 +34,11 @@ import static com.android.internal.app.ChooserListAdapter.SHORTCUT_TARGET_SCORE_
|
||||
import static com.android.internal.app.ChooserWrapperActivity.sOverrides;
|
||||
import static com.android.internal.app.MatcherUtils.first;
|
||||
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.allOf;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
@@ -1327,7 +1329,6 @@ public class ChooserActivityTest {
|
||||
assertThat(activity.getWorkListAdapter().getCount(), is(workProfileTargets));
|
||||
}
|
||||
|
||||
@Ignore // b/148156663
|
||||
@Test
|
||||
public void testWorkTab_selectingWorkTabAppOpensAppInWorkProfile() throws InterruptedException {
|
||||
// enable the work tab feature flag
|
||||
@@ -1354,8 +1355,10 @@ public class ChooserActivityTest {
|
||||
// wait for the share sheet to expand
|
||||
Thread.sleep(ChooserActivity.LIST_VIEW_UPDATE_INTERVAL_IN_MILLIS);
|
||||
|
||||
onView(first(withText(workResolvedComponentInfos.get(0)
|
||||
.getResolveInfoAt(0).activityInfo.applicationInfo.name)))
|
||||
onView(first(allOf(
|
||||
withText(workResolvedComponentInfos.get(0)
|
||||
.getResolveInfoAt(0).activityInfo.applicationInfo.name),
|
||||
isDisplayed())))
|
||||
.perform(click());
|
||||
waitForIdle();
|
||||
assertThat(chosen[0], is(workResolvedComponentInfos.get(0).getResolveInfoAt(0)));
|
||||
@@ -1953,6 +1956,45 @@ public class ChooserActivityTest {
|
||||
assertThat(activity.getAdapter().getRankedTargetCount(), is(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWorkTab_selectingWorkTabWithPausedWorkProfile_directShareTargetsNotQueried() {
|
||||
// enable the work tab feature flag
|
||||
ResolverActivity.ENABLE_TABBED_VIEW = true;
|
||||
markWorkProfileUserAvailable();
|
||||
List<ResolvedComponentInfo> personalResolvedComponentInfos =
|
||||
createResolvedComponentsForTestWithOtherProfile(3, /* userId */ 10);
|
||||
List<ResolvedComponentInfo> workResolvedComponentInfos =
|
||||
createResolvedComponentsForTest(3);
|
||||
setupResolverControllers(personalResolvedComponentInfos, workResolvedComponentInfos);
|
||||
sOverrides.isQuietModeEnabled = true;
|
||||
boolean[] isQueryDirectShareCalledOnWorkProfile = new boolean[] { false };
|
||||
sOverrides.onQueryDirectShareTargets = chooserListAdapter -> {
|
||||
isQueryDirectShareCalledOnWorkProfile[0] =
|
||||
(chooserListAdapter.getUserHandle().getIdentifier() == 10);
|
||||
return null;
|
||||
};
|
||||
boolean[] isQueryTargetServicesCalledOnWorkProfile = new boolean[] { false };
|
||||
sOverrides.onQueryTargetServices = chooserListAdapter -> {
|
||||
isQueryTargetServicesCalledOnWorkProfile[0] =
|
||||
(chooserListAdapter.getUserHandle().getIdentifier() == 10);
|
||||
return null;
|
||||
};
|
||||
Intent sendIntent = createSendTextIntent();
|
||||
sendIntent.setType("TestType");
|
||||
|
||||
mActivityRule.launchActivity(Intent.createChooser(sendIntent, "work tab test"));
|
||||
waitForIdle();
|
||||
onView(withId(R.id.contentPanel))
|
||||
.perform(swipeUp());
|
||||
onView(withText(R.string.resolver_work_tab)).perform(click());
|
||||
waitForIdle();
|
||||
|
||||
assertFalse("Direct share targets were queried on a paused work profile",
|
||||
isQueryDirectShareCalledOnWorkProfile[0]);
|
||||
assertFalse("Target services were queried on a paused work profile",
|
||||
isQueryTargetServicesCalledOnWorkProfile[0]);
|
||||
}
|
||||
|
||||
private Intent createChooserIntent(Intent intent, Intent[] initialIntents) {
|
||||
Intent chooserIntent = new Intent();
|
||||
chooserIntent.setAction(Intent.ACTION_CHOOSER);
|
||||
|
||||
@@ -205,6 +205,23 @@ public class ChooserWrapperActivity extends ChooserActivity {
|
||||
return getApplicationContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void queryDirectShareTargets(ChooserListAdapter adapter,
|
||||
boolean skipAppPredictionService) {
|
||||
if (sOverrides.onQueryDirectShareTargets != null) {
|
||||
sOverrides.onQueryDirectShareTargets.apply(adapter);
|
||||
}
|
||||
super.queryDirectShareTargets(adapter, skipAppPredictionService);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void queryTargetServices(ChooserListAdapter adapter) {
|
||||
if (sOverrides.onQueryTargetServices != null) {
|
||||
sOverrides.onQueryTargetServices.apply(adapter);
|
||||
}
|
||||
super.queryTargetServices(adapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* We cannot directly mock the activity created since instrumentation creates it.
|
||||
* <p>
|
||||
@@ -214,6 +231,8 @@ public class ChooserWrapperActivity extends ChooserActivity {
|
||||
@SuppressWarnings("Since15")
|
||||
public Function<PackageManager, PackageManager> createPackageManager;
|
||||
public Function<TargetInfo, Boolean> onSafelyStartCallback;
|
||||
public Function<ChooserListAdapter, Void> onQueryDirectShareTargets;
|
||||
public Function<ChooserListAdapter, Void> onQueryTargetServices;
|
||||
public ResolverListController resolverListController;
|
||||
public ResolverListController workResolverListController;
|
||||
public Boolean isVoiceInteraction;
|
||||
@@ -233,6 +252,8 @@ public class ChooserWrapperActivity extends ChooserActivity {
|
||||
|
||||
public void reset() {
|
||||
onSafelyStartCallback = null;
|
||||
onQueryDirectShareTargets = null;
|
||||
onQueryTargetServices = null;
|
||||
isVoiceInteraction = null;
|
||||
createPackageManager = null;
|
||||
previewThumbnail = null;
|
||||
|
||||
@@ -592,7 +592,6 @@ public class ResolverActivityTest {
|
||||
TextUtils.equals(initialText, currentText));
|
||||
}
|
||||
|
||||
@Ignore // b/148156663
|
||||
@Test
|
||||
public void testWorkTab_noPersonalApps_canStartWorkApps()
|
||||
throws InterruptedException {
|
||||
@@ -617,8 +616,10 @@ public class ResolverActivityTest {
|
||||
waitForIdle();
|
||||
// wait for the share sheet to expand
|
||||
Thread.sleep(ChooserActivity.LIST_VIEW_UPDATE_INTERVAL_IN_MILLIS);
|
||||
onView(first(allOf(withText(workResolvedComponentInfos.get(0)
|
||||
.getResolveInfoAt(0).activityInfo.applicationInfo.name), isCompletelyDisplayed())))
|
||||
onView(first(allOf(
|
||||
withText(workResolvedComponentInfos.get(0)
|
||||
.getResolveInfoAt(0).activityInfo.applicationInfo.name),
|
||||
isDisplayed())))
|
||||
.perform(click());
|
||||
onView(withId(R.id.button_once))
|
||||
.perform(click());
|
||||
|
||||
Reference in New Issue
Block a user