• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.common
18 
19 import android.content.res.Configuration
20 import android.graphics.PointF
21 import android.graphics.Rect
22 import android.graphics.RectF
23 import android.testing.TestableResources
24 import com.android.wm.shell.ShellTestCase
25 import org.junit.Assert.assertEquals
26 import org.junit.Before
27 import org.junit.Test
28 
29 /**
30  * Tests for [MultiDisplayDragMoveBoundsCalculator].
31  *
32  * Build/Install/Run: atest WMShellUnitTests:MultiDisplayDragMoveBoundsCalculatorTest
33  */
34 class MultiDisplayDragMoveBoundsCalculatorTest : ShellTestCase() {
35     private lateinit var resources: TestableResources
36 
37     @Before
setUpnull38     fun setUp() {
39         resources = mContext.getOrCreateTestableResources()
40         val configuration = Configuration()
41         configuration.uiMode = 0
42         resources.overrideConfiguration(configuration)
43     }
44 
45     @Test
testCalculateGlobalDpBoundsForDragnull46     fun testCalculateGlobalDpBoundsForDrag() {
47         val repositionStartPoint = PointF(20f, 40f)
48         val boundsAtDragStart = Rect(10, 20, 110, 120)
49         val x = 300f
50         val y = 400f
51         val displayLayout0 =
52             MultiDisplayTestUtil.createSpyDisplayLayout(
53                 MultiDisplayTestUtil.DISPLAY_GLOBAL_BOUNDS_0,
54                 MultiDisplayTestUtil.DISPLAY_DPI_0,
55                 resources.resources,
56             )
57         val displayLayout1 =
58             MultiDisplayTestUtil.createSpyDisplayLayout(
59                 MultiDisplayTestUtil.DISPLAY_GLOBAL_BOUNDS_1,
60                 MultiDisplayTestUtil.DISPLAY_DPI_1,
61                 resources.resources,
62             )
63 
64         val actualBoundsDp =
65             MultiDisplayDragMoveBoundsCalculator.calculateGlobalDpBoundsForDrag(
66                 displayLayout0,
67                 repositionStartPoint,
68                 boundsAtDragStart,
69                 displayLayout1,
70                 x,
71                 y,
72             )
73 
74         val expectedBoundsDp = RectF(240f, -820f, 340f, -720f)
75         assertEquals(expectedBoundsDp, actualBoundsDp)
76     }
77 
78     @Test
testConvertGlobalDpToLocalPxForRectnull79     fun testConvertGlobalDpToLocalPxForRect() {
80         val displayLayout =
81             MultiDisplayTestUtil.createSpyDisplayLayout(
82                 MultiDisplayTestUtil.DISPLAY_GLOBAL_BOUNDS_1,
83                 MultiDisplayTestUtil.DISPLAY_DPI_1,
84                 resources.resources,
85             )
86         val rectDp = RectF(150f, -350f, 300f, -250f)
87 
88         val actualBoundsPx =
89             MultiDisplayDragMoveBoundsCalculator.convertGlobalDpToLocalPxForRect(
90                 rectDp,
91                 displayLayout,
92             )
93 
94         val expectedBoundsPx = Rect(100, 1300, 400, 1500)
95         assertEquals(expectedBoundsPx, actualBoundsPx)
96     }
97 }
98