Debian Codegraph @

tests/FlickerTests/src/com/android/server/wm/flicker/helpers/MailAppHelper.kt

raw
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.helpers
18
19 import android.app.Instrumentation
20 import android.support.test.launcherhelper.ILauncherStrategy
21 import android.support.test.launcherhelper.LauncherStrategyFactory
22 import androidx.test.uiautomator.By
23 import androidx.test.uiautomator.Direction
24 import androidx.test.uiautomator.UiObject2
25 import androidx.test.uiautomator.Until
26 import com.android.server.wm.flicker.testapp.ActivityOptions
27 import com.android.server.wm.traces.common.FlickerComponentName
28 import com.android.server.wm.traces.parser.toFlickerComponent
29
30 class MailAppHelper @JvmOverloads constructor(
31 instr: Instrumentation,
32 launcherName: String = ActivityOptions.MAIL_ACTIVITY_LAUNCHER_NAME,
33 component: FlickerComponentName =
34 ActivityOptions.MAIL_ACTIVITY_COMPONENT_NAME.toFlickerComponent(),
35 launcherStrategy: ILauncherStrategy = LauncherStrategyFactory
36 .getInstance(instr)
37 .launcherStrategy
38 ) : StandardAppHelper(instr, launcherName, component, launcherStrategy) {
39
40 fun openMail(rowIdx: Int) {
41 val rowSel = By.res(getPackage(), "mail_row_item_text")
42 .textEndsWith(String.format("%04d", rowIdx))
43 var row: UiObject2? = null
44 for (i in 1..1000) {
45 row = uiDevice.wait(Until.findObject(rowSel), SHORT_WAIT_TIME_MS)
46 if (row != null) break
47 scrollDown()
48 }
49 require(row != null) {""}
50 row.click()
51 uiDevice.wait(Until.gone(By.res(getPackage(), MAIL_LIST_RES_ID)), FIND_TIMEOUT)
52 }
53
54 fun scrollDown() {
55 val listView = waitForMailList()
56 listView.scroll(Direction.DOWN, 1.0f)
57 }
58
59 fun waitForMailList(): UiObject2 {
60 var sel = By.res(getPackage(), MAIL_LIST_RES_ID).scrollable(true)
61 val ret = uiDevice.wait(Until.findObject(sel), FIND_TIMEOUT)
62 require(ret != null) {""}
63 return ret
64 }
65
66 companion object {
67 private const val SHORT_WAIT_TIME_MS = 5000L
68 private const val MAIL_LIST_RES_ID = "mail_recycle_view"
69 }
70 }