Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/autofill/AutofillDialogControllerTest.java

Issue 1931043002: Remove requestAutocomplete (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 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
5 package org.chromium.chrome.browser.autofill;
6
7 import android.test.suitebuilder.annotation.MediumTest;
8 import android.test.suitebuilder.annotation.SmallTest;
9 import android.text.TextUtils;
10
11 import org.chromium.base.test.util.CommandLineFlags;
12 import org.chromium.base.test.util.Feature;
13 import org.chromium.base.test.util.UrlUtils;
14 import org.chromium.chrome.browser.ChromeActivity;
15 import org.chromium.chrome.test.ChromeActivityTestCaseBase;
16 import org.chromium.content.browser.ContentViewCore;
17 import org.chromium.content.browser.test.util.Criteria;
18 import org.chromium.content.browser.test.util.CriteriaHelper;
19 import org.chromium.content.browser.test.util.DOMUtils;
20 import org.chromium.content_public.browser.WebContents;
21
22 import java.util.concurrent.TimeoutException;
23
24 /**
25 * Integration tests for the AutofillPopup.
26 */
27 @CommandLineFlags.Add("reduce-security-for-testing")
28 public class AutofillDialogControllerTest extends ChromeActivityTestCaseBase<Chr omeActivity> {
29 private static final long DIALOG_CALLBACK_DELAY_MILLISECONDS = 50;
30
31 private static final String TEST_NAME = "Joe Doe";
32 private static final String TEST_PHONE = "(415)413-0703";
33 private static final String TEST_PHONE_UNFORMATTED = "4154130703";
34 private static final String TEST_EMAIL = "email@server.com";
35
36 private static final String TEST_CC_NUMBER = "4111111111111111";
37 private static final String TEST_CC_CSC = "123";
38 private static final int TEST_CC_EXP_MONTH = 11;
39 private static final int TEST_CC_EXP_YEAR = 2015;
40
41 private static final String TEST_BILLING1 = "123 Main street";
42 private static final String TEST_BILLING2 = "apt 456";
43 private static final String TEST_BILLING3 = "leave at the office";
44 private static final String TEST_BILLING_STREET =
45 TEST_BILLING1 + "\n" + TEST_BILLING2 + "\n" + TEST_BILLING3;
46 private static final String TEST_BILLING_CITY = "Schenectady";
47 private static final String TEST_BILLING_DL = ""; // dependent locality
48 private static final String TEST_BILLING_STATE = "NY";
49 private static final String TEST_BILLING_ZIP = "12345";
50 private static final String TEST_BILLING_SORTING_CODE = ""; // sorting code
51 private static final String TEST_BILLING_COUNTRY = "US";
52 private static final String TEST_BILLING_LANGUAGE = ""; // language
53
54 private static final String TEST_SHIPPING_NAME = "Mister Receiver";
55 private static final String TEST_SHIPPING_PHONE = "+46 8 713 99 99";
56 private static final String TEST_SHIPPING_PHONE_UNFORMATTED = "+4687139999";
57 private static final String TEST_SHIPPING1 = "19 Farstaplan";
58 private static final String TEST_SHIPPING2 = "Third floor";
59 private static final String TEST_SHIPPING3 = "please call first";
60 private static final String TEST_SHIPPING_STREET =
61 TEST_SHIPPING1 + "\n" + TEST_SHIPPING2 + "\n" + TEST_SHIPPING3;
62 private static final String TEST_SHIPPING_CITY = "Farsta";
63 private static final String TEST_SHIPPING_DL = ""; // dependent locality
64 private static final String TEST_SHIPPING_STATE = "Stockholm";
65 private static final String TEST_SHIPPING_ZIP = "12346";
66 private static final String TEST_SHIPPING_SORTING_CODE = ""; // sorting cod e
67 private static final String TEST_SHIPPING_COUNTRY = "SE";
68 private static final String TEST_SHIPPING_LANGUAGE = ""; // language
69
70 private static final String HTML_PRELUDE = "<html>"
71 + "<head>"
72 + " <meta name=\"viewport\""
73 + " content=\"width=device-width, initial-scale=1.0, maximum-sc ale=1.0\" />"
74 + "</head>"
75 + "<body>"
76 + "<form id=\"id-form\">"
77 + " <button id=\"id-button\">DO INTERACTIVE AUTOCOMPLETE</button>";
78
79 private static final String HTML_POSTLUDE = "</form>"
80 + "<div id=\"was-autocompleted\">no</div>"
81 + ":<div id=\"autocomplete-failure-reason\"></div>"
82 + "<script>"
83 + "var form = document.forms[0];"
84 + "form.onsubmit = function(e) {"
85 + " e.preventDefault();"
86 + " form.requestAutocomplete();"
87 + "};"
88 + "form.onautocomplete = function() {"
89 + " document.getElementById('was-autocompleted').textContent = 'suc ceeded';"
90 + "};"
91 + "form.onautocompleteerror = function(e) {"
92 + " document.getElementById('was-autocompleted').textContent = 'fai led';"
93 + " document.getElementById('autocomplete-failure-reason').textCont ent = e.reason;"
94 + "};"
95 + "</script></body></html>";
96
97 private static String generatePage(
98 boolean requestFullBilling, boolean requestShipping, boolean request PhoneNumbers) {
99 StringBuilder sb = new StringBuilder();
100 sb.append(HTML_PRELUDE);
101 sb.append("<fieldset>"
102 + "<input id=\"id-billing-name\" autocomplete=\"billing name\" v alue=\"W\">"
103 + "<input id=\"id-cc-name\" autocomplete=\"cc-name\" value=\"W\" >"
104 + "<input id=\"id-email\" autocomplete=\"email\" type=\"email\" value=\"W@W.W\">"
105 + "<input id=\"id-cc-number\" autocomplete=\"cc-number\" value=\ "W\">"
106 + "<input id=\"id-cc-exp\" "
107 + " autocomplete=\"cc-exp\" type=\"month\" value=\"1111-11\">"
108 + "<select id=\"id-cc-exp-month\" autocomplete=\"cc-exp-month\"> "
109 + " <option value=\"1\" selected>1</option>"
110 + " <option value=\"2\">2</option>"
111 + " <option value=\"3\">3</option>"
112 + " <option value=\"4\">4</option>"
113 + " <option value=\"5\">5</option>"
114 + " <option value=\"6\">6</option>"
115 + " <option value=\"7\">7</option>"
116 + " <option value=\"8\">8</option>"
117 + " <option value=\"9\">9</option>"
118 + " <option value=\"10\">10</option>"
119 + " <option value=\"11\">11</option>"
120 + " <option value=\"12\">12</option>"
121 + "</select>"
122 + "<select id=\"id-cc-exp-year\" autocomplete=\"cc-exp-year\">"
123 + " <option value=\"2011\" selected>2011</option>"
124 + " <option value=\"2012\">2012</option>"
125 + " <option value=\"2013\">2013</option>"
126 + " <option value=\"2014\">2014</option>"
127 + " <option value=\"2015\">2015</option>"
128 + "</select>"
129 + "<input id=\"id-cc-csc\" autocomplete=\"cc-csc\" value=\"W\">"
130 + "<input id=\"id-cc-zip\" autocomplete=\"billing postal-code\" value=\"W\">");
131 if (requestFullBilling) {
132 sb.append("<input id=\"id-cc-1\" autocomplete=\"billing address-line 1\" value=\"W\">"
133 + "<input id=\"id-cc-2\" autocomplete=\"billing address-line 2\" value=\"W\">"
134 + "<textarea id=\"id-cc-str\""
135 + " autocomplete=\"billing street-address\">W</textarea>"
136 + "<input id=\"id-cc-city\" autocomplete=\"billing locality\ " value=\"W\">"
137 + "<input id=\"id-cc-state\" autocomplete=\"billing region\" value=\"W\">"
138 + "<select id=\"id-cc-country\" autocomplete=\"billing count ry\">"
139 + " <option value=\"NL\" selected>Netherlands</option>"
140 + " <option value=\"US\">United States</option>"
141 + " <option value=\"SE\">Sweden</option>"
142 + " <option value=\"RU\">Russia</option>"
143 + "</select>");
144 }
145 sb.append("</fieldset>");
146 if (requestShipping) {
147 sb.append("<fieldset>"
148 + "<input id=\"id-name\" autocomplete=\"name\" value=\"W\">"
149 + "<input id=\"id-h-name\" autocomplete=\"shipping name\" va lue=\"W\">"
150 + "<input id=\"id-h-1\" autocomplete=\"shipping address-line 1\" value=\"W\">"
151 + "<input id=\"id-h-2\" autocomplete=\"shipping address-line 2\" value=\"W\">"
152 + "<textarea id=\"id-h-str\""
153 + " autocomplete=\"shipping street-address\">W</textarea> "
154 + "<input id=\"id-h-city\" autocomplete=\"shipping locality\ " value=\"W\">"
155 + "<input id=\"id-h-state\" autocomplete=\"shipping region\" value=\"W\">"
156 + "<input id=\"id-h-zip\" autocomplete=\"shipping postal-cod e\" value=\"W\">"
157 + "<select id=\"id-h-country\" autocomplete=\"shipping count ry\">"
158 + " <option value=\"NL\" selected>Netherlands</option>"
159 + " <option value=\"US\">United States</option>"
160 + " <option value=\"SE\">Sweden</option>"
161 + " <option value=\"RU\">Russia</option>"
162 + "</select>"
163 + "</fieldset>");
164 }
165 if (requestPhoneNumbers) {
166 sb.append("<fieldset>"
167 + "<input id=\"id-cc-tel\" autocomplete=\"billing tel\" valu e=\"W\">");
168 if (requestShipping) {
169 sb.append("<input id=\"id-h-tel\" autocomplete=\"shipping tel\" value=\"W\">"
170 + "<input id=\"id-tel\" autocomplete=\"tel\" value=\"W\" >");
171 }
172 sb.append("</fieldset>");
173 }
174 sb.append(HTML_POSTLUDE);
175 return UrlUtils.encodeHtmlDataUri(sb.toString());
176 }
177
178 public AutofillDialogControllerTest() {
179 super(ChromeActivity.class);
180 }
181
182 @Override
183 public void startMainActivity() throws InterruptedException {
184 // Don't launch activity automatically.
185 }
186
187 @MediumTest
188 @Feature({"autofill"})
189 public void testFieldsAreFilledMinimal() throws InterruptedException, Timeou tException {
190 final boolean requestFullBilling = false;
191 final boolean requestShipping = false;
192 final boolean requestPhoneNumbers = false;
193 verifyFieldsAreFilled(requestFullBilling, requestShipping, requestPhoneN umbers);
194 }
195
196 @MediumTest
197 @Feature({"autofill"})
198 public void testFieldsAreFilledFullBilling() throws InterruptedException, Ti meoutException {
199 final boolean requestFullBilling = true;
200 final boolean requestShipping = false;
201 final boolean requestPhoneNumbers = false;
202 verifyFieldsAreFilled(requestFullBilling, requestShipping, requestPhoneN umbers);
203 }
204
205 @MediumTest
206 @Feature({"autofill"})
207 public void testFieldsAreFilledShipping() throws InterruptedException, Timeo utException {
208 final boolean requestFullBilling = true;
209 final boolean requestShipping = true;
210 final boolean requestPhoneNumbers = false;
211 verifyFieldsAreFilled(requestFullBilling, requestShipping, requestPhoneN umbers);
212 }
213
214 @MediumTest
215 @Feature({"autofill"})
216 public void testFieldsAreFilledBillingPhone() throws InterruptedException, T imeoutException {
217 final boolean requestFullBilling = true;
218 final boolean requestShipping = false;
219 final boolean requestPhoneNumbers = true;
220 verifyFieldsAreFilled(requestFullBilling, requestShipping, requestPhoneN umbers);
221 }
222
223 @MediumTest
224 @Feature({"autofill"})
225 public void testFieldsAreFilledEverything() throws InterruptedException, Tim eoutException {
226 final boolean requestFullBilling = true;
227 final boolean requestShipping = true;
228 final boolean requestPhoneNumbers = true;
229 verifyFieldsAreFilled(requestFullBilling, requestShipping, requestPhoneN umbers);
230 }
231
232 // It is currently unspecified whether autocomplete="name" gives a SHIPPING or a BILLING name.
233 // I'm assuming here that this is a shipping name.
234 @SmallTest
235 @Feature({"autofill"})
236 public void testRacTypeName() throws InterruptedException, TimeoutException {
237 verifyOneFieldWithCc(
238 "<input id=\"id\" autocomplete=\"name\">",
239 TEST_SHIPPING_NAME, "id", false, true, false);
240 }
241
242 @SmallTest
243 @Feature({"autofill"})
244 public void testRacTypeBillingName() throws InterruptedException, TimeoutExc eption {
245 verifyOneFieldWithCc(
246 "<input id=\"id\" autocomplete=\"billing name\">",
247 TEST_NAME, "id", false, false, false);
248 }
249
250 @SmallTest
251 @Feature({"autofill"})
252 public void testRacTypeShippingName() throws InterruptedException, TimeoutEx ception {
253 verifyOneFieldWithCc(
254 "<input id=\"id\" autocomplete=\"shipping name\">",
255 TEST_SHIPPING_NAME, "id", false, true, false);
256 }
257
258 // It is currently unspecified whether autocomplete="name" gives a SHIPPING or a BILLING phone.
259 // I'm assuming here that this is a shipping phone.
260 @SmallTest
261 @Feature({"autofill"})
262 public void testRacTypeTel() throws InterruptedException, TimeoutException {
263 verifyOneFieldWithCc(
264 "<input id=\"id\" autocomplete=\"tel\">",
265 TEST_SHIPPING_PHONE_UNFORMATTED, "id", false, true, true);
266 }
267
268 @SmallTest
269 @Feature({"autofill"})
270 public void testRacTypeBillingTel() throws InterruptedException, TimeoutExce ption {
271 verifyOneFieldWithCc(
272 "<input id=\"id\" autocomplete=\"billing tel\">",
273 TEST_PHONE_UNFORMATTED, "id", true, false, true);
274 }
275
276 @SmallTest
277 @Feature({"autofill"})
278 public void testRacTypeShippingTel() throws InterruptedException, TimeoutExc eption {
279 verifyOneFieldWithCc(
280 "<input id=\"id\" autocomplete=\"shipping tel\">",
281 TEST_SHIPPING_PHONE_UNFORMATTED, "id", false, true, true);
282 }
283
284 @SmallTest
285 @Feature({"autofill"})
286 public void testRacTypeEmail() throws InterruptedException, TimeoutException {
287 verifyOneFieldWithCc(
288 "<input id=\"id\" autocomplete=\"email\" type=\"email\">",
289 TEST_EMAIL, "id", false, false, false);
290 }
291
292 @SmallTest
293 @Feature({"autofill"})
294 public void testRacTypeCCName() throws InterruptedException, TimeoutExceptio n {
295 verifyOneField(
296 "<input id=\"id\" autocomplete=\"cc-name\">",
297 TEST_NAME, "id", false, false, false);
298 }
299
300 @SmallTest
301 @Feature({"autofill"})
302 public void testRacTypeCCNumber() throws InterruptedException, TimeoutExcept ion {
303 verifyOneField(
304 "<input id=\"id\" autocomplete=\"cc-number\">",
305 TEST_CC_NUMBER, "id", false, false, false);
306 }
307
308 @SmallTest
309 @Feature({"autofill"})
310 public void testRacTypeCCCsc() throws InterruptedException, TimeoutException {
311 verifyOneField(
312 "<input id=\"id\" autocomplete=\"cc-csc\">",
313 TEST_CC_CSC, "id", false, false, false);
314 }
315
316 @SmallTest
317 @Feature({"autofill"})
318 public void testRacTypeCCExp() throws InterruptedException, TimeoutException {
319 verifyOneField(
320 "<input id=\"id\" autocomplete=\"cc-exp\" type=\"month\" value=\ "1111-11\">",
321 "" + TEST_CC_EXP_YEAR + "-" + TEST_CC_EXP_MONTH,
322 "id", false, false, false);
323 }
324
325 @SmallTest
326 @Feature({"autofill"})
327 public void testRacTypeCCExpMonth() throws InterruptedException, TimeoutExce ption {
328 verifyOneField(
329 "<select id=\"id\" autocomplete=\"cc-exp-month\">"
330 + " <option value=\"1\" selected>1</option>"
331 + " <option value=\"2\">2</option>"
332 + " <option value=\"3\">3</option>"
333 + " <option value=\"4\">4</option>"
334 + " <option value=\"5\">5</option>"
335 + " <option value=\"6\">6</option>"
336 + " <option value=\"7\">7</option>"
337 + " <option value=\"8\">8</option>"
338 + " <option value=\"9\">9</option>"
339 + " <option value=\"10\">10</option>"
340 + " <option value=\"11\">11</option>"
341 + " <option value=\"12\">12</option>"
342 + "</select>",
343 "" + TEST_CC_EXP_MONTH, "id", false, false, false);
344 }
345
346 @SmallTest
347 @Feature({"autofill"})
348 public void testRacTypeCCExpYear() throws InterruptedException, TimeoutExcep tion {
349 verifyOneField(
350 "<select id=\"id\" autocomplete=\"cc-exp-year\">"
351 + " <option value=\"2011\" selected>2011</option>"
352 + " <option value=\"2012\">2012</option>"
353 + " <option value=\"2013\">2013</option>"
354 + " <option value=\"2014\">2014</option>"
355 + " <option value=\"2015\">2015</option>"
356 + "</select>",
357 "" + TEST_CC_EXP_YEAR, "id", false, false, false);
358 }
359
360 @SmallTest
361 @Feature({"autofill"})
362 public void testRacTypeBillingCountry() throws InterruptedException, Timeout Exception {
363 verifyOneFieldWithCc(
364 "<select id=\"id\" autocomplete=\"billing country\">"
365 + " <option value=\"NL\" selected>Netherlands</option>"
366 + " <option value=\"US\">United States</option>"
367 + " <option value=\"SE\">Sweden</option>"
368 + " <option value=\"RU\">Russia</option>"
369 + "</select>",
370 TEST_BILLING_COUNTRY, "id", true, false, false);
371 }
372
373 @SmallTest
374 @Feature({"autofill"})
375 public void testRacTypeBillingPostalCode() throws InterruptedException, Time outException {
376 verifyOneFieldWithCc(
377 "<input id=\"id\" autocomplete=\"billing postal-code\">",
378 TEST_BILLING_ZIP, "id", false, false, false);
379 }
380
381 @SmallTest
382 @Feature({"autofill"})
383 public void testRacTypeBillingAddressLine1() throws InterruptedException, Ti meoutException {
384 verifyOneFieldWithCc(
385 "<input id=\"id\" autocomplete=\"billing address-line1\">",
386 TEST_BILLING1, "id", true, false, false);
387 }
388
389 @SmallTest
390 @Feature({"autofill"})
391 public void testRacTypeBillingAddressLine2() throws InterruptedException, Ti meoutException {
392 verifyOneFieldWithCc(
393 "<input id=\"id\" autocomplete=\"billing address-line2\">",
394 TEST_BILLING2, "id", true, false, false);
395 }
396
397 @SmallTest
398 @Feature({"autofill"})
399 public void testRacTypeBillingStreetAddress() throws InterruptedException, T imeoutException {
400 verifyOneFieldWithCc(
401 "<textarea id=\"id\" autocomplete=\"billing street-address\"></t extarea>",
402 TEST_BILLING_STREET, "id", true, false, false);
403 }
404
405 @SmallTest
406 @Feature({"autofill"})
407 public void testRacTypeBillingLocality() throws InterruptedException, Timeou tException {
408 verifyOneFieldWithCc(
409 "<input id=\"id\" autocomplete=\"billing locality\">",
410 TEST_BILLING_CITY, "id", true, false, false);
411 }
412
413 @SmallTest
414 @Feature({"autofill"})
415 public void testRacTypeBillingRegion() throws InterruptedException, TimeoutE xception {
416 verifyOneFieldWithCc(
417 "<input id=\"id\" autocomplete=\"billing region\">",
418 TEST_BILLING_STATE, "id", true, false, false);
419 }
420
421 @SmallTest
422 @Feature({"autofill"})
423 public void testRacTypeShippingCountry() throws InterruptedException, Timeou tException {
424 verifyOneFieldWithCc(
425 "<select id=\"id\" autocomplete=\"shipping country\">"
426 + " <option value=\"NL\" selected>Netherlands</option>"
427 + " <option value=\"US\">United States</option>"
428 + " <option value=\"SE\">Sweden</option>"
429 + " <option value=\"RU\">Russia</option>"
430 + "</select>",
431 TEST_SHIPPING_COUNTRY, "id", false, true, false);
432 }
433
434 @SmallTest
435 @Feature({"autofill"})
436 public void testRacTypeShippingPostalCode() throws InterruptedException, Tim eoutException {
437 verifyOneFieldWithCc(
438 "<input id=\"id\" autocomplete=\"shipping postal-code\">",
439 TEST_SHIPPING_ZIP, "id", false, true, false);
440 }
441
442 @SmallTest
443 @Feature({"autofill"})
444 public void testRacTypeShippingAddressLine1() throws InterruptedException, T imeoutException {
445 verifyOneFieldWithCc(
446 "<input id=\"id\" autocomplete=\"shipping address-line1\">",
447 TEST_SHIPPING1, "id", false, true, false);
448 }
449
450 @SmallTest
451 @Feature({"autofill"})
452 public void testRacTypeShippingAddressLine2() throws InterruptedException, T imeoutException {
453 verifyOneFieldWithCc(
454 "<input id=\"id\" autocomplete=\"shipping address-line2\">",
455 TEST_SHIPPING2, "id", false, true, false);
456 }
457
458 @SmallTest
459 @Feature({"autofill"})
460 public void testRacTypeShippingStreetAddress() throws InterruptedException, TimeoutException {
461 verifyOneFieldWithCc(
462 "<textarea id=\"id\" autocomplete=\"shipping street-address\"></ textarea>",
463 TEST_SHIPPING_STREET, "id", false, true, false);
464 }
465
466 @SmallTest
467 @Feature({"autofill"})
468 public void testRacTypeShippingLocality() throws InterruptedException, Timeo utException {
469 verifyOneFieldWithCc(
470 "<input id=\"id\" autocomplete=\"shipping locality\">",
471 TEST_SHIPPING_CITY, "id", false, true, false);
472 }
473
474 @SmallTest
475 @Feature({"autofill"})
476 public void testRacTypeShippingRegion() throws InterruptedException, Timeout Exception {
477 verifyOneFieldWithCc(
478 "<input id=\"id\" autocomplete=\"shipping region\">",
479 TEST_SHIPPING_STATE, "id", false, true, false);
480 }
481
482 @SmallTest
483 @Feature({"autofill"})
484 public void testRefuseToShowWithNoCcField() throws InterruptedException, Tim eoutException {
485 String requested = "<input id=\"id\" autocomplete=\"shipping locality\"> ";
486 setUpAndExpectFailedRequestAutocomplete(
487 UrlUtils.encodeHtmlDataUri(HTML_PRELUDE + requested + HTML_POSTL UDE),
488 false, true, false);
489 }
490
491 @SmallTest
492 @Feature({"autofill"})
493 public void testRefuseToShowWithNoAutocompleteAttributes()
494 throws InterruptedException, TimeoutException {
495 String requested = "<input id=\"id-cc-csc\">"
496 + "<input id=\"id-email\" type=\"email\">"
497 + "<input id=\"id-cc-name\">"
498 + "<input id=\"id-shipping-locality\">";
499 setUpAndExpectFailedRequestAutocomplete(
500 UrlUtils.encodeHtmlDataUri(HTML_PRELUDE + requested + HTML_POSTL UDE),
501 false, true, false);
502 }
503
504 private void verifyOneField(
505 final String htmlFragment,
506 final String expected, final String actualId,
507 final boolean requestFullBilling,
508 final boolean requestShipping, final boolean requestPhoneNumbers)
509 throws InterruptedException, TimeoutException {
510 verifyOneFieldWithOptionalCc(htmlFragment, expected, actualId,
511 requestFullBilling, requestShipping, requestPhoneNumbers, false) ;
512 }
513
514 private void verifyOneFieldWithCc(
515 final String htmlFragment,
516 final String expected, final String actualId,
517 final boolean requestFullBilling,
518 final boolean requestShipping, final boolean requestPhoneNumbers)
519 throws InterruptedException, TimeoutException {
520 verifyOneFieldWithOptionalCc(htmlFragment, expected, actualId,
521 requestFullBilling, requestShipping, requestPhoneNumbers, true);
522 }
523
524 private void verifyOneFieldWithOptionalCc(
525 final String htmlFragment,
526 final String expected, final String actualId,
527 final boolean requestFullBilling,
528 final boolean requestShipping, final boolean requestPhoneNumbers,
529 final boolean requestCcInfo)
530 throws InterruptedException, TimeoutException {
531 final String optionalCcFragment = requestCcInfo
532 ? "<input id=\"id-opt-cc-csc\" autocomplete=\"cc-csc\">"
533 : "";
534 final String url = UrlUtils.encodeHtmlDataUri(
535 HTML_PRELUDE
536 + htmlFragment
537 + optionalCcFragment
538 + HTML_POSTLUDE);
539
540 setUpAndRequestAutocomplete(url, requestFullBilling, requestShipping, re questPhoneNumbers);
541
542 final WebContents webContents = getActivity().getCurrentContentViewCore( ).getWebContents();
543
544 assertEquals(actualId + " did not match",
545 expected, DOMUtils.getNodeValue(webContents, actualId));
546 if (requestCcInfo) {
547 assertEquals("cc-csc did not match",
548 TEST_CC_CSC, DOMUtils.getNodeValue(webContents, "id-opt-cc-c sc"));
549 }
550 }
551
552 private void verifyFieldsAreFilled(final boolean requestFullBilling,
553 final boolean requestShipping, final boolean requestPhoneNumbers)
554 throws InterruptedException, TimeoutException {
555 setUpAndRequestAutocomplete(
556 generatePage(requestFullBilling, requestShipping, requestPhoneNu mbers),
557 requestFullBilling, requestShipping, requestPhoneNumbers);
558
559 final WebContents webContents = getActivity().getCurrentContentViewCore( ).getWebContents();
560
561 assertEquals("billing name did not match",
562 TEST_NAME, DOMUtils.getNodeValue(webContents, "id-billing-name") );
563 assertEquals("email did not match",
564 TEST_EMAIL, DOMUtils.getNodeValue(webContents, "id-email"));
565
566 assertEquals("cc-name did not match",
567 TEST_NAME, DOMUtils.getNodeValue(webContents, "id-cc-name"));
568
569 assertEquals("cc-number did not match",
570 TEST_CC_NUMBER, DOMUtils.getNodeValue(webContents, "id-cc-number "));
571 assertEquals("cc-csc did not match",
572 TEST_CC_CSC, DOMUtils.getNodeValue(webContents, "id-cc-csc"));
573
574 assertEquals("cc-exp did not match",
575 "" + TEST_CC_EXP_YEAR + "-" + TEST_CC_EXP_MONTH,
576 DOMUtils.getNodeValue(webContents, "id-cc-exp"));
577
578 assertEquals("cc-exp-month did not match",
579 "" + TEST_CC_EXP_MONTH,
580 DOMUtils.getNodeValue(webContents, "id-cc-exp-month"));
581 assertEquals("cc-exp-year did not match",
582 "" + TEST_CC_EXP_YEAR,
583 DOMUtils.getNodeValue(webContents, "id-cc-exp-year"));
584
585 assertEquals("billing postal-code did not match",
586 TEST_BILLING_ZIP, DOMUtils.getNodeValue(webContents, "id-cc-zip" ));
587
588 if (requestFullBilling) {
589 assertEquals("billing address-line1 did not match",
590 TEST_BILLING1, DOMUtils.getNodeValue(webContents, "id-cc-1") );
591 assertEquals("billing address-line2 did not match",
592 TEST_BILLING2, DOMUtils.getNodeValue(webContents, "id-cc-2") );
593 assertEquals("billing street-address did not match",
594 TEST_BILLING_STREET, DOMUtils.getNodeValue(webContents, "id- cc-str"));
595 assertEquals("billing locality did not match",
596 TEST_BILLING_CITY, DOMUtils.getNodeValue(webContents, "id-cc -city"));
597 assertEquals("billing region did not match",
598 TEST_BILLING_STATE, DOMUtils.getNodeValue(webContents, "id-c c-state"));
599 assertEquals("billing country did not match",
600 TEST_BILLING_COUNTRY, DOMUtils.getNodeValue(webContents, "id -cc-country"));
601
602 if (requestPhoneNumbers) {
603 assertEquals("billing tel did not match",
604 TEST_PHONE_UNFORMATTED,
605 DOMUtils.getNodeValue(webContents, "id-cc-tel"));
606 }
607 }
608
609 if (requestShipping) {
610 assertEquals("shipping name did not match",
611 TEST_SHIPPING_NAME, DOMUtils.getNodeValue(webContents, "id-h -name"));
612 assertEquals("shipping postal-code did not match",
613 TEST_SHIPPING_ZIP, DOMUtils.getNodeValue(webContents, "id-h- zip"));
614 assertEquals("shipping address-line1 did not match",
615 TEST_SHIPPING1, DOMUtils.getNodeValue(webContents, "id-h-1") );
616 assertEquals("shipping address-line2 did not match",
617 TEST_SHIPPING2, DOMUtils.getNodeValue(webContents, "id-h-2") );
618 assertEquals("shipping street-address did not match",
619 TEST_SHIPPING_STREET, DOMUtils.getNodeValue(webContents, "id -h-str"));
620 assertEquals("shipping locality did not match",
621 TEST_SHIPPING_CITY, DOMUtils.getNodeValue(webContents, "id-h -city"));
622 assertEquals("shipping region did not match",
623 TEST_SHIPPING_STATE, DOMUtils.getNodeValue(webContents, "id- h-state"));
624 assertEquals("shipping country did not match",
625 TEST_SHIPPING_COUNTRY,
626 DOMUtils.getNodeValue(webContents, "id-h-country"));
627
628 // It is currently unspecified whether autocomplete="name" gives a S HIPPING or
629 // a BILLING name. I'm assuming here that this is a shipping name.
630 assertEquals("name did not match",
631 TEST_SHIPPING_NAME, DOMUtils.getNodeValue(webContents, "id-n ame"));
632
633 if (requestPhoneNumbers) {
634 assertEquals("shipping tel did not match",
635 TEST_SHIPPING_PHONE_UNFORMATTED,
636 DOMUtils.getNodeValue(webContents, "id-h-tel"));
637
638 // It is currently unspecified whether autocomplete="name" gives a SHIPPING or
639 // a BILLING phone. I'm assuming here that this is a shipping ph one.
640 assertEquals("tel did not match",
641 TEST_SHIPPING_PHONE_UNFORMATTED,
642 DOMUtils.getNodeValue(webContents, "id-tel"));
643 }
644 }
645 }
646
647 // Wait and assert helper methods ------------------------------------------ -------------------
648
649 private void setUpAndRequestAutocomplete(final String url,
650 final boolean requestFullBilling,
651 final boolean requestShipping,
652 final boolean requestPhoneNumbers) throws InterruptedException, Time outException {
653 setUpAndRequestAutocompleteImpl(url,
654 requestFullBilling, requestShipping, requestPhoneNumbers,
655 false);
656 }
657
658 private void setUpAndExpectFailedRequestAutocomplete(final String url,
659 final boolean requestFullBilling,
660 final boolean requestShipping,
661 final boolean requestPhoneNumbers) throws InterruptedException, Time outException {
662 setUpAndRequestAutocompleteImpl(url,
663 requestFullBilling, requestShipping, requestPhoneNumbers,
664 true);
665 }
666
667 private void setUpAndRequestAutocompleteImpl(final String url,
668 final boolean requestFullBilling,
669 final boolean requestShipping,
670 final boolean requestPhoneNumbers,
671 final boolean expectFailure)
672 throws InterruptedException, TimeoutException {
673 startMainActivityWithURL(url);
674
675 final ContentViewCore viewCore = getActivity().getCurrentContentViewCore ();
676 final WebContents webContents = getActivity().getCurrentContentViewCore( ).getWebContents();
677
678 AutofillDialogResult.ResultWallet result = new AutofillDialogResult.Resu ltWallet(
679 TEST_EMAIL, "Google Transaction ID",
680 new AutofillDialogResult.ResultCard(
681 TEST_CC_EXP_MONTH, TEST_CC_EXP_YEAR,
682 TEST_CC_NUMBER, TEST_CC_CSC),
683 new AutofillDialogResult.ResultAddress(
684 TEST_NAME, TEST_PHONE,
685 TEST_BILLING_STREET,
686 TEST_BILLING_CITY, TEST_BILLING_DL, TEST_BILLING_STATE,
687 TEST_BILLING_ZIP, TEST_BILLING_SORTING_CODE, TEST_BILLIN G_COUNTRY,
688 TEST_BILLING_LANGUAGE),
689 new AutofillDialogResult.ResultAddress(
690 TEST_SHIPPING_NAME, TEST_SHIPPING_PHONE,
691 TEST_SHIPPING_STREET,
692 TEST_SHIPPING_CITY, TEST_SHIPPING_DL, TEST_SHIPPING_STAT E,
693 TEST_SHIPPING_ZIP, TEST_SHIPPING_SORTING_CODE, TEST_SHIP PING_COUNTRY,
694 TEST_SHIPPING_LANGUAGE));
695 MockAutofillDialogController.installMockFactory(
696 DIALOG_CALLBACK_DELAY_MILLISECONDS,
697 result,
698 true, "", "", "", "",
699 requestFullBilling, requestShipping, requestPhoneNumbers);
700
701 DOMUtils.clickNode(this, viewCore, "id-button");
702 waitForInputFieldFill(webContents);
703
704 if (!expectFailure) {
705 assertEquals("requestAutocomplete failed",
706 "succeeded",
707 DOMUtils.getNodeContents(webContents, "was-autocompleted"));
708 } else {
709 assertEquals("requestAutocomplete succeeded when it should be failin g",
710 "failed",
711 DOMUtils.getNodeContents(webContents, "was-autocompleted"));
712 }
713 }
714
715 private void waitForInputFieldFill(final WebContents webContents) throws Int erruptedException {
716 CriteriaHelper.pollInstrumentationThread(
717 new Criteria("requestAutocomplete() never completed.") {
718 @Override
719 public boolean isSatisfied() {
720 String wasAutocompleted;
721 try {
722 wasAutocompleted = DOMUtils.getNodeContents(
723 webContents, "was-autocompleted");
724 } catch (InterruptedException e) {
725 return false;
726 } catch (TimeoutException e) {
727 return false;
728 }
729 return TextUtils.equals("succeeded", wasAutocompleted)
730 || TextUtils.equals("failed", wasAutocompleted);
731 }
732 });
733 }
734 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698