1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Copyright (c) 2013-2014 Intel Corporation. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
6 package org.xwalk.test.util;
8 import android.app.Activity;
9 import android.app.Instrumentation;
10 import android.content.Context;
12 import java.io.InputStream;
13 import java.io.IOException;
14 import java.util.concurrent.TimeUnit;
16 import org.chromium.content.browser.test.util.CallbackHelper;
17 import org.xwalk.app.runtime.XWalkRuntimeView;
19 public class XWalkRuntimeClientTestUtilBase extends XWalkTestUtilBase<XWalkRuntimeView> {
20 public class PageStatusCallback {
21 public void onPageStarted(String url) {
22 mCallbackHelpers.onPageStarted(url);
25 public void onPageFinished(String url) {
26 mCallbackHelpers.didFinishLoad(url);
29 public void onReceivedLoadError(int errorCode, String description, String failingUrl) {
30 mCallbackHelpers.onReceivedError(errorCode, description, failingUrl);
33 public void onReceivedTitle(String title) {
34 mCallbackHelpers.onTitleUpdated(title);
38 public XWalkRuntimeClientTestUtilBase(XWalkRuntimeView runtimeView,
39 Instrumentation instrumentation) {
40 super(runtimeView, instrumentation);
44 public void loadUrlAsync(final String url) throws Exception {
45 getInstrumentation().runOnMainSync(new Runnable() {
48 getTestedView().loadAppFromUrl(url);
54 public void loadDataAsync(final String data, final String mimeType,
55 final boolean isBase64Encoded) throws Exception {
56 getInstrumentation().runOnMainSync(new Runnable() {
59 getTestedView().loadDataForTest(data, mimeType, isBase64Encoded);
64 public void loadManifestSync(String url) throws Exception {
65 CallbackHelper pageFinishedHelper = mCallbackHelpers.getOnPageFinishedHelper();
66 int currentCallCount = pageFinishedHelper.getCallCount();
67 loadManifestAsync(url);
69 pageFinishedHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_SECONDS,
73 public void loadManifestAsync(final String url) throws Exception {
74 getInstrumentation().runOnMainSync(new Runnable() {
77 getTestedView().loadAppFromManifest(url);
82 public void pauseActivity(final Context activity) throws Exception {
83 getInstrumentation().runOnMainSync(new Runnable() {
86 ActivityToCausePause.pauseActivity(activity);
91 public void resumeActivity() throws Exception {
92 getInstrumentation().runOnMainSync(new Runnable() {
95 ActivityToCausePause.resumeActivity();