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

Commit b95fa817 authored by Fabián Kozynski's avatar Fabián Kozynski
Browse files

Destroy tiles created in tests

If tiles are not properly dispossed, their handlers may keep messages
past the test boundary.

Test: atest SystemUITests
Fixes 299491332

Change-Id: I100d246c30933d805dbe20e021e9e701953f97d3
parent 99c86797
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -172,6 +172,9 @@ class DeviceControlsTileTest : SysuiTestCase() {
    @Test
    fun testNotAvailableControls() {
        featureEnabled = false

        // Destroy previous tile
        tile.destroy()
        tile = createTile()

        assertThat(tile.isAvailable).isFalse()
+11 −0
Original line number Diff line number Diff line
@@ -226,6 +226,10 @@ public class DreamTileTest extends SysuiTestCase {
        assertTrue(supportedTileOnlySystemUser.isAvailable());
        when(mUserTracker.getUserInfo()).thenReturn(nonMainUserInfo);
        assertFalse(supportedTileOnlySystemUser.isAvailable());

        destroyTile(unsupportedTile);
        destroyTile(supportedTileAllUsers);
        destroyTile(supportedTileOnlySystemUser);
    }

    @Test
@@ -250,6 +254,8 @@ public class DreamTileTest extends SysuiTestCase {
        mTestableLooper.processAllMessages();
        assertEquals(QSTileImpl.ResourceIcon.get(R.drawable.ic_qs_screen_saver_undocked),
                dockedTile.getState().icon);

        destroyTile(dockedTile);
    }

    private void setScreensaverEnabled(boolean enabled) {
@@ -257,6 +263,11 @@ public class DreamTileTest extends SysuiTestCase {
                DEFAULT_USER);
    }

    private void destroyTile(QSTileImpl<?> tile) {
        tile.destroy();
        mTestableLooper.processAllMessages();
    }

    private DreamTile constructTileForTest(boolean dreamSupported,
            boolean dreamOnlyEnabledForSystemUser) {
        return new DreamTile(
+11 −3
Original line number Diff line number Diff line
@@ -216,7 +216,7 @@ public class RotationLockTileTest extends SysuiTestCase {
    public void testSecondaryString_rotationResolverDisabled_isEmpty() {
        mTestableResources.addOverride(com.android.internal.R.bool.config_allowRotationResolver,
                false);
        mLockTile = new RotationLockTile(
        RotationLockTile otherTile = new RotationLockTile(
                mHost,
                mUiEventLogger,
                mTestableLooper.getLooper(),
@@ -232,10 +232,12 @@ public class RotationLockTileTest extends SysuiTestCase {
                new FakeSettings()
        );

        mLockTile.refreshState();
        otherTile.refreshState();
        mTestableLooper.processAllMessages();

        assertEquals("", mLockTile.getState().secondaryLabel.toString());
        assertEquals("", otherTile.getState().secondaryLabel.toString());

        destroyTile(otherTile);
    }

    @Test
@@ -258,6 +260,12 @@ public class RotationLockTileTest extends SysuiTestCase {
        assertEquals(state.icon, QSTileImpl.ResourceIcon.get(R.drawable.qs_auto_rotate_icon_on));
    }


    private void destroyTile(QSTileImpl<?> tile) {
        tile.destroy();
        mTestableLooper.processAllMessages();
    }

    private void enableAutoRotation() {
        when(mRotationPolicyWrapper.isRotationLocked()).thenReturn(false);
    }