Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / android / runtime / src / org / xwalk / runtime / XWalkClientForTest.java
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.
4
5 package org.xwalk.runtime;
6
7 import android.content.Context;
8 import android.graphics.Bitmap;
9 import android.net.http.SslError;
10
11 import java.lang.reflect.Method;
12
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;
17
18 public class XWalkClientForTest extends XWalkDefaultClient {
19     private Object mCallbackForTest;
20
21     public XWalkClientForTest(Context context, XWalkView view) {
22         super(context, view);
23     }
24
25     @Override
26     public void onReceivedError(XWalkView view, int errorCode,
27             String description, String failingUrl) {
28         if (mCallbackForTest != null) {
29             try {
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) {
35                 e.printStackTrace();
36             }
37         }
38     }
39
40     @Override
41     public void onReceivedSslError(XWalkView view, SslErrorHandler handler,
42             SslError error) {
43         if (mCallbackForTest != null) {
44             try {
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) {
50                 e.printStackTrace();
51             }
52         }
53     }
54
55     @Override
56     public void onPageStarted(XWalkView view, String url, Bitmap favicon) {
57         if (mCallbackForTest != null) {
58             try {
59                 Class<?> objectClass = mCallbackForTest.getClass();
60                 Method onPageStarted = objectClass.getMethod("onPageStarted", String.class);
61                 onPageStarted.invoke(mCallbackForTest, url);
62             } catch (Exception e) {
63                 e.printStackTrace();
64             }
65         }
66     }
67
68     @Override
69     public void onPageFinished(XWalkView view, String url) {
70         if (mCallbackForTest != null) {
71             try {
72                 Class<?> objectClass = mCallbackForTest.getClass();
73                 Method onPageStarted = objectClass.getMethod("onPageFinished", String.class);
74                 onPageStarted.invoke(mCallbackForTest, url);
75             } catch (Exception e) {
76                 e.printStackTrace();
77             }
78         }
79     }
80
81     public void setCallbackForTest(Object callback) {
82         mCallbackForTest = callback;
83     }
84 }