blob: 533a58ef1dfb277c299f4cdf843ae3f6a6d9ec1d [file] [log] [blame]
Jorim Jaggif96c90a2018-09-26 16:55:15 +02001/*
2 * Copyright (C) 2018 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
17package android.view;
18
19import static android.view.InsetsState.TYPE_NAVIGATION_BAR;
Tadashi G. Takaokab4470f22019-01-15 18:29:15 +090020
Tadashi G. Takaoka82eb7a52019-03-26 18:22:01 +090021import static org.junit.Assert.assertEquals;
Jorim Jaggif96c90a2018-09-26 16:55:15 +020022
23import android.graphics.Insets;
24import android.graphics.Rect;
25import android.platform.test.annotations.Presubmit;
Tadashi G. Takaokab4470f22019-01-15 18:29:15 +090026
Tadashi G. Takaokab4470f22019-01-15 18:29:15 +090027import androidx.test.runner.AndroidJUnit4;
Jorim Jaggif96c90a2018-09-26 16:55:15 +020028
29import org.junit.Before;
30import org.junit.Test;
31import org.junit.runner.RunWith;
32
Tadashi G. Takaoka82eb7a52019-03-26 18:22:01 +090033/**
34 * Tests for {@link InsetsSource}.
35 *
36 * <p>Build/Install/Run:
37 * atest FrameworksCoreTests:InsetsSourceTest
38 *
39 * <p>This test class is a part of Window Manager Service tests and specified in
40 * {@link com.android.server.wm.test.filters.FrameworksTestsFilter}.
41 */
Jorim Jaggif96c90a2018-09-26 16:55:15 +020042@Presubmit
Jorim Jaggif96c90a2018-09-26 16:55:15 +020043@RunWith(AndroidJUnit4.class)
44public class InsetsSourceTest {
45
46 private InsetsSource mSource = new InsetsSource(TYPE_NAVIGATION_BAR);
47
48 @Before
49 public void setUp() {
50 mSource.setVisible(true);
51 }
52
53 @Test
54 public void testCalculateInsetsTop() {
55 mSource.setFrame(new Rect(0, 0, 500, 100));
56 Insets insets = mSource.calculateInsets(new Rect(0, 0, 500, 500),
57 false /* ignoreVisibility */);
58 assertEquals(Insets.of(0, 100, 0, 0), insets);
59 }
60
61 @Test
62 public void testCalculateInsetsBottom() {
63 mSource.setFrame(new Rect(0, 400, 500, 500));
64 Insets insets = mSource.calculateInsets(new Rect(0, 0, 500, 500),
65 false /* ignoreVisibility */);
66 assertEquals(Insets.of(0, 0, 0, 100), insets);
67 }
68
69 @Test
70 public void testCalculateInsetsLeft() {
71 mSource.setFrame(new Rect(0, 0, 100, 500));
72 Insets insets = mSource.calculateInsets(new Rect(0, 0, 500, 500),
73 false /* ignoreVisibility */);
74 assertEquals(Insets.of(100, 0, 0, 0), insets);
75 }
76
77 @Test
78 public void testCalculateInsetsRight() {
79 mSource.setFrame(new Rect(400, 0, 500, 500));
80 Insets insets = mSource.calculateInsets(new Rect(0, 0, 500, 500),
81 false /* ignoreVisibility */);
82 assertEquals(Insets.of(0, 0, 100, 0), insets);
83 }
84
85 @Test
86 public void testCalculateInsets_overextend() {
87 mSource.setFrame(new Rect(0, 0, 500, 100));
88 Insets insets = mSource.calculateInsets(new Rect(100, 0, 500, 500),
89 false /* ignoreVisibility */);
90 assertEquals(Insets.of(0, 100, 0, 0), insets);
91 }
92
93 @Test
94 public void testCalculateInsets_invisible() {
95 mSource.setFrame(new Rect(0, 0, 500, 100));
96 mSource.setVisible(false);
97 Insets insets = mSource.calculateInsets(new Rect(100, 0, 500, 500),
98 false /* ignoreVisibility */);
99 assertEquals(Insets.of(0, 0, 0, 0), insets);
100 }
101
102 @Test
103 public void testCalculateInsets_ignoreVisibility() {
104 mSource.setFrame(new Rect(0, 0, 500, 100));
105 mSource.setVisible(false);
106 Insets insets = mSource.calculateInsets(new Rect(100, 0, 500, 500),
107 true /* ignoreVisibility */);
108 assertEquals(Insets.of(0, 100, 0, 0), insets);
109 }
110
111 // Parcel and equals already tested via InsetsStateTest
112}