Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [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 | |
| 19 | import static android.view.InsetsState.TYPE_NAVIGATION_BAR; |
Tadashi G. Takaoka | b4470f2 | 2019-01-15 18:29:15 +0900 | [diff] [blame] | 20 | |
Tadashi G. Takaoka | 82eb7a5 | 2019-03-26 18:22:01 +0900 | [diff] [blame] | 21 | import static org.junit.Assert.assertEquals; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 22 | |
| 23 | import android.graphics.Insets; |
| 24 | import android.graphics.Rect; |
| 25 | import android.platform.test.annotations.Presubmit; |
Tadashi G. Takaoka | b4470f2 | 2019-01-15 18:29:15 +0900 | [diff] [blame] | 26 | |
Tadashi G. Takaoka | b4470f2 | 2019-01-15 18:29:15 +0900 | [diff] [blame] | 27 | import androidx.test.runner.AndroidJUnit4; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 28 | |
| 29 | import org.junit.Before; |
| 30 | import org.junit.Test; |
| 31 | import org.junit.runner.RunWith; |
| 32 | |
Tadashi G. Takaoka | 82eb7a5 | 2019-03-26 18:22:01 +0900 | [diff] [blame] | 33 | /** |
| 34 | * Tests for {@link InsetsSource}. |
| 35 | * |
| 36 | * <p>Build/Install/Run: |
| 37 | * atest FrameworksCoreTests:InsetsSourceTest |
| 38 | * |
| 39 | * <p>This test class is a part of Window Manager Service tests and specified in |
| 40 | * {@link com.android.server.wm.test.filters.FrameworksTestsFilter}. |
| 41 | */ |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 42 | @Presubmit |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 43 | @RunWith(AndroidJUnit4.class) |
| 44 | public class InsetsSourceTest { |
| 45 | |
| 46 | private InsetsSource mSource = new InsetsSource(TYPE_NAVIGATION_BAR); |
| 47 | |
| 48 | @Before |
| 49 | public void setUp() { |
| 50 | mSource.setVisible(true); |
| 51 | } |
| 52 | |
| 53 | @Test |
| 54 | public void testCalculateInsetsTop() { |
| 55 | mSource.setFrame(new Rect(0, 0, 500, 100)); |
| 56 | Insets insets = mSource.calculateInsets(new Rect(0, 0, 500, 500), |
| 57 | false /* ignoreVisibility */); |
| 58 | assertEquals(Insets.of(0, 100, 0, 0), insets); |
| 59 | } |
| 60 | |
| 61 | @Test |
| 62 | public void testCalculateInsetsBottom() { |
| 63 | mSource.setFrame(new Rect(0, 400, 500, 500)); |
| 64 | Insets insets = mSource.calculateInsets(new Rect(0, 0, 500, 500), |
| 65 | false /* ignoreVisibility */); |
| 66 | assertEquals(Insets.of(0, 0, 0, 100), insets); |
| 67 | } |
| 68 | |
| 69 | @Test |
| 70 | public void testCalculateInsetsLeft() { |
| 71 | mSource.setFrame(new Rect(0, 0, 100, 500)); |
| 72 | Insets insets = mSource.calculateInsets(new Rect(0, 0, 500, 500), |
| 73 | false /* ignoreVisibility */); |
| 74 | assertEquals(Insets.of(100, 0, 0, 0), insets); |
| 75 | } |
| 76 | |
| 77 | @Test |
| 78 | public void testCalculateInsetsRight() { |
| 79 | mSource.setFrame(new Rect(400, 0, 500, 500)); |
| 80 | Insets insets = mSource.calculateInsets(new Rect(0, 0, 500, 500), |
| 81 | false /* ignoreVisibility */); |
| 82 | assertEquals(Insets.of(0, 0, 100, 0), insets); |
| 83 | } |
| 84 | |
| 85 | @Test |
| 86 | public void testCalculateInsets_overextend() { |
| 87 | mSource.setFrame(new Rect(0, 0, 500, 100)); |
| 88 | Insets insets = mSource.calculateInsets(new Rect(100, 0, 500, 500), |
| 89 | false /* ignoreVisibility */); |
| 90 | assertEquals(Insets.of(0, 100, 0, 0), insets); |
| 91 | } |
| 92 | |
| 93 | @Test |
| 94 | public void testCalculateInsets_invisible() { |
| 95 | mSource.setFrame(new Rect(0, 0, 500, 100)); |
| 96 | mSource.setVisible(false); |
| 97 | Insets insets = mSource.calculateInsets(new Rect(100, 0, 500, 500), |
| 98 | false /* ignoreVisibility */); |
| 99 | assertEquals(Insets.of(0, 0, 0, 0), insets); |
| 100 | } |
| 101 | |
| 102 | @Test |
| 103 | public void testCalculateInsets_ignoreVisibility() { |
| 104 | mSource.setFrame(new Rect(0, 0, 500, 100)); |
| 105 | mSource.setVisible(false); |
| 106 | Insets insets = mSource.calculateInsets(new Rect(100, 0, 500, 500), |
| 107 | true /* ignoreVisibility */); |
| 108 | assertEquals(Insets.of(0, 100, 0, 0), insets); |
| 109 | } |
| 110 | |
| 111 | // Parcel and equals already tested via InsetsStateTest |
| 112 | } |