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 com.android.server.wm; |
| 18 | |
| 19 | import static android.view.InsetsState.TYPE_TOP_BAR; |
| 20 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 21 | |
Jorim Jaggi | e35c059 | 2018-11-06 16:21:08 +0100 | [diff] [blame^] | 22 | import static junit.framework.Assert.assertFalse; |
| 23 | import static junit.framework.Assert.assertNull; |
| 24 | import static junit.framework.Assert.assertTrue; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 25 | import static org.junit.Assert.assertEquals; |
Jorim Jaggi | e35c059 | 2018-11-06 16:21:08 +0100 | [diff] [blame^] | 26 | import static org.junit.Assert.assertNotNull; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 27 | |
| 28 | import android.graphics.Insets; |
| 29 | import android.graphics.Rect; |
| 30 | import android.platform.test.annotations.Presubmit; |
| 31 | import android.view.InsetsSource; |
Jorim Jaggi | e35c059 | 2018-11-06 16:21:08 +0100 | [diff] [blame^] | 32 | import android.view.InsetsState; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 33 | |
Jorim Jaggi | e35c059 | 2018-11-06 16:21:08 +0100 | [diff] [blame^] | 34 | import org.junit.Before; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 35 | import androidx.test.filters.FlakyTest; |
| 36 | import androidx.test.filters.SmallTest; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 37 | |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 38 | import org.junit.Before; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 39 | import org.junit.Test; |
| 40 | |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 41 | @SmallTest |
| 42 | @FlakyTest(detail = "Promote once confirmed non-flaky") |
| 43 | @Presubmit |
| 44 | public class InsetsSourceProviderTest extends WindowTestsBase { |
| 45 | |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 46 | private InsetsSource mSource = new InsetsSource(TYPE_TOP_BAR); |
| 47 | private InsetsSourceProvider mProvider; |
| 48 | |
| 49 | @Before |
| 50 | public void setUp() throws Exception { |
| 51 | mSource.setVisible(true); |
| 52 | mProvider = new InsetsSourceProvider(mSource, |
| 53 | mDisplayContent.getInsetsStateController(), mDisplayContent); |
| 54 | } |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 55 | |
| 56 | @Test |
| 57 | public void testPostLayout() { |
| 58 | final WindowState topBar = createWindow(null, TYPE_APPLICATION, "parentWindow"); |
| 59 | topBar.getFrameLw().set(0, 0, 500, 100); |
| 60 | topBar.mHasSurface = true; |
| 61 | mProvider.setWindow(topBar, null); |
| 62 | mProvider.onPostLayout(); |
| 63 | assertEquals(new Rect(0, 0, 500, 100), mProvider.getSource().getFrame()); |
| 64 | assertEquals(Insets.of(0, 100, 0, 0), |
| 65 | mProvider.getSource().calculateInsets(new Rect(0, 0, 500, 500), |
| 66 | false /* ignoreVisibility */)); |
| 67 | } |
| 68 | |
| 69 | @Test |
| 70 | public void testPostLayout_invisible() { |
| 71 | final WindowState topBar = createWindow(null, TYPE_APPLICATION, "parentWindow"); |
| 72 | topBar.getFrameLw().set(0, 0, 500, 100); |
| 73 | mProvider.setWindow(topBar, null); |
| 74 | mProvider.onPostLayout(); |
| 75 | assertEquals(Insets.NONE, mProvider.getSource().calculateInsets(new Rect(0, 0, 500, 500), |
| 76 | false /* ignoreVisibility */)); |
| 77 | } |
| 78 | |
| 79 | @Test |
| 80 | public void testPostLayout_frameProvider() { |
| 81 | final WindowState topBar = createWindow(null, TYPE_APPLICATION, "parentWindow"); |
| 82 | topBar.getFrameLw().set(0, 0, 500, 100); |
| 83 | mProvider.setWindow(topBar, |
| 84 | (displayFrames, windowState, rect) -> { |
| 85 | rect.set(10, 10, 20, 20); |
| 86 | }); |
| 87 | mProvider.onPostLayout(); |
| 88 | assertEquals(new Rect(10, 10, 20, 20), mProvider.getSource().getFrame()); |
| 89 | } |
Jorim Jaggi | e35c059 | 2018-11-06 16:21:08 +0100 | [diff] [blame^] | 90 | |
| 91 | @Test |
| 92 | public void testUpdateControlForTarget() { |
| 93 | final WindowState topBar = createWindow(null, TYPE_APPLICATION, "parentWindow"); |
| 94 | final WindowState target = createWindow(null, TYPE_APPLICATION, "target"); |
| 95 | topBar.getFrameLw().set(0, 0, 500, 100); |
| 96 | mProvider.setWindow(topBar, null); |
| 97 | mProvider.updateControlForTarget(target); |
| 98 | assertNotNull(mProvider.getControl()); |
| 99 | mProvider.updateControlForTarget(null); |
| 100 | assertNull(mProvider.getControl()); |
| 101 | } |
| 102 | |
| 103 | @Test |
| 104 | public void testInsetsModified() { |
| 105 | final WindowState topBar = createWindow(null, TYPE_APPLICATION, "parentWindow"); |
| 106 | final WindowState target = createWindow(null, TYPE_APPLICATION, "target"); |
| 107 | topBar.getFrameLw().set(0, 0, 500, 100); |
| 108 | mProvider.setWindow(topBar, null); |
| 109 | mProvider.updateControlForTarget(target); |
| 110 | InsetsState state = new InsetsState(); |
| 111 | state.getSource(TYPE_TOP_BAR).setVisible(false); |
| 112 | mProvider.onInsetsModified(target, state.getSource(TYPE_TOP_BAR)); |
| 113 | assertFalse(mSource.isVisible()); |
| 114 | } |
| 115 | |
| 116 | @Test |
| 117 | public void testInsetsModified_noControl() { |
| 118 | final WindowState topBar = createWindow(null, TYPE_APPLICATION, "parentWindow"); |
| 119 | final WindowState target = createWindow(null, TYPE_APPLICATION, "target"); |
| 120 | topBar.getFrameLw().set(0, 0, 500, 100); |
| 121 | mProvider.setWindow(topBar, null); |
| 122 | InsetsState state = new InsetsState(); |
| 123 | state.getSource(TYPE_TOP_BAR).setVisible(false); |
| 124 | mProvider.onInsetsModified(target, state.getSource(TYPE_TOP_BAR)); |
| 125 | assertTrue(mSource.isVisible()); |
| 126 | } |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 127 | } |