PhoneNumberDetectionTest.java revision 5821806d5e7f356e8fa4b058a389a808ea183019
1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package org.chromium.content.browser;
6
7import android.test.suitebuilder.annotation.LargeTest;
8import android.test.suitebuilder.annotation.MediumTest;
9
10import org.chromium.base.test.util.DisabledTest;
11import org.chromium.base.test.util.Feature;
12import org.chromium.content.common.CommandLine;
13
14/**
15 * Test suite for phone number detection.
16 */
17public class PhoneNumberDetectionTest extends ContentDetectionTestBase {
18
19    private static final String TELEPHONE_INTENT_PREFIX = "tel:";
20
21    private boolean isExpectedTelephoneIntent(String intentUrl, String expectedContent) {
22        if (intentUrl == null) return false;
23        final String expectedUrl = TELEPHONE_INTENT_PREFIX + urlForContent(expectedContent);
24        return intentUrl.equals(expectedUrl);
25    }
26
27    /**
28     * Starts the content shell activity with the provided test URL and setting the local country
29     * to the one provided by its 2-letter ISO code.
30     * @param testUrl Test url to load.
31     * @param countryIso 2-letter ISO country code. If set to null only international numbers
32     *                   can be assumed to be supported.
33     */
34    private void startActivityWithTestUrlAndCountryIso(String testUrl, String countryIso)
35            throws Throwable {
36        final String[] cmdlineArgs = countryIso == null ? null : new String[] {
37                "--" + CommandLine.NETWORK_COUNTRY_ISO + "=" + countryIso };
38        startActivityWithTestUrlAndCommandLineArgs(testUrl, cmdlineArgs);
39    }
40
41    @LargeTest
42    @Feature({"ContentDetection", "TabContents"})
43    public void testInternationalNumberIntents() throws Throwable {
44        startActivityWithTestUrl("content/content_detection/phone_international.html");
45
46        // US: +1 650-253-0000.
47        String intentUrl = scrollAndTapExpectingIntent("US");
48        assertTrue(isExpectedTelephoneIntent(intentUrl, "+16502530000"));
49
50        // Australia: +61 2 9374 4000.
51        intentUrl = scrollAndTapExpectingIntent("Australia");
52        assertTrue(isExpectedTelephoneIntent(intentUrl, "+61293744000"));
53
54        // China: +86-10-62503000.
55        intentUrl = scrollAndTapExpectingIntent("China");
56        assertTrue(isExpectedTelephoneIntent(intentUrl, "+861062503000"));
57
58        // Hong Kong: +852-3923-5400.
59        intentUrl = scrollAndTapExpectingIntent("Hong Kong");
60        assertTrue(isExpectedTelephoneIntent(intentUrl, "+85239235400"));
61
62        // India: +91-80-67218000.
63        intentUrl = scrollAndTapExpectingIntent("India");
64        assertTrue(isExpectedTelephoneIntent(intentUrl, "+918067218000"));
65
66        // Japan: +81-3-6384-9000.
67        intentUrl = scrollAndTapExpectingIntent("Japan");
68        assertTrue(isExpectedTelephoneIntent(intentUrl, "+81363849000"));
69
70        // Korea: +82-2-531-9000.
71        intentUrl = scrollAndTapExpectingIntent("Korea");
72        assertTrue(isExpectedTelephoneIntent(intentUrl, "+8225319000"));
73
74        // Singapore: +65 6521-8000.
75        intentUrl = scrollAndTapExpectingIntent("Singapore");
76        assertTrue(isExpectedTelephoneIntent(intentUrl, "+6565218000"));
77
78        // Taiwan: +886 2 8729 6000.
79        intentUrl = scrollAndTapExpectingIntent("Taiwan");
80        assertTrue(isExpectedTelephoneIntent(intentUrl, "+886287296000"));
81
82        // Kenya: +254 20 360 1000.
83        intentUrl = scrollAndTapExpectingIntent("Kenya");
84        assertTrue(isExpectedTelephoneIntent(intentUrl, "+254203601000"));
85
86        // France: +33 (0)1 42 68 53 00.
87        intentUrl = scrollAndTapExpectingIntent("France");
88        assertTrue(isExpectedTelephoneIntent(intentUrl, "+33142685300"));
89
90        // Germany: +49 40-80-81-79-000.
91        intentUrl = scrollAndTapExpectingIntent("Germany");
92        assertTrue(isExpectedTelephoneIntent(intentUrl, "+4940808179000"));
93
94        // Ireland: +353 (1) 436 1001.
95        intentUrl = scrollAndTapExpectingIntent("Ireland");
96        assertTrue(isExpectedTelephoneIntent(intentUrl, "+35314361001"));
97
98        // Italy: +39 02-36618 300.
99        intentUrl = scrollAndTapExpectingIntent("Italy");
100        assertTrue(isExpectedTelephoneIntent(intentUrl, "+390236618300"));
101
102        // Netherlands: +31 (0)20-5045-100.
103        intentUrl = scrollAndTapExpectingIntent("Netherlands");
104        assertTrue(isExpectedTelephoneIntent(intentUrl, "+31205045100"));
105
106        // Norway: +47 22996288.
107        intentUrl = scrollAndTapExpectingIntent("Norway");
108        assertTrue(isExpectedTelephoneIntent(intentUrl, "+4722996288"));
109
110        // Poland: +48 (12) 68 15 300.
111        intentUrl = scrollAndTapExpectingIntent("Poland");
112        assertTrue(isExpectedTelephoneIntent(intentUrl, "+48126815300"));
113
114        // Russia: +7-495-644-1400.
115        intentUrl = scrollAndTapExpectingIntent("Russia");
116        assertTrue(isExpectedTelephoneIntent(intentUrl, "+74956441400"));
117
118        // Spain: +34 91-748-6400.
119        intentUrl = scrollAndTapExpectingIntent("Spain");
120        assertTrue(isExpectedTelephoneIntent(intentUrl, "+34917486400"));
121
122        // Switzerland: +41 44-668-1800.
123        intentUrl = scrollAndTapExpectingIntent("Switzerland");
124        assertTrue(isExpectedTelephoneIntent(intentUrl, "+41446681800"));
125
126        // UK: +44 (0)20-7031-3000.
127        intentUrl = scrollAndTapExpectingIntent("UK");
128        assertTrue(isExpectedTelephoneIntent(intentUrl, "+442070313000"));
129
130        // Canada: +1 514-670-8700.
131        intentUrl = scrollAndTapExpectingIntent("Canada");
132        assertTrue(isExpectedTelephoneIntent(intentUrl, "+15146708700"));
133
134        // Argentina: +54-11-5530-3000.
135        intentUrl = scrollAndTapExpectingIntent("Argentina");
136        assertTrue(isExpectedTelephoneIntent(intentUrl, "+541155303000"));
137
138        // Brazil: +55-31-2128-6800.
139        intentUrl = scrollAndTapExpectingIntent("Brazil");
140        assertTrue(isExpectedTelephoneIntent(intentUrl, "+553121286800"));
141
142        // Mexico: +52 55-5342-8400.
143        intentUrl = scrollAndTapExpectingIntent("Mexico");
144        assertTrue(isExpectedTelephoneIntent(intentUrl, "+525553428400"));
145
146        // Israel: +972-74-746-6245.
147        intentUrl = scrollAndTapExpectingIntent("Israel");
148        assertTrue(isExpectedTelephoneIntent(intentUrl, "+972747466245"));
149
150        // UAE: +971 4 4509500.
151        intentUrl = scrollAndTapExpectingIntent("UAE");
152        assertTrue(isExpectedTelephoneIntent(intentUrl, "+97144509500"));
153    }
154
155    @MediumTest
156    @Feature({"ContentDetection", "TabContents"})
157    public void testLocalUSNumbers() throws Throwable {
158        startActivityWithTestUrlAndCountryIso("content/content_detection/phone_local.html", "US");
159
160        // US_1: 1-888-433-5788.
161        String intentUrl = scrollAndTapExpectingIntent("US_1");
162        assertTrue(isExpectedTelephoneIntent(intentUrl, "+18884335788"));
163
164        // US_2: 703-293-6299.
165        intentUrl = scrollAndTapExpectingIntent("US_2");
166        assertTrue(isExpectedTelephoneIntent(intentUrl, "+17032936299"));
167
168        // US_3: (202) 456-2121.
169        intentUrl = scrollAndTapExpectingIntent("US_3");
170        assertTrue(isExpectedTelephoneIntent(intentUrl, "+12024562121"));
171
172        // International numbers should still work.
173        intentUrl = scrollAndTapExpectingIntent("International");
174        assertTrue(isExpectedTelephoneIntent(intentUrl, "+31205045100"));
175    }
176
177    @MediumTest
178    @Feature({"ContentDetection", "TabContents"})
179    public void testLocalUKNumbers() throws Throwable {
180        startActivityWithTestUrlAndCountryIso("content/content_detection/phone_local.html", "GB");
181
182        // GB_1: (0) 20 7323 8299.
183        String intentUrl = scrollAndTapExpectingIntent("GB_1");
184        assertTrue(isExpectedTelephoneIntent(intentUrl, "+442073238299"));
185
186        // GB_2: 01227865330.
187        intentUrl = scrollAndTapExpectingIntent("GB_2");
188        assertTrue(isExpectedTelephoneIntent(intentUrl, "+441227865330"));
189
190        // GB_3: 01963 824686.
191        intentUrl = scrollAndTapExpectingIntent("GB_3");
192        assertTrue(isExpectedTelephoneIntent(intentUrl, "+441963824686"));
193
194        // International numbers should still work.
195        intentUrl = scrollAndTapExpectingIntent("International");
196        assertTrue(isExpectedTelephoneIntent(intentUrl, "+31205045100"));
197    }
198
199    @MediumTest
200    @Feature({"ContentDetection", "TabContents"})
201    public void testLocalFRNumbers() throws Throwable {
202        startActivityWithTestUrlAndCountryIso("content/content_detection/phone_local.html", "FR");
203
204        // FR_1: 01 40 20 50 50.
205        String intentUrl = scrollAndTapExpectingIntent("FR_1");
206        assertTrue(isExpectedTelephoneIntent(intentUrl, "+33140205050"));
207
208        // FR_2: 0326475534.
209        intentUrl = scrollAndTapExpectingIntent("FR_2");
210        assertTrue(isExpectedTelephoneIntent(intentUrl, "+33326475534"));
211
212        // FR_3: (0) 237 211 992.
213        intentUrl = scrollAndTapExpectingIntent("FR_3");
214        assertTrue(isExpectedTelephoneIntent(intentUrl, "+33237211992"));
215
216        // International numbers should still work.
217        intentUrl = scrollAndTapExpectingIntent("International");
218        assertTrue(isExpectedTelephoneIntent(intentUrl, "+31205045100"));
219    }
220}
221