1 /* 2 * Copyright (C) 2024 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.uiautomatorhelpers.DeviceHelpers.assertInvisible 19 import android.platform.uiautomatorhelpers.DeviceHelpers.assertVisible 20 import android.platform.uiautomatorhelpers.DeviceHelpers.waitForObj 21 import androidx.test.uiautomator.By 22 import androidx.test.uiautomator.UiObject2 23 import com.android.launcher3.tapl.LauncherInstrumentation 24 import java.time.Duration 25 26 /** System UI test automation object representing the modes list dialog. */ 27 class ModesDialog internal constructor() { 28 29 init { 30 UI_DIALOG_TITLE.assertVisible() 31 } 32 33 /* Dismisses the dialog by the Back gesture */ dismissnull34 fun dismiss() { 35 // Press back to dismiss the dialog 36 LauncherInstrumentation().pressBack() 37 UI_DIALOG_TITLE.assertInvisible() 38 } 39 getModeTilenull40 private fun getModeTile(modeName: String): UiObject2 { 41 return waitForObj(By.text(modeName)).parent 42 } 43 tapModenull44 fun tapMode(modeName: String) { 45 getModeTile(modeName).click() 46 } 47 verifyModeStatenull48 fun verifyModeState(modeName: String, isOn: Boolean) { 49 val modeTile = getModeTile(modeName) 50 modeTile.waitForObj( 51 if (isOn) MODE_STATE_ON_SELECTOR else MODE_STATE_OFF_SELECTOR, 52 errorProvider = { "Tile not in correct state, wanted ${if (isOn) "On" else "Off"}" }, 53 ) 54 } 55 56 companion object { 57 private const val UI_DIALOG_TITLE_ID = "modes_title" 58 private const val UI_ALERT_DIALOG_NEGATIVE_BUTTON_ID = "button2" 59 private val UI_DIALOG_TITLE = By.res(UI_DIALOG_TITLE_ID) 60 private val MODE_NAME_SELECTOR = By.res("name") 61 private val MODE_STATE_ON_SELECTOR = By.res("stateOn") 62 private val MODE_STATE_OFF_SELECTOR = By.res("stateOff") 63 private val UI_RESPONSE_TIMEOUT = Duration.ofSeconds(3) 64 } 65 } 66