| 1 |
/* |
| 2 |
* Copyright (C) 2022 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.server.wm.flicker.launch |
| 18 |
|
| 19 |
import android.platform.test.annotations.Postsubmit |
| 20 |
import android.platform.test.annotations.RequiresDevice |
| 21 |
import android.view.WindowInsets |
| 22 |
import android.view.WindowManager |
| 23 |
import androidx.test.filters.FlakyTest |
| 24 |
import androidx.test.uiautomator.By |
| 25 |
import androidx.test.uiautomator.Until |
| 26 |
import com.android.launcher3.tapl.LauncherInstrumentation |
| 27 |
import com.android.server.wm.flicker.FlickerParametersRunnerFactory |
| 28 |
import com.android.server.wm.flicker.FlickerTestParameter |
| 29 |
import com.android.server.wm.flicker.FlickerTestParameterFactory |
| 30 |
import com.android.server.wm.flicker.annotation.Group1 |
| 31 |
import com.android.server.wm.flicker.dsl.FlickerBuilder |
| 32 |
import com.android.server.wm.flicker.helpers.NotificationAppHelper |
| 33 |
import com.android.server.wm.flicker.helpers.isShellTransitionsEnabled |
| 34 |
import com.android.server.wm.flicker.helpers.setRotation |
| 35 |
import com.android.server.wm.flicker.helpers.wakeUpAndGoToHomeScreen |
| 36 |
import org.junit.Assume |
| 37 |
import org.junit.FixMethodOrder |
| 38 |
import org.junit.Test |
| 39 |
import org.junit.runner.RunWith |
| 40 |
import org.junit.runners.MethodSorters |
| 41 |
import org.junit.runners.Parameterized |
| 42 |
|
| 43 |
/** |
| 44 |
* Test cold launching an app from a notification. |
| 45 |
* |
| 46 |
* This test assumes the device doesn't have AOD enabled |
| 47 |
* |
| 48 |
* To run this test: `atest FlickerTests:OpenAppFromNotificationWarm` |
| 49 |
*/ |
| 50 |
@RequiresDevice |
| 51 |
@RunWith(Parameterized::class) |
| 52 |
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) |
| 53 |
@FixMethodOrder(MethodSorters.NAME_ASCENDING) |
| 54 |
@Group1 |
| 55 |
@Postsubmit |
| 56 |
open class OpenAppFromNotificationWarm(testSpec: FlickerTestParameter) |
| 57 |
: OpenAppTransition(testSpec) { |
| 58 |
protected val taplInstrumentation = LauncherInstrumentation() |
| 59 |
|
| 60 |
override val testApp: NotificationAppHelper = NotificationAppHelper(instrumentation) |
| 61 |
|
| 62 |
open val openingNotificationsFromLockScreen = false |
| 63 |
|
| 64 |
override val transition: FlickerBuilder.() -> Unit |
| 65 |
get() = { |
| 66 |
setup { |
| 67 |
test { |
| 68 |
device.wakeUpAndGoToHomeScreen() |
| 69 |
this.setRotation(testSpec.startRotation) |
| 70 |
} |
| 71 |
eachRun { |
| 72 |
testApp.launchViaIntent(wmHelper) |
| 73 |
wmHelper.waitForFullScreenApp(testApp.component) |
| 74 |
testApp.postNotification(device, wmHelper) |
| 75 |
device.pressHome() |
| 76 |
wmHelper.waitForAppTransitionIdle() |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
transitions { |
| 81 |
var startY = 10 |
| 82 |
var endY = 3 * device.displayHeight / 4 |
| 83 |
var steps = 25 |
| 84 |
if (openingNotificationsFromLockScreen) { |
| 85 |
val wm = instrumentation.context.getSystemService(WindowManager::class.java) |
| 86 |
val metricInsets = wm.currentWindowMetrics.windowInsets |
| 87 |
val insets = metricInsets.getInsetsIgnoringVisibility( |
| 88 |
WindowInsets.Type.statusBars() |
| 89 |
or WindowInsets.Type.displayCutout()) |
| 90 |
|
| 91 |
startY = insets.top + 100 |
| 92 |
endY = device.displayHeight / 2 |
| 93 |
steps = 4 |
| 94 |
} |
| 95 |
|
| 96 |
// Swipe down to show the notification shade |
| 97 |
val x = device.displayWidth / 2 |
| 98 |
device.swipe(x, startY, x, endY, steps) |
| 99 |
device.waitForIdle(2000) |
| 100 |
instrumentation.uiAutomation.syncInputTransactions() |
| 101 |
|
| 102 |
// Launch the activity by clicking the notification |
| 103 |
val notification = device.wait(Until.findObject( |
| 104 |
By.text("Flicker Test Notification")), 2000L) |
| 105 |
notification?.click() ?: error("Notification not found") |
| 106 |
instrumentation.uiAutomation.syncInputTransactions() |
| 107 |
|
| 108 |
// Wait for the app to launch |
| 109 |
wmHelper.waitForFullScreenApp(testApp.component) |
| 110 |
} |
| 111 |
|
| 112 |
teardown { |
| 113 |
test { |
| 114 |
testApp.exit(wmHelper) |
| 115 |
} |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
@Test |
| 120 |
@Postsubmit |
| 121 |
override fun navBarLayerRotatesAndScales() = super.navBarLayerRotatesAndScales() |
| 122 |
|
| 123 |
@Test |
| 124 |
@Postsubmit |
| 125 |
override fun statusBarLayerIsVisible() = super.statusBarLayerIsVisible() |
| 126 |
|
| 127 |
@Test |
| 128 |
@Postsubmit |
| 129 |
override fun statusBarLayerRotatesScales() = super.statusBarLayerRotatesScales() |
| 130 |
|
| 131 |
@Test |
| 132 |
@Postsubmit |
| 133 |
override fun visibleLayersShownMoreThanOneConsecutiveEntry() = |
| 134 |
super.visibleLayersShownMoreThanOneConsecutiveEntry() |
| 135 |
|
| 136 |
@Test |
| 137 |
@Postsubmit |
| 138 |
override fun appWindowBecomesVisible() = appWindowBecomesVisible_warmStart() |
| 139 |
|
| 140 |
@Test |
| 141 |
@Postsubmit |
| 142 |
override fun appLayerBecomesVisible() = appLayerBecomesVisible_warmStart() |
| 143 |
|
| 144 |
@Test |
| 145 |
@Postsubmit |
| 146 |
fun notificationAppWindowVisibleAtEnd() { |
| 147 |
testSpec.assertWmEnd { |
| 148 |
this.isAppWindowVisible(testApp.component) |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
@Test |
| 153 |
@Postsubmit |
| 154 |
fun notificationAppWindowOnTopAtEnd() { |
| 155 |
testSpec.assertWmEnd { |
| 156 |
this.isAppWindowOnTop(testApp.component) |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
@Test |
| 161 |
@Postsubmit |
| 162 |
fun notificationAppLayerVisibleAtEnd() { |
| 163 |
testSpec.assertLayersEnd { |
| 164 |
this.isVisible(testApp.component) |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
/** {@inheritDoc} */ |
| 169 |
@Postsubmit |
| 170 |
@Test |
| 171 |
override fun appWindowBecomesTopWindow() { |
| 172 |
Assume.assumeFalse(isShellTransitionsEnabled) |
| 173 |
super.appWindowBecomesTopWindow() |
| 174 |
} |
| 175 |
|
| 176 |
@FlakyTest(bugId = 229738092) |
| 177 |
@Test |
| 178 |
fun appWindowBecomesTopWindow_ShellTransit() { |
| 179 |
Assume.assumeTrue(isShellTransitionsEnabled) |
| 180 |
super.appWindowBecomesTopWindow() |
| 181 |
} |
| 182 |
|
| 183 |
companion object { |
| 184 |
/** |
| 185 |
* Creates the test configurations. |
| 186 |
* |
| 187 |
* See [FlickerTestParameterFactory.getConfigNonRotationTests] for configuring |
| 188 |
* repetitions, screen orientation and navigation modes. |
| 189 |
*/ |
| 190 |
@Parameterized.Parameters(name = "{0}") |
| 191 |
@JvmStatic |
| 192 |
fun getParams(): Collection<FlickerTestParameter> { |
| 193 |
return FlickerTestParameterFactory.getInstance() |
| 194 |
.getConfigNonRotationTests(repetitions = 3) |
| 195 |
} |
| 196 |
} |
| 197 |
} |