Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cb55c8ad authored by Zhen Zhang's avatar Zhen Zhang
Browse files

Modify test and wrapper for ResolverActivity to run with async loading

Bug: 142659056
Test: This is the test.
Change-Id: I9805cc5f6c14c90c6d9a9b7c30cc3ee1b3ba8085
parent 2da6b815
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -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
+31 −0
Original line number Diff line number Diff line
@@ -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();
        }
    }
}
 No newline at end of file