xref: /aosp_15_r20/platform_testing/libraries/systemui-tapl/src/android/platform/systemui_tapl/ui/PowerPanel.kt (revision dd0948b35e70be4c0246aabd6c72554a5eb8b22a)
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 package android.platform.systemui_tapl.ui
17 
18 import android.platform.systemui_tapl.utils.DeviceUtils.sysuiResSelector
19 import android.platform.uiautomatorhelpers.DeviceHelpers.assertInvisible
20 import android.platform.uiautomatorhelpers.DeviceHelpers.assertVisible
21 import androidx.test.uiautomator.By
22 import com.android.launcher3.tapl.LauncherInstrumentation
23 import java.util.regex.Pattern
24 
25 /** System UI test automation object representing the panel with power controls aka "power menu". */
26 class PowerPanel internal constructor() {
27     init {
28         POWER_PANEL_SELECTOR.assertVisible()
29         POWER_OFF_BUTTON_SELECTOR.assertVisible()
30     }
31 
32     /** Closes the panel and returns to the previous UI object. */
closenull33     fun close() {
34         LauncherInstrumentation().pressBack()
35         POWER_PANEL_SELECTOR.assertInvisible()
36         POWER_OFF_BUTTON_SELECTOR.assertInvisible { "System power menu is visible" }
37     }
38 
39     private companion object {
40         private val POWER_PANEL_SELECTOR = sysuiResSelector("list_flow")
41 
42         // https://hsv.googleplex.com/6244730548518912?node=13
43         private val POWER_OFF_BUTTON_SELECTOR =
44             By.text(Pattern.compile("Power off", Pattern.CASE_INSENSITIVE))
45     }
46 }
47