This source file includes following definitions.
- canGoBackOnUiThread
- canGoToOffsetOnUiThread
- canGoForwardOnUiThread
- clearHistoryOnUiThread
- getUrlOnUiThread
- goToOffsetSync
- goBackSync
- goForwardSync
package org.chromium.content.browser.test.util;
import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
import android.app.Instrumentation;
import org.chromium.base.test.util.InstrumentationUtils;
import org.chromium.content.browser.ContentView;
import org.chromium.content.browser.ContentViewCore;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
public class HistoryUtils {
protected static final long WAIT_TIMEOUT_SECONDS = scaleTimeout(15);
public static boolean canGoBackOnUiThread(Instrumentation instrumentation,
final ContentViewCore contentViewCore) throws Throwable {
return InstrumentationUtils.runOnMainSyncAndGetResult(
instrumentation, new Callable<Boolean>() {
@Override
public Boolean call() {
return contentViewCore.canGoBack();
}
});
}
public static boolean canGoToOffsetOnUiThread(Instrumentation instrumentation,
final ContentViewCore contentViewCore, final int offset) throws Throwable {
return InstrumentationUtils.runOnMainSyncAndGetResult(
instrumentation, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return contentViewCore.canGoToOffset(offset);
}
});
}
public static boolean canGoForwardOnUiThread(Instrumentation instrumentation,
final ContentViewCore contentViewCore) throws Throwable {
return InstrumentationUtils.runOnMainSyncAndGetResult(
instrumentation, new Callable<Boolean>() {
@Override
public Boolean call() {
return contentViewCore.canGoForward();
}
});
}
public static void clearHistoryOnUiThread(Instrumentation instrumentation,
final ContentViewCore contentViewCore) throws Throwable {
instrumentation.runOnMainSync(new Runnable() {
@Override
public void run() {
contentViewCore.clearHistory();
}
});
}
public static String getUrlOnUiThread(Instrumentation instrumentation,
final ContentViewCore contentViewCore) throws Throwable {
return InstrumentationUtils.runOnMainSyncAndGetResult(
instrumentation, new Callable<String>() {
@Override
public String call() throws Exception {
return contentViewCore.getUrl();
}
});
}
public static void goToOffsetSync(Instrumentation instrumentation,
final ContentViewCore contentViewCore, CallbackHelper onPageFinishedHelper,
final int offset) throws Throwable {
int currentCallCount = onPageFinishedHelper.getCallCount();
instrumentation.runOnMainSync(new Runnable() {
@Override
public void run() {
contentViewCore.goToOffset(offset);
}
});
onPageFinishedHelper.waitForCallback(currentCallCount, 1, 30, TimeUnit.SECONDS);
}
public static void goBackSync(Instrumentation instrumentation,
final ContentViewCore contentViewCore,
CallbackHelper onPageFinishedHelper) throws Throwable {
int currentCallCount = onPageFinishedHelper.getCallCount();
instrumentation.runOnMainSync(new Runnable() {
@Override
public void run() {
contentViewCore.goBack();
}
});
onPageFinishedHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_SECONDS,
TimeUnit.SECONDS);
}
public static void goForwardSync(Instrumentation instrumentation,
final ContentViewCore contentViewCore,
CallbackHelper onPageFinishedHelper) throws Throwable {
int currentCallCount = onPageFinishedHelper.getCallCount();
instrumentation.runOnMainSync(new Runnable() {
@Override
public void run() {
contentViewCore.goForward();
}
});
onPageFinishedHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_SECONDS,
TimeUnit.SECONDS);
}
}