PhoneNumberDetectionTest.java revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
1// Copyright 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; 8 9import org.chromium.base.test.util.Feature; 10import org.chromium.content.common.ContentSwitches; 11 12/** 13 * Test suite for phone number detection. 14 */ 15public class PhoneNumberDetectionTest extends ContentDetectionTestBase { 16 17 private static final String TELEPHONE_INTENT_PREFIX = "tel:"; 18 19 private boolean isExpectedTelephoneIntent(String intentUrl, String expectedContent) { 20 if (intentUrl == null) return false; 21 final String expectedUrl = TELEPHONE_INTENT_PREFIX + urlForContent(expectedContent); 22 return intentUrl.equals(expectedUrl); 23 } 24 25 /** 26 * Starts the content shell activity with the provided test URL and setting the local country 27 * to the one provided by its 2-letter ISO code. 28 * @param testUrl Test url to load. 29 * @param countryIso 2-letter ISO country code. If set to null only international numbers 30 * can be assumed to be supported. 31 */ 32 private void startActivityWithTestUrlAndCountryIso(String testUrl, String countryIso) 33 throws Throwable { 34 final String[] cmdlineArgs = countryIso == null ? null : new String[] { 35 "--" + ContentSwitches.NETWORK_COUNTRY_ISO + "=" + countryIso }; 36 startActivityWithTestUrlAndCommandLineArgs(testUrl, cmdlineArgs); 37 } 38 39 /* @LargeTest */ 40 @FlakyTest 41 @Feature({"ContentDetection", "TabContents"}) 42 public void testInternationalNumberIntents() throws Throwable { 43 startActivityWithTestUrl("content/content_detection/phone_international.html"); 44 assertWaitForPageScaleFactorMatch(1.0f); 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 @FlakyTest 157 @Feature({"ContentDetection", "TabContents"}) 158 public void testLocalUSNumbers() throws Throwable { 159 startActivityWithTestUrlAndCountryIso("content/content_detection/phone_local.html", "US"); 160 assertWaitForPageScaleFactorMatch(1.0f); 161 162 // US_1: 1-888-433-5788. 163 String intentUrl = scrollAndTapExpectingIntent("US_1"); 164 assertTrue(isExpectedTelephoneIntent(intentUrl, "+18884335788")); 165 166 // US_2: 703-293-6299. 167 intentUrl = scrollAndTapExpectingIntent("US_2"); 168 assertTrue(isExpectedTelephoneIntent(intentUrl, "+17032936299")); 169 170 // US_3: (202) 456-2121. 171 intentUrl = scrollAndTapExpectingIntent("US_3"); 172 assertTrue(isExpectedTelephoneIntent(intentUrl, "+12024562121")); 173 174 // International numbers should still work. 175 intentUrl = scrollAndTapExpectingIntent("International"); 176 assertTrue(isExpectedTelephoneIntent(intentUrl, "+31205045100")); 177 } 178 179 /* @MediumTest */ 180 @FlakyTest 181 @Feature({"ContentDetection", "TabContents"}) 182 public void testLocalUKNumbers() throws Throwable { 183 startActivityWithTestUrlAndCountryIso("content/content_detection/phone_local.html", "GB"); 184 assertWaitForPageScaleFactorMatch(1.0f); 185 186 // GB_1: (0) 20 7323 8299. 187 String intentUrl = scrollAndTapExpectingIntent("GB_1"); 188 assertTrue(isExpectedTelephoneIntent(intentUrl, "+442073238299")); 189 190 // GB_2: 01227865330. 191 intentUrl = scrollAndTapExpectingIntent("GB_2"); 192 assertTrue(isExpectedTelephoneIntent(intentUrl, "+441227865330")); 193 194 // GB_3: 01963 824686. 195 intentUrl = scrollAndTapExpectingIntent("GB_3"); 196 assertTrue(isExpectedTelephoneIntent(intentUrl, "+441963824686")); 197 198 // International numbers should still work. 199 intentUrl = scrollAndTapExpectingIntent("International"); 200 assertTrue(isExpectedTelephoneIntent(intentUrl, "+31205045100")); 201 } 202 203 /* @MediumTest */ 204 @FlakyTest 205 @Feature({"ContentDetection", "TabContents"}) 206 public void testLocalFRNumbers() throws Throwable { 207 startActivityWithTestUrlAndCountryIso("content/content_detection/phone_local.html", "FR"); 208 assertWaitForPageScaleFactorMatch(1.0f); 209 210 // FR_1: 01 40 20 50 50. 211 String intentUrl = scrollAndTapExpectingIntent("FR_1"); 212 assertTrue(isExpectedTelephoneIntent(intentUrl, "+33140205050")); 213 214 // FR_2: 0326475534. 215 intentUrl = scrollAndTapExpectingIntent("FR_2"); 216 assertTrue(isExpectedTelephoneIntent(intentUrl, "+33326475534")); 217 218 // FR_3: (0) 237 211 992. 219 intentUrl = scrollAndTapExpectingIntent("FR_3"); 220 assertTrue(isExpectedTelephoneIntent(intentUrl, "+33237211992")); 221 222 // International numbers should still work. 223 intentUrl = scrollAndTapExpectingIntent("International"); 224 assertTrue(isExpectedTelephoneIntent(intentUrl, "+31205045100")); 225 } 226} 227