Modify test and wrapper for ResolverActivity to run with async loading

Bug: 142659056
Test: This is the test.
Change-Id: I9805cc5f6c14c90c6d9a9b7c30cc3ee1b3ba8085
This commit is contained in:
Zhen Zhang
2019-10-22 14:49:09 -07:00
parent 2da6b815d6
commit cb55c8ad21
2 changed files with 36 additions and 0 deletions

View File

@@ -38,6 +38,7 @@ import android.view.View;
import android.widget.RelativeLayout;
import androidx.test.InstrumentationRegistry;
import androidx.test.espresso.Espresso;
import androidx.test.rule.ActivityTestRule;
import androidx.test.runner.AndroidJUnit4;
@@ -82,6 +83,7 @@ public class ResolverActivityTest {
Mockito.isA(List.class))).thenReturn(resolvedComponentInfos);
final ResolverWrapperActivity activity = mActivityRule.launchActivity(sendIntent);
Espresso.registerIdlingResources(activity.getLabelIdlingResource());
waitForIdle();
assertThat(activity.getAdapter().getCount(), is(2));
@@ -214,6 +216,7 @@ public class ResolverActivityTest {
Mockito.isA(List.class))).thenReturn(resolvedComponentInfos);
final ResolverWrapperActivity activity = mActivityRule.launchActivity(sendIntent);
Espresso.registerIdlingResources(activity.getLabelIdlingResource());
waitForIdle();
// The other entry is filtered to the last used slot
@@ -251,6 +254,7 @@ public class ResolverActivityTest {
Mockito.isA(List.class))).thenReturn(resolvedComponentInfos);
final ResolverWrapperActivity activity = mActivityRule.launchActivity(sendIntent);
Espresso.registerIdlingResources(activity.getLabelIdlingResource());
waitForIdle();
// The other entry is filtered to the other profile slot
@@ -296,6 +300,7 @@ public class ResolverActivityTest {
.thenReturn(resolvedComponentInfos.get(1).getResolveInfoAt(0));
final ResolverWrapperActivity activity = mActivityRule.launchActivity(sendIntent);
Espresso.registerIdlingResources(activity.getLabelIdlingResource());
waitForIdle();
// The other entry is filtered to the other profile slot

View File

@@ -21,6 +21,8 @@ import static org.mockito.Mockito.mock;
import android.app.usage.UsageStatsManager;
import android.content.pm.PackageManager;
import androidx.test.espresso.idling.CountingIdlingResource;
import java.util.function.Function;
/*
@@ -29,6 +31,12 @@ import java.util.function.Function;
public class ResolverWrapperActivity extends ResolverActivity {
static final OverrideData sOverrides = new OverrideData();
private UsageStatsManager mUsm;
private CountingIdlingResource mLabelIdlingResource =
new CountingIdlingResource("LoadLabelTask");
public CountingIdlingResource getLabelIdlingResource() {
return mLabelIdlingResource;
}
ResolveListAdapter getAdapter() {
return mAdapter;
@@ -64,6 +72,11 @@ public class ResolverWrapperActivity extends ResolverActivity {
return super.getPackageManager();
}
@Override
protected LoadLabelTask getLoadLabelTask(DisplayResolveInfo info, ViewHolder holder) {
return new LoadLabelWrapperTask(info, holder);
}
/**
* We cannot directly mock the activity created since instrumentation creates it.
* <p>
@@ -83,4 +96,22 @@ public class ResolverWrapperActivity extends ResolverActivity {
resolverListController = mock(ResolverListController.class);
}
}
class LoadLabelWrapperTask extends LoadLabelTask {
protected LoadLabelWrapperTask(DisplayResolveInfo dri, ViewHolder holder) {
super(dri, holder);
}
@Override
protected void onPreExecute() {
mLabelIdlingResource.increment();
}
@Override
protected void onPostExecute(CharSequence[] result) {
super.onPostExecute(result);
mLabelIdlingResource.decrement();
}
}
}