blob: d57fa8f9f612c4efbbaf9d324954ea2f517777d5 [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;
Adrian Roosb8493862018-11-14 06:50:55 -080023import static org.junit.Assert.assertTrue;
24
Jorim Jaggi297985a2018-11-30 17:24:58 +010025import android.graphics.Insets;
Adrian Roosb8493862018-11-14 06:50:55 -080026import android.graphics.Rect;
27import android.platform.test.annotations.Presubmit;
Jorim Jaggi297985a2018-11-30 17:24:58 +010028import android.view.WindowInsets.Builder;
Tadashi G. Takaokab4470f22019-01-15 18:29:15 +090029
30import androidx.test.filters.SmallTest;
31import androidx.test.runner.AndroidJUnit4;
Adrian Roosb8493862018-11-14 06:50:55 -080032
33import org.junit.Test;
34import org.junit.runner.RunWith;
35
36@RunWith(AndroidJUnit4.class)
37@SmallTest
38@Presubmit
39public class WindowInsetsTest {
40
41 @Test
42 public void systemWindowInsets_afterConsuming_isConsumed() {
Jorim Jaggi297985a2018-11-30 17:24:58 +010043 assertTrue(new WindowInsets(new Rect(1, 2, 3, 4), null, false, false, null)
Adrian Roosb8493862018-11-14 06:50:55 -080044 .consumeSystemWindowInsets().isConsumed());
45 }
46
47 @Test
48 public void multiNullConstructor_isConsumed() {
Jorim Jaggi297985a2018-11-30 17:24:58 +010049 assertTrue(new WindowInsets((Rect) null, null, false, false, null).isConsumed());
Adrian Roosb8493862018-11-14 06:50:55 -080050 }
51
52 @Test
53 public void singleNullConstructor_isConsumed() {
54 assertTrue(new WindowInsets((Rect) null).isConsumed());
55 }
56
Jorim Jaggi73f3e8a2019-01-14 13:06:23 +010057 // TODO: Move this to CTS once API made public
Jorim Jaggi297985a2018-11-30 17:24:58 +010058 @Test
59 public void typeMap() {
60 Builder b = new WindowInsets.Builder();
61 b.setInsets(sideBars(), Insets.of(0, 0, 0, 100));
62 b.setInsets(ime(), Insets.of(0, 0, 0, 300));
63 WindowInsets insets = b.build();
64 assertEquals(300, insets.getSystemWindowInsets().bottom);
65 }
Jorim Jaggi73f3e8a2019-01-14 13:06:23 +010066
67 // TODO: Move this to CTS once API made public
68 @Test
69 public void compatInsets() {
70 Builder b = new WindowInsets.Builder();
71 b.setSystemWindowInsets(Insets.of(0, 50, 30, 10));
72 WindowInsets insets = b.build();
73 assertEquals(Insets.of(0, 50, 0, 0), insets.getInsets(topBar()));
74 assertEquals(Insets.of(0, 0, 30, 10), insets.getInsets(sideBars()));
75 }
Adrian Roosb8493862018-11-14 06:50:55 -080076}