blob: 8c7b28af2e78290f55fd50c6783ddf4635d909f1 [file] [log] [blame]
Adrian Roosb8493862018-11-14 06:50:55 -08001/*
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
Jorim Jaggi297985a2018-11-30 17:24:58 +010019import static android.view.WindowInsets.Type.ime;
Tiger Huang332793b2019-10-29 23:21:27 +080020import static android.view.WindowInsets.Type.navigationBars;
21import static android.view.WindowInsets.Type.statusBars;
22
Jorim Jaggi297985a2018-11-30 17:24:58 +010023import static org.junit.Assert.assertEquals;
Jorim Jaggi90990792019-01-21 23:00:20 +010024import static org.junit.Assert.assertFalse;
Adrian Roosb8493862018-11-14 06:50:55 -080025import static org.junit.Assert.assertTrue;
26
Jorim Jaggi297985a2018-11-30 17:24:58 +010027import android.graphics.Insets;
Adrian Roosb8493862018-11-14 06:50:55 -080028import android.graphics.Rect;
29import android.platform.test.annotations.Presubmit;
Jorim Jaggi297985a2018-11-30 17:24:58 +010030import android.view.WindowInsets.Builder;
Tadashi G. Takaokab4470f22019-01-15 18:29:15 +090031
32import androidx.test.filters.SmallTest;
33import androidx.test.runner.AndroidJUnit4;
Adrian Roosb8493862018-11-14 06:50:55 -080034
35import org.junit.Test;
36import org.junit.runner.RunWith;
37
38@RunWith(AndroidJUnit4.class)
39@SmallTest
40@Presubmit
41public class WindowInsetsTest {
42
43 @Test
44 public void systemWindowInsets_afterConsuming_isConsumed() {
Jorim Jaggi297985a2018-11-30 17:24:58 +010045 assertTrue(new WindowInsets(new Rect(1, 2, 3, 4), null, false, false, null)
Adrian Roosb8493862018-11-14 06:50:55 -080046 .consumeSystemWindowInsets().isConsumed());
47 }
48
49 @Test
50 public void multiNullConstructor_isConsumed() {
Jorim Jaggi297985a2018-11-30 17:24:58 +010051 assertTrue(new WindowInsets((Rect) null, null, false, false, null).isConsumed());
Adrian Roosb8493862018-11-14 06:50:55 -080052 }
53
54 @Test
55 public void singleNullConstructor_isConsumed() {
56 assertTrue(new WindowInsets((Rect) null).isConsumed());
57 }
58
Jorim Jaggi73f3e8a2019-01-14 13:06:23 +010059 // TODO: Move this to CTS once API made public
Jorim Jaggi297985a2018-11-30 17:24:58 +010060 @Test
61 public void typeMap() {
62 Builder b = new WindowInsets.Builder();
Tiger Huang332793b2019-10-29 23:21:27 +080063 b.setInsets(navigationBars(), Insets.of(0, 0, 0, 100));
Jorim Jaggi297985a2018-11-30 17:24:58 +010064 b.setInsets(ime(), Insets.of(0, 0, 0, 300));
65 WindowInsets insets = b.build();
66 assertEquals(300, insets.getSystemWindowInsets().bottom);
67 }
Jorim Jaggi73f3e8a2019-01-14 13:06:23 +010068
69 // TODO: Move this to CTS once API made public
70 @Test
71 public void compatInsets() {
72 Builder b = new WindowInsets.Builder();
73 b.setSystemWindowInsets(Insets.of(0, 50, 30, 10));
74 WindowInsets insets = b.build();
Tiger Huang332793b2019-10-29 23:21:27 +080075 assertEquals(Insets.of(0, 50, 0, 0), insets.getInsets(statusBars()));
76 assertEquals(Insets.of(0, 0, 30, 10), insets.getInsets(navigationBars()));
Jorim Jaggi73f3e8a2019-01-14 13:06:23 +010077 }
Jorim Jaggi90990792019-01-21 23:00:20 +010078
79 // TODO: Move this to CTS once API made public
80 @Test
81 public void visibility() {
82 Builder b = new WindowInsets.Builder();
Tiger Huang332793b2019-10-29 23:21:27 +080083 b.setInsets(navigationBars(), Insets.of(0, 0, 0, 100));
Jorim Jaggi90990792019-01-21 23:00:20 +010084 b.setInsets(ime(), Insets.of(0, 0, 0, 300));
Tiger Huang332793b2019-10-29 23:21:27 +080085 b.setVisible(navigationBars(), true);
Jorim Jaggi90990792019-01-21 23:00:20 +010086 b.setVisible(ime(), true);
87 WindowInsets insets = b.build();
Tiger Huang332793b2019-10-29 23:21:27 +080088 assertTrue(insets.isVisible(navigationBars()));
89 assertTrue(insets.isVisible(navigationBars() | ime()));
90 assertFalse(insets.isVisible(navigationBars() | statusBars()));
Jorim Jaggi90990792019-01-21 23:00:20 +010091 }
92
93 // TODO: Move this to CTS once API made public
94 @Test
95 public void consume_doesntChangeVisibility() {
96 Builder b = new WindowInsets.Builder();
97 b.setInsets(ime(), Insets.of(0, 0, 0, 300));
98 b.setVisible(ime(), true);
99 WindowInsets insets = b.build();
100 insets = insets.consumeSystemWindowInsets();
101 assertTrue(insets.isVisible(ime()));
102 }
Adrian Roosb8493862018-11-14 06:50:55 -0800103}