Merge "Add test for tapping Work share tab when work profile is off" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
8f27cd8e55
@@ -1809,7 +1809,8 @@ public class ChooserActivity extends ResolverActivity implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void queryTargetServices(ChooserListAdapter adapter) {
|
@VisibleForTesting
|
||||||
|
protected void queryTargetServices(ChooserListAdapter adapter) {
|
||||||
mQueriedTargetServicesTimeMs = System.currentTimeMillis();
|
mQueriedTargetServicesTimeMs = System.currentTimeMillis();
|
||||||
|
|
||||||
Context selectedProfileContext = createContextAsUser(
|
Context selectedProfileContext = createContextAsUser(
|
||||||
@@ -1962,7 +1963,8 @@ public class ChooserActivity extends ResolverActivity implements
|
|||||||
return driList;
|
return driList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void queryDirectShareTargets(
|
@VisibleForTesting
|
||||||
|
protected void queryDirectShareTargets(
|
||||||
ChooserListAdapter adapter, boolean skipAppPredictionService) {
|
ChooserListAdapter adapter, boolean skipAppPredictionService) {
|
||||||
mQueriedSharingShortcutsTimeMs = System.currentTimeMillis();
|
mQueriedSharingShortcutsTimeMs = System.currentTimeMillis();
|
||||||
UserHandle userHandle = adapter.getUserHandle();
|
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.ChooserWrapperActivity.sOverrides;
|
||||||
import static com.android.internal.app.MatcherUtils.first;
|
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.assertNull;
|
||||||
import static junit.framework.Assert.assertTrue;
|
import static junit.framework.Assert.assertTrue;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.allOf;
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.hamcrest.CoreMatchers.not;
|
import static org.hamcrest.CoreMatchers.not;
|
||||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||||
@@ -1327,7 +1329,6 @@ public class ChooserActivityTest {
|
|||||||
assertThat(activity.getWorkListAdapter().getCount(), is(workProfileTargets));
|
assertThat(activity.getWorkListAdapter().getCount(), is(workProfileTargets));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore // b/148156663
|
|
||||||
@Test
|
@Test
|
||||||
public void testWorkTab_selectingWorkTabAppOpensAppInWorkProfile() throws InterruptedException {
|
public void testWorkTab_selectingWorkTabAppOpensAppInWorkProfile() throws InterruptedException {
|
||||||
// enable the work tab feature flag
|
// enable the work tab feature flag
|
||||||
@@ -1354,8 +1355,10 @@ public class ChooserActivityTest {
|
|||||||
// wait for the share sheet to expand
|
// wait for the share sheet to expand
|
||||||
Thread.sleep(ChooserActivity.LIST_VIEW_UPDATE_INTERVAL_IN_MILLIS);
|
Thread.sleep(ChooserActivity.LIST_VIEW_UPDATE_INTERVAL_IN_MILLIS);
|
||||||
|
|
||||||
onView(first(withText(workResolvedComponentInfos.get(0)
|
onView(first(allOf(
|
||||||
.getResolveInfoAt(0).activityInfo.applicationInfo.name)))
|
withText(workResolvedComponentInfos.get(0)
|
||||||
|
.getResolveInfoAt(0).activityInfo.applicationInfo.name),
|
||||||
|
isDisplayed())))
|
||||||
.perform(click());
|
.perform(click());
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
assertThat(chosen[0], is(workResolvedComponentInfos.get(0).getResolveInfoAt(0)));
|
assertThat(chosen[0], is(workResolvedComponentInfos.get(0).getResolveInfoAt(0)));
|
||||||
@@ -1953,6 +1956,45 @@ public class ChooserActivityTest {
|
|||||||
assertThat(activity.getAdapter().getRankedTargetCount(), is(3));
|
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) {
|
private Intent createChooserIntent(Intent intent, Intent[] initialIntents) {
|
||||||
Intent chooserIntent = new Intent();
|
Intent chooserIntent = new Intent();
|
||||||
chooserIntent.setAction(Intent.ACTION_CHOOSER);
|
chooserIntent.setAction(Intent.ACTION_CHOOSER);
|
||||||
|
|||||||
@@ -205,6 +205,23 @@ public class ChooserWrapperActivity extends ChooserActivity {
|
|||||||
return getApplicationContext();
|
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.
|
* We cannot directly mock the activity created since instrumentation creates it.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -214,6 +231,8 @@ public class ChooserWrapperActivity extends ChooserActivity {
|
|||||||
@SuppressWarnings("Since15")
|
@SuppressWarnings("Since15")
|
||||||
public Function<PackageManager, PackageManager> createPackageManager;
|
public Function<PackageManager, PackageManager> createPackageManager;
|
||||||
public Function<TargetInfo, Boolean> onSafelyStartCallback;
|
public Function<TargetInfo, Boolean> onSafelyStartCallback;
|
||||||
|
public Function<ChooserListAdapter, Void> onQueryDirectShareTargets;
|
||||||
|
public Function<ChooserListAdapter, Void> onQueryTargetServices;
|
||||||
public ResolverListController resolverListController;
|
public ResolverListController resolverListController;
|
||||||
public ResolverListController workResolverListController;
|
public ResolverListController workResolverListController;
|
||||||
public Boolean isVoiceInteraction;
|
public Boolean isVoiceInteraction;
|
||||||
@@ -233,6 +252,8 @@ public class ChooserWrapperActivity extends ChooserActivity {
|
|||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
onSafelyStartCallback = null;
|
onSafelyStartCallback = null;
|
||||||
|
onQueryDirectShareTargets = null;
|
||||||
|
onQueryTargetServices = null;
|
||||||
isVoiceInteraction = null;
|
isVoiceInteraction = null;
|
||||||
createPackageManager = null;
|
createPackageManager = null;
|
||||||
previewThumbnail = null;
|
previewThumbnail = null;
|
||||||
|
|||||||
@@ -592,7 +592,6 @@ public class ResolverActivityTest {
|
|||||||
TextUtils.equals(initialText, currentText));
|
TextUtils.equals(initialText, currentText));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore // b/148156663
|
|
||||||
@Test
|
@Test
|
||||||
public void testWorkTab_noPersonalApps_canStartWorkApps()
|
public void testWorkTab_noPersonalApps_canStartWorkApps()
|
||||||
throws InterruptedException {
|
throws InterruptedException {
|
||||||
@@ -617,8 +616,10 @@ public class ResolverActivityTest {
|
|||||||
waitForIdle();
|
waitForIdle();
|
||||||
// wait for the share sheet to expand
|
// wait for the share sheet to expand
|
||||||
Thread.sleep(ChooserActivity.LIST_VIEW_UPDATE_INTERVAL_IN_MILLIS);
|
Thread.sleep(ChooserActivity.LIST_VIEW_UPDATE_INTERVAL_IN_MILLIS);
|
||||||
onView(first(allOf(withText(workResolvedComponentInfos.get(0)
|
onView(first(allOf(
|
||||||
.getResolveInfoAt(0).activityInfo.applicationInfo.name), isCompletelyDisplayed())))
|
withText(workResolvedComponentInfos.get(0)
|
||||||
|
.getResolveInfoAt(0).activityInfo.applicationInfo.name),
|
||||||
|
isDisplayed())))
|
||||||
.perform(click());
|
.perform(click());
|
||||||
onView(withId(R.id.button_once))
|
onView(withId(R.id.button_once))
|
||||||
.perform(click());
|
.perform(click());
|
||||||
|
|||||||
Reference in New Issue
Block a user