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

Commit 5bfb84cf authored by Arthur Hung's avatar Arthur Hung
Browse files

Fix CombinationKeyTests failure

The mock context would be reset after init, add more mock enviroment to
prevent tests access wrong state or the apis which need the specific
permission.

Bug: 279233062
Test: atest CombinationKeyTests PowerKeyGestureTests ModifierShortcutTests
Change-Id: I4da8afdb45cca83ce61b92909baf41b1b9e33387
parent 836df19f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -395,7 +395,7 @@ public final class SingleKeyGestureDetector {

    private class KeyHandler extends Handler {
        KeyHandler() {
            super(Looper.getMainLooper());
            super(Looper.myLooper());
        }

        @Override
+9 −3
Original line number Diff line number Diff line
@@ -202,9 +202,11 @@ class TestPhoneWindowManager {
                    .canonicalToCurrentPackageNames(any());
        } catch (PackageManager.NameNotFoundException ignored) { }

        doReturn(mTelecomManager).when(mContext).getSystemService(eq(Context.TELECOM_SERVICE));
        doReturn(mNotificationManager).when(mContext)
                .getSystemService(eq(NotificationManager.class));
        doReturn(false).when(mTelecomManager).isInCall();
        doReturn(false).when(mTelecomManager).isRinging();
        doReturn(mTelecomManager).when(mPhoneWindowManager).getTelecommService();
        doNothing().when(mNotificationManager).silenceNotificationSound();
        doReturn(mNotificationManager).when(mPhoneWindowManager).getNotificationService();
        doReturn(mVibrator).when(mContext).getSystemService(eq(Context.VIBRATOR_SERVICE));

        final PowerManager.WakeLock wakeLock = mock(PowerManager.WakeLock.class);
@@ -235,6 +237,7 @@ class TestPhoneWindowManager {
        doNothing().when(mPhoneWindowManager).screenTurnedOn(anyInt());
        doNothing().when(mPhoneWindowManager).startedWakingUp(anyInt(), anyInt());
        doNothing().when(mPhoneWindowManager).finishedWakingUp(anyInt(), anyInt());
        doNothing().when(mPhoneWindowManager).lockNow(any());

        mPhoneWindowManager.init(new TestInjector(mContext, mWindowManagerFuncsImpl));
        mPhoneWindowManager.systemReady();
@@ -249,6 +252,7 @@ class TestPhoneWindowManager {
    void tearDown() {
        mHandlerThread.quitSafely();
        LocalServices.removeServiceForTest(InputMethodManagerInternal.class);
        Mockito.reset(mPhoneWindowManager);
        mMockitoSession.finishMocking();
    }

@@ -322,6 +326,7 @@ class TestPhoneWindowManager {

    void overrideDisplayState(int state) {
        doReturn(state).when(mDisplay).getState();
        doReturn(state == STATE_ON).when(mDisplayPolicy).isAwake();
        Mockito.reset(mPowerManager);
    }

@@ -388,6 +393,7 @@ class TestPhoneWindowManager {
    }

    void assertDreamRequest() {
        waitForIdle();
        verify(mDreamManagerInternal).requestDream();
    }