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

Commit 85784a4b authored by Daniel Norman's avatar Daniel Norman
Browse files

Replace SetFlagsRule with CheckFlagsRule.

SetFlagsRule is intended for unit tests of completely isolated
unit test methods; while ProxyManagerTest does use mocking in order
to keep its execution environment simpler & assert that certain mocked
methods are executed, it is still an executed as an integration test
that depends on the running state of the device and interacts with
other classes on the device.

CheckFlagsRule is better suited for testing non-isolated methods
because it uses the default value of all flags on the device (it
doesn't change any flags) and instead skips irrelevant tests if
a flag is required to be enabled or disable for a given test.

Bug: 286587811
Test: atest ProxyManagerTest, both with flag disabled & enabled
Change-Id: I615af25b71c5696f11e7901b12948a8fc0d7f79b
parent 28aef0fe
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -47,7 +47,9 @@ import android.graphics.Region;
import android.os.IBinder;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.platform.test.flag.junit.SetFlagsRule;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.util.ArraySet;
import android.view.KeyEvent;
import android.view.MotionEvent;
@@ -90,8 +92,7 @@ public class ProxyManagerTest {
    private static final int STREAMED_CALLING_UID = 9876;

    @Rule
    public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();

    public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();

    @Mock private Context mMockContext;
    @Mock private AccessibilitySecurityPolicy mMockSecurityPolicy;
@@ -116,8 +117,6 @@ public class ProxyManagerTest {
        MockitoAnnotations.initMocks(this);
        final Resources resources = InstrumentationRegistry.getContext().getResources();

        mSetFlagsRule.enableFlags(Flags.FLAG_PROXY_USE_APPS_ON_VIRTUAL_DEVICE_LISTENER);

        mFocusStrokeWidthDefaultValue =
                resources.getDimensionPixelSize(R.dimen.accessibility_focus_highlight_stroke_width);
        mFocusColorDefaultValue = resources.getColor(R.color.accessibility_focus_highlight_color);
@@ -230,6 +229,7 @@ public class ProxyManagerTest {
     * app changes to the proxy device.
     */
    @Test
    @RequiresFlagsEnabled(Flags.FLAG_PROXY_USE_APPS_ON_VIRTUAL_DEVICE_LISTENER)
    public void testUpdateProxyOfRunningAppsChange_changedUidIsStreamedApp_propagatesChange() {
        final VirtualDeviceManagerInternal localVdm =
                Mockito.mock(VirtualDeviceManagerInternal.class);