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

Commit 3150dbf7 authored by Adrian Roos's avatar Adrian Roos
Browse files

WM Tests: Use a separate WindowManager instance per test

Fixes a bunch of flakes, where the WindowManagerService instance
was reused between tests, which caused delayed callbacks from a
previous test affecting state of a future test.

Also introduces a DexmakerShareClassLoaderRule to manage
the 'dexmaker.share_classloader' property instead of sprinkling
error prone System.setProperty() invocations all over the tests.

Change-Id: Ic9445d1b2cef594e79365c425632aabced6343a9
Fixes: 76111404
Fixes: 75991352
Fixes: 75991878
Fixes: 75992153
Test: atest services/tests/servicestests DexmakerShareClassLoaderRuleTest packages/SystemUI/tests packages/SystemUI/shared/tests
parent 52c15f16
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.app.Fragment;
import android.app.Instrumentation;
import android.support.test.InstrumentationRegistry;
import android.testing.BaseFragmentTest;
import android.testing.DexmakerShareClassLoaderRule;

import com.android.systemui.utils.leaks.LeakCheckedTest;
import com.android.systemui.utils.leaks.LeakCheckedTest.SysuiLeakCheck;
@@ -36,6 +37,10 @@ public abstract class SysuiBaseFragmentTest extends BaseFragmentTest {
    @Rule
    public final SysuiLeakCheck mLeakCheck = new SysuiLeakCheck();

    @Rule
    public final DexmakerShareClassLoaderRule mDexmakerShareClassLoaderRule =
            new DexmakerShareClassLoaderRule();

    protected final TestableDependency mDependency = new TestableDependency(mContext);
    protected SysuiTestableContext mSysuiContext;
    private Instrumentation mRealInstrumentation;
@@ -46,7 +51,6 @@ public abstract class SysuiBaseFragmentTest extends BaseFragmentTest {

    @Before
    public void SysuiSetup() {
        System.setProperty("dexmaker.share_classloader", "true");
        SystemUIFactory.createFromConfig(mContext);
        // TODO: Figure out another way to give reference to a SysuiTestableContext.
        mSysuiContext = (SysuiTestableContext) mContext;
+4 −5
Original line number Diff line number Diff line
@@ -19,21 +19,18 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

import android.app.Instrumentation;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.MessageQueue;
import android.os.ParcelFileDescriptor;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.testing.DexmakerShareClassLoaderRule;
import android.testing.LeakCheck;
import android.util.Log;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import java.io.FileInputStream;
import java.io.IOException;
@@ -51,12 +48,14 @@ public abstract class SysuiTestCase {
    @Rule
    public SysuiTestableContext mContext = new SysuiTestableContext(
            InstrumentationRegistry.getContext(), getLeakCheck());
    @Rule
    public final DexmakerShareClassLoaderRule mDexmakerShareClassLoaderRule =
            new DexmakerShareClassLoaderRule();
    public TestableDependency mDependency = new TestableDependency(mContext);
    private Instrumentation mRealInstrumentation;

    @Before
    public void SysuiSetup() throws Exception {
        System.setProperty("dexmaker.share_classloader", "true");
        mContext.setTheme(R.style.Theme_SystemUI);
        SystemUIFactory.createFromConfig(mContext);

+6 −3
Original line number Diff line number Diff line
@@ -34,11 +34,13 @@ import android.content.pm.UserInfo;
import android.os.UserHandle;
import android.os.UserManager;
import android.support.test.filters.SmallTest;
import android.testing.DexmakerShareClassLoaderRule;

import com.android.internal.app.UnlaunchableAppActivity;
import com.android.server.LocalServices;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -64,6 +66,10 @@ public class ActivityStartInterceptorTest {
            0 /* flags */);
    private static final String TEST_PACKAGE_NAME = "com.test.package";

    @Rule
    public final DexmakerShareClassLoaderRule mDexmakerShareClassLoaderRule =
            new DexmakerShareClassLoaderRule();

    @Mock
    private Context mContext;
    @Mock
@@ -84,9 +90,6 @@ public class ActivityStartInterceptorTest {

    @Before
    public void setUp() {
        // This property is used to allow mocking of package private classes with mockito
        System.setProperty("dexmaker.share_classloader", "true");

        MockitoAnnotations.initMocks(this);
        mInterceptor = new ActivityStartInterceptor(mService, mSupervisor, mContext,
                mUserController);
+8 −3
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@ import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.spy;

import com.android.server.wm.DisplayWindowController;

import org.junit.Rule;
import org.mockito.invocation.InvocationOnMock;

import android.app.IApplicationThread;
@@ -47,6 +49,8 @@ import android.os.HandlerThread;
import android.os.Looper;
import android.service.voice.IVoiceInteractionSession;
import android.support.test.InstrumentationRegistry;
import android.testing.DexmakerShareClassLoaderRule;

import com.android.server.AttributeCache;
import com.android.server.wm.AppWindowContainerController;
import com.android.server.wm.PinnedStackWindowController;
@@ -64,6 +68,10 @@ import org.mockito.MockitoAnnotations;
public class ActivityTestsBase {
    private static boolean sOneTimeSetupDone = false;

    @Rule
    public final DexmakerShareClassLoaderRule mDexmakerShareClassLoaderRule =
            new DexmakerShareClassLoaderRule();

    private final Context mContext = InstrumentationRegistry.getContext();
    private HandlerThread mHandlerThread;

@@ -77,9 +85,6 @@ public class ActivityTestsBase {
    public void setUp() throws Exception {
        if (!sOneTimeSetupDone) {
            sOneTimeSetupDone = true;

            // Allows to mock package local classes and methods
            System.setProperty("dexmaker.share_classloader", "true");
            MockitoAnnotations.initMocks(this);
        }
        mHandlerThread = new HandlerThread("ActivityTestsBaseThread");
+6 −3
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ import android.provider.Settings;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.telecom.TelecomManager;
import android.testing.DexmakerShareClassLoaderRule;
import android.util.Pair;

import com.android.internal.statusbar.IStatusBarService;
@@ -65,6 +66,7 @@ import com.android.server.wm.WindowManagerService;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -85,6 +87,10 @@ public class LockTaskControllerTest {
    private static final int TEST_USER_ID = 123;
    private static final int TEST_UID = 10467;

    @Rule
    public final DexmakerShareClassLoaderRule mDexmakerShareClassLoaderRule =
            new DexmakerShareClassLoaderRule();

    @Mock private ActivityStackSupervisor mSupervisor;
    @Mock private IDevicePolicyManager mDevicePolicyManager;
    @Mock private IStatusBarService mStatusBarService;
@@ -100,9 +106,6 @@ public class LockTaskControllerTest {

    @Before
    public void setUp() throws Exception {
        // This property is used to allow mocking of package private classes with mockito
        System.setProperty("dexmaker.share_classloader", "true");

        MockitoAnnotations.initMocks(this);

        mContext = InstrumentationRegistry.getTargetContext();
Loading