| 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 |
package com.android.test.taskembed |
| 17 |
|
| 18 |
import android.app.Instrumentation |
| 19 |
import android.graphics.Point |
| 20 |
import android.graphics.Rect |
| 21 |
import androidx.test.ext.junit.rules.ActivityScenarioRule |
| 22 |
import androidx.test.platform.app.InstrumentationRegistry |
| 23 |
import androidx.test.runner.AndroidJUnit4 |
| 24 |
import com.android.server.wm.flicker.monitor.LayersTraceMonitor |
| 25 |
import com.android.server.wm.flicker.monitor.withSFTracing |
| 26 |
import com.android.server.wm.flicker.traces.layers.LayersTraceSubject.Companion.assertThat |
| 27 |
import org.junit.After |
| 28 |
import org.junit.Before |
| 29 |
import org.junit.FixMethodOrder |
| 30 |
import org.junit.Rule |
| 31 |
import org.junit.Test |
| 32 |
import org.junit.runner.RunWith |
| 33 |
import org.junit.runners.MethodSorters |
| 34 |
import java.util.concurrent.CountDownLatch |
| 35 |
import org.junit.Assert.assertNotEquals |
| 36 |
|
| 37 |
@RunWith(AndroidJUnit4::class) |
| 38 |
@FixMethodOrder(MethodSorters.NAME_ASCENDING) |
| 39 |
class ResizeTasksSyncTest { |
| 40 |
@get:Rule |
| 41 |
var scenarioRule: ActivityScenarioRule<TaskOrganizerMultiWindowTest> = |
| 42 |
ActivityScenarioRule<TaskOrganizerMultiWindowTest>( |
| 43 |
TaskOrganizerMultiWindowTest::class.java) |
| 44 |
|
| 45 |
protected val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation() |
| 46 |
|
| 47 |
@Before |
| 48 |
fun setup() { |
| 49 |
val tmpDir = instrumentation.targetContext.dataDir.toPath() |
| 50 |
LayersTraceMonitor(tmpDir).stop() |
| 51 |
val firstTaskBounds = Rect(0, 0, 1080, 1000) |
| 52 |
val secondTaskBounds = Rect(0, 1000, 1080, 2000) |
| 53 |
|
| 54 |
lateinit var surfaceReadyLatch: CountDownLatch |
| 55 |
scenarioRule.getScenario().onActivity { |
| 56 |
surfaceReadyLatch = it.openTaskView(firstTaskBounds, secondTaskBounds) |
| 57 |
} |
| 58 |
surfaceReadyLatch.await() |
| 59 |
} |
| 60 |
|
| 61 |
@After |
| 62 |
fun teardown() { |
| 63 |
scenarioRule.getScenario().close() |
| 64 |
} |
| 65 |
|
| 66 |
@Test |
| 67 |
fun testResizeTwoTaskSync() { |
| 68 |
val firstBounds = Rect(0, 0, 1080, 800) |
| 69 |
val secondBounds = Rect(0, 1000, 1080, 1800) |
| 70 |
|
| 71 |
val trace = withSFTracing(TRACE_FLAGS, |
| 72 |
outputDir = instrumentation.targetContext.dataDir.toPath()) { |
| 73 |
lateinit var resizeReadyLatch: CountDownLatch |
| 74 |
scenarioRule.getScenario().onActivity { |
| 75 |
resizeReadyLatch = it.resizeTaskView(firstBounds, secondBounds) |
| 76 |
} |
| 77 |
resizeReadyLatch.await() |
| 78 |
} |
| 79 |
|
| 80 |
// find the frame which match resized buffer size. |
| 81 |
val frame = trace.entries.flatMap { it.flattenedLayers.toList() } |
| 82 |
.firstOrNull { layer -> |
| 83 |
!layer.isActiveBufferEmpty && |
| 84 |
layer.activeBuffer?.width == firstBounds.width() && |
| 85 |
layer.activeBuffer?.height == firstBounds.height() |
| 86 |
}?.currFrame ?: -1 |
| 87 |
|
| 88 |
assertNotEquals(-1, frame) |
| 89 |
// layer bounds should be related to parent surfaceview. |
| 90 |
secondBounds.offsetTo(0, 0) |
| 91 |
|
| 92 |
// verify buffer size should be changed to expected values. |
| 93 |
assertThat(trace).layer(FIRST_ACTIVITY, frame.toLong()).also { |
| 94 |
val firstTaskSize = Point(firstBounds.width(), firstBounds.height()) |
| 95 |
it.hasLayerSize(firstTaskSize) |
| 96 |
it.hasBufferSize(firstTaskSize) |
| 97 |
} |
| 98 |
|
| 99 |
assertThat(trace).layer(SECOND_ACTIVITY, frame.toLong()).also { |
| 100 |
val secondTaskSize = Point(secondBounds.width(), secondBounds.height()) |
| 101 |
it.hasLayerSize(secondTaskSize) |
| 102 |
it.hasBufferSize(secondTaskSize) |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
companion object { |
| 107 |
private const val TRACE_FLAGS = 0x1 // TRACE_CRITICAL |
| 108 |
private const val FIRST_ACTIVITY = "Activity1" |
| 109 |
private const val SECOND_ACTIVITY = "Activity2" |
| 110 |
} |
| 111 |
} |