5df0f546ed14c59e302dba56063dc5a1735fc157
[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         getInstrumentation().runOnMainSync(new Runnable() {
50             @Override
51             public void run() {
52                 mNavigationHandler = new TestXWalkNavigationHandler(
53                         getXWalkView().getActivity());
54                 getXWalkView().setNavigationHandler(mNavigationHandler);
55             }
56         });
57     }
58
59     /**
60      * @param uri the uri to be loaded
61      * @return the Intent will be used to start activity.
62      * @throws Throwable
63      */
64     private Intent loadActionUri(String uri) throws Throwable {
65         loadUrlSync(uri);
66         return mNavigationHandler.getIntent();
67     }
68
69     @SmallTest
70     @Feature({"ActionUri"})
71     public void testTelUri() throws Throwable {
72         final String uri = "tel:5551212";
73         Intent intent = loadActionUri(uri);
74         assertEquals(uri, intent.toUri(0).substring(0, uri.length()));
75     }
76
77     @SmallTest
78     @Feature({"ActionUri"})
79     public void testMailUri() throws Throwable {
80         final String uri = "mailto:abc@corp.com";
81         Intent intent = loadActionUri(uri);
82         assertEquals(uri, intent.toUri(0).substring(0, uri.length()));
83     }
84
85     @SmallTest
86     @Feature({"ActionUri"})
87     public void testSmsUri() throws Throwable {
88         final String body = "This is the message";
89         final String address = "5551212";
90         final String uri = "sms:" + address + "?body=" + body;
91         Intent intent = loadActionUri(uri);
92         assertEquals("vnd.android-dir/mms-sms", intent.getType());
93         assertEquals(body, intent.getStringExtra("sms_body"));
94         assertEquals(address, intent.getStringExtra("address"));
95     }
96
97     @SmallTest
98     @Feature({"ActionUri"})
99     public void testGeoUri() throws Throwable {
100         final String uri = "geo:0,0?q=address";
101         Intent intent = loadActionUri(uri);
102         assertEquals(uri, intent.toUri(0).substring(0, uri.length()));
103     }
104
105     @SmallTest
106     @Feature({"ActionUri"})
107     public void testMarketUri() throws Throwable {
108         final String uri = "market:";
109         Intent intent = loadActionUri(uri);
110         assertEquals(uri, intent.toUri(0).substring(0, uri.length()));
111     }
112
113     @SmallTest
114     @Feature({"WTAIUri"})
115     public void testWTAICallUri() throws Throwable {
116         final String uri = "wtai://wp/mc;5551212";
117         Intent intent = loadActionUri(uri);
118         final String equalTelUri = uri.replace("wtai://wp/mc;", "tel:");
119         assertEquals(equalTelUri,
120                 intent.toUri(0).substring(0, equalTelUri.length()));
121     }
122 }