From 0f2a227b396a6263c91a3d6d3bc1df7bf8bf9368 Mon Sep 17 00:00:00 2001 From: Caitlin Shkuratov Date: Mon, 14 Nov 2022 19:41:07 +0000 Subject: [PATCH] [Privacy Chip] Minor updates to StatusBarContentInsetsProviderTest Updates: - A previous CL updated the provider to not care about `context.display.uniqueId`, so this updates the test to not set that ID either. - Remove `ConfigurationController.onConfigurationChanged` calls, since they weren't needed (the provider just uses the context directly) - Add additional listener tests Bug: 212924195 Bug: 245799099 Test: atest StatusBarContentInsetsProviderTest Change-Id: I8191982299f26c01b2a0c92bdfd8e2f5551c7568 --- .../StatusBarContentInsetsProviderTest.kt | 76 ++++++++++++------- 1 file changed, 49 insertions(+), 27 deletions(-) diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProviderTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProviderTest.kt index e32260d4c42b3..1759fb794bd6e 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProviderTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProviderTest.kt @@ -19,9 +19,9 @@ package com.android.systemui.statusbar.phone import android.content.Context import android.content.res.Configuration import android.graphics.Rect -import android.test.suitebuilder.annotation.SmallTest import android.view.Display import android.view.DisplayCutout +import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.dump.DumpManager import com.android.systemui.statusbar.policy.ConfigurationController @@ -463,16 +463,10 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { val provider = StatusBarContentInsetsProvider(contextMock, configurationController, mock(DumpManager::class.java)) - givenDisplay( - screenBounds = Rect(0, 0, 1080, 2160), - displayUniqueId = "1" - ) + configuration.windowConfiguration.maxBounds = Rect(0, 0, 1080, 2160) val firstDisplayInsets = provider.getStatusBarContentAreaForRotation(ROTATION_NONE) - givenDisplay( - screenBounds = Rect(0, 0, 800, 600), - displayUniqueId = "2" - ) - configurationController.onConfigurationChanged(configuration) + + configuration.windowConfiguration.maxBounds = Rect(0, 0, 800, 600) // WHEN: get insets on the second display val secondDisplayInsets = provider.getStatusBarContentAreaForRotation(ROTATION_NONE) @@ -487,23 +481,15 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { // get insets and switch back val provider = StatusBarContentInsetsProvider(contextMock, configurationController, mock(DumpManager::class.java)) - givenDisplay( - screenBounds = Rect(0, 0, 1080, 2160), - displayUniqueId = "1" - ) + + configuration.windowConfiguration.maxBounds = Rect(0, 0, 1080, 2160) val firstDisplayInsetsFirstCall = provider .getStatusBarContentAreaForRotation(ROTATION_NONE) - givenDisplay( - screenBounds = Rect(0, 0, 800, 600), - displayUniqueId = "2" - ) - configurationController.onConfigurationChanged(configuration) + + configuration.windowConfiguration.maxBounds = Rect(0, 0, 800, 600) provider.getStatusBarContentAreaForRotation(ROTATION_NONE) - givenDisplay( - screenBounds = Rect(0, 0, 1080, 2160), - displayUniqueId = "1" - ) - configurationController.onConfigurationChanged(configuration) + + configuration.windowConfiguration.maxBounds = Rect(0, 0, 1080, 2160) // WHEN: get insets on the first display again val firstDisplayInsetsSecondCall = provider @@ -538,9 +524,45 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { assertThat(listener.triggered).isTrue() } - private fun givenDisplay(screenBounds: Rect, displayUniqueId: String) { - `when`(display.uniqueId).thenReturn(displayUniqueId) - configuration.windowConfiguration.maxBounds = screenBounds + @Test + fun onDensityOrFontScaleChanged_listenerNotified() { + configuration.densityDpi = 12 + val provider = StatusBarContentInsetsProvider(contextMock, configurationController, + mock(DumpManager::class.java)) + val listener = object : StatusBarContentInsetsChangedListener { + var triggered = false + + override fun onStatusBarContentInsetsChanged() { + triggered = true + } + } + provider.addCallback(listener) + + // WHEN the config is updated + configuration.densityDpi = 20 + configurationController.onConfigurationChanged(configuration) + + // THEN the listener is notified + assertThat(listener.triggered).isTrue() + } + + @Test + fun onThemeChanged_listenerNotified() { + val provider = StatusBarContentInsetsProvider(contextMock, configurationController, + mock(DumpManager::class.java)) + val listener = object : StatusBarContentInsetsChangedListener { + var triggered = false + + override fun onStatusBarContentInsetsChanged() { + triggered = true + } + } + provider.addCallback(listener) + + configurationController.notifyThemeChanged() + + // THEN the listener is notified + assertThat(listener.triggered).isTrue() } private fun assertRects(