Debian Codegraph @

tests/Input/src/com/android/test/input/ViewFrameInfoTest.kt

raw
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.test.input
18
19 import android.graphics.FrameInfo
20 import android.os.IInputConstants.INVALID_INPUT_EVENT_ID
21 import android.os.SystemClock
22 import android.view.ViewFrameInfo
23 import com.google.common.truth.Truth.assertThat
24 import org.junit.Before
25 import org.junit.Test
26
27 class ViewFrameInfoTest {
28 companion object {
29 private const val TAG = "ViewFrameInfoTest"
30 }
31 private val mViewFrameInfo = ViewFrameInfo()
32 private var mTimeStarted: Long = 0
33
34 @Before
35 fun setUp() {
36 mViewFrameInfo.reset()
37 mViewFrameInfo.setInputEvent(139)
38 mViewFrameInfo.flags = mViewFrameInfo.flags or FrameInfo.FLAG_WINDOW_VISIBILITY_CHANGED
39 mTimeStarted = SystemClock.uptimeNanos()
40 mViewFrameInfo.markDrawStart()
41 }
42
43 @Test
44 fun testPopulateFields() {
45 assertThat(mViewFrameInfo.drawStart).isGreaterThan(mTimeStarted)
46 assertThat(mViewFrameInfo.flags).isEqualTo(FrameInfo.FLAG_WINDOW_VISIBILITY_CHANGED)
47 }
48
49 @Test
50 fun testReset() {
51 mViewFrameInfo.reset()
52 // Ensure that the original object is reset correctly
53 assertThat(mViewFrameInfo.drawStart).isEqualTo(0)
54 assertThat(mViewFrameInfo.flags).isEqualTo(0)
55 }
56
57 @Test
58 fun testUpdateFrameInfoFromViewFrameInfo() {
59 val frameInfo = FrameInfo()
60 // By default, all values should be zero
61 assertThat(frameInfo.frameInfo[FrameInfo.INPUT_EVENT_ID]).isEqualTo(INVALID_INPUT_EVENT_ID)
62 assertThat(frameInfo.frameInfo[FrameInfo.FLAGS]).isEqualTo(0)
63 assertThat(frameInfo.frameInfo[FrameInfo.DRAW_START]).isEqualTo(0)
64
65 // The values inside FrameInfo should match those from ViewFrameInfo after we update them
66 mViewFrameInfo.populateFrameInfo(frameInfo)
67 assertThat(frameInfo.frameInfo[FrameInfo.INPUT_EVENT_ID]).isEqualTo(139)
68 assertThat(frameInfo.frameInfo[FrameInfo.FLAGS]).isEqualTo(
69 FrameInfo.FLAG_WINDOW_VISIBILITY_CHANGED)
70 assertThat(frameInfo.frameInfo[FrameInfo.DRAW_START]).isGreaterThan(mTimeStarted)
71 }
72 }