1 /* 2 * Copyright (C) 2020 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 18 19 import android.app.Instrumentation 20 import android.content.pm.PackageManager 21 import android.content.pm.PackageManager.FEATURE_LEANBACK 22 import android.content.pm.PackageManager.FEATURE_LEANBACK_ONLY 23 import android.view.Surface 24 import androidx.test.platform.app.InstrumentationRegistry 25 import androidx.test.uiautomator.UiDevice 26 import org.junit.Assume.assumeFalse 27 import org.junit.Before 28 import org.junit.runners.Parameterized 29 30 /** 31 * Base class of all Flicker test that performs common functions for all flicker tests: 32 * 33 * - Caches transitions so that a transition is run once and the transition results are used by 34 * tests multiple times. This is needed for parameterized tests which call the BeforeClass methods 35 * multiple times. 36 * - Keeps track of all test artifacts and deletes ones which do not need to be reviewed. 37 * - Fails tests if results are not available for any test due to jank. 38 */ 39 abstract class FlickerTestBase( 40 protected val rotationName: String, 41 protected val rotation: Int 42 ) { 43 val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation() 44 val uiDevice = UiDevice.getInstance(instrumentation) 45 val packageManager: PackageManager = instrumentation.context.packageManager 46 protected val isTelevision: Boolean by lazy { 47 packageManager.run { 48 hasSystemFeature(FEATURE_LEANBACK) || hasSystemFeature(FEATURE_LEANBACK_ONLY) 49 } 50 } 51 52 /** 53 * By default WmShellFlickerTests do not run on TV devices. 54 * If the test should run on TV - it should override this method. 55 */ 56 @Before 57 open fun televisionSetUp() = assumeFalse(isTelevision) 58 59 companion object { 60 @Parameterized.Parameters(name = "{0}") 61 @JvmStatic 62 fun getParams(): Collection<Array<Any>> { 63 val supportedRotations = intArrayOf(Surface.ROTATION_0, Surface.ROTATION_90) 64 return supportedRotations.map { arrayOf(Surface.rotationToString(it), it) } 65 } 66 } 67 } 68