Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 177ed906 authored by Yunfan Chen's avatar Yunfan Chen
Browse files

Introduce new legacy size test case

This patch introduce a new test case to cover the legacy bounds getter.
It uses the insets to calculate the legacy bounds from the window
metrics.

Test: WindowMetricsHelperTest
Bug: 151861875
Change-Id: I4189edaa77a3486859aeb774be35f1ce6cf25beb
parent db7588db
Loading
Loading
Loading
Loading
+35 −8
Original line number Diff line number Diff line
@@ -16,12 +16,19 @@

package android.window;

import static android.view.WindowInsets.Type.displayCutout;
import static android.view.WindowInsets.Type.navigationBars;

import static org.junit.Assert.assertEquals;

import android.app.Activity;
import android.graphics.Point;
import android.graphics.Rect;
import android.platform.test.annotations.Presubmit;
import android.platform.test.annotations.RequiresFlagsDisabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.view.WindowInsets;
import android.view.WindowMetrics;

import androidx.test.filters.SmallTest;
@@ -51,24 +58,44 @@ public class WindowMetricsHelperTest {
    @Rule
    public ActivityTestRule<TestActivity> mActivityRule =
            new ActivityTestRule<>(TestActivity.class);
    @Rule
    public final CheckFlagsRule mCheckFlagsRule =
            DeviceFlagsValueProvider.createCheckFlagsRule();

    @Test
    public void testGetLegacySizeMatchesDisplayGetSize() throws Throwable {
        if (Flags.insetsDecoupledConfiguration()) {
            // TODO (b/151861875): Introduce new test to cover the new behavior.
            return;
        }
    @RequiresFlagsDisabled(Flags.FLAG_INSETS_DECOUPLED_CONFIGURATION)
    public void testGetBoundsExcludingNavigationBarAndCutoutMatchesDisplayGetSize()
            throws Throwable {
        mActivityRule.runOnUiThread(() -> {
            Activity activity = mActivityRule.getActivity();
            final WindowMetrics metrics = activity.getWindowManager().getCurrentWindowMetrics();
            final Rect legacyBounds = WindowMetricsHelper
            final Rect boundsExcludingNavBarAndCutout = WindowMetricsHelper
                    .getBoundsExcludingNavigationBarAndCutout(metrics);

            final Point expectedSize = new Point();
            activity.getDisplay().getSize(expectedSize);

            assertEquals(expectedSize.x, legacyBounds.width());
            assertEquals(expectedSize.y, legacyBounds.height());
            assertEquals(expectedSize.x, boundsExcludingNavBarAndCutout.width());
            assertEquals(expectedSize.y, boundsExcludingNavBarAndCutout.height());
        });
    }

    @Test
    public void testGetBoundsExcludingNavigationBarAndCutout()
            throws Throwable {
        mActivityRule.runOnUiThread(() -> {
            Activity activity = mActivityRule.getActivity();
            final WindowMetrics metrics = activity.getWindowManager().getCurrentWindowMetrics();
            final Rect boundsExcludingNavBarAndCutout = WindowMetricsHelper
                    .getBoundsExcludingNavigationBarAndCutout(metrics);

            final WindowInsets windowInsets = metrics.getWindowInsets();
            final Rect expectedBounds = new Rect(metrics.getBounds());
            expectedBounds.inset(windowInsets.getInsetsIgnoringVisibility(
                    navigationBars() | displayCutout()));

            assertEquals(expectedBounds.width(), boundsExcludingNavBarAndCutout.width());
            assertEquals(expectedBounds.height(), boundsExcludingNavBarAndCutout.height());
        });
    }