Upstream version 5.34.104.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.XWalkDefaultClient;
14 import org.xwalk.core.SslErrorHandler;
15 import org.xwalk.core.XWalkView;
16
17 class XWalkClientForTest extends XWalkDefaultClient {
18     private Object mCallbackForTest;
19
20     public XWalkClientForTest(Context context, XWalkView view) {
21         super(context, view);
22     }
23
24     @Override
25     public void onReceivedError(XWalkView view, int errorCode,
26             String description, String failingUrl) {
27         if (mCallbackForTest != null) {
28             try {
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) {
34                 e.printStackTrace();
35             }
36         }
37     }
38
39     @Override
40     public void onReceivedSslError(XWalkView view, SslErrorHandler handler,
41             SslError error) {
42         if (mCallbackForTest != null) {
43             try {
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) {
49                 e.printStackTrace();
50             }
51         }
52     }
53
54     @Override
55     public void onPageStarted(XWalkView view, String url, Bitmap favicon) {
56         if (mCallbackForTest != null) {
57             try {
58                 Class<?> objectClass = mCallbackForTest.getClass();
59                 Method onPageStarted = objectClass.getMethod("onPageStarted", String.class);
60                 onPageStarted.invoke(mCallbackForTest, url);
61             } catch (Exception e) {
62                 e.printStackTrace();
63             }
64         }
65     }
66
67     @Override
68     public void onPageFinished(XWalkView view, String url) {
69         if (mCallbackForTest != null) {
70             try {
71                 Class<?> objectClass = mCallbackForTest.getClass();
72                 Method onPageStarted = objectClass.getMethod("onPageFinished", String.class);
73                 onPageStarted.invoke(mCallbackForTest, url);
74             } catch (Exception e) {
75                 e.printStackTrace();
76             }
77         }
78     }
79
80     public void setCallbackForTest(Object callback) {
81         mCallbackForTest = callback;
82     }
83 }