diff options
| author | 2021-03-16 15:14:10 -0400 | |
|---|---|---|
| committer | 2021-03-19 19:20:31 -0400 | |
| commit | 95f98799f863ea126757a2b5457f45b530c83d19 (patch) | |
| tree | bc5fb66332de121b92b49e8946fe1ba0e76bb06a | |
| parent | df786ca150b47170af6c30019a913def8ccbe15e (diff) | |
Ensure Display Settings Overrides Do Not Impact TestDisplayContent
Display overrides such as width, height, and density
should not override values set in TestDisplayContent.
Otherwise, test conditions are not consistent and can
lead to test failures on some devices.
To prevent this, set the uniqueId of the DisplayInfo
of the TestDisplayContent to a value different from
that of the actual device displays. This ensures that
DisplayWindowSettingsProvider does not apply override
settings by comparing against uniqueId.
Bug: b/182499175
Test: atest DisplayContentTests
Change-Id: I0ad10c2b3dc30849373a938bfd06533731f1a6dc
3 files changed, 92 insertions, 6 deletions
diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java index 67fe7bf436b7..ed4b954edcc0 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java @@ -1925,6 +1925,81 @@ public class DisplayContentTests extends WindowTestsBase { assertEquals(new Rect(500, 0, 2000, 700), rotateBounds); } + /** + * Creates a TestDisplayContent using the constructor that takes in display width and height as + * parameters and validates that the newly-created TestDisplayContent's DisplayInfo and + * WindowConfiguration match the parameters passed into the constructor. Additionally, this test + * checks that device-specific overrides are not applied. + */ + @Test + public void testCreateTestDisplayContentFromDimensions() { + final int displayWidth = 1000; + final int displayHeight = 2000; + final int windowingMode = WINDOWING_MODE_FULLSCREEN; + final boolean ignoreOrientationRequests = false; + final float fixedOrientationLetterboxRatio = 0; + final DisplayContent testDisplayContent = new TestDisplayContent.Builder(mAtm, displayWidth, + displayHeight).build(); + + // test display info + final DisplayInfo di = testDisplayContent.getDisplayInfo(); + assertEquals(displayWidth, di.logicalWidth); + assertEquals(displayHeight, di.logicalHeight); + assertEquals(TestDisplayContent.DEFAULT_LOGICAL_DISPLAY_DENSITY, di.logicalDensityDpi); + + // test configuration + final WindowConfiguration windowConfig = testDisplayContent.getConfiguration() + .windowConfiguration; + assertEquals(displayWidth, windowConfig.getBounds().width()); + assertEquals(displayHeight, windowConfig.getBounds().height()); + assertEquals(windowingMode, windowConfig.getWindowingMode()); + + // test misc display overrides + assertEquals(ignoreOrientationRequests, testDisplayContent.mIgnoreOrientationRequest); + assertEquals(fixedOrientationLetterboxRatio, mWm.getFixedOrientationLetterboxAspectRatio(), + 0 /* delta */); + } + + /** + * Creates a TestDisplayContent using the constructor that takes in a DisplayInfo as a parameter + * and validates that the newly-created TestDisplayContent's DisplayInfo and WindowConfiguration + * match the width, height, and density values set in the DisplayInfo passed as a parameter. + * Additionally, this test checks that device-specific overrides are not applied. + */ + @Test + public void testCreateTestDisplayContentFromDisplayInfo() { + final int displayWidth = 1000; + final int displayHeight = 2000; + final int windowingMode = WINDOWING_MODE_FULLSCREEN; + final boolean ignoreOrientationRequests = false; + final float fixedOrientationLetterboxRatio = 0; + final DisplayInfo testDisplayInfo = new DisplayInfo(); + mContext.getDisplay().getDisplayInfo(testDisplayInfo); + testDisplayInfo.logicalWidth = displayWidth; + testDisplayInfo.logicalHeight = displayHeight; + testDisplayInfo.logicalDensityDpi = TestDisplayContent.DEFAULT_LOGICAL_DISPLAY_DENSITY; + final DisplayContent testDisplayContent = new TestDisplayContent.Builder(mAtm, + testDisplayInfo).build(); + + // test display info + final DisplayInfo di = testDisplayContent.getDisplayInfo(); + assertEquals(displayWidth, di.logicalWidth); + assertEquals(displayHeight, di.logicalHeight); + assertEquals(TestDisplayContent.DEFAULT_LOGICAL_DISPLAY_DENSITY, di.logicalDensityDpi); + + // test configuration + final WindowConfiguration windowConfig = testDisplayContent.getConfiguration() + .windowConfiguration; + assertEquals(displayWidth, windowConfig.getBounds().width()); + assertEquals(displayHeight, windowConfig.getBounds().height()); + assertEquals(windowingMode, windowConfig.getWindowingMode()); + + // test misc display overrides + assertEquals(ignoreOrientationRequests, testDisplayContent.mIgnoreOrientationRequest); + assertEquals(fixedOrientationLetterboxRatio, mWm.getFixedOrientationLetterboxAspectRatio(), + 0 /* delta */); + } + private boolean isOptionsPanelAtRight(int displayId) { return (mWm.getPreferredOptionsPanelGravity(displayId) & Gravity.RIGHT) == Gravity.RIGHT; } diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayWindowSettingsProviderTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayWindowSettingsProviderTests.java index 3e05c86898e2..18a1caa71939 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayWindowSettingsProviderTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayWindowSettingsProviderTests.java @@ -102,7 +102,7 @@ public class DisplayWindowSettingsProviderTests extends WindowTestsBase { SettingsEntry expectedSettings = new SettingsEntry(); expectedSettings.mWindowingMode = WINDOWING_MODE_PINNED; - readAndAssertExpectedSettings(mPrimaryDisplay, expectedSettings); + readAndAssertExpectedSettings(mSecondaryDisplay, expectedSettings); } @Test @@ -176,17 +176,17 @@ public class DisplayWindowSettingsProviderTests extends WindowTestsBase { // Expected settings should be empty because the default is to read from the primary vendor // settings location. SettingsEntry expectedSettings = new SettingsEntry(); - assertEquals(expectedSettings, provider.getSettings(mPrimaryDisplay.getDisplayInfo())); + assertEquals(expectedSettings, provider.getSettings(mSecondaryDisplay.getDisplayInfo())); // Now switch to secondary vendor settings and assert proper settings. provider.setBaseSettingsStorage(mSecondaryVendorSettingsStorage); expectedSettings.mWindowingMode = WINDOWING_MODE_FULLSCREEN; - assertEquals(expectedSettings, provider.getSettings(mPrimaryDisplay.getDisplayInfo())); + assertEquals(expectedSettings, provider.getSettings(mSecondaryDisplay.getDisplayInfo())); // Switch back to primary and assert settings are empty again. provider.setBaseSettingsStorage(mDefaultVendorSettingsStorage); expectedSettings.mWindowingMode = WINDOWING_MODE_UNDEFINED; - assertEquals(expectedSettings, provider.getSettings(mPrimaryDisplay.getDisplayInfo())); + assertEquals(expectedSettings, provider.getSettings(mSecondaryDisplay.getDisplayInfo())); } @Test @@ -204,7 +204,7 @@ public class DisplayWindowSettingsProviderTests extends WindowTestsBase { // take precedence over the vendor provided settings. SettingsEntry expectedSettings = new SettingsEntry(); expectedSettings.mWindowingMode = WINDOWING_MODE_PINNED; - assertEquals(expectedSettings, provider.getSettings(mPrimaryDisplay.getDisplayInfo())); + assertEquals(expectedSettings, provider.getSettings(mSecondaryDisplay.getDisplayInfo())); } @Test diff --git a/services/tests/wmtests/src/com/android/server/wm/TestDisplayContent.java b/services/tests/wmtests/src/com/android/server/wm/TestDisplayContent.java index 21536a6e1cfb..777149b60098 100644 --- a/services/tests/wmtests/src/com/android/server/wm/TestDisplayContent.java +++ b/services/tests/wmtests/src/com/android/server/wm/TestDisplayContent.java @@ -37,6 +37,8 @@ import android.view.DisplayInfo; class TestDisplayContent extends DisplayContent { + public static final int DEFAULT_LOGICAL_DISPLAY_DENSITY = 300; + /** Please use the {@link Builder} to create, visible for use in test builder overrides only. */ TestDisplayContent(RootWindowContainer rootWindowContainer, Display display) { super(display, rootWindowContainer); @@ -82,12 +84,21 @@ class TestDisplayContent extends DisplayContent { mService.mContext.getDisplay().getDisplayInfo(mInfo); mInfo.logicalWidth = width; mInfo.logicalHeight = height; - mInfo.logicalDensityDpi = 300; + mInfo.logicalDensityDpi = DEFAULT_LOGICAL_DISPLAY_DENSITY; mInfo.displayCutout = null; + // Set unique ID so physical display overrides are not inheritted from + // DisplayWindowSettings. + mInfo.uniqueId = generateUniqueId(); } Builder(ActivityTaskManagerService service, DisplayInfo info) { mService = service; mInfo = info; + // Set unique ID so physical display overrides are not inheritted from + // DisplayWindowSettings. + mInfo.uniqueId = generateUniqueId(); + } + private String generateUniqueId() { + return "TEST_DISPLAY_CONTENT_" + System.currentTimeMillis(); } Builder setSystemDecorations(boolean yes) { mSystemDecorations = yes; |