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

Commit 7aeff231 authored by Roy Chou's avatar Roy Chou
Browse files

fix(magnification): fix WindowMagnificationPromptControllerTest fails on target cf_x86_64_auto

Ref to the bug, since the window magnification is not supported for the auto devices, so we add Assume check to skip the tests if window magnification is not supported.

Besides, in test case tapTurnOnAction_isShown_settingsValueIsFalseAndUnregisterReceiver, we find that the Settings getter should be getIntForUser but but not getInt. Because inside getInt it requires the data with contextResolver.getUserId(), which might not equal to the userId used in WindowMagnificationPromptController. Therefore, we should use getIntForUser with TEST_USER as userId to prevent the not-equal issue.

Bug: 315425459
Flag: NA
Test: atest WindowMagnificationPromptControllerTest
Change-Id: Ic4a5a249fcbe0025c78e72f59783deadcd4d3d0c
parent 88f614db
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.accessibility.magnification;

import static android.content.pm.PackageManager.FEATURE_WINDOW_MAGNIFICATION;
import static android.provider.Settings.Secure.ACCESSIBILITY_SHOW_WINDOW_MAGNIFICATION_PROMPT;

import static com.android.internal.messages.nano.SystemMessageProto.SystemMessage.NOTE_A11Y_WINDOW_MAGNIFICATION_FEATURE;
@@ -44,6 +45,7 @@ import android.testing.TestableContext;
import androidx.test.InstrumentationRegistry;

import org.junit.After;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -70,6 +72,13 @@ public class WindowMagnificationPromptControllerTest {
    private WindowMagnificationPromptController mWindowMagnificationPromptController;
    private BroadcastReceiver mReceiver;

    /**
     *  return whether window magnification is supported for current test context.
     */
    private boolean isWindowModeSupported() {
        return mTestableContext.getPackageManager().hasSystemFeature(FEATURE_WINDOW_MAGNIFICATION);
    }

    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
@@ -78,6 +87,9 @@ public class WindowMagnificationPromptControllerTest {
        setWindowMagnificationPromptSettings(true);
        mWindowMagnificationPromptController = new WindowMagnificationPromptController(
                mTestableContext, TEST_USER);

        // skip test if window magnification is not supported to prevent fail results.
        Assume.assumeTrue(isWindowModeSupported());
    }

    @After
@@ -111,8 +123,8 @@ public class WindowMagnificationPromptControllerTest {
        final Intent intent = new Intent(ACTION_TURN_ON_IN_SETTINGS);
        mReceiver.onReceive(mTestableContext, intent);

        assertThat(Settings.Secure.getInt(mResolver, ACCESSIBILITY_SHOW_WINDOW_MAGNIFICATION_PROMPT,
                -1)).isEqualTo(0);
        assertThat(Settings.Secure.getIntForUser(mResolver,
                ACCESSIBILITY_SHOW_WINDOW_MAGNIFICATION_PROMPT, -1, TEST_USER)).isEqualTo(0);
        verify(mTestableContext.getSpyContext()).unregisterReceiver(mReceiver);
    }