This source file includes following definitions.
- runOnUiThread
- settleDownUI
package org.chromium.content.browser.test.util;
import android.app.Activity;
import android.app.Instrumentation;
import junit.framework.Assert;
import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
public class UiUtils {
private static final long WAIT_FOR_RESPONSE_MS = scaleTimeout(10000);
public static void runOnUiThread(Activity activity, final Runnable runnable) {
final Semaphore finishedSemaphore = new Semaphore(0);
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
runnable.run();
finishedSemaphore.release();
}
});
try {
Assert.assertTrue(finishedSemaphore.tryAcquire(1, WAIT_FOR_RESPONSE_MS,
TimeUnit.MILLISECONDS));
} catch (InterruptedException ignored) {
Assert.assertTrue("Interrupted while waiting for main thread Runnable", false);
}
}
public static void settleDownUI(Instrumentation instrumentation) throws InterruptedException {
instrumentation.waitForIdleSync();
Thread.sleep(1000);
}
}