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

Commit 7a4fa239 authored by Ben Lin's avatar Ben Lin
Browse files

Fix running small/medium tests on ARC++ devices.

A lot of our unit tests does not respect Features flag. This CL will
make it so tests now toggle features on/off depending on the config overlay.

Bug: 37358647
Change-Id: I13798c112eb6ff1009aa43b2b5d154e4cd7f9912
parent 3b987ccd
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -19,12 +19,10 @@ package com.android.documentsui.testing;
import android.content.Intent;

import com.android.documentsui.AbstractActionHandler;
import com.android.documentsui.ActionHandler;
import com.android.documentsui.TestActivity;
import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.RootInfo;
import com.android.documentsui.dirlist.DocumentDetails;
import com.android.documentsui.Model;

import java.util.function.Consumer;

+7 −2
Original line number Diff line number Diff line
@@ -15,13 +15,16 @@
 */
package com.android.documentsui.testing;

import android.content.Context;
import android.provider.DocumentsContract.Document;
import android.support.test.InstrumentationRegistry;
import android.test.mock.MockContentResolver;

import com.android.documentsui.FocusManager;
import com.android.documentsui.Injector;
import com.android.documentsui.archives.ArchivesProvider;
import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.Features;
import com.android.documentsui.base.RootInfo;
import com.android.documentsui.base.State;
import com.android.documentsui.dirlist.TestFocusHandler;
@@ -64,7 +67,7 @@ public class TestEnv {
    public final SelectionManager selectionMgr;
    public final TestSearchViewManager searchViewManager;
    public final Injector injector;
    public final TestFeatures features;
    public final Features features;

    public final MockContentResolver contentResolver;
    public final Map<String, TestDocumentsProvider> providers;
@@ -72,7 +75,9 @@ public class TestEnv {
    private TestEnv(String authority) {
        state.sortModel = SortModel.createModel();
        mExecutor = new TestScheduledExecutorService();
        features = new TestFeatures();
        features = new Features.RuntimeFeatures(
                InstrumentationRegistry.getInstrumentation().getTargetContext().getResources(),
                null);
        model = new TestModel(authority, features);
        archiveModel = new TestModel(ArchivesProvider.AUTHORITY, features);
        selectionMgr = SelectionManagers.createTestInstance();
+13 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static junit.framework.Assert.assertTrue;

import static org.junit.Assert.assertEquals;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Parcelable;
@@ -107,6 +108,10 @@ public class AbstractActionHandlerTest {

    @Test
    public void testOpensContainerDocuments_jumpToNewLocation() throws Exception {
        if (!mEnv.features.isLaunchToDocumentEnabled()) {
            return;
        }

        mEnv.populateStack();

        mEnv.searchViewManager.isSearching = true;
@@ -154,6 +159,10 @@ public class AbstractActionHandlerTest {

    @Test
    public void testLaunchToDocuments() throws Exception {
        if (!mEnv.features.isLaunchToDocumentEnabled()) {
            return;
        }

        mEnv.docs.nextIsDocumentsUri = true;
        mEnv.docs.nextPath = new Path(
                TestProvidersAccess.HOME.rootId,
@@ -176,6 +185,10 @@ public class AbstractActionHandlerTest {

    @Test
    public void testLaunchToDocuments_convertsTreeUriToDocumentUri() throws Exception {
        if (!mEnv.features.isLaunchToDocumentEnabled()) {
            return;
        }

        mEnv.docs.nextIsDocumentsUri = true;
        mEnv.docs.nextPath = new Path(
                TestProvidersAccess.HOME.rootId,
+20 −3
Original line number Diff line number Diff line
@@ -214,6 +214,10 @@ public class ActionHandlerTest {

    @Test
    public void testShareSelectedDocuments_VirtualFiles() {
        if (!mEnv.features.isVirtualFilesSharingEnabled()) {
            return;
        }

        mActivity.resources.strings.put(R.string.share_via, "Sharezilla!");
        mEnv.selectionMgr.clearSelection();
        mEnv.selectDocument(TestEnv.FILE_VIRTUAL);
@@ -235,9 +239,14 @@ public class ActionHandlerTest {

        Intent intent = assertHasExtraIntent(mActivity.startActivity.getLastValue());
        assertHasAction(intent, Intent.ACTION_SEND_MULTIPLE);
        assertTrue(intent.hasCategory(Intent.CATEGORY_TYPED_OPENABLE));

        assertFalse(intent.hasCategory(Intent.CATEGORY_OPENABLE));
        if (mEnv.features.isVirtualFilesSharingEnabled()) {
            assertTrue(intent.hasCategory(Intent.CATEGORY_TYPED_OPENABLE));
            assertHasExtraList(intent, Intent.EXTRA_STREAM, 3);
        }else {
            assertHasExtraList(intent, Intent.EXTRA_STREAM, 2);
        }
    }

    @Test
@@ -365,6 +374,10 @@ public class ActionHandlerTest {

    @Test
    public void testInitLocation_LaunchToDocuments() throws Exception {
        if (!mEnv.features.isLaunchToDocumentEnabled()) {
            return;
        }

        mEnv.docs.nextIsDocumentsUri = true;
        mEnv.docs.nextPath = new Path(
                TestProvidersAccess.HOME.rootId,
@@ -452,7 +465,11 @@ public class ActionHandlerTest {
        });

        mEnv.beforeAsserts();
        if (mEnv.features.isContentRefreshEnabled()) {
            assertTrue(refreshAnswer);
        } else {
            assertFalse(refreshAnswer);
        }
    }

    private void assertRootPicked(Uri expectedUri) throws Exception {
+4 −0
Original line number Diff line number Diff line
@@ -110,6 +110,10 @@ public class ActionHandlerTest {

    @Test
    public void testInitLocation_LaunchToDocuments() throws Exception {
        if (!mEnv.features.isLaunchToDocumentEnabled()) {
            return;
        }

        mEnv.docs.nextIsDocumentsUri = true;
        mEnv.docs.nextPath = new Path(
                TestProvidersAccess.HOME.rootId,