Commit df0b3392 authored by newt's avatar newt Committed by Commit bot

Delete UiUtils.runOnUiThread().

This method is identical to ThreadUtils.runOnUiThreadBlocking(), and
ThreadUtils has a variety of helpful variations.

BUG=430226

Review URL: https://codereview.chromium.org/700013002

Cr-Commit-Position: refs/heads/master@{#302750}
parent 31d809c9
...@@ -8,13 +8,13 @@ import android.test.suitebuilder.annotation.SmallTest; ...@@ -8,13 +8,13 @@ import android.test.suitebuilder.annotation.SmallTest;
import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.chrome.shell.ChromeShellActivity; import org.chromium.chrome.shell.ChromeShellActivity;
import org.chromium.chrome.shell.ChromeShellTestBase; import org.chromium.chrome.shell.ChromeShellTestBase;
import org.chromium.content.browser.test.util.Criteria; import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper; import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content.browser.test.util.TouchCommon; import org.chromium.content.browser.test.util.TouchCommon;
import org.chromium.content.browser.test.util.UiUtils;
import org.chromium.ui.autofill.AutofillPopup; import org.chromium.ui.autofill.AutofillPopup;
import org.chromium.ui.autofill.AutofillPopup.AutofillPopupDelegate; import org.chromium.ui.autofill.AutofillPopup.AutofillPopupDelegate;
import org.chromium.ui.autofill.AutofillSuggestion; import org.chromium.ui.autofill.AutofillSuggestion;
...@@ -46,7 +46,7 @@ public class AutofillTest extends ChromeShellTestBase { ...@@ -46,7 +46,7 @@ public class AutofillTest extends ChromeShellTestBase {
final ViewAndroidDelegate viewDelegate = final ViewAndroidDelegate viewDelegate =
activity.getActiveContentViewCore().getViewAndroidDelegate(); activity.getActiveContentViewCore().getViewAndroidDelegate();
UiUtils.runOnUiThread(getActivity(), new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
public void run() { public void run() {
mAutofillPopup = new AutofillPopup(mWindowAndroid.getActivity().get(), mAutofillPopup = new AutofillPopup(mWindowAndroid.getActivity().get(),
...@@ -105,7 +105,7 @@ public class AutofillTest extends ChromeShellTestBase { ...@@ -105,7 +105,7 @@ public class AutofillTest extends ChromeShellTestBase {
public boolean openAutofillPopupAndWaitUntilReady(final AutofillSuggestion[] suggestions) public boolean openAutofillPopupAndWaitUntilReady(final AutofillSuggestion[] suggestions)
throws InterruptedException { throws InterruptedException {
UiUtils.runOnUiThread(getActivity(), new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
public void run() { public void run() {
mAutofillPopup.filterAndShow(suggestions, false); mAutofillPopup.filterAndShow(suggestions, false);
......
...@@ -11,6 +11,7 @@ import android.os.Build; ...@@ -11,6 +11,7 @@ import android.os.Build;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.test.suitebuilder.annotation.MediumTest; import android.test.suitebuilder.annotation.MediumTest;
import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.UrlUtils; import org.chromium.base.test.util.UrlUtils;
import org.chromium.chrome.shell.ChromeShellActivity; import org.chromium.chrome.shell.ChromeShellActivity;
...@@ -20,7 +21,6 @@ import org.chromium.content.browser.ContentViewCore; ...@@ -20,7 +21,6 @@ import org.chromium.content.browser.ContentViewCore;
import org.chromium.content.browser.test.util.Criteria; import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper; import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content.browser.test.util.DOMUtils; import org.chromium.content.browser.test.util.DOMUtils;
import org.chromium.content.browser.test.util.UiUtils;
import org.chromium.ui.base.ActivityWindowAndroid; import org.chromium.ui.base.ActivityWindowAndroid;
/** /**
...@@ -128,7 +128,7 @@ public class SelectFileDialogTest extends ChromeShellTestBase { ...@@ -128,7 +128,7 @@ public class SelectFileDialogTest extends ChromeShellTestBase {
} }
private void resetActivityWindowAndroidForTest() { private void resetActivityWindowAndroidForTest() {
UiUtils.runOnUiThread(getActivity(), new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
public void run() { public void run() {
mActivityWindowAndroidForTest.lastCallback.onIntentCompleted( mActivityWindowAndroidForTest.lastCallback.onIntentCompleted(
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.input; package org.chromium.chrome.browser.input;
import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.DisabledTest; import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.UrlUtils; import org.chromium.base.test.util.UrlUtils;
import org.chromium.chrome.browser.ContentViewUtil; import org.chromium.chrome.browser.ContentViewUtil;
...@@ -13,7 +14,6 @@ import org.chromium.content.browser.ContentViewCore; ...@@ -13,7 +14,6 @@ import org.chromium.content.browser.ContentViewCore;
import org.chromium.content.browser.test.util.Criteria; import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper; import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content.browser.test.util.DOMUtils; import org.chromium.content.browser.test.util.DOMUtils;
import org.chromium.content.browser.test.util.UiUtils;
import org.chromium.ui.base.ActivityWindowAndroid; import org.chromium.ui.base.ActivityWindowAndroid;
import org.chromium.ui.base.WindowAndroid; import org.chromium.ui.base.WindowAndroid;
...@@ -66,7 +66,7 @@ public class SelectPopupOtherContentViewTest extends ChromeShellTestBase { ...@@ -66,7 +66,7 @@ public class SelectPopupOtherContentViewTest extends ChromeShellTestBase {
CriteriaHelper.pollForCriteria(new PopupShowingCriteria())); CriteriaHelper.pollForCriteria(new PopupShowingCriteria()));
// Now create and destroy a different ContentView. // Now create and destroy a different ContentView.
UiUtils.runOnUiThread(getActivity(), new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
public void run() { public void run() {
long nativeWebContents = ContentViewUtil.createNativeWebContents(false); long nativeWebContents = ContentViewUtil.createNativeWebContents(false);
......
...@@ -4,50 +4,20 @@ ...@@ -4,50 +4,20 @@
package org.chromium.content.browser.test.util; package org.chromium.content.browser.test.util;
import android.app.Activity;
import android.app.Instrumentation; 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;
/** /**
* Collection of UI utilities. * Collection of UI utilities.
*/ */
public class UiUtils { public class UiUtils {
// timeout to wait for runOnUiThread()
private static final long WAIT_FOR_RESPONSE_MS = scaleTimeout(10000);
/**
* Runs the runnable on the UI thread.
*
* @param activity The activity on which the runnable must run.
* @param runnable The runnable to run.
*/
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);
}
}
/** /**
* Waits for the UI thread to settle down. * Waits for the UI thread to settle down and then waits for another second.
* <p> * <p>
* Waits for an extra period of time after the UI loop is idle. * Avoid this method like the plague. It's a fantastically evil source of flakiness in tests.
* Instead, you should either:
* - Use an observer interface if possible (preferred), or
* - Use CriteriaHelper to poll for the desired condition becoming true
* *
* @param instrumentation Instrumentation object used by the test. * @param instrumentation Instrumentation object used by the test.
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment