1 /* 2 * Copyright (C) 2020 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.window; 18 19 import static org.junit.Assert.assertEquals; 20 21 import android.app.Activity; 22 import android.graphics.Point; 23 import android.graphics.Rect; 24 import android.platform.test.annotations.Presubmit; 25 import android.view.WindowMetrics; 26 27 import androidx.test.filters.SmallTest; 28 import androidx.test.rule.ActivityTestRule; 29 import androidx.test.runner.AndroidJUnit4; 30 31 import org.junit.Rule; 32 import org.junit.Test; 33 import org.junit.runner.RunWith; 34 35 /** 36 * Tests for {@link WindowMetricsHelper} 37 * 38 * <p>Build/Install/Run: 39 * atest FrameworksCoreTests:WindowMetricsHelperTest 40 * 41 * <p>This test class is a part of Window Manager Service tests and specified in 42 * {@link com.android.server.wm.test.filters.FrameworksTestsFilter}. 43 */ 44 @RunWith(AndroidJUnit4.class) 45 @SmallTest 46 @Presubmit 47 public class WindowMetricsHelperTest { 48 49 @Rule 50 public ActivityTestRule<TestActivity> mActivityRule = 51 new ActivityTestRule<>(TestActivity.class); 52 53 @Test testGetLegacySizeMatchesDisplayGetSize()54 public void testGetLegacySizeMatchesDisplayGetSize() throws Throwable { 55 mActivityRule.runOnUiThread(() -> { 56 Activity activity = mActivityRule.getActivity(); 57 final WindowMetrics metrics = activity.getWindowManager().getCurrentWindowMetrics(); 58 final Rect legacyBounds = WindowMetricsHelper 59 .getBoundsExcludingNavigationBarAndCutout(metrics); 60 61 final Point expectedSize = new Point(); 62 activity.getDisplay().getSize(expectedSize); 63 64 assertEquals(expectedSize.x, legacyBounds.width()); 65 assertEquals(expectedSize.y, legacyBounds.height()); 66 }); 67 } 68 69 public static class TestActivity extends Activity { } 70 } 71