1 /* 2 * Copyright (C) 2023 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 android.tools.flicker.assertions 18 19 import android.tools.flicker.subject.events.EventLogSubject 20 import android.tools.flicker.subject.layers.LayerTraceEntrySubject 21 import android.tools.flicker.subject.layers.LayersTraceSubject 22 import android.tools.flicker.subject.region.RegionTraceSubject 23 import android.tools.flicker.subject.wm.WindowManagerStateSubject 24 import android.tools.flicker.subject.wm.WindowManagerTraceSubject 25 import android.tools.traces.component.IComponentMatcher 26 import android.tools.withTracing 27 28 abstract class BaseFlickerTest( 29 private val assertionFactory: AssertionFactory = AssertionFactory() 30 ) : FlickerTest { doProcessnull31 protected abstract fun doProcess(assertion: AssertionData) 32 33 override fun assertWmStart(assertion: WindowManagerStateSubject.() -> Unit) { 34 withTracing("assertWmStart") { 35 val assertionData = assertionFactory.createWmStartAssertion(assertion) 36 doProcess(assertionData) 37 } 38 } 39 assertWmEndnull40 override fun assertWmEnd(assertion: WindowManagerStateSubject.() -> Unit) { 41 withTracing("assertWmEnd") { 42 val assertionData = assertionFactory.createWmEndAssertion(assertion) 43 doProcess(assertionData) 44 } 45 } 46 assertWmnull47 override fun assertWm(assertion: WindowManagerTraceSubject.() -> Unit) { 48 withTracing("assertWm") { 49 val assertionData = assertionFactory.createWmAssertion(assertion) 50 doProcess(assertionData) 51 } 52 } 53 assertWmTagnull54 override fun assertWmTag(tag: String, assertion: WindowManagerStateSubject.() -> Unit) { 55 withTracing("assertWmTag") { 56 val assertionData = assertionFactory.createWmTagAssertion(tag, assertion) 57 doProcess(assertionData) 58 } 59 } 60 assertWmVisibleRegionnull61 override fun assertWmVisibleRegion( 62 componentMatcher: IComponentMatcher, 63 assertion: RegionTraceSubject.() -> Unit 64 ) { 65 withTracing("assertWmVisibleRegion") { 66 val assertionData = 67 assertionFactory.createWmVisibleRegionAssertion(componentMatcher, assertion) 68 doProcess(assertionData) 69 } 70 } 71 assertLayersStartnull72 override fun assertLayersStart(assertion: LayerTraceEntrySubject.() -> Unit) { 73 withTracing("assertLayersStart") { 74 val assertionData = assertionFactory.createLayersStartAssertion(assertion) 75 doProcess(assertionData) 76 } 77 } 78 assertLayersEndnull79 override fun assertLayersEnd(assertion: LayerTraceEntrySubject.() -> Unit) { 80 withTracing("assertLayersEnd") { 81 val assertionData = assertionFactory.createLayersEndAssertion(assertion) 82 doProcess(assertionData) 83 } 84 } 85 assertLayersnull86 override fun assertLayers(assertion: LayersTraceSubject.() -> Unit) { 87 withTracing("assertLayers") { 88 val assertionData = assertionFactory.createLayersAssertion(assertion) 89 doProcess(assertionData) 90 } 91 } 92 assertLayersTagnull93 override fun assertLayersTag(tag: String, assertion: LayerTraceEntrySubject.() -> Unit) { 94 withTracing("assertLayersTag") { 95 val assertionData = assertionFactory.createLayersTagAssertion(tag, assertion) 96 doProcess(assertionData) 97 } 98 } 99 assertLayersVisibleRegionnull100 override fun assertLayersVisibleRegion( 101 componentMatcher: IComponentMatcher, 102 useCompositionEngineRegionOnly: Boolean, 103 assertion: RegionTraceSubject.() -> Unit 104 ) { 105 withTracing("assertLayersVisibleRegion") { 106 val assertionData = 107 assertionFactory.createLayersVisibleRegionAssertion( 108 componentMatcher, 109 useCompositionEngineRegionOnly, 110 assertion 111 ) 112 doProcess(assertionData) 113 } 114 } 115 assertEventLognull116 override fun assertEventLog(assertion: EventLogSubject.() -> Unit) { 117 withTracing("assertEventLog") { 118 val assertionData = assertionFactory.createEventLogAssertion(assertion) 119 doProcess(assertionData) 120 } 121 } 122 } 123