Merge "Reduce usages of main looper in sysui tests" into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
5be1956952
@@ -137,9 +137,15 @@ public class NotificationInflater {
|
||||
return;
|
||||
}
|
||||
StatusBarNotification sbn = mRow.getEntry().notification;
|
||||
new AsyncInflationTask(sbn, reInflateFlags, mRow, mIsLowPriority,
|
||||
AsyncInflationTask task = new AsyncInflationTask(sbn, reInflateFlags, mRow,
|
||||
mIsLowPriority,
|
||||
mIsChildInGroup, mUsesIncreasedHeight, mUsesIncreasedHeadsUpHeight, mRedactAmbient,
|
||||
mCallback, mRemoteViewClickHandler).execute();
|
||||
mCallback, mRemoteViewClickHandler);
|
||||
if (mCallback != null && mCallback.doInflateSynchronous()) {
|
||||
task.onPostExecute(task.doInBackground());
|
||||
} else {
|
||||
task.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -331,6 +337,30 @@ public class NotificationInflater {
|
||||
final HashMap<Integer, CancellationSignal> runningInflations,
|
||||
ApplyCallback applyCallback) {
|
||||
RemoteViews newContentView = applyCallback.getRemoteView();
|
||||
if (callback != null && callback.doInflateSynchronous()) {
|
||||
try {
|
||||
if (isNewView) {
|
||||
View v = newContentView.apply(
|
||||
result.packageContext,
|
||||
parentLayout,
|
||||
remoteViewClickHandler);
|
||||
v.setIsRootNamespace(true);
|
||||
applyCallback.setResultView(v);
|
||||
} else {
|
||||
newContentView.reapply(
|
||||
result.packageContext,
|
||||
existingView,
|
||||
remoteViewClickHandler);
|
||||
existingWrapper.onReinflated();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
handleInflationError(runningInflations, e, entry.notification, callback);
|
||||
// Add a running inflation to make sure we don't trigger callbacks.
|
||||
// Safe to do because only happens in tests.
|
||||
runningInflations.put(inflationId, new CancellationSignal());
|
||||
}
|
||||
return;
|
||||
}
|
||||
RemoteViews.OnViewAppliedListener listener
|
||||
= new RemoteViews.OnViewAppliedListener() {
|
||||
|
||||
@@ -515,6 +545,13 @@ public class NotificationInflater {
|
||||
public interface InflationCallback {
|
||||
void handleInflationException(StatusBarNotification notification, Exception e);
|
||||
void onAsyncInflationFinished(NotificationData.Entry entry);
|
||||
|
||||
/**
|
||||
* Used to disable async-ness for tests. Should only be used for tests.
|
||||
*/
|
||||
default boolean doInflateSynchronous() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void onDensityOrFontScaleChanged() {
|
||||
@@ -646,6 +683,11 @@ public class NotificationInflater {
|
||||
mRow.onNotificationUpdated();
|
||||
mCallback.onAsyncInflationFinished(mRow.getEntry());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doInflateSynchronous() {
|
||||
return mCallback != null && mCallback.doInflateSynchronous();
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
||||
@@ -20,10 +20,9 @@ import static junit.framework.Assert.assertEquals;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper.RunWithLooper;
|
||||
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
|
||||
@@ -32,33 +31,25 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@RunWithLooper
|
||||
public class KeyguardMessageAreaTest extends SysuiTestCase {
|
||||
private Handler mHandler = new Handler(Looper.getMainLooper());
|
||||
private KeyguardMessageArea mMessageArea;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
KeyguardUpdateMonitor monitor = mock(KeyguardUpdateMonitor.class);
|
||||
mHandler.post(()-> mMessageArea = new KeyguardMessageArea(mContext, null, monitor));
|
||||
mMessageArea = new KeyguardMessageArea(mContext, null, monitor);
|
||||
waitForIdleSync();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearFollowedByMessage_keepsMessage() {
|
||||
mHandler.post(()-> {
|
||||
mMessageArea.setMessage("");
|
||||
mMessageArea.setMessage("test");
|
||||
});
|
||||
|
||||
waitForIdleSync();
|
||||
mMessageArea.setMessage("");
|
||||
mMessageArea.setMessage("test");
|
||||
|
||||
CharSequence[] messageText = new CharSequence[1];
|
||||
mHandler.post(()-> {
|
||||
messageText[0] = mMessageArea.getText();
|
||||
});
|
||||
|
||||
waitForIdleSync();
|
||||
messageText[0] = mMessageArea.getText();
|
||||
|
||||
assertEquals("test", messageText[0]);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.annotation.UiThreadTest;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper.RunWithLooper;
|
||||
|
||||
import com.android.systemui.statusbar.ExpandableNotificationRow;
|
||||
import com.android.systemui.statusbar.NotificationTestHelper;
|
||||
@@ -35,7 +37,8 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@RunWithLooper(setAsMainLooper = true)
|
||||
public class ExpandHelperTest extends SysuiTestCase {
|
||||
|
||||
private ExpandableNotificationRow mRow;
|
||||
@@ -47,9 +50,7 @@ public class ExpandHelperTest extends SysuiTestCase {
|
||||
Context context = getContext();
|
||||
mRow = new NotificationTestHelper(context).createRow();
|
||||
mCallback = mock(ExpandHelper.Callback.class);
|
||||
InstrumentationRegistry.getInstrumentation().runOnMainSync(
|
||||
() -> mExpandHelper = new ExpandHelper(context, mCallback, 10, 100));
|
||||
|
||||
mExpandHelper = new ExpandHelper(context, mCallback, 10, 100);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -29,7 +29,8 @@ import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper.RunWithLooper;
|
||||
|
||||
import com.android.internal.hardware.AmbientDisplayConfiguration;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
@@ -46,7 +47,8 @@ import org.junit.runner.RunWith;
|
||||
|
||||
@SmallTest
|
||||
@Ignore("failing")
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@RunWithLooper(setAsMainLooper = true)
|
||||
public class DozeTriggersTest extends SysuiTestCase {
|
||||
private DozeTriggers mTriggers;
|
||||
private DozeMachine mMachine;
|
||||
@@ -54,7 +56,6 @@ public class DozeTriggersTest extends SysuiTestCase {
|
||||
private AmbientDisplayConfiguration mConfig;
|
||||
private DozeParameters mParameters;
|
||||
private FakeSensorManager mSensors;
|
||||
private Handler mHandler;
|
||||
private WakeLock mWakeLock;
|
||||
private Instrumentation mInstrumentation;
|
||||
private AlarmManager mAlarmManager;
|
||||
@@ -74,40 +75,29 @@ public class DozeTriggersTest extends SysuiTestCase {
|
||||
mConfig = DozeConfigurationUtil.createMockConfig();
|
||||
mParameters = DozeConfigurationUtil.createMockParameters();
|
||||
mSensors = new FakeSensorManager(mContext);
|
||||
mHandler = new Handler(Looper.getMainLooper());
|
||||
mWakeLock = new WakeLockFake();
|
||||
|
||||
mInstrumentation.runOnMainSync(() -> {
|
||||
mTriggers = new DozeTriggers(mContext, mMachine, mHost, mAlarmManager,
|
||||
mConfig, mParameters, mSensors, mHandler, mWakeLock, true);
|
||||
});
|
||||
mTriggers = new DozeTriggers(mContext, mMachine, mHost, mAlarmManager, mConfig, mParameters,
|
||||
mSensors, Handler.createAsync(Looper.myLooper()), mWakeLock, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnNotification_stillWorksAfterOneFailedProxCheck() throws Exception {
|
||||
when(mMachine.getState()).thenReturn(DozeMachine.State.DOZE);
|
||||
|
||||
mInstrumentation.runOnMainSync(()->{
|
||||
mTriggers.transitionTo(DozeMachine.State.UNINITIALIZED, DozeMachine.State.INITIALIZED);
|
||||
mTriggers.transitionTo(DozeMachine.State.INITIALIZED, DozeMachine.State.DOZE);
|
||||
mTriggers.transitionTo(DozeMachine.State.UNINITIALIZED, DozeMachine.State.INITIALIZED);
|
||||
mTriggers.transitionTo(DozeMachine.State.INITIALIZED, DozeMachine.State.DOZE);
|
||||
|
||||
mHost.callback.onNotificationHeadsUp();
|
||||
});
|
||||
mHost.callback.onNotificationHeadsUp();
|
||||
|
||||
mInstrumentation.runOnMainSync(() -> {
|
||||
mSensors.getMockProximitySensor().sendProximityResult(false); /* Near */
|
||||
});
|
||||
mSensors.getMockProximitySensor().sendProximityResult(false); /* Near */
|
||||
|
||||
verify(mMachine, never()).requestState(any());
|
||||
verify(mMachine, never()).requestPulse(anyInt());
|
||||
|
||||
mInstrumentation.runOnMainSync(()->{
|
||||
mHost.callback.onNotificationHeadsUp();
|
||||
});
|
||||
mHost.callback.onNotificationHeadsUp();
|
||||
|
||||
mInstrumentation.runOnMainSync(() -> {
|
||||
mSensors.getMockProximitySensor().sendProximityResult(true); /* Far */
|
||||
});
|
||||
mSensors.getMockProximitySensor().sendProximityResult(true); /* Far */
|
||||
|
||||
verify(mMachine).requestPulse(anyInt());
|
||||
}
|
||||
|
||||
@@ -24,43 +24,36 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.Looper;
|
||||
import android.os.SystemClock;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper;
|
||||
import android.testing.TestableLooper.RunWithLooper;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.ViewConfiguration;
|
||||
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.pip.phone.PipTouchState;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@SmallTest
|
||||
@RunWithLooper
|
||||
public class PipTouchStateTest extends SysuiTestCase {
|
||||
|
||||
private Handler mHandler;
|
||||
private HandlerThread mHandlerThread;
|
||||
private PipTouchState mTouchState;
|
||||
private CountDownLatch mDoubleTapCallbackTriggeredLatch;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mHandlerThread = new HandlerThread("PipTouchStateTestThread");
|
||||
mHandlerThread.start();
|
||||
mHandler = new Handler(mHandlerThread.getLooper());
|
||||
|
||||
mDoubleTapCallbackTriggeredLatch = new CountDownLatch(1);
|
||||
mTouchState = new PipTouchState(ViewConfiguration.get(getContext()),
|
||||
mHandler, () -> {
|
||||
Handler.createAsync(Looper.myLooper()), () -> {
|
||||
mDoubleTapCallbackTriggeredLatch.countDown();
|
||||
});
|
||||
assertFalse(mTouchState.isDoubleTap());
|
||||
@@ -91,7 +84,10 @@ public class PipTouchStateTest extends SysuiTestCase {
|
||||
|
||||
assertTrue(mTouchState.getDoubleTapTimeoutCallbackDelay() == 10);
|
||||
mTouchState.scheduleDoubleTapTimeoutCallback();
|
||||
mDoubleTapCallbackTriggeredLatch.await(1, TimeUnit.SECONDS);
|
||||
|
||||
// TODO: Remove this sleep. Its only being added because it speeds up this test a bit.
|
||||
Thread.sleep(15);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
assertTrue(mDoubleTapCallbackTriggeredLatch.getCount() == 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,12 +22,15 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.LayoutInflaterBuilder;
|
||||
import android.testing.TestableImageView;
|
||||
import android.testing.TestableLooper;
|
||||
import android.testing.TestableLooper.RunWithLooper;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -38,8 +41,6 @@ import com.android.systemui.Dependency;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.statusbar.policy.SecurityController;
|
||||
import android.testing.LayoutInflaterBuilder;
|
||||
import android.testing.TestableImageView;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -56,7 +57,8 @@ import org.mockito.Mockito;
|
||||
*/
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@RunWithLooper(setAsMainLooper = true)
|
||||
public class QSSecurityFooterTest extends SysuiTestCase {
|
||||
|
||||
private final String MANAGING_ORGANIZATION = "organization";
|
||||
@@ -81,12 +83,10 @@ public class QSSecurityFooterTest extends SysuiTestCase {
|
||||
.build());
|
||||
mUserManager = Mockito.mock(UserManager.class);
|
||||
mContext.addMockSystemService(Context.USER_SERVICE, mUserManager);
|
||||
Handler h = new Handler(Looper.getMainLooper());
|
||||
h.post(() -> mFooter = new QSSecurityFooter(null, mContext));
|
||||
waitForIdleSync(h);
|
||||
mFooter = new QSSecurityFooter(null, mContext);
|
||||
mRootView = (ViewGroup) mFooter.getView();
|
||||
mFooterText = (TextView) mRootView.findViewById(R.id.footer_text);
|
||||
mFooterIcon = (TestableImageView) mRootView.findViewById(R.id.footer_icon);
|
||||
mFooterText = mRootView.findViewById(R.id.footer_text);
|
||||
mFooterIcon = mRootView.findViewById(R.id.footer_icon);
|
||||
mFooter.setHostEnvironment(null);
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
|
||||
when(mSecurityController.isDeviceManaged()).thenReturn(false);
|
||||
mFooter.refreshState();
|
||||
|
||||
waitForIdleSync(mFooter.mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
assertEquals(View.GONE, mRootView.getVisibility());
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
|
||||
when(mSecurityController.getDeviceOwnerOrganizationName()).thenReturn(null);
|
||||
mFooter.refreshState();
|
||||
|
||||
waitForIdleSync(mFooter.mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
assertEquals(mContext.getString(R.string.quick_settings_disclosure_management),
|
||||
mFooterText.getText());
|
||||
assertEquals(View.VISIBLE, mRootView.getVisibility());
|
||||
@@ -121,7 +121,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
|
||||
.thenReturn(MANAGING_ORGANIZATION);
|
||||
mFooter.refreshState();
|
||||
|
||||
waitForIdleSync(mFooter.mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
assertEquals(mContext.getString(R.string.quick_settings_disclosure_named_management,
|
||||
MANAGING_ORGANIZATION),
|
||||
mFooterText.getText());
|
||||
@@ -142,7 +142,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
|
||||
|
||||
mFooter.refreshState();
|
||||
|
||||
waitForIdleSync(mFooter.mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
assertEquals(View.GONE, mRootView.getVisibility());
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
|
||||
when(mSecurityController.isNetworkLoggingEnabled()).thenReturn(true);
|
||||
mFooter.refreshState();
|
||||
|
||||
waitForIdleSync(mFooter.mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
assertEquals(mContext.getString(R.string.quick_settings_disclosure_management_monitoring),
|
||||
mFooterText.getText());
|
||||
assertEquals(View.VISIBLE, mFooterIcon.getVisibility());
|
||||
@@ -164,7 +164,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
|
||||
.thenReturn(MANAGING_ORGANIZATION);
|
||||
mFooter.refreshState();
|
||||
|
||||
waitForIdleSync(mFooter.mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
assertEquals(mContext.getString(
|
||||
R.string.quick_settings_disclosure_named_management_monitoring,
|
||||
MANAGING_ORGANIZATION),
|
||||
@@ -177,7 +177,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
|
||||
when(mSecurityController.hasCACertInCurrentUser()).thenReturn(true);
|
||||
mFooter.refreshState();
|
||||
|
||||
waitForIdleSync(mFooter.mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
assertEquals(mContext.getString(R.string.quick_settings_disclosure_management_monitoring),
|
||||
mFooterText.getText());
|
||||
}
|
||||
@@ -189,7 +189,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
|
||||
when(mSecurityController.getPrimaryVpnName()).thenReturn(VPN_PACKAGE);
|
||||
mFooter.refreshState();
|
||||
|
||||
waitForIdleSync(mFooter.mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
assertEquals(mContext.getString(R.string.quick_settings_disclosure_management_named_vpn,
|
||||
VPN_PACKAGE),
|
||||
mFooterText.getText());
|
||||
@@ -201,7 +201,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
|
||||
.thenReturn(MANAGING_ORGANIZATION);
|
||||
mFooter.refreshState();
|
||||
|
||||
waitForIdleSync(mFooter.mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
assertEquals(mContext.getString(
|
||||
R.string.quick_settings_disclosure_named_management_named_vpn,
|
||||
MANAGING_ORGANIZATION, VPN_PACKAGE),
|
||||
@@ -216,7 +216,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
|
||||
when(mSecurityController.getWorkProfileVpnName()).thenReturn(VPN_PACKAGE_2);
|
||||
mFooter.refreshState();
|
||||
|
||||
waitForIdleSync(mFooter.mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
assertEquals(mContext.getString(R.string.quick_settings_disclosure_management_vpns),
|
||||
mFooterText.getText());
|
||||
assertEquals(View.VISIBLE, mFooterIcon.getVisibility());
|
||||
@@ -227,7 +227,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
|
||||
.thenReturn(MANAGING_ORGANIZATION);
|
||||
mFooter.refreshState();
|
||||
|
||||
waitForIdleSync(mFooter.mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
assertEquals(mContext.getString(R.string.quick_settings_disclosure_named_management_vpns,
|
||||
MANAGING_ORGANIZATION),
|
||||
mFooterText.getText());
|
||||
@@ -241,7 +241,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
|
||||
when(mSecurityController.getPrimaryVpnName()).thenReturn("VPN Test App");
|
||||
mFooter.refreshState();
|
||||
|
||||
waitForIdleSync(mFooter.mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
assertEquals(View.VISIBLE, mFooterIcon.getVisibility());
|
||||
assertEquals(R.drawable.ic_qs_vpn, mFooterIcon.getLastImageResource());
|
||||
assertEquals(mContext.getString(R.string.quick_settings_disclosure_management_monitoring),
|
||||
@@ -254,7 +254,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
|
||||
when(mSecurityController.hasCACertInWorkProfile()).thenReturn(true);
|
||||
mFooter.refreshState();
|
||||
|
||||
waitForIdleSync(mFooter.mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
// -1 == never set.
|
||||
assertEquals(-1, mFooterIcon.getLastImageResource());
|
||||
assertEquals(mContext.getString(
|
||||
@@ -266,7 +266,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
|
||||
.thenReturn(MANAGING_ORGANIZATION);
|
||||
mFooter.refreshState();
|
||||
|
||||
waitForIdleSync(mFooter.mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
assertEquals(mContext.getString(
|
||||
R.string.quick_settings_disclosure_named_managed_profile_monitoring,
|
||||
MANAGING_ORGANIZATION),
|
||||
@@ -279,7 +279,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
|
||||
when(mSecurityController.hasCACertInCurrentUser()).thenReturn(true);
|
||||
mFooter.refreshState();
|
||||
|
||||
waitForIdleSync(mFooter.mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
// -1 == never set.
|
||||
assertEquals(-1, mFooterIcon.getLastImageResource());
|
||||
assertEquals(mContext.getString(R.string.quick_settings_disclosure_monitoring),
|
||||
@@ -293,7 +293,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
|
||||
when(mSecurityController.getWorkProfileVpnName()).thenReturn(VPN_PACKAGE_2);
|
||||
mFooter.refreshState();
|
||||
|
||||
waitForIdleSync(mFooter.mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
assertEquals(R.drawable.ic_qs_vpn, mFooterIcon.getLastImageResource());
|
||||
assertEquals(mContext.getString(R.string.quick_settings_disclosure_vpns),
|
||||
mFooterText.getText());
|
||||
@@ -305,7 +305,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
|
||||
when(mSecurityController.getWorkProfileVpnName()).thenReturn(VPN_PACKAGE_2);
|
||||
mFooter.refreshState();
|
||||
|
||||
waitForIdleSync(mFooter.mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
assertEquals(R.drawable.ic_qs_vpn, mFooterIcon.getLastImageResource());
|
||||
assertEquals(mContext.getString(
|
||||
R.string.quick_settings_disclosure_managed_profile_named_vpn,
|
||||
@@ -319,7 +319,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
|
||||
when(mSecurityController.getPrimaryVpnName()).thenReturn(VPN_PACKAGE);
|
||||
mFooter.refreshState();
|
||||
|
||||
waitForIdleSync(mFooter.mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
assertEquals(R.drawable.ic_qs_vpn, mFooterIcon.getLastImageResource());
|
||||
assertEquals(mContext.getString(R.string.quick_settings_disclosure_named_vpn,
|
||||
VPN_PACKAGE),
|
||||
@@ -328,7 +328,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
|
||||
when(mSecurityController.hasWorkProfile()).thenReturn(true);
|
||||
mFooter.refreshState();
|
||||
|
||||
waitForIdleSync(mFooter.mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
assertEquals(mContext.getString(
|
||||
R.string.quick_settings_disclosure_personal_profile_named_vpn,
|
||||
VPN_PACKAGE),
|
||||
|
||||
@@ -81,7 +81,7 @@ public class TileLifecycleManagerTest extends SysuiTestCase {
|
||||
mUser = new UserHandle(UserHandle.myUserId());
|
||||
mThread = new HandlerThread("TestThread");
|
||||
mThread.start();
|
||||
mHandler = new Handler(mThread.getLooper());
|
||||
mHandler = Handler.createAsync(mThread.getLooper());
|
||||
mStateManager = new TileLifecycleManager(mHandler, mContext,
|
||||
Mockito.mock(IQSService.class), new Tile(),
|
||||
mTileServiceIntent,
|
||||
|
||||
@@ -46,7 +46,7 @@ public class TileServiceManagerTest extends SysuiTestCase {
|
||||
public void setUp() throws Exception {
|
||||
mThread = new HandlerThread("TestThread");
|
||||
mThread.start();
|
||||
mHandler = new Handler(mThread.getLooper());
|
||||
mHandler = Handler.createAsync(mThread.getLooper());
|
||||
mTileServices = Mockito.mock(TileServices.class);
|
||||
Mockito.when(mTileServices.getContext()).thenReturn(mContext);
|
||||
mTileLifecycle = Mockito.mock(TileLifecycleManager.class);
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package com.android.systemui.statusbar;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -53,7 +51,6 @@ public class AppOpsListenerTest extends SysuiTestCase {
|
||||
@Mock private ForegroundServiceController mFsc;
|
||||
|
||||
private AppOpsListener mListener;
|
||||
private Handler mHandler;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -61,8 +58,7 @@ public class AppOpsListenerTest extends SysuiTestCase {
|
||||
mDependency.injectTestDependency(NotificationEntryManager.class, mEntryManager);
|
||||
mDependency.injectTestDependency(ForegroundServiceController.class, mFsc);
|
||||
getContext().addMockSystemService(AppOpsManager.class, mAppOpsManager);
|
||||
mHandler = new Handler(Looper.getMainLooper());
|
||||
when(mPresenter.getHandler()).thenReturn(mHandler);
|
||||
when(mPresenter.getHandler()).thenReturn(Handler.createAsync(Looper.myLooper()));
|
||||
|
||||
mListener = new AppOpsListener(mContext);
|
||||
}
|
||||
@@ -85,7 +81,7 @@ public class AppOpsListenerTest extends SysuiTestCase {
|
||||
mListener.setUpWithPresenter(mPresenter, mEntryManager);
|
||||
mListener.onOpActiveChanged(
|
||||
AppOpsManager.OP_RECORD_AUDIO, TEST_UID, TEST_PACKAGE_NAME, true);
|
||||
waitForIdleSync(mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
verify(mEntryManager, times(1)).updateNotificationsForAppOp(
|
||||
AppOpsManager.OP_RECORD_AUDIO, TEST_UID, TEST_PACKAGE_NAME, true);
|
||||
}
|
||||
@@ -95,7 +91,7 @@ public class AppOpsListenerTest extends SysuiTestCase {
|
||||
mListener.setUpWithPresenter(mPresenter, mEntryManager);
|
||||
mListener.onOpActiveChanged(
|
||||
AppOpsManager.OP_RECORD_AUDIO, TEST_UID, TEST_PACKAGE_NAME, true);
|
||||
waitForIdleSync(mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
verify(mFsc, times(1)).onAppOpChanged(
|
||||
AppOpsManager.OP_RECORD_AUDIO, TEST_UID, TEST_PACKAGE_NAME, true);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.android.systemui.statusbar;
|
||||
|
||||
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -33,7 +34,8 @@ import static org.mockito.Mockito.when;
|
||||
import android.app.AppOpsManager;
|
||||
import android.app.NotificationChannel;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper.RunWithLooper;
|
||||
import android.util.ArraySet;
|
||||
import android.view.NotificationHeaderView;
|
||||
import android.view.View;
|
||||
@@ -49,15 +51,14 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@RunWithLooper(setAsMainLooper = true)
|
||||
public class ExpandableNotificationRowTest extends SysuiTestCase {
|
||||
|
||||
private ExpandableNotificationRow mGroupRow;
|
||||
|
||||
@@ -55,13 +55,10 @@ public class NonPhoneDependencyTest extends SysuiTestCase {
|
||||
@Mock private NotificationGutsManager.OnSettingsClickListener mOnClickListener;
|
||||
@Mock private NotificationRemoteInputManager.Callback mRemoteInputManagerCallback;
|
||||
|
||||
private Handler mHandler;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mHandler = new Handler(Looper.getMainLooper());
|
||||
when(mPresenter.getHandler()).thenReturn(mHandler);
|
||||
when(mPresenter.getHandler()).thenReturn(Handler.createAsync(Looper.myLooper()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -52,7 +52,7 @@ import static org.mockito.Mockito.when;
|
||||
@SmallTest
|
||||
@FlakyTest
|
||||
@org.junit.runner.RunWith(AndroidTestingRunner.class)
|
||||
@TestableLooper.RunWithLooper
|
||||
@TestableLooper.RunWithLooper(setAsMainLooper = true)
|
||||
public class NotificationBlockingHelperManagerTest extends SysuiTestCase {
|
||||
|
||||
private NotificationBlockingHelperManager mBlockingHelperManager;
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
package com.android.systemui.statusbar;
|
||||
|
||||
import android.support.test.annotation.UiThreadTest;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper.RunWithLooper;
|
||||
import android.view.View;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
@@ -33,7 +33,8 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@RunWithLooper(setAsMainLooper = true)
|
||||
public class NotificationCustomViewWrapperTest extends SysuiTestCase {
|
||||
|
||||
private ExpandableNotificationRow mRow;
|
||||
|
||||
@@ -47,6 +47,8 @@ import android.service.notification.StatusBarNotification;
|
||||
import android.support.test.annotation.UiThreadTest;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper.RunWithLooper;
|
||||
import android.util.ArraySet;
|
||||
|
||||
import com.android.systemui.ForegroundServiceController;
|
||||
@@ -61,7 +63,8 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@RunWithLooper(setAsMainLooper = true)
|
||||
public class NotificationDataTest extends SysuiTestCase {
|
||||
|
||||
private static final int UID_NORMAL = 123;
|
||||
|
||||
@@ -100,7 +100,6 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
|
||||
|
||||
private NotificationData.Entry mEntry;
|
||||
private StatusBarNotification mSbn;
|
||||
private Handler mHandler;
|
||||
private TestableNotificationEntryManager mEntryManager;
|
||||
private CountDownLatch mCountDownLatch;
|
||||
|
||||
@@ -160,10 +159,9 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
|
||||
mDependency.injectTestDependency(VisualStabilityManager.class, mVisualStabilityManager);
|
||||
mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger);
|
||||
|
||||
mHandler = new Handler(Looper.getMainLooper());
|
||||
mCountDownLatch = new CountDownLatch(1);
|
||||
|
||||
when(mPresenter.getHandler()).thenReturn(mHandler);
|
||||
when(mPresenter.getHandler()).thenReturn(Handler.createAsync(Looper.myLooper()));
|
||||
when(mPresenter.getNotificationLockscreenUserManager()).thenReturn(mLockscreenUserManager);
|
||||
when(mPresenter.getGroupManager()).thenReturn(mGroupManager);
|
||||
when(mRemoteInputManager.getController()).thenReturn(mRemoteInputController);
|
||||
@@ -188,6 +186,7 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void testAddNotification() throws Exception {
|
||||
com.android.systemui.util.Assert.isNotMainThread();
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
|
||||
doAnswer(invocation -> {
|
||||
mCountDownLatch.countDown();
|
||||
@@ -196,12 +195,10 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
|
||||
|
||||
// Post on main thread, otherwise we will be stuck waiting here for the inflation finished
|
||||
// callback forever, since it won't execute until the tests ends.
|
||||
mHandler.post(() -> {
|
||||
mEntryManager.addNotification(mSbn, mRankingMap);
|
||||
});
|
||||
assertTrue(mCountDownLatch.await(1, TimeUnit.MINUTES));
|
||||
assertTrue(mEntryManager.getCountDownLatch().await(1, TimeUnit.MINUTES));
|
||||
waitForIdleSync(mHandler);
|
||||
mEntryManager.addNotification(mSbn, mRankingMap);
|
||||
TestableLooper.get(this).processMessages(1);
|
||||
assertTrue(mCountDownLatch.await(10, TimeUnit.SECONDS));
|
||||
assertTrue(mEntryManager.getCountDownLatch().await(10, TimeUnit.SECONDS));
|
||||
|
||||
// Check that no inflation error occurred.
|
||||
verify(mBarService, never()).onNotificationError(any(), any(), anyInt(), anyInt(), anyInt(),
|
||||
@@ -228,17 +225,16 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void testUpdateNotification() throws Exception {
|
||||
com.android.systemui.util.Assert.isNotMainThread();
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
|
||||
mEntryManager.getNotificationData().add(mEntry);
|
||||
|
||||
setUserSentiment(mEntry.key, NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE);
|
||||
|
||||
mHandler.post(() -> {
|
||||
mEntryManager.updateNotification(mSbn, mRankingMap);
|
||||
});
|
||||
mEntryManager.updateNotification(mSbn, mRankingMap);
|
||||
TestableLooper.get(this).processMessages(1);
|
||||
// Wait for content update.
|
||||
mEntryManager.getCountDownLatch().await(1, TimeUnit.MINUTES);
|
||||
waitForIdleSync(mHandler);
|
||||
assertTrue(mEntryManager.getCountDownLatch().await(10, TimeUnit.SECONDS));
|
||||
|
||||
verify(mBarService, never()).onNotificationError(any(), any(), anyInt(), anyInt(), anyInt(),
|
||||
any(), anyInt());
|
||||
@@ -259,10 +255,7 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
|
||||
mEntry.row = mRow;
|
||||
mEntryManager.getNotificationData().add(mEntry);
|
||||
|
||||
mHandler.post(() -> {
|
||||
mEntryManager.removeNotification(mSbn.getKey(), mRankingMap);
|
||||
});
|
||||
waitForIdleSync(mHandler);
|
||||
mEntryManager.removeNotification(mSbn.getKey(), mRankingMap);
|
||||
|
||||
verify(mBarService, never()).onNotificationError(any(), any(), anyInt(), anyInt(), anyInt(),
|
||||
any(), anyInt());
|
||||
@@ -287,12 +280,9 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
|
||||
mEntry.row = mRow;
|
||||
mEntryManager.getNotificationData().add(mEntry);
|
||||
|
||||
mHandler.post(() -> {
|
||||
mEntryManager.updateNotificationsForAppOp(
|
||||
AppOpsManager.OP_CAMERA, mEntry.notification.getUid(),
|
||||
mEntry.notification.getPackageName(), true);
|
||||
});
|
||||
waitForIdleSync(mHandler);
|
||||
mEntryManager.updateNotificationsForAppOp(
|
||||
AppOpsManager.OP_CAMERA, mEntry.notification.getUid(),
|
||||
mEntry.notification.getPackageName(), true);
|
||||
|
||||
verify(mPresenter, times(1)).updateNotificationViews();
|
||||
assertTrue(mEntryManager.getNotificationData().get(mEntry.key).mActiveAppOps.contains(
|
||||
@@ -305,10 +295,7 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
|
||||
|
||||
when(mForegroundServiceController.getStandardLayoutKey(anyInt(), anyString()))
|
||||
.thenReturn(null);
|
||||
mHandler.post(() -> {
|
||||
mEntryManager.updateNotificationsForAppOp(AppOpsManager.OP_CAMERA, 1000, "pkg", true);
|
||||
});
|
||||
waitForIdleSync(mHandler);
|
||||
mEntryManager.updateNotificationsForAppOp(AppOpsManager.OP_CAMERA, 1000, "pkg", true);
|
||||
|
||||
verify(mPresenter, never()).updateNotificationViews();
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ import java.util.Set;
|
||||
*/
|
||||
@SmallTest
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@TestableLooper.RunWithLooper
|
||||
@TestableLooper.RunWithLooper(setAsMainLooper = true)
|
||||
public class NotificationGutsManagerTest extends SysuiTestCase {
|
||||
private static final String TEST_CHANNEL_ID = "NotificationManagerServiceTestChannelId";
|
||||
|
||||
@@ -95,7 +95,7 @@ public class NotificationGutsManagerTest extends SysuiTestCase {
|
||||
@Before
|
||||
public void setUp() {
|
||||
mTestableLooper = TestableLooper.get(this);
|
||||
mHandler = new Handler(mTestableLooper.getLooper());
|
||||
mHandler = Handler.createAsync(mTestableLooper.getLooper());
|
||||
|
||||
mHelper = new NotificationTestHelper(mContext);
|
||||
|
||||
|
||||
@@ -59,7 +59,6 @@ public class NotificationListenerTest extends SysuiTestCase {
|
||||
@Mock private NotificationRemoteInputManager mRemoteInputManager;
|
||||
|
||||
private NotificationListener mListener;
|
||||
private Handler mHandler;
|
||||
private StatusBarNotification mSbn;
|
||||
private Set<String> mKeysKeptForRemoteInput;
|
||||
|
||||
@@ -70,10 +69,9 @@ public class NotificationListenerTest extends SysuiTestCase {
|
||||
mDependency.injectTestDependency(NotificationRemoteInputManager.class,
|
||||
mRemoteInputManager);
|
||||
|
||||
mHandler = new Handler(Looper.getMainLooper());
|
||||
mKeysKeptForRemoteInput = new HashSet<>();
|
||||
|
||||
when(mPresenter.getHandler()).thenReturn(mHandler);
|
||||
when(mPresenter.getHandler()).thenReturn(Handler.createAsync(Looper.myLooper()));
|
||||
when(mEntryManager.getNotificationData()).thenReturn(mNotificationData);
|
||||
when(mRemoteInputManager.getKeysKeptForRemoteInput()).thenReturn(mKeysKeptForRemoteInput);
|
||||
|
||||
@@ -87,7 +85,7 @@ public class NotificationListenerTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void testNotificationAddCallsAddNotification() {
|
||||
mListener.onNotificationPosted(mSbn, mRanking);
|
||||
waitForIdleSync(mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
verify(mEntryManager).addNotification(mSbn, mRanking);
|
||||
}
|
||||
|
||||
@@ -95,7 +93,7 @@ public class NotificationListenerTest extends SysuiTestCase {
|
||||
public void testPostNotificationRemovesKeyKeptForRemoteInput() {
|
||||
mKeysKeptForRemoteInput.add(mSbn.getKey());
|
||||
mListener.onNotificationPosted(mSbn, mRanking);
|
||||
waitForIdleSync(mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
assertTrue(mKeysKeptForRemoteInput.isEmpty());
|
||||
}
|
||||
|
||||
@@ -103,21 +101,21 @@ public class NotificationListenerTest extends SysuiTestCase {
|
||||
public void testNotificationUpdateCallsUpdateNotification() {
|
||||
when(mNotificationData.get(mSbn.getKey())).thenReturn(new NotificationData.Entry(mSbn));
|
||||
mListener.onNotificationPosted(mSbn, mRanking);
|
||||
waitForIdleSync(mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
verify(mEntryManager).updateNotification(mSbn, mRanking);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotificationRemovalCallsRemoveNotification() {
|
||||
mListener.onNotificationRemoved(mSbn, mRanking);
|
||||
waitForIdleSync(mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
verify(mEntryManager).removeNotification(mSbn.getKey(), mRanking);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRankingUpdateCallsNotificationRankingUpdate() {
|
||||
mListener.onNotificationRankingUpdate(mRanking);
|
||||
waitForIdleSync(mHandler);
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
// RankingMap may be modified by plugins.
|
||||
verify(mEntryManager).updateNotificationRanking(any());
|
||||
}
|
||||
|
||||
@@ -63,7 +63,6 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
|
||||
@Mock private DeviceProvisionedController mDeviceProvisionedController;
|
||||
|
||||
private int mCurrentUserId;
|
||||
private Handler mHandler;
|
||||
private TestNotificationLockscreenUserManager mLockscreenUserManager;
|
||||
|
||||
@Before
|
||||
@@ -73,13 +72,12 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
|
||||
mDependency.injectTestDependency(DeviceProvisionedController.class,
|
||||
mDeviceProvisionedController);
|
||||
|
||||
mHandler = new Handler(Looper.getMainLooper());
|
||||
mContext.addMockSystemService(UserManager.class, mUserManager);
|
||||
mCurrentUserId = ActivityManager.getCurrentUser();
|
||||
|
||||
when(mUserManager.getProfiles(mCurrentUserId)).thenReturn(Lists.newArrayList(
|
||||
new UserInfo(mCurrentUserId, "", 0), new UserInfo(mCurrentUserId + 1, "", 0)));
|
||||
when(mPresenter.getHandler()).thenReturn(mHandler);
|
||||
when(mPresenter.getHandler()).thenReturn(Handler.createAsync(Looper.myLooper()));
|
||||
|
||||
mLockscreenUserManager = new TestNotificationLockscreenUserManager(mContext);
|
||||
mLockscreenUserManager.setUpWithPresenter(mPresenter, mEntryManager);
|
||||
|
||||
@@ -26,7 +26,6 @@ import android.app.Notification;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.UserHandle;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
@@ -35,7 +34,6 @@ import android.testing.TestableLooper;
|
||||
import com.android.internal.statusbar.IStatusBarService;
|
||||
import com.android.internal.statusbar.NotificationVisibility;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.UiOffloadThread;
|
||||
|
||||
import com.google.android.collect.Lists;
|
||||
|
||||
@@ -48,7 +46,7 @@ import org.mockito.MockitoAnnotations;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@TestableLooper.RunWithLooper
|
||||
@TestableLooper.RunWithLooper(setAsMainLooper = true)
|
||||
public class NotificationLoggerTest extends SysuiTestCase {
|
||||
private static final String TEST_PACKAGE_NAME = "test";
|
||||
private static final int TEST_UID = 0;
|
||||
@@ -89,7 +87,7 @@ public class NotificationLoggerTest extends SysuiTestCase {
|
||||
when(mListContainer.isInVisibleLocation(any())).thenReturn(true);
|
||||
when(mNotificationData.getActiveNotifications()).thenReturn(Lists.newArrayList(mEntry));
|
||||
mLogger.getChildLocationsChangedListenerForTest().onChildLocationsChanged();
|
||||
waitForIdleSync(mLogger.getHandlerForTest());
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
waitForUiOffloadThread();
|
||||
|
||||
NotificationVisibility[] newlyVisibleKeys = {
|
||||
@@ -101,7 +99,7 @@ public class NotificationLoggerTest extends SysuiTestCase {
|
||||
// |mEntry| won't change visibility, so it shouldn't be reported again:
|
||||
Mockito.reset(mBarService);
|
||||
mLogger.getChildLocationsChangedListenerForTest().onChildLocationsChanged();
|
||||
waitForIdleSync(mLogger.getHandlerForTest());
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
waitForUiOffloadThread();
|
||||
|
||||
verify(mBarService, never()).onNotificationVisibilityChanged(any(), any());
|
||||
@@ -113,7 +111,7 @@ public class NotificationLoggerTest extends SysuiTestCase {
|
||||
when(mListContainer.isInVisibleLocation(any())).thenReturn(true);
|
||||
when(mNotificationData.getActiveNotifications()).thenReturn(Lists.newArrayList(mEntry));
|
||||
mLogger.getChildLocationsChangedListenerForTest().onChildLocationsChanged();
|
||||
waitForIdleSync(mLogger.getHandlerForTest());
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
waitForUiOffloadThread();
|
||||
Mockito.reset(mBarService);
|
||||
|
||||
@@ -128,8 +126,8 @@ public class NotificationLoggerTest extends SysuiTestCase {
|
||||
|
||||
public TestableNotificationLogger(IStatusBarService barService) {
|
||||
mBarService = barService;
|
||||
// Make this on the main thread so we can wait for it during tests.
|
||||
mHandler = new Handler(Looper.getMainLooper());
|
||||
// Make this on the current thread so we can wait for it during tests.
|
||||
mHandler = Handler.createAsync(Looper.myLooper());
|
||||
}
|
||||
|
||||
public OnChildLocationsChangedListener
|
||||
|
||||
@@ -45,7 +45,6 @@ public class NotificationRemoteInputManagerTest extends SysuiTestCase {
|
||||
@Mock private NotificationEntryManager mEntryManager;
|
||||
@Mock private NotificationLockscreenUserManager mLockscreenUserManager;
|
||||
|
||||
private Handler mHandler;
|
||||
private TestableNotificationRemoteInputManager mRemoteInputManager;
|
||||
private StatusBarNotification mSbn;
|
||||
private NotificationData.Entry mEntry;
|
||||
@@ -56,9 +55,8 @@ public class NotificationRemoteInputManagerTest extends SysuiTestCase {
|
||||
mDependency.injectTestDependency(NotificationEntryManager.class, mEntryManager);
|
||||
mDependency.injectTestDependency(NotificationLockscreenUserManager.class,
|
||||
mLockscreenUserManager);
|
||||
mHandler = new Handler(Looper.getMainLooper());
|
||||
|
||||
when(mPresenter.getHandler()).thenReturn(mHandler);
|
||||
when(mPresenter.getHandler()).thenReturn(Handler.createAsync(Looper.myLooper()));
|
||||
when(mEntryManager.getLatestRankingMap()).thenReturn(mRanking);
|
||||
|
||||
mRemoteInputManager = new TestableNotificationRemoteInputManager(mContext);
|
||||
|
||||
@@ -143,12 +143,10 @@ public class NotificationTestHelper {
|
||||
throws Exception {
|
||||
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
|
||||
mContext.LAYOUT_INFLATER_SERVICE);
|
||||
mInstrumentation.runOnMainSync(() ->
|
||||
mRow = (ExpandableNotificationRow) inflater.inflate(
|
||||
R.layout.status_bar_notification_row,
|
||||
null /* root */,
|
||||
false /* attachToRoot */)
|
||||
);
|
||||
mRow = (ExpandableNotificationRow) inflater.inflate(
|
||||
R.layout.status_bar_notification_row,
|
||||
null /* root */,
|
||||
false /* attachToRoot */);
|
||||
ExpandableNotificationRow row = mRow;
|
||||
row.setGroupManager(mGroupManager);
|
||||
row.setHeadsUpManager(mHeadsUpManager);
|
||||
|
||||
@@ -50,7 +50,7 @@ import java.util.List;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@TestableLooper.RunWithLooper
|
||||
@TestableLooper.RunWithLooper(setAsMainLooper = true)
|
||||
public class NotificationViewHierarchyManagerTest extends SysuiTestCase {
|
||||
@Mock private NotificationPresenter mPresenter;
|
||||
@Mock private NotificationData mNotificationData;
|
||||
|
||||
@@ -21,6 +21,8 @@ import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper.RunWithLooper;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
@@ -33,7 +35,8 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@RunWithLooper(setAsMainLooper = true)
|
||||
public class AboveShelfObserverTest extends SysuiTestCase {
|
||||
|
||||
private AboveShelfObserver mObserver;
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.android.systemui.statusbar.notification;
|
||||
|
||||
import static com.android.systemui.statusbar.notification.NotificationInflater.FLAG_REINFLATE_ALL;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -28,10 +29,9 @@ import android.os.CancellationSignal;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
import android.support.test.annotation.UiThreadTest;
|
||||
import android.support.test.filters.FlakyTest;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper.RunWithLooper;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.RemoteViews;
|
||||
@@ -52,9 +52,11 @@ import org.junit.runner.RunWith;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@RunWithLooper(setAsMainLooper = true)
|
||||
public class NotificationInflaterTest extends SysuiTestCase {
|
||||
|
||||
private NotificationInflater mNotificationInflater;
|
||||
@@ -85,7 +87,6 @@ public class NotificationInflaterTest extends SysuiTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void testIncreasedHeadsUpBeingUsed() {
|
||||
mNotificationInflater.setUsesIncreasedHeadsUpHeight(true);
|
||||
Notification.Builder builder = spy(mBuilder);
|
||||
@@ -94,7 +95,6 @@ public class NotificationInflaterTest extends SysuiTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void testIncreasedHeightBeingUsed() {
|
||||
mNotificationInflater.setUsesIncreasedHeight(true);
|
||||
Notification.Builder builder = spy(mBuilder);
|
||||
@@ -115,8 +115,8 @@ public class NotificationInflaterTest extends SysuiTestCase {
|
||||
mRow.getEntry().cachedBigContentView = null;
|
||||
runThenWaitForInflation(() -> mNotificationInflater.inflateNotificationViews(
|
||||
NotificationInflater.FLAG_REINFLATE_EXPANDED_VIEW), mNotificationInflater);
|
||||
Assert.assertTrue(mRow.getPrivateLayout().getChildCount() == 1);
|
||||
Assert.assertTrue(mRow.getPrivateLayout().getChildAt(0)
|
||||
assertTrue(mRow.getPrivateLayout().getChildCount() == 1);
|
||||
assertTrue(mRow.getPrivateLayout().getChildAt(0)
|
||||
== mRow.getPrivateLayout().getExpandedChild());
|
||||
verify(mRow).onNotificationUpdated();
|
||||
}
|
||||
@@ -128,7 +128,7 @@ public class NotificationInflaterTest extends SysuiTestCase {
|
||||
= new RemoteViews(mContext.getPackageName(), R.layout.status_bar);
|
||||
runThenWaitForInflation(() -> mNotificationInflater.inflateNotificationViews(),
|
||||
true /* expectingException */, mNotificationInflater);
|
||||
Assert.assertTrue(mRow.getPrivateLayout().getChildCount() == 0);
|
||||
assertTrue(mRow.getPrivateLayout().getChildCount() == 0);
|
||||
verify(mRow, times(0)).onNotificationUpdated();
|
||||
}
|
||||
|
||||
@@ -181,12 +181,11 @@ public class NotificationInflaterTest extends SysuiTestCase {
|
||||
R.layout.custom_view_dark);
|
||||
}
|
||||
});
|
||||
countDownLatch.await();
|
||||
assertTrue(countDownLatch.await(500, TimeUnit.MILLISECONDS));
|
||||
}
|
||||
|
||||
/* Cancelling requires us to be on the UI thread otherwise we might have a race */
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void testSupersedesExistingTask() throws Exception {
|
||||
mNotificationInflater.inflateNotificationViews();
|
||||
mNotificationInflater.setIsLowPriority(true);
|
||||
@@ -219,7 +218,6 @@ public class NotificationInflaterTest extends SysuiTestCase {
|
||||
|
||||
private static void runThenWaitForInflation(Runnable block, boolean expectingException,
|
||||
NotificationInflater inflater) throws Exception {
|
||||
com.android.systemui.util.Assert.isNotMainThread();
|
||||
CountDownLatch countDownLatch = new CountDownLatch(1);
|
||||
final ExceptionHolder exceptionHolder = new ExceptionHolder();
|
||||
inflater.setInflationCallback(new NotificationInflater.InflationCallback() {
|
||||
@@ -240,9 +238,14 @@ public class NotificationInflaterTest extends SysuiTestCase {
|
||||
}
|
||||
countDownLatch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doInflateSynchronous() {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
block.run();
|
||||
countDownLatch.await();
|
||||
assertTrue(countDownLatch.await(500, TimeUnit.MILLISECONDS));
|
||||
if (exceptionHolder.mException != null) {
|
||||
throw exceptionHolder.mException;
|
||||
}
|
||||
@@ -257,7 +260,7 @@ public class NotificationInflaterTest extends SysuiTestCase {
|
||||
}
|
||||
|
||||
private class AsyncFailRemoteView extends RemoteViews {
|
||||
Handler mHandler = new Handler(Looper.getMainLooper());
|
||||
Handler mHandler = Handler.createAsync(Looper.getMainLooper());
|
||||
|
||||
public AsyncFailRemoteView(String packageName, int layoutId) {
|
||||
super(packageName, layoutId);
|
||||
|
||||
@@ -20,6 +20,8 @@ import android.content.Context;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper.RunWithLooper;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
@@ -30,8 +32,9 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@SmallTest
|
||||
@RunWithLooper(setAsMainLooper = true)
|
||||
public class NotificationViewWrapperTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
|
||||
@@ -51,7 +51,7 @@ public class AutoTileManagerTest extends SysuiTestCase {
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mAutoTileManager = new AutoTileManager(mContext, mAutoAddTracker, mQsTileHost,
|
||||
new Handler(TestableLooper.get(this).getLooper()));
|
||||
Handler.createAsync(TestableLooper.get(this).getLooper()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -26,6 +26,8 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper.RunWithLooper;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -47,7 +49,8 @@ import org.junit.runner.RunWith;
|
||||
import java.util.HashSet;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@RunWithLooper(setAsMainLooper = true)
|
||||
public class HeadsUpAppearanceControllerTest extends SysuiTestCase {
|
||||
|
||||
private final NotificationStackScrollLayout mStackScroller =
|
||||
|
||||
@@ -48,6 +48,7 @@ import android.os.Binder;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.IPowerManager;
|
||||
import android.os.Looper;
|
||||
import android.os.PowerManager;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
@@ -173,10 +174,8 @@ public class StatusBarTest extends SysuiTestCase {
|
||||
mNotificationLogger = new NotificationLogger();
|
||||
|
||||
IPowerManager powerManagerService = mock(IPowerManager.class);
|
||||
HandlerThread handlerThread = new HandlerThread("TestThread");
|
||||
handlerThread.start();
|
||||
mPowerManager = new PowerManager(mContext, powerManagerService,
|
||||
new Handler(handlerThread.getLooper()));
|
||||
Handler.createAsync(Looper.myLooper()));
|
||||
|
||||
CommandQueue commandQueue = mock(CommandQueue.class);
|
||||
when(commandQueue.asBinder()).thenReturn(new Binder());
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.app.RemoteInput;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ShortcutManager;
|
||||
import android.os.Handler;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper;
|
||||
@@ -28,6 +29,7 @@ import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
|
||||
import com.android.systemui.Dependency;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.statusbar.ExpandableNotificationRow;
|
||||
@@ -42,7 +44,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@TestableLooper.RunWithLooper
|
||||
@TestableLooper.RunWithLooper(setAsMainLooper = true)
|
||||
@SmallTest
|
||||
public class RemoteInputViewTest extends SysuiTestCase {
|
||||
|
||||
@@ -60,7 +62,8 @@ public class RemoteInputViewTest extends SysuiTestCase {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mReceiver = new BlockingQueueIntentReceiver();
|
||||
mContext.registerReceiver(mReceiver, new IntentFilter(TEST_ACTION));
|
||||
mContext.registerReceiver(mReceiver, new IntentFilter(TEST_ACTION), null,
|
||||
Handler.createAsync(Dependency.get(Dependency.BG_LOOPER)));
|
||||
|
||||
// Avoid SecurityException RemoteInputView#sendRemoteInput().
|
||||
mContext.addMockSystemService(ShortcutManager.class, mShortcutManager);
|
||||
|
||||
@@ -51,7 +51,7 @@ public class SmartReplyConstantsTest extends SysuiTestCase {
|
||||
resources.addOverride(R.bool.config_smart_replies_in_notifications_enabled, true);
|
||||
resources.addOverride(
|
||||
R.integer.config_smart_replies_in_notifications_max_squeeze_remeasure_attempts, 7);
|
||||
mConstants = new SmartReplyConstants(new Handler(Looper.getMainLooper()), mContext);
|
||||
mConstants = new SmartReplyConstants(Handler.createAsync(Looper.myLooper()), mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -24,6 +24,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.provider.Settings;
|
||||
import android.service.notification.ZenModeConfig;
|
||||
import android.support.test.filters.SmallTest;
|
||||
@@ -58,7 +59,7 @@ public class ZenModeControllerImplTest extends SysuiTestCase {
|
||||
mContext.addMockSystemService(NotificationManager.class, mNm);
|
||||
when(mNm.getZenModeConfig()).thenReturn(mConfig);
|
||||
|
||||
mController = new ZenModeControllerImpl(mContext, new Handler());
|
||||
mController = new ZenModeControllerImpl(mContext, Handler.createAsync(Looper.myLooper()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -18,6 +18,8 @@ package com.android.systemui.statusbar.stack;
|
||||
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper.RunWithLooper;
|
||||
import android.view.NotificationHeaderView;
|
||||
import android.view.View;
|
||||
|
||||
@@ -31,7 +33,8 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@RunWithLooper(setAsMainLooper = true)
|
||||
public class NotificationChildrenContainerTest extends SysuiTestCase {
|
||||
|
||||
private ExpandableNotificationRow mGroup;
|
||||
|
||||
@@ -16,29 +16,18 @@
|
||||
|
||||
package com.android.systemui.statusbar.stack;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyFloat;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.atLeast;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.support.test.annotation.UiThreadTest;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper.RunWithLooper;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.statusbar.ActivatableNotificationView;
|
||||
import com.android.systemui.statusbar.ExpandableNotificationRow;
|
||||
import com.android.systemui.statusbar.NotificationTestHelper;
|
||||
import com.android.systemui.statusbar.StatusBarState;
|
||||
import com.android.systemui.statusbar.phone.ScrimController;
|
||||
import com.android.systemui.statusbar.phone.StatusBar;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
@@ -46,10 +35,10 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@RunWithLooper(setAsMainLooper = true)
|
||||
public class NotificationRoundnessManagerTest extends SysuiTestCase {
|
||||
|
||||
private NotificationRoundnessManager mRoundnessManager = new NotificationRoundnessManager();
|
||||
|
||||
Reference in New Issue
Block a user