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