1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.wm.shell.flicker.bubble 18 19 import android.platform.test.annotations.FlakyTest 20 import android.platform.test.annotations.Postsubmit 21 import android.tools.common.traces.component.ComponentNameMatcher 22 import android.tools.device.flicker.junit.FlickerParametersRunnerFactory 23 import android.tools.device.flicker.legacy.FlickerBuilder 24 import android.tools.device.flicker.legacy.LegacyFlickerTest 25 import android.view.WindowInsets 26 import android.view.WindowManager 27 import androidx.test.filters.RequiresDevice 28 import androidx.test.uiautomator.By 29 import androidx.test.uiautomator.Until 30 import com.android.server.wm.flicker.navBarLayerIsVisibleAtEnd 31 import com.android.server.wm.flicker.navBarLayerPositionAtEnd 32 import org.junit.Assume 33 import org.junit.Ignore 34 import org.junit.Test 35 import org.junit.runner.RunWith 36 import org.junit.runners.Parameterized 37 38 /** 39 * Test launching a new activity from bubble. 40 * 41 * To run this test: `atest WMShellFlickerTests:OpenActivityFromBubbleOnLocksreenTest` 42 * 43 * Actions: 44 * ``` 45 * Launch an bubble from notification on lock screen 46 * ``` 47 */ 48 @RequiresDevice 49 @RunWith(Parameterized::class) 50 @Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) 51 class OpenActivityFromBubbleOnLocksreenTest(flicker: LegacyFlickerTest) : 52 BaseBubbleScreen(flicker) { 53 54 /** {@inheritDoc} */ 55 override val transition: FlickerBuilder.() -> Unit 56 get() = buildTransition { 57 setup { 58 val addBubbleBtn = waitAndGetAddBubbleBtn() 59 addBubbleBtn?.click() ?: error("Bubble widget not found") 60 device.sleep() 61 wmHelper.StateSyncBuilder().withoutTopVisibleAppWindows().waitForAndVerify() 62 device.wakeUp() 63 } 64 transitions { 65 // Swipe & wait for the notification shade to expand so all can be seen 66 val wm = 67 context.getSystemService(WindowManager::class.java) 68 ?: error("Unable to obtain WM service") 69 val metricInsets = wm.currentWindowMetrics.windowInsets 70 val insets = 71 metricInsets.getInsetsIgnoringVisibility( 72 WindowInsets.Type.statusBars() or WindowInsets.Type.displayCutout() 73 ) 74 device.swipe(100, insets.top + 100, 100, device.displayHeight / 2, 4) 75 device.waitForIdle(2000) 76 instrumentation.uiAutomation.syncInputTransactions() 77 78 val notification = 79 device.wait(Until.findObject(By.text("BubbleChat")), FIND_OBJECT_TIMEOUT) 80 notification?.click() ?: error("Notification not found") 81 instrumentation.uiAutomation.syncInputTransactions() 82 val showBubble = 83 device.wait( 84 Until.findObject(By.res(SYSTEM_UI_PACKAGE, BUBBLE_RES_NAME)), 85 FIND_OBJECT_TIMEOUT 86 ) 87 showBubble?.click() ?: error("Bubble notify not found") 88 instrumentation.uiAutomation.syncInputTransactions() 89 val cancelAllBtn = waitAndGetCancelAllBtn() 90 cancelAllBtn?.click() ?: error("Cancel widget not found") 91 } 92 } 93 94 @FlakyTest(bugId = 242088970) 95 @Test 96 fun testAppIsVisibleAtEnd() { 97 flicker.assertLayersEnd { this.isVisible(testApp) } 98 } 99 100 @Postsubmit 101 @Test 102 fun navBarLayerIsVisibleAtEnd() { 103 Assume.assumeFalse(flicker.scenario.isTablet) 104 flicker.navBarLayerIsVisibleAtEnd() 105 } 106 107 @Postsubmit 108 @Test 109 fun navBarLayerPositionAtEnd() { 110 Assume.assumeFalse(flicker.scenario.isTablet) 111 flicker.navBarLayerPositionAtEnd() 112 } 113 114 /** {@inheritDoc} */ 115 @FlakyTest 116 @Test 117 override fun visibleLayersShownMoreThanOneConsecutiveEntry() = 118 super.visibleLayersShownMoreThanOneConsecutiveEntry() 119 120 /** {@inheritDoc} */ 121 @Postsubmit 122 @Test 123 override fun navBarLayerIsVisibleAtStartAndEnd() { 124 Assume.assumeTrue(flicker.scenario.isGesturalNavigation) 125 super.navBarLayerIsVisibleAtStartAndEnd() 126 } 127 128 /** {@inheritDoc} */ 129 @Postsubmit 130 @Test 131 override fun navBarLayerPositionAtStartAndEnd() { 132 Assume.assumeTrue(flicker.scenario.isGesturalNavigation) 133 super.navBarLayerPositionAtStartAndEnd() 134 } 135 136 /** {@inheritDoc} */ 137 @Postsubmit 138 @Test 139 override fun navBarWindowIsAlwaysVisible() { 140 Assume.assumeTrue(flicker.scenario.isGesturalNavigation) 141 super.navBarWindowIsAlwaysVisible() 142 } 143 144 /** {@inheritDoc} */ 145 @Test 146 @Ignore("Not applicable to this CUJ. Taskbar is not shown on lock screen") 147 override fun taskBarLayerIsVisibleAtStartAndEnd() {} 148 149 @Test 150 @Ignore("Not applicable to this CUJ. Taskbar is not shown on lock screen") 151 override fun taskBarWindowIsAlwaysVisible() {} 152 153 /** Checks that the [ComponentNameMatcher.TASK_BAR] is visible at the end of the transition */ 154 @Postsubmit 155 @Test 156 fun taskBarLayerIsVisibleAtEnd() { 157 Assume.assumeTrue(flicker.scenario.isTablet) 158 flicker.assertLayersEnd { this.isVisible(ComponentNameMatcher.TASK_BAR) } 159 } 160 } 161