Upstream version 8.36.161.0
[platform/framework/web/crosswalk.git] / src / xwalk / test / android / core / javatests / src / org / xwalk / core / xwview / test / HandleActionUriTest.java
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Copyright (c) 2013 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.
5
6 package org.xwalk.core.xwview.test;
7
8 import android.content.ActivityNotFoundException;
9 import android.content.Context;
10 import android.content.Intent;
11 import android.graphics.Bitmap;
12 import android.test.suitebuilder.annotation.SmallTest;
13
14 import org.chromium.base.test.util.Feature;
15 import org.xwalk.core.XWalkView;
16 import org.xwalk.core.internal.XWalkClient;
17 import org.xwalk.core.internal.XWalkNavigationHandlerImpl;
18
19 /**
20  * Test suite for handling ActionUri.
21  */
22 public class HandleActionUriTest extends XWalkViewTestBase {
23
24     class TestXWalkNavigationHandler extends XWalkNavigationHandlerImpl {
25         private Intent intentToStart;
26
27         public TestXWalkNavigationHandler(Context context) {
28             super(context);
29         }
30
31         @Override
32         protected boolean startActivity(Intent intent) {
33             // For testing purpose, instead of sending out the Intent,
34             // just keep it for verification.
35             intentToStart = intent;
36             return true;
37         }
38
39         protected Intent getIntent() {
40             return intentToStart;
41         }
42     }
43
44     private TestXWalkNavigationHandler mNavigationHandler;
45
46     @Override
47     public void setUp() throws Exception {
48         super.setUp();
49
50         setXWalkClient(new XWalkViewTestBase.TestXWalkClient());
51         getInstrumentation().runOnMainSync(new Runnable() {
52             @Override
53             public void run() {
54                 mNavigationHandler = new TestXWalkNavigationHandler(
55                         getXWalkView().getActivity());
56                 getXWalkView().setNavigationHandler(mNavigationHandler);
57             }
58         });
59     }
60
61     /**
62      * @param uri the uri to be loaded
63      * @return the Intent will be used to start activity.
64      * @throws Throwable
65      */
66     private Intent loadActionUri(String uri) throws Throwable {
67         loadUrlSync(uri);
68         return mNavigationHandler.getIntent();
69     }
70
71     @SmallTest
72     @Feature({"ActionUri"})
73     public void testTelUri() throws Throwable {
74         final String uri = "tel:5551212";
75         Intent intent = loadActionUri(uri);
76         assertEquals(uri, intent.toUri(0).substring(0, uri.length()));
77     }
78
79     @SmallTest
80     @Feature({"ActionUri"})
81     public void testMailUri() throws Throwable {
82         final String uri = "mailto:abc@corp.com";
83         Intent intent = loadActionUri(uri);
84         assertEquals(uri, intent.toUri(0).substring(0, uri.length()));
85     }
86
87     @SmallTest
88     @Feature({"ActionUri"})
89     public void testSmsUri() throws Throwable {
90         final String body = "This is the message";
91         final String address = "5551212";
92         final String uri = "sms:" + address + "?body=" + body;
93         Intent intent = loadActionUri(uri);
94         assertEquals("vnd.android-dir/mms-sms", intent.getType());
95         assertEquals(body, intent.getStringExtra("sms_body"));
96         assertEquals(address, intent.getStringExtra("address"));
97     }
98
99     @SmallTest
100     @Feature({"ActionUri"})
101     public void testGeoUri() throws Throwable {
102         final String uri = "geo:0,0?q=address";
103         Intent intent = loadActionUri(uri);
104         assertEquals(uri, intent.toUri(0).substring(0, uri.length()));
105     }
106
107     @SmallTest
108     @Feature({"ActionUri"})
109     public void testMarketUri() throws Throwable {
110         final String uri = "market:";
111         Intent intent = loadActionUri(uri);
112         assertEquals(uri, intent.toUri(0).substring(0, uri.length()));
113     }
114
115     @SmallTest
116     @Feature({"WTAIUri"})
117     public void testWTAICallUri() throws Throwable {
118         final String uri = "wtai://wp/mc;5551212";
119         Intent intent = loadActionUri(uri);
120         final String equalTelUri = uri.replace("wtai://wp/mc;", "tel:");
121         assertEquals(equalTelUri,
122                 intent.toUri(0).substring(0, equalTelUri.length()));
123     }
124 }