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

Commit 79c33b8c authored by Vincent Wang's avatar Vincent Wang Committed by Android (Google) Code Review
Browse files

Merge "[Flicker tests for bubbles]"

parents 6bc08fd2 14e2c026
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -42,6 +42,9 @@
    <uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL"/>
    <!-- ATM.removeRootTasksWithActivityTypes() -->
    <uses-permission android:name="android.permission.MANAGE_ACTIVITY_TASKS" />
    <!-- Enable bubble notification-->
    <uses-permission android:name="android.permission.STATUS_BAR_SERVICE" />

    <!-- Allow the test to write directly to /sdcard/ -->
    <application android:requestLegacyExternalStorage="true">
        <uses-library android:name="android.test.runner"/>
+112 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.wm.shell.flicker.bubble

import android.app.INotificationManager
import android.app.Instrumentation
import android.app.NotificationManager
import android.content.Context
import android.os.ServiceManager
import android.view.Surface
import androidx.test.filters.FlakyTest
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiObject2
import androidx.test.uiautomator.Until
import com.android.server.wm.flicker.FlickerBuilderProvider
import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.FlickerTestParameterFactory
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.flicker.repetitions
import com.android.wm.shell.flicker.helpers.LaunchBubbleHelper
import org.junit.Test
import org.junit.runners.Parameterized

/**
 * Base configurations for Bubble flicker tests
 */
abstract class BaseBubbleScreen(protected val testSpec: FlickerTestParameter) {

    protected val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
    protected val context: Context = instrumentation.context
    protected val testApp = LaunchBubbleHelper(instrumentation)

    protected val notifyManager = INotificationManager.Stub.asInterface(
            ServiceManager.getService(Context.NOTIFICATION_SERVICE))

    protected val packageManager = context.getPackageManager()
    protected val uid = packageManager.getApplicationInfo(
            testApp.component.packageName, 0).uid

    protected lateinit var addBubbleBtn: UiObject2

    protected abstract val transition: FlickerBuilder.(Map<String, Any?>) -> Unit

    @JvmOverloads
    protected open fun buildTransition(
        extraSpec: FlickerBuilder.(Map<String, Any?>) -> Unit = {}
    ): FlickerBuilder.(Map<String, Any?>) -> Unit {
        return { configuration ->

            setup {
                test {
                    notifyManager.setBubblesAllowed(testApp.component.packageName,
                            uid, NotificationManager.BUBBLE_PREFERENCE_ALL)
                    testApp.launchViaIntent(wmHelper)
                    addBubbleBtn = device.wait(Until.findObject(
                            By.text("Add Bubble")), FIND_OBJECT_TIMEOUT)
                }
            }

            teardown {
                notifyManager.setBubblesAllowed(testApp.component.packageName,
                        uid, NotificationManager.BUBBLE_PREFERENCE_NONE)
                testApp.exit()
            }

            extraSpec(this, configuration)
        }
    }

    @FlakyTest
    @Test
    fun testAppIsAlwaysVisible() {
        testSpec.assertLayers {
            this.isVisible(testApp.component)
        }
    }

    @FlickerBuilderProvider
    fun buildFlicker(): FlickerBuilder {
        return FlickerBuilder(instrumentation).apply {
            repeat { testSpec.config.repetitions }
            transition(this, testSpec.config)
        }
    }

    companion object {
        @Parameterized.Parameters(name = "{0}")
        @JvmStatic
        fun getParams(): List<FlickerTestParameter> {
            return FlickerTestParameterFactory.getInstance()
                    .getConfigNonRotationTests(supportedRotations = listOf(Surface.ROTATION_0),
                            repetitions = 5)
        }

        const val FIND_OBJECT_TIMEOUT = 2000L
    }
}
+59 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.wm.shell.flicker.bubble

import androidx.test.filters.RequiresDevice
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Until
import com.android.server.wm.flicker.FlickerParametersRunnerFactory
import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.annotation.Group4
import com.android.server.wm.flicker.dsl.FlickerBuilder
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

/**
 * Test launching a new activity from bubble.
 *
 * To run this test: `atest WMShellFlickerTests:ExpandBubbleScreen`
 *
 * Actions:
 *     Launch an app and enable app's bubble notification
 *     Send a bubble notification
 *     The activity for the bubble is launched
 */
@RequiresDevice
@RunWith(Parameterized::class)
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@Group4
class ExpandBubbleScreen(testSpec: FlickerTestParameter) : BaseBubbleScreen(testSpec) {

    override val transition: FlickerBuilder.(Map<String, Any?>) -> Unit
        get() = buildTransition() {
            setup {
                test {
                    addBubbleBtn?.run { addBubbleBtn.click() } ?: error("Bubble widget not found")
                }
            }
            transitions {
                val showBubble = device.wait(Until.findObject(
                        By.res("com.android.systemui", "bubble_view")), FIND_OBJECT_TIMEOUT)
                showBubble?.run { showBubble.click() } ?: error("Bubble notify not found")
                device.pressBack()
            }
        }
}
+48 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.wm.shell.flicker.bubble

import androidx.test.filters.RequiresDevice
import com.android.server.wm.flicker.FlickerParametersRunnerFactory
import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.annotation.Group4
import com.android.server.wm.flicker.dsl.FlickerBuilder
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

/**
 * Test creating a bubble notification
 *
 * To run this test: `atest WMShellFlickerTests:LaunchBubbleScreen`
 *
 * Actions:
 *     Launch an app and enable app's bubble notification
 *     Send a bubble notification
 */
@RequiresDevice
@RunWith(Parameterized::class)
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@Group4
class LaunchBubbleScreen(testSpec: FlickerTestParameter) : BaseBubbleScreen(testSpec) {

    override val transition: FlickerBuilder.(Map<String, Any?>) -> Unit
        get() = buildTransition() {
            transitions {
                addBubbleBtn?.run { addBubbleBtn.click() } ?: error("Bubble widget not found")
            }
        }
}
+33 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.wm.shell.flicker.helpers

import android.app.Instrumentation
import com.android.server.wm.traces.parser.toFlickerComponent
import com.android.wm.shell.flicker.testapp.Components

class LaunchBubbleHelper(instrumentation: Instrumentation) : BaseAppHelper(
    instrumentation,
    Components.LaunchBubbleActivity.LABEL,
    Components.LaunchBubbleActivity.COMPONENT.toFlickerComponent()
) {

    companion object {
        const val TEST_REPETITIONS = 1
        const val TIMEOUT_MS = 3_000L
    }
}
Loading