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

Commit c0254c80 authored by Nataniel Borges's avatar Nataniel Borges
Browse files

Convert flicker tests to kotlin

This will allow us to replace the Consumer/Runnable based assertions for lambdas, making the code easier to read and maintain.

Test: atest FlickerTests
Change-Id: I3c6a6bd8cd18f7eae0d5daa4510d30a8020d3f6b
parent 28dca240
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

android_test {
    name: "FlickerTests",
    srcs: ["src/**/*.java"],
    srcs: ["src/**/*.java", "src/**/*.kt"],
    manifest: "AndroidManifest.xml",
    test_config: "AndroidTest.xml",
    platform_apis: true,
+0 −174
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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 com.android.server.wm.flicker;

import static android.view.Surface.rotationToString;

import static com.android.server.wm.flicker.CommonTransitions.changeAppRotation;
import static com.android.server.wm.flicker.WindowUtils.getAppPosition;
import static com.android.server.wm.flicker.WindowUtils.getNavigationBarPosition;
import static com.android.server.wm.flicker.WindowUtils.getStatusBarPosition;
import static com.android.server.wm.flicker.WmTraceSubject.assertThat;

import android.graphics.Rect;
import android.util.Log;
import android.view.Surface;

import androidx.test.InstrumentationRegistry;
import androidx.test.filters.FlakyTest;
import androidx.test.filters.LargeTest;

import org.junit.FixMethodOrder;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

import java.util.ArrayList;
import java.util.Collection;

/**
 * Cycle through supported app rotations.
 * To run this test: {@code atest FlickerTest:ChangeAppRotationTest}
 */
@LargeTest
@RunWith(Parameterized.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class ChangeAppRotationTest extends FlickerTestBase {
    private int mBeginRotation;
    private int mEndRotation;

    public ChangeAppRotationTest(String beginRotationName, String endRotationName,
            int beginRotation, int endRotation) {
        this.mTestApp = new StandardAppHelper(InstrumentationRegistry.getInstrumentation(),
                "com.android.server.wm.flicker.testapp", "SimpleApp");
        this.mBeginRotation = beginRotation;
        this.mEndRotation = endRotation;
    }

    @Parameters(name = "{0}-{1}")
    public static Collection<Object[]> getParams() {
        int[] supportedRotations =
                {Surface.ROTATION_0, Surface.ROTATION_90};
        Collection<Object[]> params = new ArrayList<>();
        for (int begin : supportedRotations) {
            for (int end : supportedRotations) {
                if (begin != end) {
                    params.add(new Object[]{rotationToString(begin), rotationToString(end), begin,
                            end});
                }
            }
        }
        return params;
    }

    @Override
    TransitionRunner getTransitionToRun() {
        return changeAppRotation(mTestApp, mUiDevice, mBeginRotation, mEndRotation)
                .includeJankyRuns().build();
    }

    @FlakyTest(bugId = 140855415)
    @Ignore("Waiting bug feedback")
    @Test
    public void checkVisibility_navBarWindowIsAlwaysVisible() {
        checkResults(result -> assertThat(result)
                .showsAboveAppWindow(NAVIGATION_BAR_WINDOW_TITLE).forAllEntries());
    }

    @FlakyTest(bugId = 140855415)
    @Ignore("Waiting bug feedback")
    @Test
    public void checkVisibility_statusBarWindowIsAlwaysVisible() {
        checkResults(result -> assertThat(result)
                .showsAboveAppWindow(STATUS_BAR_WINDOW_TITLE).forAllEntries());
    }

    @Test
    public void checkPosition_navBarLayerRotatesAndScales() {
        Rect startingPos = getNavigationBarPosition(mBeginRotation);
        Rect endingPos = getNavigationBarPosition(mEndRotation);
        checkResults(result -> {
                    LayersTraceSubject.assertThat(result)
                            .hasVisibleRegion(NAVIGATION_BAR_WINDOW_TITLE, startingPos)
                            .inTheBeginning();
                    LayersTraceSubject.assertThat(result)
                            .hasVisibleRegion(NAVIGATION_BAR_WINDOW_TITLE, endingPos).atTheEnd();
                }
        );
    }

    @Test
    public void checkPosition_appLayerRotates() {
        Rect startingPos = getAppPosition(mBeginRotation);
        Rect endingPos = getAppPosition(mEndRotation);
        Log.e(TAG, "startingPos=" + startingPos + " endingPos=" + endingPos);
        checkResults(result -> {
                    LayersTraceSubject.assertThat(result)
                            .hasVisibleRegion(mTestApp.getPackage(), startingPos).inTheBeginning();
                    LayersTraceSubject.assertThat(result)
                            .hasVisibleRegion(mTestApp.getPackage(), endingPos).atTheEnd();
                }
        );
    }

    @Test
    public void checkPosition_statusBarLayerScales() {
        Rect startingPos = getStatusBarPosition(mBeginRotation);
        Rect endingPos = getStatusBarPosition(mEndRotation);
        checkResults(result -> {
                    LayersTraceSubject.assertThat(result)
                            .hasVisibleRegion(STATUS_BAR_WINDOW_TITLE, startingPos)
                            .inTheBeginning();
                    LayersTraceSubject.assertThat(result)
                            .hasVisibleRegion(STATUS_BAR_WINDOW_TITLE, endingPos).atTheEnd();
                }
        );
    }

    @Ignore("Flaky. Pending debug")
    @Test
    public void checkVisibility_screenshotLayerBecomesInvisible() {
        checkResults(result -> LayersTraceSubject.assertThat(result)
                .showsLayer(mTestApp.getPackage())
                .then()
                .replaceVisibleLayer(mTestApp.getPackage(), SCREENSHOT_LAYER)
                .then()
                .showsLayer(mTestApp.getPackage()).and().showsLayer(SCREENSHOT_LAYER)
                .then()
                .replaceVisibleLayer(SCREENSHOT_LAYER, mTestApp.getPackage())
                .forAllEntries());
    }

    @FlakyTest(bugId = 140855415)
    @Ignore("Waiting bug feedback")
    @Test
    public void checkVisibility_navBarLayerIsAlwaysVisible() {
        checkResults(result -> LayersTraceSubject.assertThat(result)
                .showsLayer(NAVIGATION_BAR_WINDOW_TITLE).forAllEntries());
    }

    @FlakyTest(bugId = 140855415)
    @Ignore("Waiting bug feedback")
    @Test
    public void checkVisibility_statusBarLayerIsAlwaysVisible() {
        checkResults(result -> LayersTraceSubject.assertThat(result)
                .showsLayer(STATUS_BAR_WINDOW_TITLE).forAllEntries());
    }
}
+80 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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 com.android.server.wm.flicker

import android.util.Log
import androidx.test.InstrumentationRegistry
import androidx.test.filters.LargeTest
import org.junit.FixMethodOrder
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.MethodSorters
import org.junit.runners.Parameterized

/**
 * Cycle through supported app rotations.
 * To run this test: `atest FlickerTest:ChangeAppRotationTest`
 */
@LargeTest
@RunWith(Parameterized::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class ChangeAppRotationTest(
    beginRotationName: String,
    endRotationName: String,
    beginRotation: Int,
    endRotation: Int
) : RotationTestBase(beginRotationName, endRotationName, beginRotation, endRotation) {
    init {
        testApp = StandardAppHelper(InstrumentationRegistry.getInstrumentation(),
                "com.android.server.wm.flicker.testapp", "SimpleApp")
    }

    override val transitionToRun: TransitionRunner
        get() = CommonTransitions.changeAppRotation(testApp, uiDevice,
                beginRotation, endRotation)
                .includeJankyRuns().build()

    @Test
    fun checkPosition_appLayerRotates() {
        val startingPos = WindowUtils.getAppPosition(beginRotation)
        val endingPos = WindowUtils.getAppPosition(endRotation)
        Log.e(TAG, "startingPos=$startingPos endingPos=$endingPos")
        checkResults {
            LayersTraceSubject.assertThat(it)
                    .hasVisibleRegion(testApp.getPackage(), startingPos).inTheBeginning()
            LayersTraceSubject.assertThat(it)
                    .hasVisibleRegion(testApp.getPackage(), endingPos).atTheEnd()
        }
    }

    @Ignore("Flaky. Pending debug")
    @Test
    fun checkVisibility_screenshotLayerBecomesInvisible() {
        checkResults {
            LayersTraceSubject.assertThat(it)
                    .showsLayer(testApp.getPackage())
                    .then()
                    .replaceVisibleLayer(testApp.getPackage(), SCREENSHOT_LAYER)
                    .then()
                    .showsLayer(testApp.getPackage()).and().showsLayer(SCREENSHOT_LAYER)
                    .then()
                    .replaceVisibleLayer(SCREENSHOT_LAYER, testApp.getPackage())
                    .forAllEntries()
        }
    }
}
+70 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 * Copyright (C) 2020 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.
@@ -14,63 +14,57 @@
 * limitations under the License.
 */

package com.android.server.wm.flicker;
package com.android.server.wm.flicker

import static com.android.server.wm.flicker.CommonTransitions.editTextLoseFocusToApp;

import androidx.test.InstrumentationRegistry;
import androidx.test.filters.FlakyTest;
import androidx.test.filters.LargeTest;

import com.android.server.wm.flicker.helpers.ImeAppAutoFocusHelper;

import org.junit.FixMethodOrder;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.junit.runners.Parameterized;
import androidx.test.InstrumentationRegistry
import androidx.test.filters.FlakyTest
import androidx.test.filters.LargeTest
import com.android.server.wm.flicker.helpers.ImeAppAutoFocusHelper
import org.junit.FixMethodOrder
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.MethodSorters
import org.junit.runners.Parameterized

/**
 * Test IME window closing back to app window transitions.
 * To run this test: {@code atest FlickerTests:CloseImeWindowToAppTest}
 * To run this test: `atest FlickerTests:CloseImeWindowToAppTest`
 */
@LargeTest
@RunWith(Parameterized.class)
@RunWith(Parameterized::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class CloseImeAutoOpenWindowToAppTest extends CloseImeWindowToAppTest {

    public CloseImeAutoOpenWindowToAppTest(String beginRotationName, int beginRotation) {
        super(beginRotationName, beginRotation);

        mTestApp = new ImeAppAutoFocusHelper(InstrumentationRegistry.getInstrumentation());
class CloseImeAutoOpenWindowToAppTest(
    beginRotationName: String,
    beginRotation: Int
) : CloseImeWindowToAppTest(beginRotationName, beginRotation) {
    init {
        testApp = ImeAppAutoFocusHelper(InstrumentationRegistry.getInstrumentation())
    }

    @Override
    TransitionRunner getTransitionToRun() {
        return editTextLoseFocusToApp((ImeAppAutoFocusHelper) mTestApp, mUiDevice, mBeginRotation)
                .includeJankyRuns().build();
    }
    override val transitionToRun: TransitionRunner
        get() = CommonTransitions.editTextLoseFocusToApp(testApp as ImeAppAutoFocusHelper,
                uiDevice, beginRotation)
                .includeJankyRuns().build()

    @FlakyTest(bugId = 141458352)
    @Ignore("Waiting bug feedback")
    @Test
    public void checkVisibility_imeLayerBecomesInvisible() {
        super.checkVisibility_imeLayerBecomesInvisible();
    override fun checkVisibility_imeLayerBecomesInvisible() {
        super.checkVisibility_imeLayerBecomesInvisible()
    }

    @FlakyTest(bugId = 141458352)
    @Ignore("Waiting bug feedback")
    @Test
    public void checkVisibility_imeAppLayerIsAlwaysVisible() {
        super.checkVisibility_imeAppLayerIsAlwaysVisible();
    override fun checkVisibility_imeAppLayerIsAlwaysVisible() {
        super.checkVisibility_imeAppLayerIsAlwaysVisible()
    }

    @FlakyTest(bugId = 141458352)
    @Ignore("Waiting bug feedback")
    @Test
    public void checkVisibility_imeAppWindowIsAlwaysVisible() {
        super.checkVisibility_imeAppWindowIsAlwaysVisible();
    override fun checkVisibility_imeAppWindowIsAlwaysVisible() {
        super.checkVisibility_imeAppWindowIsAlwaysVisible()
    }

}
+70 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 * Copyright (C) 2020 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.
@@ -14,62 +14,57 @@
 * limitations under the License.
 */

package com.android.server.wm.flicker;
package com.android.server.wm.flicker

import static com.android.server.wm.flicker.CommonTransitions.editTextLoseFocusToHome;

import androidx.test.InstrumentationRegistry;
import androidx.test.filters.FlakyTest;
import androidx.test.filters.LargeTest;

import com.android.server.wm.flicker.helpers.ImeAppAutoFocusHelper;

import org.junit.FixMethodOrder;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.junit.runners.Parameterized;
import androidx.test.InstrumentationRegistry
import androidx.test.filters.FlakyTest
import androidx.test.filters.LargeTest
import com.android.server.wm.flicker.helpers.ImeAppAutoFocusHelper
import org.junit.FixMethodOrder
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.MethodSorters
import org.junit.runners.Parameterized

/**
 * Test IME window closing back to app window transitions.
 * To run this test: {@code atest FlickerTests:CloseImeWindowToAppTest}
 * To run this test: `atest FlickerTests:CloseImeWindowToAppTest`
 */
@LargeTest
@RunWith(Parameterized.class)
@RunWith(Parameterized::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class CloseImeAutoOpenWindowToHomeTest extends CloseImeWindowToHomeTest {

    public CloseImeAutoOpenWindowToHomeTest(String beginRotationName, int beginRotation) {
        super(beginRotationName, beginRotation);

        mTestApp = new ImeAppAutoFocusHelper(InstrumentationRegistry.getInstrumentation());
class CloseImeAutoOpenWindowToHomeTest(
    beginRotationName: String,
    beginRotation: Int
) : CloseImeWindowToHomeTest(beginRotationName, beginRotation) {
    init {
        testApp = ImeAppAutoFocusHelper(InstrumentationRegistry.getInstrumentation())
    }

    @Override
    TransitionRunner getTransitionToRun() {
        return editTextLoseFocusToHome((ImeAppAutoFocusHelper) mTestApp, mUiDevice, mBeginRotation)
                .includeJankyRuns().build();
    }
    override val transitionToRun: TransitionRunner
        get() = CommonTransitions.editTextLoseFocusToHome(testApp as ImeAppAutoFocusHelper,
                uiDevice, beginRotation)
                .includeJankyRuns().build()

    @FlakyTest(bugId = 141458352)
    @Ignore("Waiting bug feedback")
    @Test
    public void checkVisibility_imeWindowBecomesInvisible() {
        super.checkVisibility_imeWindowBecomesInvisible();
    override fun checkVisibility_imeWindowBecomesInvisible() {
        super.checkVisibility_imeWindowBecomesInvisible()
    }

    @FlakyTest(bugId = 141458352)
    @Ignore("Waiting bug feedback")
    @Test
    public void checkVisibility_imeLayerBecomesInvisible() {
        super.checkVisibility_imeLayerBecomesInvisible();
    override fun checkVisibility_imeLayerBecomesInvisible() {
        super.checkVisibility_imeLayerBecomesInvisible()
    }

    @FlakyTest(bugId = 157449248)
    @Ignore("Waiting bug feedback")
    @Test
    public void checkVisibility_imeAppWindowBecomesInvisible() {
        super.checkVisibility_imeAppWindowBecomesInvisible();
    override fun checkVisibility_imeAppWindowBecomesInvisible() {
        super.checkVisibility_imeAppWindowBecomesInvisible()
    }
}
Loading