Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3552)

Unified Diff: android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java

Issue 131743020: [android_webivew] Refactor polling checks in test code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java
index f7f81ffe310261e93477dfca67e58a67815bc76b..d8a161a801b255f40ccd062cdb3b79abf261130a 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java
@@ -31,13 +31,12 @@ import org.chromium.base.test.util.TestFileUtil;
import org.chromium.base.test.util.UrlUtils;
import org.chromium.content.browser.ContentViewCore;
import org.chromium.content.browser.test.util.CallbackHelper;
-import org.chromium.content.browser.test.util.Criteria;
-import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content.browser.test.util.HistoryUtils;
import org.chromium.net.test.util.TestWebServer;
import org.chromium.ui.gfx.DeviceDisplayInfo;
import java.io.File;
+import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -99,7 +98,7 @@ public class AwSettingsTest extends AwTestBase {
protected abstract void doEnsureSettingHasValue(T value) throws Throwable;
- protected String getTitleOnUiThread() throws Throwable {
+ protected String getTitleOnUiThread() throws Exception {
return AwSettingsTest.this.getTitleOnUiThread(mAwContents);
}
@@ -127,7 +126,7 @@ public class AwSettingsTest extends AwTestBase {
url);
}
- protected String executeJavaScriptAndWaitForResult(String script) throws Throwable {
+ protected String executeJavaScriptAndWaitForResult(String script) throws Exception {
return AwSettingsTest.this.executeJavaScriptAndWaitForResult(
mAwContents, mContentViewClient, script);
}
@@ -926,20 +925,14 @@ public class AwSettingsTest extends AwTestBase {
executeJavaScriptAndWaitForResult("setTitleToActualFontSize()");
} else {
final float oldFontSize = mOldFontSize;
- assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
- @Override
- public boolean isSatisfied() {
- try {
- executeJavaScriptAndWaitForResult("setTitleToActualFontSize()");
- float newFontSize = Float.parseFloat(getTitleOnUiThread());
- return newFontSize != oldFontSize;
- } catch (Throwable t) {
- t.printStackTrace();
- fail("Failed to getTitleOnUiThread: " + t.toString());
- return false;
- }
- }
- }, WAIT_TIMEOUT_MS, CHECK_INTERVAL));
+ poll(new Callable<Boolean>() {
+ @Override
+ public Boolean call() throws Exception {
+ executeJavaScriptAndWaitForResult("setTitleToActualFontSize()");
+ float newFontSize = Float.parseFloat(getTitleOnUiThread());
+ return newFontSize != oldFontSize;
+ }
+ });
mNeedToWaitForFontSizeChange = false;
}
return Float.parseFloat(getTitleOnUiThread());
@@ -1147,20 +1140,14 @@ public class AwSettingsTest extends AwTestBase {
protected void doEnsureSettingHasValue(Boolean value) throws Throwable {
loadDataSync(getData());
final boolean expectPopupEnabled = value;
- assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
+ poll(new Callable<Boolean>() {
@Override
- public boolean isSatisfied() {
- try {
- String title = getTitleOnUiThread();
- return expectPopupEnabled ? POPUP_ENABLED.equals(title) :
- POPUP_BLOCKED.equals(title);
- } catch (Throwable t) {
- t.printStackTrace();
- fail("Failed to getTitleOnUiThread: " + t.toString());
- return false;
- }
+ public Boolean call() throws Exception {
+ String title = getTitleOnUiThread();
+ return expectPopupEnabled ? POPUP_ENABLED.equals(title) :
+ POPUP_BLOCKED.equals(title);
}
- }, WAIT_TIMEOUT_MS, CHECK_INTERVAL));
+ });
assertEquals(value ? POPUP_ENABLED : POPUP_BLOCKED, getTitleOnUiThread());
}
@@ -1443,19 +1430,13 @@ public class AwSettingsTest extends AwTestBase {
assertEquals(ImagePageGenerator.IMAGE_NOT_LOADED_STRING,
getTitleOnUiThread(awContents));
settings.setLoadsImagesAutomatically(true);
- assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
+ poll(new Callable<Boolean>() {
@Override
- public boolean isSatisfied() {
- try {
- return !ImagePageGenerator.IMAGE_NOT_LOADED_STRING.equals(
- getTitleOnUiThread(awContents));
- } catch (Throwable t) {
- t.printStackTrace();
- fail("Failed to getTitleOnUiThread: " + t.toString());
- return false;
- }
+ public Boolean call() throws Exception {
+ return !ImagePageGenerator.IMAGE_NOT_LOADED_STRING.equals(
+ getTitleOnUiThread(awContents));
}
- }, WAIT_TIMEOUT_MS, CHECK_INTERVAL));
+ });
assertEquals(ImagePageGenerator.IMAGE_LOADED_STRING, getTitleOnUiThread(awContents));
}
@@ -1825,19 +1806,13 @@ public class AwSettingsTest extends AwTestBase {
getTitleOnUiThread(awContents));
settings.setImagesEnabled(true);
- assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
+ poll(new Callable<Boolean>() {
@Override
- public boolean isSatisfied() {
- try {
- return ImagePageGenerator.IMAGE_LOADED_STRING.equals(
- getTitleOnUiThread(awContents));
- } catch (Throwable t) {
- t.printStackTrace();
- fail("Failed to getTitleOnUIThread: " + t.toString());
- return false;
- }
+ public Boolean call() throws Exception {
+ return ImagePageGenerator.IMAGE_LOADED_STRING.equals(
+ getTitleOnUiThread(awContents));
}
- }, WAIT_TIMEOUT_MS, CHECK_INTERVAL));
+ });
} finally {
if (webServer != null) webServer.shutdown();
}
@@ -1919,7 +1894,7 @@ public class AwSettingsTest extends AwTestBase {
}
}
- public static class AudioEvent {
+ private static class AudioEvent {
private CallbackHelper mCallback;
public AudioEvent(CallbackHelper callback) {
mCallback = callback;
@@ -2237,23 +2212,22 @@ public class AwSettingsTest extends AwTestBase {
return mManifestPath;
}
- int waitUntilHtmlIsRequested(final int initialRequestCount) throws InterruptedException {
+ int waitUntilHtmlIsRequested(final int initialRequestCount) throws Exception {
return waitUntilResourceIsRequested(mHtmlPath, initialRequestCount);
}
- int waitUntilManifestIsRequested(final int initialRequestCount)
- throws InterruptedException {
+ int waitUntilManifestIsRequested(final int initialRequestCount) throws Exception {
return waitUntilResourceIsRequested(mManifestPath, initialRequestCount);
}
private int waitUntilResourceIsRequested(
- final String path, final int initialRequestCount) throws InterruptedException {
- assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
+ final String path, final int initialRequestCount) throws Exception {
+ poll(new Callable<Boolean>() {
@Override
- public boolean isSatisfied() {
+ public Boolean call() throws Exception {
return mWebServer.getRequestCount(path) > initialRequestCount;
}
- }, WAIT_TIMEOUT_MS, CHECK_INTERVAL));
+ });
return mWebServer.getRequestCount(path);
}
}

Powered by Google App Engine
This is Rietveld 408576698