blob: b08e953383e9f1e6f4e1dfa9c4d64c0dd8245c74 [file] [log] [blame]
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.content.cts;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
import android.app.SearchManager;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.test.AndroidTestCase;
import java.util.List;
@TestTargetClass(Intent.class)
public class AvailableIntentsTest extends AndroidTestCase {
private static final String NORMAL_URL = "http://www.google.com/";
private static final String SECURE_URL = "https://www.google.com/";
/**
* Assert target intent can be handled by at least one Activity.
* @param intent - the Intent will be handled.
*/
private void assertCanBeHandled(final Intent intent) {
PackageManager packageManager = mContext.getPackageManager();
List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(intent, 0);
assertNotNull(resolveInfoList);
// one or more activity can handle this intent.
assertTrue(resolveInfoList.size() > 0);
}
/**
* Test ACTION_VIEW when url is http://web_address,
* it will open a browser window to the URL specified.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "Intent",
args = {java.lang.String.class, android.net.Uri.class}
)
public void testViewNormalUrl() {
Uri uri = Uri.parse(NORMAL_URL);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
assertCanBeHandled(intent);
}
/**
* Test ACTION_VIEW when url is https://web_address,
* it will open a browser window to the URL specified.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "Intent",
args = {java.lang.String.class, android.net.Uri.class}
)
public void testViewSecureUrl() {
Uri uri = Uri.parse(SECURE_URL);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
assertCanBeHandled(intent);
}
/**
* Test ACTION_WEB_SEARCH when url is http://web_address,
* it will open a browser window to the URL specified.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "Intent",
args = {java.lang.String.class, android.net.Uri.class}
)
public void testWebSearchNormalUrl() {
Uri uri = Uri.parse(NORMAL_URL);
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY, uri);
assertCanBeHandled(intent);
}
/**
* Test ACTION_WEB_SEARCH when url is https://web_address,
* it will open a browser window to the URL specified.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "Intent",
args = {java.lang.String.class, android.net.Uri.class}
)
public void testWebSearchSecureUrl() {
Uri uri = Uri.parse(SECURE_URL);
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY, uri);
assertCanBeHandled(intent);
}
/**
* Test ACTION_WEB_SEARCH when url is empty string,
* google search will be applied for the plain text.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "Intent",
args = {java.lang.String.class, android.net.Uri.class}
)
public void testWebSearchPlainText() {
String searchString = "where am I?";
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY, searchString);
assertCanBeHandled(intent);
}
/**
* Test ACTION_CALL when uri is a phone number, it will call the entered phone number.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "Intent",
args = {java.lang.String.class, android.net.Uri.class}
)
public void testCallPhoneNumber() {
Uri uri = Uri.parse("tel:2125551212");
Intent intent = new Intent(Intent.ACTION_CALL, uri);
assertCanBeHandled(intent);
}
/**
* Test ACTION_DIAL when uri is a phone number, it will dial the entered phone number.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "Intent",
args = {java.lang.String.class, android.net.Uri.class}
)
public void testDialPhoneNumber() {
Uri uri = Uri.parse("tel:(212)5551212");
Intent intent = new Intent(Intent.ACTION_DIAL, uri);
assertCanBeHandled(intent);
}
/**
* Test ACTION_DIAL when uri is a phone number, it will dial the entered phone number.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "Intent",
args = {java.lang.String.class, android.net.Uri.class}
)
public void testDialVoicemail() {
Uri uri = Uri.parse("voicemail:");
Intent intent = new Intent(Intent.ACTION_DIAL, uri);
assertCanBeHandled(intent);
}
}