import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
+import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
*/
public class AwTestBase
extends ActivityInstrumentationTestCase2<AwTestRunnerActivity> {
- protected static final long WAIT_TIMEOUT_MS = scaleTimeout(15000);
- protected static final int CHECK_INTERVAL = 100;
+ public static final long WAIT_TIMEOUT_MS = scaleTimeout(15000);
+ public static final int CHECK_INTERVAL = 100;
private static final String TAG = "AwTestBase";
public AwTestBase() {
return task.get();
}
- protected void enableJavaScriptOnUiThread(final AwContents awContents) {
+ public void enableJavaScriptOnUiThread(final AwContents awContents) {
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
});
}
- protected void setNetworkAvailableOnUiThread(final AwContents awContents,
+ public void setNetworkAvailableOnUiThread(final AwContents awContents,
final boolean networkUp) {
getInstrumentation().runOnMainSync(new Runnable() {
@Override
/**
* Loads url on the UI thread and blocks until onPageFinished is called.
*/
- protected void loadUrlSync(final AwContents awContents,
+ public void loadUrlSync(final AwContents awContents,
CallbackHelper onPageFinishedHelper,
final String url) throws Exception {
+ loadUrlSync(awContents, onPageFinishedHelper, url, null);
+ }
+
+ public void loadUrlSync(final AwContents awContents,
+ CallbackHelper onPageFinishedHelper,
+ final String url,
+ final Map<String, String> extraHeaders) throws Exception {
int currentCallCount = onPageFinishedHelper.getCallCount();
- loadUrlAsync(awContents, url);
+ loadUrlAsync(awContents, url, extraHeaders);
onPageFinishedHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_MS,
TimeUnit.MILLISECONDS);
}
- protected void loadUrlSyncAndExpectError(final AwContents awContents,
+ public void loadUrlSyncAndExpectError(final AwContents awContents,
CallbackHelper onPageFinishedHelper,
CallbackHelper onReceivedErrorHelper,
final String url) throws Exception {
/**
* Loads url on the UI thread but does not block.
*/
- protected void loadUrlAsync(final AwContents awContents,
+ public void loadUrlAsync(final AwContents awContents,
final String url) throws Exception {
+ loadUrlAsync(awContents, url, null);
+ }
+
+ public void loadUrlAsync(final AwContents awContents,
+ final String url,
+ final Map<String, String> extraHeaders) {
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
- awContents.loadUrl(new LoadUrlParams(url));
+ LoadUrlParams params = new LoadUrlParams(url);
+ params.setExtraHeaders(extraHeaders);
+ awContents.loadUrl(params);
}
});
}
/**
* Posts url on the UI thread and blocks until onPageFinished is called.
*/
- protected void postUrlSync(final AwContents awContents,
+ public void postUrlSync(final AwContents awContents,
CallbackHelper onPageFinishedHelper, final String url,
byte[] postData) throws Exception {
int currentCallCount = onPageFinishedHelper.getCallCount();
/**
* Loads url on the UI thread but does not block.
*/
- protected void postUrlAsync(final AwContents awContents,
+ public void postUrlAsync(final AwContents awContents,
final String url, byte[] postData) throws Exception {
class PostUrl implements Runnable {
byte[] mPostData;
/**
* Loads data on the UI thread and blocks until onPageFinished is called.
*/
- protected void loadDataSync(final AwContents awContents,
+ public void loadDataSync(final AwContents awContents,
CallbackHelper onPageFinishedHelper,
final String data, final String mimeType,
final boolean isBase64Encoded) throws Exception {
TimeUnit.MILLISECONDS);
}
- protected void loadDataSyncWithCharset(final AwContents awContents,
+ public void loadDataSyncWithCharset(final AwContents awContents,
CallbackHelper onPageFinishedHelper,
final String data, final String mimeType,
final boolean isBase64Encoded, final String charset)
/**
* Loads data on the UI thread but does not block.
*/
- protected void loadDataAsync(final AwContents awContents, final String data,
+ public void loadDataAsync(final AwContents awContents, final String data,
final String mimeType, final boolean isBase64Encoded)
throws Exception {
getInstrumentation().runOnMainSync(new Runnable() {
});
}
- protected void loadDataWithBaseUrlSync(final AwContents awContents,
+ public void loadDataWithBaseUrlSync(final AwContents awContents,
CallbackHelper onPageFinishedHelper, final String data, final String mimeType,
final boolean isBase64Encoded, final String baseUrl,
final String historyUrl) throws Throwable {
TimeUnit.MILLISECONDS);
}
- protected void loadDataWithBaseUrlAsync(final AwContents awContents,
+ public void loadDataWithBaseUrlAsync(final AwContents awContents,
final String data, final String mimeType, final boolean isBase64Encoded,
final String baseUrl, final String historyUrl) throws Throwable {
runTestOnUiThread(new Runnable() {
/**
* Reloads the current page synchronously.
*/
- protected void reloadSync(final AwContents awContents,
+ public void reloadSync(final AwContents awContents,
CallbackHelper onPageFinishedHelper) throws Exception {
int currentCallCount = onPageFinishedHelper.getCallCount();
getInstrumentation().runOnMainSync(new Runnable() {
return new TestDependencyFactory();
}
- protected AwTestContainerView createAwTestContainerView(
+ public AwTestContainerView createAwTestContainerView(
final AwContentsClient awContentsClient) {
return createAwTestContainerView(awContentsClient, false);
}
- protected AwTestContainerView createAwTestContainerView(
+ public AwTestContainerView createAwTestContainerView(
final AwContentsClient awContentsClient, boolean supportsLegacyQuirks) {
AwTestContainerView testContainerView =
createDetachedAwTestContainerView(awContentsClient, supportsLegacyQuirks);
private AwBrowserContext mBrowserContext =
new AwBrowserContext(new InMemorySharedPreferences());
- protected AwTestContainerView createDetachedAwTestContainerView(
+ public AwTestContainerView createDetachedAwTestContainerView(
final AwContentsClient awContentsClient) {
return createDetachedAwTestContainerView(awContentsClient, false);
}
- protected AwTestContainerView createDetachedAwTestContainerView(
+ public AwTestContainerView createDetachedAwTestContainerView(
final AwContentsClient awContentsClient, boolean supportsLegacyQuirks) {
final TestDependencyFactory testDependencyFactory = createTestDependencyFactory();
final AwTestContainerView testContainerView =
return testContainerView;
}
- protected AwTestContainerView createAwTestContainerViewOnMainSync(
+ public AwTestContainerView createAwTestContainerViewOnMainSync(
final AwContentsClient client) throws Exception {
return createAwTestContainerViewOnMainSync(client, false);
}
- protected AwTestContainerView createAwTestContainerViewOnMainSync(
+ public AwTestContainerView createAwTestContainerViewOnMainSync(
final AwContentsClient client, final boolean supportsLegacyQuirks) throws Exception {
final AtomicReference<AwTestContainerView> testContainerView =
new AtomicReference<AwTestContainerView>();
return testContainerView.get();
}
- protected void destroyAwContentsOnMainSync(final AwContents awContents) {
+ public void destroyAwContentsOnMainSync(final AwContents awContents) {
if (awContents == null) return;
getInstrumentation().runOnMainSync(new Runnable() {
@Override
});
}
- protected String getTitleOnUiThread(final AwContents awContents) throws Exception {
+ public String getTitleOnUiThread(final AwContents awContents) throws Exception {
return runTestOnUiThreadAndGetResult(new Callable<String>() {
@Override
public String call() throws Exception {
});
}
- protected ContentSettings getContentSettingsOnUiThread(
+ public ContentSettings getContentSettingsOnUiThread(
final AwContents awContents) throws Exception {
return runTestOnUiThreadAndGetResult(new Callable<ContentSettings>() {
@Override
});
}
- protected AwSettings getAwSettingsOnUiThread(
+ public AwSettings getAwSettingsOnUiThread(
final AwContents awContents) throws Exception {
return runTestOnUiThreadAndGetResult(new Callable<AwSettings>() {
@Override
* Executes the given snippet of JavaScript code within the given ContentView. Returns the
* result of its execution in JSON format.
*/
- protected String executeJavaScriptAndWaitForResult(final AwContents awContents,
+ public String executeJavaScriptAndWaitForResult(final AwContents awContents,
TestAwContentsClient viewClient, final String code) throws Exception {
return JSUtils.executeJavaScriptAndWaitForResult(this, awContents,
viewClient.getOnEvaluateJavaScriptResultHelper(),
* Wrapper around CriteriaHelper.pollForCriteria. This uses AwTestBase-specifc timeouts and
* treats timeouts and exceptions as test failures automatically.
*/
- protected static void poll(final Callable<Boolean> callable) throws Exception {
+ public static void poll(final Callable<Boolean> callable) throws Exception {
assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
@Override
public boolean isSatisfied() {
/**
* Wrapper around {@link AwTestBase#poll()} but runs the callable on the UI thread.
*/
- protected void pollOnUiThread(final Callable<Boolean> callable) throws Exception {
+ public void pollOnUiThread(final Callable<Boolean> callable) throws Exception {
poll(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
* Clears the resource cache. Note that the cache is per-application, so this will clear the
* cache for all WebViews used.
*/
- protected void clearCacheOnUiThread(
+ public void clearCacheOnUiThread(
final AwContents awContents,
final boolean includeDiskFiles) throws Exception {
getInstrumentation().runOnMainSync(new Runnable() {
/**
* Returns pure page scale.
*/
- protected float getScaleOnUiThread(final AwContents awContents) throws Exception {
+ public float getScaleOnUiThread(final AwContents awContents) throws Exception {
return runTestOnUiThreadAndGetResult(new Callable<Float>() {
@Override
public Float call() throws Exception {
/**
* Returns page scale multiplied by the screen density.
*/
- protected float getPixelScaleOnUiThread(final AwContents awContents) throws Exception {
+ public float getPixelScaleOnUiThread(final AwContents awContents) throws Exception {
return runTestOnUiThreadAndGetResult(new Callable<Float>() {
@Override
public Float call() throws Exception {
/**
* Returns whether a user can zoom the page in.
*/
- protected boolean canZoomInOnUiThread(final AwContents awContents) throws Exception {
+ public boolean canZoomInOnUiThread(final AwContents awContents) throws Exception {
return runTestOnUiThreadAndGetResult(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
/**
* Returns whether a user can zoom the page out.
*/
- protected boolean canZoomOutOnUiThread(final AwContents awContents) throws Exception {
+ public boolean canZoomOutOnUiThread(final AwContents awContents) throws Exception {
return runTestOnUiThreadAndGetResult(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
}
});
}
+
}