1 /* 2 * Copyright (C) 2021 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.service.assertors 18 19 import com.android.server.wm.flicker.readLayerTraceFromFile 20 import com.android.server.wm.flicker.readTestFile 21 import com.android.server.wm.flicker.readWmTraceFromFile 22 import com.android.server.wm.traces.common.tags.Tag 23 import com.android.server.wm.traces.common.tags.Transition 24 import com.google.common.truth.Truth 25 import org.junit.FixMethodOrder 26 import org.junit.Test 27 import org.junit.runners.MethodSorters 28 29 /** 30 * Contains tests for Pip Enter assertions. To run this test: 31 * `atest FlickerLibTest:PipEnterAssertionsTest` 32 */ 33 @FixMethodOrder(MethodSorters.NAME_ASCENDING) 34 class PipEnterAssertionsTest { 35 private val jsonByteArray = readTestFile("assertors/config.json") 36 private val assertions = 37 AssertionConfigParser.parseConfigFile(String(jsonByteArray)) <lambda>null38 .filter { it.transitionType == Transition.PIP_ENTER } 39 <lambda>null40 private val pipEnterAssertor = TransitionAssertor(assertions) { } 41 42 @Test testValidPipEnterTracesnull43 fun testValidPipEnterTraces() { 44 val wmTrace = readWmTraceFromFile( 45 "assertors/pip/enter/WindowManagerTrace.winscope") 46 val layersTrace = readLayerTraceFromFile( 47 "assertors/pip/enter/SurfaceFlingerTrace.winscope") 48 val errorTrace = pipEnterAssertor.analyze(VALID_PIP_ENTER_TAG, wmTrace, layersTrace) 49 50 Truth.assertThat(errorTrace).isEmpty() 51 } 52 53 @Test testInvalidPipEnterTracesnull54 fun testInvalidPipEnterTraces() { 55 val wmTrace = readWmTraceFromFile( 56 "assertors/pip/enter/WindowManagerInvalidTrace.winscope") 57 val layersTrace = readLayerTraceFromFile( 58 "assertors/pip/enter/SurfaceFlingerInvalidTrace.winscope") 59 val errorTrace = pipEnterAssertor.analyze(INVALID_PIP_ENTER_TAG, wmTrace, layersTrace) 60 61 Truth.assertThat(errorTrace).isNotEmpty() 62 Truth.assertThat(errorTrace.entries).asList().hasSize(3) 63 } 64 65 companion object { 66 private val VALID_PIP_ENTER_TAG = Tag(1, Transition.PIP_ENTER, true, 67 layerId = 620) 68 private val INVALID_PIP_ENTER_TAG = Tag(2, Transition.PIP_ENTER, true, 69 layerId = 188) 70 } 71 }