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

Commit a716bac5 authored by Jason Monk's avatar Jason Monk
Browse files

Reduce main thread usage in sysui tests

Make assert more testable and fix up the tests in simple ways so
they still work but not on the main thread because that may or
may not, but is definitely not not flaky.

Test: atest frameworks/base/packages/SystemUI/tests
Change-Id: Ie19d772570b92c4b7f467f5ef9519f81500e63bc
parent 1e31f82a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ public class QSSecurityFooter implements OnClickListener, DialogInterface.OnClic
        mFooterIcon = (ImageView) mRootView.findViewById(R.id.footer_icon);
        mFooterIconId = R.drawable.ic_info_outline;
        mContext = context;
        mMainHandler = new Handler(Looper.getMainLooper());
        mMainHandler = new Handler(Looper.myLooper());
        mActivityStarter = Dependency.get(ActivityStarter.class);
        mSecurityController = Dependency.get(SecurityController.class);
        mHandler = new H(Dependency.get(Dependency.BG_LOOPER));
+7 −2
Original line number Diff line number Diff line
@@ -18,19 +18,24 @@ package com.android.systemui.util;

import android.os.Looper;

import com.android.internal.annotations.VisibleForTesting;

/**
 * Helper providing common assertions.
 */
public class Assert {

    @VisibleForTesting
    public static Looper sMainLooper = Looper.getMainLooper();

    public static void isMainThread() {
        if (!Looper.getMainLooper().isCurrentThread()) {
        if (!sMainLooper.isCurrentThread()) {
            throw new IllegalStateException("should be called from the main thread.");
        }
    }

    public static void isNotMainThread() {
        if (Looper.getMainLooper().isCurrentThread()) {
        if (sMainLooper.isCurrentThread()) {
            throw new IllegalStateException("should not be called from the main thread.");
        }
    }
+1 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

@SmallTest
@RunWithLooper(setAsMainLooper = true)
@RunWithLooper
@RunWith(AndroidTestingRunner.class)
public class KeyguardClockSwitchTest extends SysuiTestCase {
    private PluginManager mPluginManager;
+1 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ import org.mockito.MockitoAnnotations;

@SmallTest
@RunWith(AndroidTestingRunner.class)
@RunWithLooper(setAsMainLooper = true)
@RunWithLooper
public class KeyguardPinBasedInputViewTest extends SysuiTestCase {

    @Mock
+7 −5
Original line number Diff line number Diff line
@@ -19,9 +19,14 @@ import android.graphics.Color;
import android.net.Uri;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.testing.TestableLooper.RunWithLooper;
import android.view.LayoutInflater;

import androidx.slice.SliceProvider;
import androidx.slice.SliceSpecs;
import androidx.slice.builders.ListBuilder;

import com.android.systemui.SysuiTestCase;
import com.android.systemui.keyguard.KeyguardSliceProvider;

@@ -34,12 +39,8 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.concurrent.atomic.AtomicBoolean;

import androidx.slice.SliceProvider;
import androidx.slice.SliceSpecs;
import androidx.slice.builders.ListBuilder;

@SmallTest
@RunWithLooper(setAsMainLooper = true)
@RunWithLooper
@RunWith(AndroidTestingRunner.class)
public class KeyguardSliceViewTest extends SysuiTestCase {
    private KeyguardSliceView mKeyguardSliceView;
@@ -47,6 +48,7 @@ public class KeyguardSliceViewTest extends SysuiTestCase {

    @Before
    public void setUp() throws Exception {
        com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper();
        mKeyguardSliceView = (KeyguardSliceView) LayoutInflater.from(getContext())
                .inflate(R.layout.keyguard_status_area, null);
        mSliceUri = Uri.parse(KeyguardSliceProvider.KEYGUARD_SLICE_URI);
Loading