[Flicker tests for bubbles]
Add new test as below for bubble notification to detect flicker
1. Dismiss bubble notification
2. Multiple bubble notifications switching
Test: 1. atest WMShellFlickerTests:DismissBubbleScreen
2. atest WMShellFlickerTests:MultiBubblesScreen
Bug: 167521723
Change-Id: I2bbd458424e2121d6ab70a3dee170f77bf6a7066
This commit is contained in:
@@ -31,6 +31,7 @@ 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.helpers.SYSTEMUI_PACKAGE
|
||||
import com.android.server.wm.flicker.repetitions
|
||||
import com.android.wm.shell.flicker.helpers.LaunchBubbleHelper
|
||||
import org.junit.Test
|
||||
@@ -53,6 +54,7 @@ abstract class BaseBubbleScreen(protected val testSpec: FlickerTestParameter) {
|
||||
testApp.component.packageName, 0).uid
|
||||
|
||||
protected lateinit var addBubbleBtn: UiObject2
|
||||
protected lateinit var cancelAllBtn: UiObject2
|
||||
|
||||
protected abstract val transition: FlickerBuilder.(Map<String, Any?>) -> Unit
|
||||
|
||||
@@ -69,6 +71,8 @@ abstract class BaseBubbleScreen(protected val testSpec: FlickerTestParameter) {
|
||||
testApp.launchViaIntent(wmHelper)
|
||||
addBubbleBtn = device.wait(Until.findObject(
|
||||
By.text("Add Bubble")), FIND_OBJECT_TIMEOUT)
|
||||
cancelAllBtn = device.wait(Until.findObject(
|
||||
By.text("Cancel All Bubble")), FIND_OBJECT_TIMEOUT)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,5 +112,7 @@ abstract class BaseBubbleScreen(protected val testSpec: FlickerTestParameter) {
|
||||
}
|
||||
|
||||
const val FIND_OBJECT_TIMEOUT = 2000L
|
||||
const val SYSTEM_UI_PACKAGE = SYSTEMUI_PACKAGE
|
||||
const val BUBBLE_RES_NAME = "bubble_view"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.content.Context
|
||||
import android.graphics.Point
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.WindowManager
|
||||
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:DismissBubbleScreen`
|
||||
*
|
||||
* Actions:
|
||||
* Dismiss a bubble notification
|
||||
*/
|
||||
@RequiresDevice
|
||||
@RunWith(Parameterized::class)
|
||||
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
|
||||
@Group4
|
||||
class DismissBubbleScreen(testSpec: FlickerTestParameter) : BaseBubbleScreen(testSpec) {
|
||||
|
||||
val wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
||||
val displaySize = DisplayMetrics()
|
||||
|
||||
override val transition: FlickerBuilder.(Map<String, Any?>) -> Unit
|
||||
get() = buildTransition() {
|
||||
setup {
|
||||
eachRun {
|
||||
addBubbleBtn?.run { addBubbleBtn.click() } ?: error("Add Bubble not found")
|
||||
}
|
||||
}
|
||||
transitions {
|
||||
wm?.run { wm.getDefaultDisplay().getMetrics(displaySize) } ?: error("WM not found")
|
||||
val dist = Point((displaySize.widthPixels / 2), displaySize.heightPixels)
|
||||
val showBubble = device.wait(Until.findObject(
|
||||
By.res(SYSTEM_UI_PACKAGE, BUBBLE_RES_NAME)), FIND_OBJECT_TIMEOUT)
|
||||
showBubble?.run { drag(dist, 1000) } ?: error("Show bubble not found")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.os.SystemClock
|
||||
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:MultiBubblesScreen`
|
||||
*
|
||||
* Actions:
|
||||
* Switch in different bubble notifications
|
||||
*/
|
||||
@RequiresDevice
|
||||
@RunWith(Parameterized::class)
|
||||
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
|
||||
@Group4
|
||||
class MultiBubblesScreen(testSpec: FlickerTestParameter) : BaseBubbleScreen(testSpec) {
|
||||
|
||||
override val transition: FlickerBuilder.(Map<String, Any?>) -> Unit
|
||||
get() = buildTransition() {
|
||||
setup {
|
||||
test {
|
||||
for (i in 1..3) {
|
||||
addBubbleBtn?.run { addBubbleBtn.click() } ?: error("Add Bubble not found")
|
||||
}
|
||||
val showBubble = device.wait(Until.findObject(
|
||||
By.res(SYSTEM_UI_PACKAGE, BUBBLE_RES_NAME)), FIND_OBJECT_TIMEOUT)
|
||||
showBubble?.run { showBubble.click() } ?: error("Show bubble not found")
|
||||
SystemClock.sleep(1000)
|
||||
}
|
||||
}
|
||||
transitions {
|
||||
val bubbles = device.wait(Until.findObjects(
|
||||
By.res(SYSTEM_UI_PACKAGE, BUBBLE_RES_NAME)), FIND_OBJECT_TIMEOUT)
|
||||
for (entry in bubbles) {
|
||||
entry?.run { entry.click() } ?: error("Bubble not found")
|
||||
SystemClock.sleep(1000)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,15 +14,35 @@
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:background="@android:color/black">
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_create"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:text="Add Bubble" />
|
||||
</FrameLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_cancel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/button_create"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="Cancel Bubble" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_cancel_all"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/button_cancel"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="Cancel All Bubble" />
|
||||
</RelativeLayout>
|
||||
|
||||
@@ -28,6 +28,7 @@ import android.content.Intent;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.SystemClock;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -151,4 +152,27 @@ public class BubbleHelper {
|
||||
.setIcon(info.icon)
|
||||
.setDesiredHeight(info.height);
|
||||
}
|
||||
}
|
||||
|
||||
public void cancel(int id) {
|
||||
mNotificationManager.cancel(id);
|
||||
}
|
||||
|
||||
public void cancelAll() {
|
||||
mNotificationManager.cancelAll();
|
||||
}
|
||||
|
||||
public void cancelLast() {
|
||||
StatusBarNotification[] activeNotifications = mNotificationManager.getActiveNotifications();
|
||||
if (activeNotifications.length > 0) {
|
||||
mNotificationManager.cancel(
|
||||
activeNotifications[activeNotifications.length - 1].getId());
|
||||
}
|
||||
}
|
||||
|
||||
public void cancelFirst() {
|
||||
StatusBarNotification[] activeNotifications = mNotificationManager.getActiveNotifications();
|
||||
if (activeNotifications.length > 0) {
|
||||
mNotificationManager.cancel(activeNotifications[0].getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import android.content.pm.ShortcutInfo;
|
||||
import android.content.pm.ShortcutManager;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.View;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -41,12 +40,22 @@ public class LaunchBubbleActivity extends Activity {
|
||||
mBubbleHelper = BubbleHelper.getInstance(this);
|
||||
setContentView(R.layout.activity_main);
|
||||
findViewById(R.id.button_create).setOnClickListener(this::add);
|
||||
findViewById(R.id.button_cancel).setOnClickListener(this::cancel);
|
||||
findViewById(R.id.button_cancel_all).setOnClickListener(this::cancelAll);
|
||||
}
|
||||
|
||||
private void add(View v) {
|
||||
mBubbleHelper.addNewBubble(false /* autoExpand */, false /* suppressNotif */);
|
||||
}
|
||||
|
||||
private void cancel(View v) {
|
||||
mBubbleHelper.cancelLast();
|
||||
}
|
||||
|
||||
private void cancelAll(View v) {
|
||||
mBubbleHelper.cancelAll();
|
||||
}
|
||||
|
||||
private void addInboxShortcut(Context context) {
|
||||
Icon icon = Icon.createWithResource(this, R.drawable.bg);
|
||||
Person[] persons = new Person[4];
|
||||
|
||||
Reference in New Issue
Block a user