Adrian Roos | b849386 | 2018-11-14 06:50:55 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.view; |
| 18 | |
Jorim Jaggi | 297985a | 2018-11-30 17:24:58 +0100 | [diff] [blame] | 19 | import static android.view.WindowInsets.Type.ime; |
Jorim Jaggi | 297985a | 2018-11-30 17:24:58 +0100 | [diff] [blame] | 20 | import static android.view.WindowInsets.Type.sideBars; |
Jorim Jaggi | 73f3e8a | 2019-01-14 13:06:23 +0100 | [diff] [blame] | 21 | import static android.view.WindowInsets.Type.topBar; |
Jorim Jaggi | 297985a | 2018-11-30 17:24:58 +0100 | [diff] [blame] | 22 | import static org.junit.Assert.assertEquals; |
Jorim Jaggi | 9099079 | 2019-01-21 23:00:20 +0100 | [diff] [blame] | 23 | import static org.junit.Assert.assertFalse; |
Adrian Roos | b849386 | 2018-11-14 06:50:55 -0800 | [diff] [blame] | 24 | import static org.junit.Assert.assertTrue; |
| 25 | |
Jorim Jaggi | 297985a | 2018-11-30 17:24:58 +0100 | [diff] [blame] | 26 | import android.graphics.Insets; |
Adrian Roos | b849386 | 2018-11-14 06:50:55 -0800 | [diff] [blame] | 27 | import android.graphics.Rect; |
| 28 | import android.platform.test.annotations.Presubmit; |
Jorim Jaggi | 297985a | 2018-11-30 17:24:58 +0100 | [diff] [blame] | 29 | import android.view.WindowInsets.Builder; |
Tadashi G. Takaoka | b4470f2 | 2019-01-15 18:29:15 +0900 | [diff] [blame] | 30 | |
| 31 | import androidx.test.filters.SmallTest; |
| 32 | import androidx.test.runner.AndroidJUnit4; |
Adrian Roos | b849386 | 2018-11-14 06:50:55 -0800 | [diff] [blame] | 33 | |
| 34 | import org.junit.Test; |
| 35 | import org.junit.runner.RunWith; |
| 36 | |
| 37 | @RunWith(AndroidJUnit4.class) |
| 38 | @SmallTest |
| 39 | @Presubmit |
| 40 | public class WindowInsetsTest { |
| 41 | |
| 42 | @Test |
| 43 | public void systemWindowInsets_afterConsuming_isConsumed() { |
Jorim Jaggi | 297985a | 2018-11-30 17:24:58 +0100 | [diff] [blame] | 44 | assertTrue(new WindowInsets(new Rect(1, 2, 3, 4), null, false, false, null) |
Adrian Roos | b849386 | 2018-11-14 06:50:55 -0800 | [diff] [blame] | 45 | .consumeSystemWindowInsets().isConsumed()); |
| 46 | } |
| 47 | |
| 48 | @Test |
| 49 | public void multiNullConstructor_isConsumed() { |
Jorim Jaggi | 297985a | 2018-11-30 17:24:58 +0100 | [diff] [blame] | 50 | assertTrue(new WindowInsets((Rect) null, null, false, false, null).isConsumed()); |
Adrian Roos | b849386 | 2018-11-14 06:50:55 -0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | @Test |
| 54 | public void singleNullConstructor_isConsumed() { |
| 55 | assertTrue(new WindowInsets((Rect) null).isConsumed()); |
| 56 | } |
| 57 | |
Jorim Jaggi | 73f3e8a | 2019-01-14 13:06:23 +0100 | [diff] [blame] | 58 | // TODO: Move this to CTS once API made public |
Jorim Jaggi | 297985a | 2018-11-30 17:24:58 +0100 | [diff] [blame] | 59 | @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 Jaggi | 73f3e8a | 2019-01-14 13:06:23 +0100 | [diff] [blame] | 67 | |
| 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 Jaggi | 9099079 | 2019-01-21 23:00:20 +0100 | [diff] [blame] | 77 | |
| 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 Roos | b849386 | 2018-11-14 06:50:55 -0800 | [diff] [blame] | 102 | } |