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.
5 package org.chromium.chrome.browser.autofill;
7 import android.test.suitebuilder.annotation.MediumTest;
8 import android.test.suitebuilder.annotation.SmallTest;
9 import android.text.TextUtils;
11 import org.chromium.base.CommandLine;
12 import org.chromium.base.test.util.Feature;
13 import org.chromium.base.test.util.UrlUtils;
14 import org.chromium.chrome.shell.ChromeShellTestBase;
15 import org.chromium.content.browser.ContentViewCore;
16 import org.chromium.content.browser.test.util.Criteria;
17 import org.chromium.content.browser.test.util.CriteriaHelper;
18 import org.chromium.content.browser.test.util.DOMUtils;
20 import java.util.concurrent.TimeoutException;
23 * Integration tests for the AutofillPopup.
25 public class AutofillDialogControllerTest extends ChromeShellTestBase {
26 private static final String SWITCH_REDUCE_SECURITY_FOR_TESTING = "reduce-security-for-testing";
27 private static final long DIALOG_CALLBACK_DELAY_MILLISECONDS = 50;
29 private static final String TEST_NAME = "Joe Doe";
30 private static final String TEST_PHONE = "(415)413-0703";
31 private static final String TEST_PHONE_UNFORMATTED = "4154130703";
32 private static final String TEST_EMAIL = "email@server.com";
34 private static final String TEST_CC_NUMBER = "4111111111111111";
35 private static final String TEST_CC_CSC = "123";
36 private static final int TEST_CC_EXP_MONTH = 11;
37 private static final int TEST_CC_EXP_YEAR = 2015;
39 private static final String TEST_BILLING1 = "123 Main street";
40 private static final String TEST_BILLING2 = "apt 456";
41 private static final String TEST_BILLING3 = "leave at the office";
42 private static final String TEST_BILLING_STREET =
43 TEST_BILLING1 + "\n" + TEST_BILLING2 + "\n" + TEST_BILLING3;
44 private static final String TEST_BILLING_CITY = "Schenectady";
45 private static final String TEST_BILLING_DL = ""; // dependent locality
46 private static final String TEST_BILLING_STATE = "NY";
47 private static final String TEST_BILLING_ZIP = "12345";
48 private static final String TEST_BILLING_SORTING_CODE = ""; // sorting code
49 private static final String TEST_BILLING_COUNTRY = "US";
50 private static final String TEST_BILLING_LANGUAGE = ""; // language
52 private static final String TEST_SHIPPING_NAME = "Mister Receiver";
53 private static final String TEST_SHIPPING_PHONE = "+46 8 713 99 99";
54 private static final String TEST_SHIPPING_PHONE_UNFORMATTED = "4687139999";
55 private static final String TEST_SHIPPING1 = "19 Farstaplan";
56 private static final String TEST_SHIPPING2 = "Third floor";
57 private static final String TEST_SHIPPING3 = "please call first";
58 private static final String TEST_SHIPPING_STREET =
59 TEST_SHIPPING1 + "\n" + TEST_SHIPPING2 + "\n" + TEST_SHIPPING3;
60 private static final String TEST_SHIPPING_CITY = "Farsta";
61 private static final String TEST_SHIPPING_DL = ""; // dependent locality
62 private static final String TEST_SHIPPING_STATE = "Stockholm";
63 private static final String TEST_SHIPPING_ZIP = "12346";
64 private static final String TEST_SHIPPING_SORTING_CODE = ""; // sorting code
65 private static final String TEST_SHIPPING_COUNTRY = "SE";
66 private static final String TEST_SHIPPING_LANGUAGE = ""; // language
68 private static final String HTML_PRELUDE = "<html>"
70 + " <meta name=\"viewport\""
71 + " content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0\" />"
74 + "<form id=\"id-form\">"
75 + " <button id=\"id-button\">DO INTERACTIVE AUTOCOMPLETE</button>";
77 private static final String HTML_POSTLUDE = "</form>"
78 + "<div id=\"was-autocompleted\">no</div>"
79 + ":<div id=\"autocomplete-failure-reason\"></div>"
81 + "var form = document.forms[0];"
82 + "form.onsubmit = function(e) {"
83 + " e.preventDefault();"
84 + " form.requestAutocomplete();"
86 + "form.onautocomplete = function() {"
87 + " document.getElementById('was-autocompleted').textContent = 'succeeded';"
89 + "form.onautocompleteerror = function(e) {"
90 + " document.getElementById('was-autocompleted').textContent = 'failed';"
91 + " document.getElementById('autocomplete-failure-reason').textContent = e.reason;"
93 + "</script></body></html>";
95 private static String generatePage(
96 boolean requestFullBilling, boolean requestShipping, boolean requestPhoneNumbers) {
97 StringBuilder sb = new StringBuilder();
98 sb.append(HTML_PRELUDE);
99 sb.append("<fieldset>"
100 + "<input id=\"id-billing-name\" autocomplete=\"billing name\" value=\"W\">"
101 + "<input id=\"id-cc-name\" autocomplete=\"cc-name\" value=\"W\">"
102 + "<input id=\"id-email\" autocomplete=\"email\" type=\"email\" value=\"W@W.W\">"
103 + "<input id=\"id-cc-number\" autocomplete=\"cc-number\" value=\"W\">"
104 + "<input id=\"id-cc-exp\" "
105 + " autocomplete=\"cc-exp\" type=\"month\" value=\"1111-11\">"
106 + "<select id=\"id-cc-exp-month\" autocomplete=\"cc-exp-month\">"
107 + " <option value=\"1\" selected>1</option>"
108 + " <option value=\"2\">2</option>"
109 + " <option value=\"3\">3</option>"
110 + " <option value=\"4\">4</option>"
111 + " <option value=\"5\">5</option>"
112 + " <option value=\"6\">6</option>"
113 + " <option value=\"7\">7</option>"
114 + " <option value=\"8\">8</option>"
115 + " <option value=\"9\">9</option>"
116 + " <option value=\"10\">10</option>"
117 + " <option value=\"11\">11</option>"
118 + " <option value=\"12\">12</option>"
120 + "<select id=\"id-cc-exp-year\" autocomplete=\"cc-exp-year\">"
121 + " <option value=\"2011\" selected>2011</option>"
122 + " <option value=\"2012\">2012</option>"
123 + " <option value=\"2013\">2013</option>"
124 + " <option value=\"2014\">2014</option>"
125 + " <option value=\"2015\">2015</option>"
127 + "<input id=\"id-cc-csc\" autocomplete=\"cc-csc\" value=\"W\">"
128 + "<input id=\"id-cc-zip\" autocomplete=\"billing postal-code\" value=\"W\">");
129 if (requestFullBilling) {
130 sb.append("<input id=\"id-cc-1\" autocomplete=\"billing address-line1\" value=\"W\">"
131 + "<input id=\"id-cc-2\" autocomplete=\"billing address-line2\" value=\"W\">"
132 + "<textarea id=\"id-cc-str\""
133 + " autocomplete=\"billing street-address\">W</textarea>"
134 + "<input id=\"id-cc-city\" autocomplete=\"billing locality\" value=\"W\">"
135 + "<input id=\"id-cc-state\" autocomplete=\"billing region\" value=\"W\">"
136 + "<select id=\"id-cc-country\" autocomplete=\"billing country\">"
137 + " <option value=\"NL\" selected>Netherlands</option>"
138 + " <option value=\"US\">United States</option>"
139 + " <option value=\"SE\">Sweden</option>"
140 + " <option value=\"RU\">Russia</option>"
143 sb.append("</fieldset>");
144 if (requestShipping) {
145 sb.append("<fieldset>"
146 + "<input id=\"id-name\" autocomplete=\"name\" value=\"W\">"
147 + "<input id=\"id-h-name\" autocomplete=\"shipping name\" value=\"W\">"
148 + "<input id=\"id-h-1\" autocomplete=\"shipping address-line1\" value=\"W\">"
149 + "<input id=\"id-h-2\" autocomplete=\"shipping address-line2\" value=\"W\">"
150 + "<textarea id=\"id-h-str\""
151 + " autocomplete=\"shipping street-address\">W</textarea>"
152 + "<input id=\"id-h-city\" autocomplete=\"shipping locality\" value=\"W\">"
153 + "<input id=\"id-h-state\" autocomplete=\"shipping region\" value=\"W\">"
154 + "<input id=\"id-h-zip\" autocomplete=\"shipping postal-code\" value=\"W\">"
155 + "<select id=\"id-h-country\" autocomplete=\"shipping country\">"
156 + " <option value=\"NL\" selected>Netherlands</option>"
157 + " <option value=\"US\">United States</option>"
158 + " <option value=\"SE\">Sweden</option>"
159 + " <option value=\"RU\">Russia</option>"
163 if (requestPhoneNumbers) {
164 sb.append("<fieldset>"
165 + "<input id=\"id-cc-tel\" autocomplete=\"billing tel\" value=\"W\">");
166 if (requestShipping) {
167 sb.append("<input id=\"id-h-tel\" autocomplete=\"shipping tel\" value=\"W\">"
168 + "<input id=\"id-tel\" autocomplete=\"tel\" value=\"W\">");
170 sb.append("</fieldset>");
172 sb.append(HTML_POSTLUDE);
173 return UrlUtils.encodeHtmlDataUri(sb.toString());
177 public void setUp() throws Exception {
180 CommandLine.init(new String[]{});
181 CommandLine.getInstance().appendSwitch(SWITCH_REDUCE_SECURITY_FOR_TESTING);
185 @Feature({"autofill"})
186 public void testFieldsAreFilledMinimal() throws InterruptedException, TimeoutException {
187 final boolean requestFullBilling = false;
188 final boolean requestShipping = false;
189 final boolean requestPhoneNumbers = false;
190 verifyFieldsAreFilled(requestFullBilling, requestShipping, requestPhoneNumbers);
194 @Feature({"autofill"})
195 public void testFieldsAreFilledFullBilling() throws InterruptedException, TimeoutException {
196 final boolean requestFullBilling = true;
197 final boolean requestShipping = false;
198 final boolean requestPhoneNumbers = false;
199 verifyFieldsAreFilled(requestFullBilling, requestShipping, requestPhoneNumbers);
203 @Feature({"autofill"})
204 public void testFieldsAreFilledShipping() throws InterruptedException, TimeoutException {
205 final boolean requestFullBilling = true;
206 final boolean requestShipping = true;
207 final boolean requestPhoneNumbers = false;
208 verifyFieldsAreFilled(requestFullBilling, requestShipping, requestPhoneNumbers);
212 @Feature({"autofill"})
213 public void testFieldsAreFilledBillingPhone() throws InterruptedException, TimeoutException {
214 final boolean requestFullBilling = true;
215 final boolean requestShipping = false;
216 final boolean requestPhoneNumbers = true;
217 verifyFieldsAreFilled(requestFullBilling, requestShipping, requestPhoneNumbers);
221 @Feature({"autofill"})
222 public void testFieldsAreFilledEverything() throws InterruptedException, TimeoutException {
223 final boolean requestFullBilling = true;
224 final boolean requestShipping = true;
225 final boolean requestPhoneNumbers = true;
226 verifyFieldsAreFilled(requestFullBilling, requestShipping, requestPhoneNumbers);
229 // It is currently unspecified whether autocomplete="name" gives a SHIPPING or a BILLING name.
230 // I'm assuming here that this is a shipping name.
232 @Feature({"autofill"})
233 public void testRacTypeName() throws InterruptedException, TimeoutException {
234 verifyOneFieldWithCc(
235 "<input id=\"id\" autocomplete=\"name\">",
236 TEST_SHIPPING_NAME, "id", false, true, false);
240 @Feature({"autofill"})
241 public void testRacTypeBillingName() throws InterruptedException, TimeoutException {
242 verifyOneFieldWithCc(
243 "<input id=\"id\" autocomplete=\"billing name\">",
244 TEST_NAME, "id", false, false, false);
248 @Feature({"autofill"})
249 public void testRacTypeShippingName() throws InterruptedException, TimeoutException {
250 verifyOneFieldWithCc(
251 "<input id=\"id\" autocomplete=\"shipping name\">",
252 TEST_SHIPPING_NAME, "id", false, true, false);
255 // It is currently unspecified whether autocomplete="name" gives a SHIPPING or a BILLING phone.
256 // I'm assuming here that this is a shipping phone.
258 @Feature({"autofill"})
259 public void testRacTypeTel() throws InterruptedException, TimeoutException {
260 verifyOneFieldWithCc(
261 "<input id=\"id\" autocomplete=\"tel\">",
262 TEST_SHIPPING_PHONE_UNFORMATTED, "id", false, true, true);
266 @Feature({"autofill"})
267 public void testRacTypeBillingTel() throws InterruptedException, TimeoutException {
268 verifyOneFieldWithCc(
269 "<input id=\"id\" autocomplete=\"billing tel\">",
270 TEST_PHONE_UNFORMATTED, "id", true, false, true);
274 @Feature({"autofill"})
275 public void testRacTypeShippingTel() throws InterruptedException, TimeoutException {
276 verifyOneFieldWithCc(
277 "<input id=\"id\" autocomplete=\"shipping tel\">",
278 TEST_SHIPPING_PHONE_UNFORMATTED, "id", false, true, true);
282 @Feature({"autofill"})
283 public void testRacTypeEmail() throws InterruptedException, TimeoutException {
284 verifyOneFieldWithCc(
285 "<input id=\"id\" autocomplete=\"email\" type=\"email\">",
286 TEST_EMAIL, "id", false, false, false);
290 @Feature({"autofill"})
291 public void testRacTypeCCName() throws InterruptedException, TimeoutException {
293 "<input id=\"id\" autocomplete=\"cc-name\">",
294 TEST_NAME, "id", false, false, false);
298 @Feature({"autofill"})
299 public void testRacTypeCCNumber() throws InterruptedException, TimeoutException {
301 "<input id=\"id\" autocomplete=\"cc-number\">",
302 TEST_CC_NUMBER, "id", false, false, false);
306 @Feature({"autofill"})
307 public void testRacTypeCCCsc() throws InterruptedException, TimeoutException {
309 "<input id=\"id\" autocomplete=\"cc-csc\">",
310 TEST_CC_CSC, "id", false, false, false);
314 @Feature({"autofill"})
315 public void testRacTypeCCExp() throws InterruptedException, TimeoutException {
317 "<input id=\"id\" autocomplete=\"cc-exp\" type=\"month\" value=\"1111-11\">",
318 "" + TEST_CC_EXP_YEAR + "-" + TEST_CC_EXP_MONTH,
319 "id", false, false, false);
323 @Feature({"autofill"})
324 public void testRacTypeCCExpMonth() throws InterruptedException, TimeoutException {
326 "<select id=\"id\" autocomplete=\"cc-exp-month\">"
327 + " <option value=\"1\" selected>1</option>"
328 + " <option value=\"2\">2</option>"
329 + " <option value=\"3\">3</option>"
330 + " <option value=\"4\">4</option>"
331 + " <option value=\"5\">5</option>"
332 + " <option value=\"6\">6</option>"
333 + " <option value=\"7\">7</option>"
334 + " <option value=\"8\">8</option>"
335 + " <option value=\"9\">9</option>"
336 + " <option value=\"10\">10</option>"
337 + " <option value=\"11\">11</option>"
338 + " <option value=\"12\">12</option>"
340 "" + TEST_CC_EXP_MONTH, "id", false, false, false);
344 @Feature({"autofill"})
345 public void testRacTypeCCExpYear() throws InterruptedException, TimeoutException {
347 "<select id=\"id\" autocomplete=\"cc-exp-year\">"
348 + " <option value=\"2011\" selected>2011</option>"
349 + " <option value=\"2012\">2012</option>"
350 + " <option value=\"2013\">2013</option>"
351 + " <option value=\"2014\">2014</option>"
352 + " <option value=\"2015\">2015</option>"
354 "" + TEST_CC_EXP_YEAR, "id", false, false, false);
358 @Feature({"autofill"})
359 public void testRacTypeBillingCountry() throws InterruptedException, TimeoutException {
360 verifyOneFieldWithCc(
361 "<select id=\"id\" autocomplete=\"billing country\">"
362 + " <option value=\"NL\" selected>Netherlands</option>"
363 + " <option value=\"US\">United States</option>"
364 + " <option value=\"SE\">Sweden</option>"
365 + " <option value=\"RU\">Russia</option>"
367 TEST_BILLING_COUNTRY, "id", true, false, false);
371 @Feature({"autofill"})
372 public void testRacTypeBillingPostalCode() throws InterruptedException, TimeoutException {
373 verifyOneFieldWithCc(
374 "<input id=\"id\" autocomplete=\"billing postal-code\">",
375 TEST_BILLING_ZIP, "id", false, false, false);
379 @Feature({"autofill"})
380 public void testRacTypeBillingAddressLine1() throws InterruptedException, TimeoutException {
381 verifyOneFieldWithCc(
382 "<input id=\"id\" autocomplete=\"billing address-line1\">",
383 TEST_BILLING1, "id", true, false, false);
387 @Feature({"autofill"})
388 public void testRacTypeBillingAddressLine2() throws InterruptedException, TimeoutException {
389 verifyOneFieldWithCc(
390 "<input id=\"id\" autocomplete=\"billing address-line2\">",
391 TEST_BILLING2, "id", true, false, false);
395 @Feature({"autofill"})
396 public void testRacTypeBillingStreetAddress() throws InterruptedException, TimeoutException {
397 verifyOneFieldWithCc(
398 "<textarea id=\"id\" autocomplete=\"billing street-address\"></textarea>",
399 TEST_BILLING_STREET, "id", true, false, false);
403 @Feature({"autofill"})
404 public void testRacTypeBillingLocality() throws InterruptedException, TimeoutException {
405 verifyOneFieldWithCc(
406 "<input id=\"id\" autocomplete=\"billing locality\">",
407 TEST_BILLING_CITY, "id", true, false, false);
411 @Feature({"autofill"})
412 public void testRacTypeBillingRegion() throws InterruptedException, TimeoutException {
413 verifyOneFieldWithCc(
414 "<input id=\"id\" autocomplete=\"billing region\">",
415 TEST_BILLING_STATE, "id", true, false, false);
419 @Feature({"autofill"})
420 public void testRacTypeShippingCountry() throws InterruptedException, TimeoutException {
421 verifyOneFieldWithCc(
422 "<select id=\"id\" autocomplete=\"shipping country\">"
423 + " <option value=\"NL\" selected>Netherlands</option>"
424 + " <option value=\"US\">United States</option>"
425 + " <option value=\"SE\">Sweden</option>"
426 + " <option value=\"RU\">Russia</option>"
428 TEST_SHIPPING_COUNTRY, "id", false, true, false);
432 @Feature({"autofill"})
433 public void testRacTypeShippingPostalCode() throws InterruptedException, TimeoutException {
434 verifyOneFieldWithCc(
435 "<input id=\"id\" autocomplete=\"shipping postal-code\">",
436 TEST_SHIPPING_ZIP, "id", false, true, false);
440 @Feature({"autofill"})
441 public void testRacTypeShippingAddressLine1() throws InterruptedException, TimeoutException {
442 verifyOneFieldWithCc(
443 "<input id=\"id\" autocomplete=\"shipping address-line1\">",
444 TEST_SHIPPING1, "id", false, true, false);
448 @Feature({"autofill"})
449 public void testRacTypeShippingAddressLine2() throws InterruptedException, TimeoutException {
450 verifyOneFieldWithCc(
451 "<input id=\"id\" autocomplete=\"shipping address-line2\">",
452 TEST_SHIPPING2, "id", false, true, false);
456 @Feature({"autofill"})
457 public void testRacTypeShippingStreetAddress() throws InterruptedException, TimeoutException {
458 verifyOneFieldWithCc(
459 "<textarea id=\"id\" autocomplete=\"shipping street-address\"></textarea>",
460 TEST_SHIPPING_STREET, "id", false, true, false);
464 @Feature({"autofill"})
465 public void testRacTypeShippingLocality() throws InterruptedException, TimeoutException {
466 verifyOneFieldWithCc(
467 "<input id=\"id\" autocomplete=\"shipping locality\">",
468 TEST_SHIPPING_CITY, "id", false, true, false);
472 @Feature({"autofill"})
473 public void testRacTypeShippingRegion() throws InterruptedException, TimeoutException {
474 verifyOneFieldWithCc(
475 "<input id=\"id\" autocomplete=\"shipping region\">",
476 TEST_SHIPPING_STATE, "id", false, true, false);
480 @Feature({"autofill"})
481 public void testRefuseToShowWithNoCcField() throws InterruptedException, TimeoutException {
482 String requested = "<input id=\"id\" autocomplete=\"shipping locality\">";
483 setUpAndExpectFailedRequestAutocomplete(
484 UrlUtils.encodeHtmlDataUri(HTML_PRELUDE + requested + HTML_POSTLUDE),
489 @Feature({"autofill"})
490 public void testRefuseToShowWithNoAutocompleteAttributes()
491 throws InterruptedException, TimeoutException {
492 String requested = "<input id=\"id-cc-csc\">"
493 + "<input id=\"id-email\" type=\"email\">"
494 + "<input id=\"id-cc-name\">"
495 + "<input id=\"id-shipping-locality\">";
496 setUpAndExpectFailedRequestAutocomplete(
497 UrlUtils.encodeHtmlDataUri(HTML_PRELUDE + requested + HTML_POSTLUDE),
501 private void verifyOneField(
502 final String htmlFragment,
503 final String expected, final String actualId,
504 final boolean requestFullBilling,
505 final boolean requestShipping, final boolean requestPhoneNumbers)
506 throws InterruptedException, TimeoutException {
507 verifyOneFieldWithOptionalCc(htmlFragment, expected, actualId,
508 requestFullBilling, requestShipping, requestPhoneNumbers, false);
511 private void verifyOneFieldWithCc(
512 final String htmlFragment,
513 final String expected, final String actualId,
514 final boolean requestFullBilling,
515 final boolean requestShipping, final boolean requestPhoneNumbers)
516 throws InterruptedException, TimeoutException {
517 verifyOneFieldWithOptionalCc(htmlFragment, expected, actualId,
518 requestFullBilling, requestShipping, requestPhoneNumbers, true);
521 private void verifyOneFieldWithOptionalCc(
522 final String htmlFragment,
523 final String expected, final String actualId,
524 final boolean requestFullBilling,
525 final boolean requestShipping, final boolean requestPhoneNumbers,
526 final boolean requestCcInfo)
527 throws InterruptedException, TimeoutException {
528 final String optionalCcFragment = requestCcInfo
529 ? "<input id=\"id-opt-cc-csc\" autocomplete=\"cc-csc\">"
531 final String url = UrlUtils.encodeHtmlDataUri(
537 setUpAndRequestAutocomplete(url, requestFullBilling, requestShipping, requestPhoneNumbers);
539 final ContentViewCore viewCore = getActivity().getActiveContentViewCore();
541 assertEquals(actualId + " did not match",
542 expected, DOMUtils.getNodeValue(viewCore, actualId));
544 assertEquals("cc-csc did not match",
545 TEST_CC_CSC, DOMUtils.getNodeValue(viewCore, "id-opt-cc-csc"));
549 private void verifyFieldsAreFilled(final boolean requestFullBilling,
550 final boolean requestShipping, final boolean requestPhoneNumbers)
551 throws InterruptedException, TimeoutException {
552 setUpAndRequestAutocomplete(
553 generatePage(requestFullBilling, requestShipping, requestPhoneNumbers),
554 requestFullBilling, requestShipping, requestPhoneNumbers);
556 final ContentViewCore viewCore = getActivity().getActiveContentViewCore();
558 assertEquals("billing name did not match",
559 TEST_NAME, DOMUtils.getNodeValue(viewCore, "id-billing-name"));
560 assertEquals("email did not match",
561 TEST_EMAIL, DOMUtils.getNodeValue(viewCore, "id-email"));
563 assertEquals("cc-name did not match",
564 TEST_NAME, DOMUtils.getNodeValue(viewCore, "id-cc-name"));
566 assertEquals("cc-number did not match",
567 TEST_CC_NUMBER, DOMUtils.getNodeValue(viewCore, "id-cc-number"));
568 assertEquals("cc-csc did not match",
569 TEST_CC_CSC, DOMUtils.getNodeValue(viewCore, "id-cc-csc"));
571 assertEquals("cc-exp did not match",
572 "" + TEST_CC_EXP_YEAR + "-" + TEST_CC_EXP_MONTH,
573 DOMUtils.getNodeValue(viewCore, "id-cc-exp"));
575 assertEquals("cc-exp-month did not match",
576 "" + TEST_CC_EXP_MONTH,
577 DOMUtils.getNodeValue(viewCore, "id-cc-exp-month"));
578 assertEquals("cc-exp-year did not match",
579 "" + TEST_CC_EXP_YEAR,
580 DOMUtils.getNodeValue(viewCore, "id-cc-exp-year"));
582 assertEquals("billing postal-code did not match",
583 TEST_BILLING_ZIP, DOMUtils.getNodeValue(viewCore, "id-cc-zip"));
585 if (requestFullBilling) {
586 assertEquals("billing address-line1 did not match",
587 TEST_BILLING1, DOMUtils.getNodeValue(viewCore, "id-cc-1"));
588 assertEquals("billing address-line2 did not match",
589 TEST_BILLING2, DOMUtils.getNodeValue(viewCore, "id-cc-2"));
590 assertEquals("billing street-address did not match",
591 TEST_BILLING_STREET, DOMUtils.getNodeValue(viewCore, "id-cc-str"));
592 assertEquals("billing locality did not match",
593 TEST_BILLING_CITY, DOMUtils.getNodeValue(viewCore, "id-cc-city"));
594 assertEquals("billing region did not match",
595 TEST_BILLING_STATE, DOMUtils.getNodeValue(viewCore, "id-cc-state"));
596 assertEquals("billing country did not match",
597 TEST_BILLING_COUNTRY, DOMUtils.getNodeValue(viewCore, "id-cc-country"));
599 if (requestPhoneNumbers) {
600 assertEquals("billing tel did not match",
601 TEST_PHONE_UNFORMATTED,
602 DOMUtils.getNodeValue(viewCore, "id-cc-tel"));
606 if (requestShipping) {
607 assertEquals("shipping name did not match",
608 TEST_SHIPPING_NAME, DOMUtils.getNodeValue(viewCore, "id-h-name"));
609 assertEquals("shipping postal-code did not match",
610 TEST_SHIPPING_ZIP, DOMUtils.getNodeValue(viewCore, "id-h-zip"));
611 assertEquals("shipping address-line1 did not match",
612 TEST_SHIPPING1, DOMUtils.getNodeValue(viewCore, "id-h-1"));
613 assertEquals("shipping address-line2 did not match",
614 TEST_SHIPPING2, DOMUtils.getNodeValue(viewCore, "id-h-2"));
615 assertEquals("shipping street-address did not match",
616 TEST_SHIPPING_STREET, DOMUtils.getNodeValue(viewCore, "id-h-str"));
617 assertEquals("shipping locality did not match",
618 TEST_SHIPPING_CITY, DOMUtils.getNodeValue(viewCore, "id-h-city"));
619 assertEquals("shipping region did not match",
620 TEST_SHIPPING_STATE, DOMUtils.getNodeValue(viewCore, "id-h-state"));
621 assertEquals("shipping country did not match",
622 TEST_SHIPPING_COUNTRY,
623 DOMUtils.getNodeValue(viewCore, "id-h-country"));
625 // It is currently unspecified whether autocomplete="name" gives a SHIPPING or
626 // a BILLING name. I'm assuming here that this is a shipping name.
627 assertEquals("name did not match",
628 TEST_SHIPPING_NAME, DOMUtils.getNodeValue(viewCore, "id-name"));
630 if (requestPhoneNumbers) {
631 assertEquals("shipping tel did not match",
632 TEST_SHIPPING_PHONE_UNFORMATTED,
633 DOMUtils.getNodeValue(viewCore, "id-h-tel"));
635 // It is currently unspecified whether autocomplete="name" gives a SHIPPING or
636 // a BILLING phone. I'm assuming here that this is a shipping phone.
637 assertEquals("tel did not match",
638 TEST_SHIPPING_PHONE_UNFORMATTED,
639 DOMUtils.getNodeValue(viewCore, "id-tel"));
644 // Wait and assert helper methods -------------------------------------------------------------
646 private void setUpAndRequestAutocomplete(final String url,
647 final boolean requestFullBilling,
648 final boolean requestShipping,
649 final boolean requestPhoneNumbers) throws InterruptedException, TimeoutException {
650 setUpAndRequestAutocompleteImpl(url,
651 requestFullBilling, requestShipping, requestPhoneNumbers,
655 private void setUpAndExpectFailedRequestAutocomplete(final String url,
656 final boolean requestFullBilling,
657 final boolean requestShipping,
658 final boolean requestPhoneNumbers) throws InterruptedException, TimeoutException {
659 setUpAndRequestAutocompleteImpl(url,
660 requestFullBilling, requestShipping, requestPhoneNumbers,
664 private void setUpAndRequestAutocompleteImpl(final String url,
665 final boolean requestFullBilling,
666 final boolean requestShipping,
667 final boolean requestPhoneNumbers,
668 final boolean expectFailure)
669 throws InterruptedException, TimeoutException {
670 launchChromeShellWithUrl(url);
671 assertTrue(waitForActiveShellToBeDoneLoading());
673 final ContentViewCore viewCore = getActivity().getActiveContentViewCore();
675 AutofillDialogResult.ResultWallet result = new AutofillDialogResult.ResultWallet(
676 TEST_EMAIL, "Google Transaction ID",
677 new AutofillDialogResult.ResultCard(
678 TEST_CC_EXP_MONTH, TEST_CC_EXP_YEAR,
679 TEST_CC_NUMBER, TEST_CC_CSC),
680 new AutofillDialogResult.ResultAddress(
681 TEST_NAME, TEST_PHONE,
683 TEST_BILLING_CITY, TEST_BILLING_DL, TEST_BILLING_STATE,
684 TEST_BILLING_ZIP, TEST_BILLING_SORTING_CODE, TEST_BILLING_COUNTRY,
685 TEST_BILLING_LANGUAGE),
686 new AutofillDialogResult.ResultAddress(
687 TEST_SHIPPING_NAME, TEST_SHIPPING_PHONE,
688 TEST_SHIPPING_STREET,
689 TEST_SHIPPING_CITY, TEST_SHIPPING_DL, TEST_SHIPPING_STATE,
690 TEST_SHIPPING_ZIP, TEST_SHIPPING_SORTING_CODE, TEST_SHIPPING_COUNTRY,
691 TEST_SHIPPING_LANGUAGE));
692 MockAutofillDialogController.installMockFactory(
693 DIALOG_CALLBACK_DELAY_MILLISECONDS,
695 true, "", "", "", "",
696 requestFullBilling, requestShipping, requestPhoneNumbers);
698 DOMUtils.clickNode(this, viewCore, "id-button");
699 waitForInputFieldFill(viewCore);
701 if (!expectFailure) {
702 assertEquals("requestAutocomplete failed",
704 DOMUtils.getNodeContents(viewCore, "was-autocompleted"));
706 assertEquals("requestAutocomplete succeeded when it should be failing",
708 DOMUtils.getNodeContents(viewCore, "was-autocompleted"));
712 private void waitForInputFieldFill(final ContentViewCore viewCore) throws InterruptedException {
713 assertTrue("requestAutocomplete() never completed.",
714 CriteriaHelper.pollForCriteria(new Criteria() {
716 public boolean isSatisfied() {
717 String wasAutocompleted;
719 wasAutocompleted = DOMUtils.getNodeContents(
720 viewCore, "was-autocompleted");
721 } catch (InterruptedException e) {
723 } catch (TimeoutException e) {
726 return TextUtils.equals("succeeded", wasAutocompleted)
727 || TextUtils.equals("failed", wasAutocompleted);