1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.xwalk.runtime;
7 import android.content.Context;
8 import android.graphics.Bitmap;
9 import android.net.http.SslError;
11 import java.lang.reflect.Method;
13 import org.xwalk.core.XWalkDefaultClient;
14 import org.xwalk.core.SslErrorHandler;
15 import org.xwalk.core.XWalkView;
17 class XWalkClientForTest extends XWalkDefaultClient {
18 private Object mCallbackForTest;
20 public XWalkClientForTest(Context context, XWalkView view) {
25 public void onReceivedError(XWalkView view, int errorCode,
26 String description, String failingUrl) {
27 if (mCallbackForTest != null) {
29 Class<?> objectClass = mCallbackForTest.getClass();
30 Method onReceivedError = objectClass.getMethod(
31 "onReceivedError", int.class, String.class, String.class);
32 onReceivedError.invoke(mCallbackForTest, errorCode, description, failingUrl);
33 } catch (Exception e) {
40 public void onReceivedSslError(XWalkView view, SslErrorHandler handler,
42 if (mCallbackForTest != null) {
44 Class<?> objectClass = mCallbackForTest.getClass();
45 Method onReceivedSslError = objectClass.getMethod(
46 "onReceivedSslError", SslErrorHandler.class, SslError.class);
47 onReceivedSslError.invoke(mCallbackForTest, handler, error);
48 } catch (Exception e) {
55 public void onPageStarted(XWalkView view, String url, Bitmap favicon) {
56 if (mCallbackForTest != null) {
58 Class<?> objectClass = mCallbackForTest.getClass();
59 Method onPageStarted = objectClass.getMethod("onPageStarted", String.class);
60 onPageStarted.invoke(mCallbackForTest, url);
61 } catch (Exception e) {
68 public void onPageFinished(XWalkView view, String url) {
69 if (mCallbackForTest != null) {
71 Class<?> objectClass = mCallbackForTest.getClass();
72 Method onPageStarted = objectClass.getMethod("onPageFinished", String.class);
73 onPageStarted.invoke(mCallbackForTest, url);
74 } catch (Exception e) {
80 public void setCallbackForTest(Object callback) {
81 mCallbackForTest = callback;