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 {
49 getInstrumentation().runOnMainSync(new Runnable() {
52 mNavigationHandler = new TestXWalkNavigationHandler(
53 getXWalkView().getActivity());
54 getXWalkView().setNavigationHandler(mNavigationHandler);
60 * @param uri the uri to be loaded
61 * @return the Intent will be used to start activity.
64 private Intent loadActionUri(String uri) throws Throwable {
66 return mNavigationHandler.getIntent();
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()));
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()));
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"));
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()));
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()));
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()));