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.
6 package org.xwalk.core.xwview.test;
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;
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;
20 * Test suite for handling ActionUri.
22 public class HandleActionUriTest extends XWalkViewTestBase {
24 class TestXWalkNavigationHandler extends XWalkNavigationHandlerImpl {
25 private Intent intentToStart;
27 public TestXWalkNavigationHandler(Context context) {
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;
39 protected Intent getIntent() {
44 private TestXWalkNavigationHandler mNavigationHandler;
47 public void setUp() throws Exception {
50 setXWalkClient(new XWalkViewTestBase.TestXWalkClient());
51 getInstrumentation().runOnMainSync(new Runnable() {
54 mNavigationHandler = new TestXWalkNavigationHandler(
55 getXWalkView().getActivity());
56 getXWalkView().setNavigationHandler(mNavigationHandler);
62 * @param uri the uri to be loaded
63 * @return the Intent will be used to start activity.
66 private Intent loadActionUri(String uri) throws Throwable {
68 return mNavigationHandler.getIntent();
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()));
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()));
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"));
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()));
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()));
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()));