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

Commit 02416de3 authored by Abodunrinwa Toki's avatar Abodunrinwa Toki
Browse files

Ensure that TextViewActivityTest still pass for the new system toolbar.

The tests pass for both the old (local) and system toolbars.

Bug: 190031097
Test: atest android.widget.TextViewActivityTes
Change-Id: I1542d966d363c4a8bd2ac9465c982b82019472d7
parent 2ccaf53c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1318,6 +1318,7 @@ final class RemoteSelectionToolbar {
        contentContainer.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        contentContainer.setTag(FloatingToolbar.FLOATING_TOOLBAR_TAG);
        contentContainer.setContentDescription(FloatingToolbar.FLOATING_TOOLBAR_TAG);
        contentContainer.setClipToOutline(true);
        return contentContainer;
    }
+1 −0
Original line number Diff line number Diff line
@@ -1475,6 +1475,7 @@ public final class LocalFloatingToolbarPopup implements FloatingToolbarPopup {
        contentContainer.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        contentContainer.setTag(FloatingToolbar.FLOATING_TOOLBAR_TAG);
        contentContainer.setContentDescription(FloatingToolbar.FLOATING_TOOLBAR_TAG);
        contentContainer.setClipToOutline(true);
        return contentContainer;
    }
+102 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.widget;

import static com.android.internal.widget.floatingtoolbar.FloatingToolbar.FLOATING_TOOLBAR_TAG;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;

import android.content.res.Resources;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.Until;

import androidx.test.InstrumentationRegistry;

import com.android.internal.R;

final class FloatingToolbarUtils {

    private final UiDevice mDevice;

    FloatingToolbarUtils() {
        mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
    }

    void waitForFloatingToolbarPopup() {
        mDevice.wait(Until.findObject(By.desc(FLOATING_TOOLBAR_TAG)), 500);
    }

    void assertFloatingToolbarIsDisplayed() {
        waitForFloatingToolbarPopup();
        assertThat(mDevice.hasObject(By.desc(FLOATING_TOOLBAR_TAG))).isTrue();
    }

    void assertFloatingToolbarContainsItem(String itemLabel) {
        waitForFloatingToolbarPopup();
        assertWithMessage("Expected to find item labelled [" + itemLabel + "]")
                .that(mDevice.hasObject(
                        By.desc(FLOATING_TOOLBAR_TAG).hasDescendant(By.text(itemLabel))))
                .isTrue();
    }

    void assertFloatingToolbarDoesNotContainItem(String itemLabel) {
        waitForFloatingToolbarPopup();
        assertWithMessage("Expected to not find item labelled [" + itemLabel + "]")
                .that(mDevice.hasObject(
                        By.desc(FLOATING_TOOLBAR_TAG).hasDescendant(By.text(itemLabel))))
                .isFalse();
    }

    void assertFloatingToolbarContainsItemAtIndex(String itemLabel, int index) {
        waitForFloatingToolbarPopup();
        assertWithMessage("Expected to find item labelled [" + itemLabel + "] at index " + index)
                .that(mDevice.findObject(By.desc(FLOATING_TOOLBAR_TAG))
                        .findObjects(By.clickable(true))
                        .get(index)
                        .getChildren()
                        .get(1)
                        .getText())
                .isEqualTo(itemLabel);
    }

    void clickFloatingToolbarItem(String label) {
        waitForFloatingToolbarPopup();
        mDevice.findObject(By.desc(FLOATING_TOOLBAR_TAG))
                .findObject(By.text(label))
                .click();
    }

    void clickFloatingToolbarOverflowItem(String label) {
        // TODO: There might be a benefit to combining this with "clickFloatingToolbarItem" method.
        waitForFloatingToolbarPopup();
        mDevice.findObject(By.desc(FLOATING_TOOLBAR_TAG))
                .findObject(By.desc(str(R.string.floating_toolbar_open_overflow_description)))
                .click();
        mDevice.wait(
                Until.findObject(By.desc(FLOATING_TOOLBAR_TAG).hasDescendant(By.text(label))),
                1000);
        mDevice.findObject(By.desc(FLOATING_TOOLBAR_TAG))
                .findObject(By.text(label))
                .click();
    }

    private static String str(int id) {
        return Resources.getSystem().getString(id);
    }
}
+5 −13
Original line number Diff line number Diff line
@@ -17,9 +17,6 @@
package android.widget;

import static android.widget.espresso.DragHandleUtils.onHandleView;
import static android.widget.espresso.FloatingToolbarEspressoUtils.assertFloatingToolbarContainsItem;
import static android.widget.espresso.FloatingToolbarEspressoUtils.clickFloatingToolbarItem;
import static android.widget.espresso.FloatingToolbarEspressoUtils.sleepForFloatingToolbarPopup;
import static android.widget.espresso.SuggestionsPopupwindowUtils.assertSuggestionsPopupContainsItem;
import static android.widget.espresso.SuggestionsPopupwindowUtils.assertSuggestionsPopupIsDisplayed;
import static android.widget.espresso.SuggestionsPopupwindowUtils.assertSuggestionsPopupIsNotDisplayed;
@@ -72,6 +69,7 @@ public class SuggestionsPopupWindowTest {
    @Rule
    public final ActivityTestRule<TextViewActivity> mActivityRule =
            new ActivityTestRule<>(TextViewActivity.class);
    private final FloatingToolbarUtils mToolbar = new FloatingToolbarUtils();

    private TextViewActivity getActivity() {
        return mActivityRule.getActivity();
@@ -118,22 +116,19 @@ public class SuggestionsPopupWindowTest {
        setSuggestionSpan(suggestionSpan, text.indexOf('d'), text.indexOf('f') + 1);

        onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf('e')));
        sleepForFloatingToolbarPopup();
        assertFloatingToolbarContainsItem(
                getActivity().getString(com.android.internal.R.string.replace));
        sleepForFloatingToolbarPopup();
        clickFloatingToolbarItem(
        mToolbar.clickFloatingToolbarOverflowItem(
                getActivity().getString(com.android.internal.R.string.replace));

        assertSuggestionsPopupIsDisplayed();
    }

    @Test
    public void testInsertionActionMode() {
    public void testInsertionActionMode() throws Throwable {
        final String text = "abc def ghi";

        onView(withId(R.id.textview)).perform(click());
        onView(withId(R.id.textview)).perform(replaceText(text));
        Thread.sleep(500);

        final SuggestionSpan suggestionSpan = new SuggestionSpan(getActivity(),
                new String[]{"DEF", "Def"}, SuggestionSpan.FLAG_AUTO_CORRECTION);
@@ -141,10 +136,7 @@ public class SuggestionsPopupWindowTest {

        onView(withId(R.id.textview)).perform(clickOnTextAtIndex(text.indexOf('e')));
        onHandleView(com.android.internal.R.id.insertion_handle).perform(click());
        sleepForFloatingToolbarPopup();
        assertFloatingToolbarContainsItem(
                getActivity().getString(com.android.internal.R.string.replace));
        clickFloatingToolbarItem(
        mToolbar.clickFloatingToolbarItem(
                getActivity().getString(com.android.internal.R.string.replace));

        assertSuggestionsPopupIsDisplayed();
+189 −190

File changed.

Preview size limit exceeded, changes collapsed.

Loading