/** * Causes {@link Runnable}s that have been scheduled to run immediately to actually run. Does not advance the * scheduler's clock; */ public void idle() { idle(0, TimeUnit.MILLISECONDS); }
/** * Causes {@link Runnable}s that have been scheduled to run within the next {@code intervalMillis} milliseconds to * run while advancing the scheduler's clock. * * @deprecated Use {@link #idle(long, TimeUnit)}. */ @Deprecated public void idle(long intervalMillis) { idle(intervalMillis, TimeUnit.MILLISECONDS); }
/** * Runs any immediately runnable tasks previously queued on the UI thread, * e.g. by {@link android.app.Activity#runOnUiThread(Runnable)} or {@link android.os.AsyncTask#onPostExecute(Object)}. * * **Note:** calling this method does not pause or un-pause the scheduler. * * @see #runUiThreadTasksIncludingDelayedTasks */ public static void runUiThreadTasks() { getShadowMainLooper().idle(); }
@Override public void drainMainThreadUntilIdle() { shadowOf(Looper.getMainLooper()).idle(); } }
@Override public void loopMainThreadUntilIdle() { shadowOf(Looper.getMainLooper()).idle(); }
@Override public void loopMainThreadForAtLeast(long millisDelay) { shadowOf(Looper.getMainLooper()).idle(millisDelay, TimeUnit.MILLISECONDS); }
public static void idleMainLooper(long amount, TimeUnit unit) { getShadowMainLooper().idle(amount, unit); }
@Override public void waitForIdleSync() { shadowOf(Looper.getMainLooper()).idle(); }
public static void idleMainLooper() { getShadowMainLooper().idle(); }
public ActivityController<T> windowFocusChanged(boolean hasFocus) { ViewRootImpl root = getViewRoot(); if (root == null) { // root can be null if looper was paused during visible. Flush the looper and try again shadowMainLooper.idle(); root = checkNotNull(getViewRoot()); callDispatchResized(root); } ReflectionHelpers.callInstanceMethod(root, "windowFocusChanged", from(boolean.class, hasFocus), /* hasFocus */ from(boolean.class, false) /* inTouchMode */); return this; }
@Test public void testDefaultConstructorUsesDefaultLooper() throws Exception { Handler handler1 = new Handler(); handler1.post(new Say("first thing")); Handler handler2 = new Handler(Looper.myLooper()); handler2.post(new Say("second thing")); shadowOf(Looper.myLooper()).idle(); assertThat(transcript).containsExactly("first thing", "second thing"); }
@Test public void testInsertsRunnablesBasedOnLooper() throws Exception { Looper looper = newLooper(false); Handler handler1 = new Handler(looper); handler1.post(new Say("first thing")); Handler handler2 = new Handler(looper); handler2.post(new Say("second thing")); shadowOf(looper).idle(); assertThat(transcript).containsExactly("first thing", "second thing"); }
@Test public void sendBroadcast_shouldSendIntentUsingHandlerIfOneIsProvided() { HandlerThread handlerThread = new HandlerThread("test"); handlerThread.start(); Handler handler = new Handler(handlerThread.getLooper()); assertNotSame(handler.getLooper(), Looper.getMainLooper()); BroadcastReceiver receiver = broadcastReceiver("Larry"); contextWrapper.registerReceiver(receiver, intentFilter("foo", "baz"), null, handler); assertThat(shadowOf(handler.getLooper()).getScheduler().size()).isEqualTo(0); contextWrapper.sendBroadcast(new Intent("foo")); assertThat(shadowOf(handler.getLooper()).getScheduler().size()).isEqualTo(1); shadowOf(handlerThread.getLooper()).idle(); assertThat(shadowOf(handler.getLooper()).getScheduler().size()).isEqualTo(0); assertThat(transcript).containsExactly("Larry notified of foo"); }
@Test public void testDifferentLoopersGetDifferentQueues() throws Exception { Looper looper1 = newLooper(true); ShadowLooper.pauseLooper(looper1); Looper looper2 = newLooper(true); ShadowLooper.pauseLooper(looper2); // Make sure looper has a different scheduler to the first shadowOf(looper2.getQueue()).setScheduler(new Scheduler()); Handler handler1 = new Handler(looper1); handler1.post(new Say("first thing")); Handler handler2 = new Handler(looper2); handler2.post(new Say("second thing")); shadowOf(looper2).idle(); assertThat(transcript).containsExactly("second thing"); }
@Override public void drainMainThreadUntilIdle() { shadowOf(Looper.getMainLooper()).idle(); } }
@After public void tearDown() throws Exception { getLooper().idle(); dm.destroy(); }
@After public void tearDown() throws Exception { getLooper().idle(); getInstance().destroy(); }
@Before public void setup() throws Exception { mockStatic(WXSoInstallMgrSdk.class); when(WXSoInstallMgrSdk.initSo("weexv8", 1, null)).thenReturn(true); WXSDKEngine.initialize(RuntimeEnvironment.application,new InitConfig.Builder().build()); mInstance = createInstance(); WXBridgeManagerTest.getLooper().idle(); mockStatic(WXFileUtils.class); when(WXFileUtils.loadAsset(null,null)).thenReturn("{}"); }
@Before public void setUp() throws Exception { WXSDKEngine.initialize(RuntimeEnvironment.application,new InitConfig.Builder().build()); instance = WXSDKInstanceTest.createInstance(); WXModuleManager.registerModule("test",null,false); WXModuleManager.registerModule("test1",new TypeModuleFactory<>(TestModule.class),true); WXModuleManager.registerModule("test2",new TypeModuleFactory<>(TestModule.class),false); WXBridgeManagerTest.getLooper().idle(); }