blob: 6a83c29b0943692e7c0e9b393187e64058ab05c3 [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;
Jorim Jaggi297985a2018-11-30 17:24:58 +010020import static android.view.WindowInsets.Type.sideBars;
Jorim Jaggi73f3e8a2019-01-14 13:06:23 +010021import static android.view.WindowInsets.Type.topBar;
Jorim Jaggi297985a2018-11-30 17:24:58 +010022import static org.junit.Assert.assertEquals;
Jorim Jaggi90990792019-01-21 23:00:20 +010023import static org.junit.Assert.assertFalse;
Adrian Roosb8493862018-11-14 06:50:55 -080024import static org.junit.Assert.assertTrue;
25
Jorim Jaggi297985a2018-11-30 17:24:58 +010026import android.graphics.Insets;
Adrian Roosb8493862018-11-14 06:50:55 -080027import android.graphics.Rect;
28import android.platform.test.annotations.Presubmit;
Jorim Jaggi297985a2018-11-30 17:24:58 +010029import android.view.WindowInsets.Builder;
Tadashi G. Takaokab4470f22019-01-15 18:29:15 +090030
31import androidx.test.filters.SmallTest;
32import androidx.test.runner.AndroidJUnit4;
Adrian Roosb8493862018-11-14 06:50:55 -080033
34import org.junit.Test;
35import org.junit.runner.RunWith;
36
37@RunWith(AndroidJUnit4.class)
38@SmallTest
39@Presubmit
40public class WindowInsetsTest {
41
42 @Test
43 public void systemWindowInsets_afterConsuming_isConsumed() {
Jorim Jaggi297985a2018-11-30 17:24:58 +010044 assertTrue(new WindowInsets(new Rect(1, 2, 3, 4), null, false, false, null)
Adrian Roosb8493862018-11-14 06:50:55 -080045 .consumeSystemWindowInsets().isConsumed());
46 }
47
48 @Test
49 public void multiNullConstructor_isConsumed() {
Jorim Jaggi297985a2018-11-30 17:24:58 +010050 assertTrue(new WindowInsets((Rect) null, null, false, false, null).isConsumed());
Adrian Roosb8493862018-11-14 06:50:55 -080051 }
52
53 @Test
54 public void singleNullConstructor_isConsumed() {
55 assertTrue(new WindowInsets((Rect) null).isConsumed());
56 }
57
Jorim Jaggi73f3e8a2019-01-14 13:06:23 +010058 // TODO: Move this to CTS once API made public
Jorim Jaggi297985a2018-11-30 17:24:58 +010059 @Test
60 public void typeMap() {
61 Builder b = new WindowInsets.Builder();
62 b.setInsets(sideBars(), Insets.of(0, 0, 0, 100));
63 b.setInsets(ime(), Insets.of(0, 0, 0, 300));
64 WindowInsets insets = b.build();
65 assertEquals(300, insets.getSystemWindowInsets().bottom);
66 }
Jorim Jaggi73f3e8a2019-01-14 13:06:23 +010067
68 // TODO: Move this to CTS once API made public
69 @Test
70 public void compatInsets() {
71 Builder b = new WindowInsets.Builder();
72 b.setSystemWindowInsets(Insets.of(0, 50, 30, 10));
73 WindowInsets insets = b.build();
74 assertEquals(Insets.of(0, 50, 0, 0), insets.getInsets(topBar()));
75 assertEquals(Insets.of(0, 0, 30, 10), insets.getInsets(sideBars()));
76 }
Jorim Jaggi90990792019-01-21 23:00:20 +010077
78 // TODO: Move this to CTS once API made public
79 @Test
80 public void visibility() {
81 Builder b = new WindowInsets.Builder();
82 b.setInsets(sideBars(), Insets.of(0, 0, 0, 100));
83 b.setInsets(ime(), Insets.of(0, 0, 0, 300));
84 b.setVisible(sideBars(), true);
85 b.setVisible(ime(), true);
86 WindowInsets insets = b.build();
87 assertTrue(insets.isVisible(sideBars()));
88 assertTrue(insets.isVisible(sideBars() | ime()));
89 assertFalse(insets.isVisible(sideBars() | topBar()));
90 }
91
92 // TODO: Move this to CTS once API made public
93 @Test
94 public void consume_doesntChangeVisibility() {
95 Builder b = new WindowInsets.Builder();
96 b.setInsets(ime(), Insets.of(0, 0, 0, 300));
97 b.setVisible(ime(), true);
98 WindowInsets insets = b.build();
99 insets = insets.consumeSystemWindowInsets();
100 assertTrue(insets.isVisible(ime()));
101 }
Adrian Roosb8493862018-11-14 06:50:55 -0800102}