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.client.XWalkDefaultClient;
14 import org.xwalk.core.SslErrorHandler;
15 import org.xwalk.core.XWalkHttpAuthHandler;
16 import org.xwalk.core.XWalkView;
18 public class XWalkClientForTest extends XWalkDefaultClient {
19 private Object mCallbackForTest;
21 public XWalkClientForTest(Context context, XWalkView view) {
26 public void onReceivedError(XWalkView view, int errorCode,
27 String description, String failingUrl) {
28 if (mCallbackForTest != null) {
30 Class<?> objectClass = mCallbackForTest.getClass();
31 Method onReceivedError = objectClass.getMethod(
32 "onReceivedError", int.class, String.class, String.class);
33 onReceivedError.invoke(mCallbackForTest, errorCode, description, failingUrl);
34 } catch (Exception e) {
41 public void onReceivedSslError(XWalkView view, SslErrorHandler handler,
43 if (mCallbackForTest != null) {
45 Class<?> objectClass = mCallbackForTest.getClass();
46 Method onReceivedSslError = objectClass.getMethod(
47 "onReceivedSslError", SslErrorHandler.class, SslError.class);
48 onReceivedSslError.invoke(mCallbackForTest, handler, error);
49 } catch (Exception e) {
56 public void onPageStarted(XWalkView view, String url, Bitmap favicon) {
57 if (mCallbackForTest != null) {
59 Class<?> objectClass = mCallbackForTest.getClass();
60 Method onPageStarted = objectClass.getMethod("onPageStarted", String.class);
61 onPageStarted.invoke(mCallbackForTest, url);
62 } catch (Exception e) {
69 public void onPageFinished(XWalkView view, String url) {
70 if (mCallbackForTest != null) {
72 Class<?> objectClass = mCallbackForTest.getClass();
73 Method onPageStarted = objectClass.getMethod("onPageFinished", String.class);
74 onPageStarted.invoke(mCallbackForTest, url);
75 } catch (Exception e) {
81 public void setCallbackForTest(Object callback) {
82 mCallbackForTest = callback;