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

Commit 0f2a227b authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[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
parent be5a6e5c
Loading
Loading
Loading
Loading
+49 −27
Original line number Original line Diff line number Diff line
@@ -19,9 +19,9 @@ package com.android.systemui.statusbar.phone
import android.content.Context
import android.content.Context
import android.content.res.Configuration
import android.content.res.Configuration
import android.graphics.Rect
import android.graphics.Rect
import android.test.suitebuilder.annotation.SmallTest
import android.view.Display
import android.view.Display
import android.view.DisplayCutout
import android.view.DisplayCutout
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.SysuiTestCase
import com.android.systemui.dump.DumpManager
import com.android.systemui.dump.DumpManager
import com.android.systemui.statusbar.policy.ConfigurationController
import com.android.systemui.statusbar.policy.ConfigurationController
@@ -463,16 +463,10 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
        val provider = StatusBarContentInsetsProvider(contextMock, configurationController,
        val provider = StatusBarContentInsetsProvider(contextMock, configurationController,
            mock(DumpManager::class.java))
            mock(DumpManager::class.java))


        givenDisplay(
        configuration.windowConfiguration.maxBounds = Rect(0, 0, 1080, 2160)
            screenBounds = Rect(0, 0, 1080, 2160),
            displayUniqueId = "1"
        )
        val firstDisplayInsets = provider.getStatusBarContentAreaForRotation(ROTATION_NONE)
        val firstDisplayInsets = provider.getStatusBarContentAreaForRotation(ROTATION_NONE)
        givenDisplay(

            screenBounds = Rect(0, 0, 800, 600),
        configuration.windowConfiguration.maxBounds = Rect(0, 0, 800, 600)
            displayUniqueId = "2"
        )
        configurationController.onConfigurationChanged(configuration)


        // WHEN: get insets on the second display
        // WHEN: get insets on the second display
        val secondDisplayInsets = provider.getStatusBarContentAreaForRotation(ROTATION_NONE)
        val secondDisplayInsets = provider.getStatusBarContentAreaForRotation(ROTATION_NONE)
@@ -487,23 +481,15 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
        // get insets and switch back
        // get insets and switch back
        val provider = StatusBarContentInsetsProvider(contextMock, configurationController,
        val provider = StatusBarContentInsetsProvider(contextMock, configurationController,
            mock(DumpManager::class.java))
            mock(DumpManager::class.java))
        givenDisplay(

            screenBounds = Rect(0, 0, 1080, 2160),
        configuration.windowConfiguration.maxBounds = Rect(0, 0, 1080, 2160)
            displayUniqueId = "1"
        )
        val firstDisplayInsetsFirstCall = provider
        val firstDisplayInsetsFirstCall = provider
            .getStatusBarContentAreaForRotation(ROTATION_NONE)
            .getStatusBarContentAreaForRotation(ROTATION_NONE)
        givenDisplay(

            screenBounds = Rect(0, 0, 800, 600),
        configuration.windowConfiguration.maxBounds = Rect(0, 0, 800, 600)
            displayUniqueId = "2"
        )
        configurationController.onConfigurationChanged(configuration)
        provider.getStatusBarContentAreaForRotation(ROTATION_NONE)
        provider.getStatusBarContentAreaForRotation(ROTATION_NONE)
        givenDisplay(

            screenBounds = Rect(0, 0, 1080, 2160),
        configuration.windowConfiguration.maxBounds = Rect(0, 0, 1080, 2160)
            displayUniqueId = "1"
        )
        configurationController.onConfigurationChanged(configuration)


        // WHEN: get insets on the first display again
        // WHEN: get insets on the first display again
        val firstDisplayInsetsSecondCall = provider
        val firstDisplayInsetsSecondCall = provider
@@ -538,9 +524,45 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() {
        assertThat(listener.triggered).isTrue()
        assertThat(listener.triggered).isTrue()
    }
    }


    private fun givenDisplay(screenBounds: Rect, displayUniqueId: String) {
    @Test
        `when`(display.uniqueId).thenReturn(displayUniqueId)
    fun onDensityOrFontScaleChanged_listenerNotified() {
        configuration.windowConfiguration.maxBounds = screenBounds
        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(
    private fun assertRects(