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; |
Tadashi G. Takaoka | b4470f2 | 2019-01-15 18:29:15 +0900 | [diff] [blame^] | 21 | |
Jorim Jaggi | 297985a | 2018-11-30 17:24:58 +0100 | [diff] [blame] | 22 | import static org.junit.Assert.assertEquals; |
Adrian Roos | b849386 | 2018-11-14 06:50:55 -0800 | [diff] [blame] | 23 | import static org.junit.Assert.assertTrue; |
| 24 | |
Jorim Jaggi | 297985a | 2018-11-30 17:24:58 +0100 | [diff] [blame] | 25 | import android.graphics.Insets; |
Adrian Roos | b849386 | 2018-11-14 06:50:55 -0800 | [diff] [blame] | 26 | import android.graphics.Rect; |
| 27 | import android.platform.test.annotations.Presubmit; |
Jorim Jaggi | 297985a | 2018-11-30 17:24:58 +0100 | [diff] [blame] | 28 | import android.view.WindowInsets.Builder; |
Tadashi G. Takaoka | b4470f2 | 2019-01-15 18:29:15 +0900 | [diff] [blame^] | 29 | |
| 30 | import androidx.test.filters.SmallTest; |
| 31 | import androidx.test.runner.AndroidJUnit4; |
Adrian Roos | b849386 | 2018-11-14 06:50:55 -0800 | [diff] [blame] | 32 | |
| 33 | import org.junit.Test; |
| 34 | import org.junit.runner.RunWith; |
| 35 | |
| 36 | @RunWith(AndroidJUnit4.class) |
| 37 | @SmallTest |
| 38 | @Presubmit |
| 39 | public class WindowInsetsTest { |
| 40 | |
| 41 | @Test |
| 42 | public void systemWindowInsets_afterConsuming_isConsumed() { |
Jorim Jaggi | 297985a | 2018-11-30 17:24:58 +0100 | [diff] [blame] | 43 | 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] | 44 | .consumeSystemWindowInsets().isConsumed()); |
| 45 | } |
| 46 | |
| 47 | @Test |
| 48 | public void multiNullConstructor_isConsumed() { |
Jorim Jaggi | 297985a | 2018-11-30 17:24:58 +0100 | [diff] [blame] | 49 | assertTrue(new WindowInsets((Rect) null, null, false, false, null).isConsumed()); |
Adrian Roos | b849386 | 2018-11-14 06:50:55 -0800 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | @Test |
| 53 | public void singleNullConstructor_isConsumed() { |
| 54 | assertTrue(new WindowInsets((Rect) null).isConsumed()); |
| 55 | } |
| 56 | |
Jorim Jaggi | 297985a | 2018-11-30 17:24:58 +0100 | [diff] [blame] | 57 | @Test |
| 58 | public void typeMap() { |
| 59 | Builder b = new WindowInsets.Builder(); |
| 60 | b.setInsets(sideBars(), Insets.of(0, 0, 0, 100)); |
| 61 | b.setInsets(ime(), Insets.of(0, 0, 0, 300)); |
| 62 | WindowInsets insets = b.build(); |
| 63 | assertEquals(300, insets.getSystemWindowInsets().bottom); |
| 64 | } |
Adrian Roos | b849386 | 2018-11-14 06:50:55 -0800 | [diff] [blame] | 65 | } |