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

Commit 7ad8ff21 authored by Ben Reich's avatar Ben Reich
Browse files

Migrate SearchViewUiTest to JUnit 4 for upcoming test addition

An upcoming change requires JUnit 4 to be used to filter tests, migrate
the underlying class as a precursor to this change to avoid having the
change contain unnecessary updates.

Bug: 405288522
Test: atest com.android.documentsui.SearchViewUiTest
Flag: com.android.documentsui.flags.use_material3
Change-Id: Ibadfaae7fb933cf3a8cdf97467e0ae035968f5c7
parent 51e193f3
Loading
Loading
Loading
Loading
+47 −6
Original line number Diff line number Diff line
@@ -18,21 +18,33 @@ package com.android.documentsui;

import static com.android.documentsui.StubProvider.ROOT_0_ID;
import static com.android.documentsui.StubProvider.ROOT_1_ID;
import static com.android.documentsui.flags.Flags.FLAG_USE_MATERIAL3;

import static org.junit.Assert.assertFalse;

import android.platform.test.annotations.RequiresFlagsDisabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;

import androidx.test.filters.LargeTest;
import androidx.test.filters.Suppress;
import androidx.test.uiautomator.UiObjectNotFoundException;

import com.android.documentsui.files.FilesActivity;
import com.android.documentsui.filters.HugeLongTest;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

@LargeTest
public class SearchViewUiTest extends ActivityTest<FilesActivity> {
public class SearchViewUiTest extends ActivityTestJunit4<FilesActivity> {

    public SearchViewUiTest() {
        super(FilesActivity.class);
    }
    @Rule
    public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();

    @Override
    @Before
    public void setUp() throws Exception {
      super.setUp();
      initTestFiles();
@@ -43,7 +55,7 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
      bots.directory.waitForDocument(fileName1);
    }

    @Override
    @After
    public void tearDown() throws Exception {
        // manually close activity to avoid SearchFragment show when Activity close. ref b/142840883
        device.waitForIdle();
@@ -53,12 +65,28 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
        super.tearDown();
    }

    private void assertDefaultContentOfTestDir0() throws UiObjectNotFoundException {
        bots.directory.waitForDocument(fileName1);
        bots.directory.waitForDocument(fileName2);
        bots.directory.waitForDocument(dirName1);
        bots.directory.waitForDocument(fileNameNoRename);
        bots.directory.assertDocumentsCount(4);
    }

    private void assertDefaultContentOfTestDir1() throws UiObjectNotFoundException {
        bots.directory.waitForDocument(fileName3);
        bots.directory.waitForDocument(fileName4);
        bots.directory.assertDocumentsCount(2);
    }

    @Test
    public void testSearchIconVisible() throws Exception {
        // The default root (root 0) supports search
        bots.search.assertInputExists(false);
        bots.search.assertIconVisible(true);
    }

    @Test
    @HugeLongTest
    public void testSearchIconHidden() throws Exception {
        bots.roots.openRoot(ROOT_1_ID);  // root 1 doesn't support search
@@ -67,6 +95,7 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
        bots.search.assertInputExists(false);
    }

    @Test
    public void testSearchView_ExpandsOnClick() throws Exception {
        bots.search.clickIcon();
        device.waitForIdle();
@@ -78,6 +107,8 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
        // bots.search.assertIconVisible(false);
    }

    @Test
    @RequiresFlagsDisabled({FLAG_USE_MATERIAL3}) // Enable when b/397315793 is fixed.
    public void testSearchView_ShouldHideOptionMenuOnExpanding() throws Exception {
        bots.search.clickIcon();
        device.waitForIdle();
@@ -91,6 +122,7 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
        assertFalse(bots.menu.hasMenuItemByDesc("More options"));
    }

    @Test
    public void testSearchView_CollapsesOnBack() throws Exception {
        bots.search.clickIcon();
        device.pressBack();
@@ -99,6 +131,7 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
        bots.search.assertInputExists(false);
    }

    @Test
    public void testSearchFragment_DismissedOnCloseAfterCancel() throws Exception {
        bots.search.clickIcon();
        bots.search.setInputText("query text");
@@ -116,6 +149,7 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
        bots.search.assertSearchHistoryVisible(false);
    }

    @Test
    public void testSearchView_ClearsTextOnBack() throws Exception {
        bots.search.clickIcon();
        bots.search.setInputText("file2");
@@ -130,6 +164,7 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
        bots.search.assertInputExists(false);
    }

    @Test
    public void testSearchView_ClearsSearchOnBack() throws Exception {
        bots.search.clickIcon();
        bots.search.setInputText("file1");
@@ -142,6 +177,7 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
        bots.search.assertInputExists(false);
    }

    @Test
    public void testSearchView_ClearsAutoSearchOnBack() throws Exception {
        bots.search.clickIcon();
        bots.search.setInputText("chocolate");
@@ -155,6 +191,7 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
        bots.search.assertInputExists(false);
    }

    @Test
    public void testSearchView_StateAfterSearch() throws Exception {
        bots.search.clickIcon();
        bots.search.setInputText("file1");
@@ -164,6 +201,7 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
        bots.search.assertInputEquals("file1");
    }

    @Test
    public void testSearch_ResultsFound() throws Exception {
        bots.search.clickIcon();
        bots.search.setInputText("file1");
@@ -173,6 +211,7 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
        bots.directory.assertDocumentsPresent(fileName1, fileName2);
    }

    @Test
    public void testSearch_NoResults() throws Exception {
        bots.search.clickIcon();
        bots.search.setInputText("chocolate");
@@ -231,6 +270,7 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
        assertDefaultContentOfTestDir0();
    }

    @Test
    public void testSearchHistory_showAfterSearchViewClear() throws Exception {
        bots.search.clickIcon();
        bots.search.setInputText("chocolate");
@@ -246,6 +286,7 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
        bots.search.assertSearchHistoryVisible(true);
    }

    @Test
    public void testSearchView_focusClearedAfterSelectingSearchHistory() throws Exception {
        String queryText = "history";
        bots.search.clickIcon();