OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.autofill; | 5 package org.chromium.chrome.browser.autofill; |
6 | 6 |
7 import android.test.suitebuilder.annotation.MediumTest; | 7 import android.test.suitebuilder.annotation.MediumTest; |
8 import android.test.suitebuilder.annotation.SmallTest; | 8 import android.test.suitebuilder.annotation.SmallTest; |
9 import android.text.TextUtils; | 9 import android.text.TextUtils; |
10 | 10 |
11 import org.chromium.base.CommandLine; | 11 import org.chromium.base.CommandLine; |
12 import org.chromium.base.test.util.Feature; | 12 import org.chromium.base.test.util.Feature; |
13 import org.chromium.base.test.util.UrlUtils; | 13 import org.chromium.base.test.util.UrlUtils; |
14 import org.chromium.chrome.shell.ChromeShellTestBase; | 14 import org.chromium.chrome.shell.ChromeShellTestBase; |
15 import org.chromium.content.browser.ContentViewCore; | 15 import org.chromium.content.browser.ContentViewCore; |
16 import org.chromium.content.browser.test.util.Criteria; | 16 import org.chromium.content.browser.test.util.Criteria; |
17 import org.chromium.content.browser.test.util.CriteriaHelper; | 17 import org.chromium.content.browser.test.util.CriteriaHelper; |
18 import org.chromium.content.browser.test.util.DOMUtils; | 18 import org.chromium.content.browser.test.util.DOMUtils; |
| 19 import org.chromium.content_public.browser.WebContents; |
19 | 20 |
20 import java.util.concurrent.TimeoutException; | 21 import java.util.concurrent.TimeoutException; |
21 | 22 |
22 /** | 23 /** |
23 * Integration tests for the AutofillPopup. | 24 * Integration tests for the AutofillPopup. |
24 */ | 25 */ |
25 public class AutofillDialogControllerTest extends ChromeShellTestBase { | 26 public class AutofillDialogControllerTest extends ChromeShellTestBase { |
26 private static final String SWITCH_REDUCE_SECURITY_FOR_TESTING = "reduce-sec
urity-for-testing"; | 27 private static final String SWITCH_REDUCE_SECURITY_FOR_TESTING = "reduce-sec
urity-for-testing"; |
27 private static final long DIALOG_CALLBACK_DELAY_MILLISECONDS = 50; | 28 private static final long DIALOG_CALLBACK_DELAY_MILLISECONDS = 50; |
28 | 29 |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 ? "<input id=\"id-opt-cc-csc\" autocomplete=\"cc-csc\">" | 530 ? "<input id=\"id-opt-cc-csc\" autocomplete=\"cc-csc\">" |
530 : ""; | 531 : ""; |
531 final String url = UrlUtils.encodeHtmlDataUri( | 532 final String url = UrlUtils.encodeHtmlDataUri( |
532 HTML_PRELUDE | 533 HTML_PRELUDE |
533 + htmlFragment | 534 + htmlFragment |
534 + optionalCcFragment | 535 + optionalCcFragment |
535 + HTML_POSTLUDE); | 536 + HTML_POSTLUDE); |
536 | 537 |
537 setUpAndRequestAutocomplete(url, requestFullBilling, requestShipping, re
questPhoneNumbers); | 538 setUpAndRequestAutocomplete(url, requestFullBilling, requestShipping, re
questPhoneNumbers); |
538 | 539 |
539 final ContentViewCore viewCore = getActivity().getActiveContentViewCore(
); | 540 final WebContents webContents = getActivity().getActiveContentViewCore()
.getWebContents(); |
540 | 541 |
541 assertEquals(actualId + " did not match", | 542 assertEquals(actualId + " did not match", |
542 expected, DOMUtils.getNodeValue(viewCore, actualId)); | 543 expected, DOMUtils.getNodeValue(webContents, actualId)); |
543 if (requestCcInfo) { | 544 if (requestCcInfo) { |
544 assertEquals("cc-csc did not match", | 545 assertEquals("cc-csc did not match", |
545 TEST_CC_CSC, DOMUtils.getNodeValue(viewCore, "id-opt-cc-csc"
)); | 546 TEST_CC_CSC, DOMUtils.getNodeValue(webContents, "id-opt-cc-c
sc")); |
546 } | 547 } |
547 } | 548 } |
548 | 549 |
549 private void verifyFieldsAreFilled(final boolean requestFullBilling, | 550 private void verifyFieldsAreFilled(final boolean requestFullBilling, |
550 final boolean requestShipping, final boolean requestPhoneNumbers) | 551 final boolean requestShipping, final boolean requestPhoneNumbers) |
551 throws InterruptedException, TimeoutException { | 552 throws InterruptedException, TimeoutException { |
552 setUpAndRequestAutocomplete( | 553 setUpAndRequestAutocomplete( |
553 generatePage(requestFullBilling, requestShipping, requestPhoneNu
mbers), | 554 generatePage(requestFullBilling, requestShipping, requestPhoneNu
mbers), |
554 requestFullBilling, requestShipping, requestPhoneNumbers); | 555 requestFullBilling, requestShipping, requestPhoneNumbers); |
555 | 556 |
556 final ContentViewCore viewCore = getActivity().getActiveContentViewCore(
); | 557 final WebContents webContents = getActivity().getActiveContentViewCore()
.getWebContents(); |
557 | 558 |
558 assertEquals("billing name did not match", | 559 assertEquals("billing name did not match", |
559 TEST_NAME, DOMUtils.getNodeValue(viewCore, "id-billing-name")); | 560 TEST_NAME, DOMUtils.getNodeValue(webContents, "id-billing-name")
); |
560 assertEquals("email did not match", | 561 assertEquals("email did not match", |
561 TEST_EMAIL, DOMUtils.getNodeValue(viewCore, "id-email")); | 562 TEST_EMAIL, DOMUtils.getNodeValue(webContents, "id-email")); |
562 | 563 |
563 assertEquals("cc-name did not match", | 564 assertEquals("cc-name did not match", |
564 TEST_NAME, DOMUtils.getNodeValue(viewCore, "id-cc-name")); | 565 TEST_NAME, DOMUtils.getNodeValue(webContents, "id-cc-name")); |
565 | 566 |
566 assertEquals("cc-number did not match", | 567 assertEquals("cc-number did not match", |
567 TEST_CC_NUMBER, DOMUtils.getNodeValue(viewCore, "id-cc-number"))
; | 568 TEST_CC_NUMBER, DOMUtils.getNodeValue(webContents, "id-cc-number
")); |
568 assertEquals("cc-csc did not match", | 569 assertEquals("cc-csc did not match", |
569 TEST_CC_CSC, DOMUtils.getNodeValue(viewCore, "id-cc-csc")); | 570 TEST_CC_CSC, DOMUtils.getNodeValue(webContents, "id-cc-csc")); |
570 | 571 |
571 assertEquals("cc-exp did not match", | 572 assertEquals("cc-exp did not match", |
572 "" + TEST_CC_EXP_YEAR + "-" + TEST_CC_EXP_MONTH, | 573 "" + TEST_CC_EXP_YEAR + "-" + TEST_CC_EXP_MONTH, |
573 DOMUtils.getNodeValue(viewCore, "id-cc-exp")); | 574 DOMUtils.getNodeValue(webContents, "id-cc-exp")); |
574 | 575 |
575 assertEquals("cc-exp-month did not match", | 576 assertEquals("cc-exp-month did not match", |
576 "" + TEST_CC_EXP_MONTH, | 577 "" + TEST_CC_EXP_MONTH, |
577 DOMUtils.getNodeValue(viewCore, "id-cc-exp-month")); | 578 DOMUtils.getNodeValue(webContents, "id-cc-exp-month")); |
578 assertEquals("cc-exp-year did not match", | 579 assertEquals("cc-exp-year did not match", |
579 "" + TEST_CC_EXP_YEAR, | 580 "" + TEST_CC_EXP_YEAR, |
580 DOMUtils.getNodeValue(viewCore, "id-cc-exp-year")); | 581 DOMUtils.getNodeValue(webContents, "id-cc-exp-year")); |
581 | 582 |
582 assertEquals("billing postal-code did not match", | 583 assertEquals("billing postal-code did not match", |
583 TEST_BILLING_ZIP, DOMUtils.getNodeValue(viewCore, "id-cc-zip")); | 584 TEST_BILLING_ZIP, DOMUtils.getNodeValue(webContents, "id-cc-zip"
)); |
584 | 585 |
585 if (requestFullBilling) { | 586 if (requestFullBilling) { |
586 assertEquals("billing address-line1 did not match", | 587 assertEquals("billing address-line1 did not match", |
587 TEST_BILLING1, DOMUtils.getNodeValue(viewCore, "id-cc-1")); | 588 TEST_BILLING1, DOMUtils.getNodeValue(webContents, "id-cc-1")
); |
588 assertEquals("billing address-line2 did not match", | 589 assertEquals("billing address-line2 did not match", |
589 TEST_BILLING2, DOMUtils.getNodeValue(viewCore, "id-cc-2")); | 590 TEST_BILLING2, DOMUtils.getNodeValue(webContents, "id-cc-2")
); |
590 assertEquals("billing street-address did not match", | 591 assertEquals("billing street-address did not match", |
591 TEST_BILLING_STREET, DOMUtils.getNodeValue(viewCore, "id-cc-
str")); | 592 TEST_BILLING_STREET, DOMUtils.getNodeValue(webContents, "id-
cc-str")); |
592 assertEquals("billing locality did not match", | 593 assertEquals("billing locality did not match", |
593 TEST_BILLING_CITY, DOMUtils.getNodeValue(viewCore, "id-cc-ci
ty")); | 594 TEST_BILLING_CITY, DOMUtils.getNodeValue(webContents, "id-cc
-city")); |
594 assertEquals("billing region did not match", | 595 assertEquals("billing region did not match", |
595 TEST_BILLING_STATE, DOMUtils.getNodeValue(viewCore, "id-cc-s
tate")); | 596 TEST_BILLING_STATE, DOMUtils.getNodeValue(webContents, "id-c
c-state")); |
596 assertEquals("billing country did not match", | 597 assertEquals("billing country did not match", |
597 TEST_BILLING_COUNTRY, DOMUtils.getNodeValue(viewCore, "id-cc
-country")); | 598 TEST_BILLING_COUNTRY, DOMUtils.getNodeValue(webContents, "id
-cc-country")); |
598 | 599 |
599 if (requestPhoneNumbers) { | 600 if (requestPhoneNumbers) { |
600 assertEquals("billing tel did not match", | 601 assertEquals("billing tel did not match", |
601 TEST_PHONE_UNFORMATTED, | 602 TEST_PHONE_UNFORMATTED, |
602 DOMUtils.getNodeValue(viewCore, "id-cc-tel")); | 603 DOMUtils.getNodeValue(webContents, "id-cc-tel")); |
603 } | 604 } |
604 } | 605 } |
605 | 606 |
606 if (requestShipping) { | 607 if (requestShipping) { |
607 assertEquals("shipping name did not match", | 608 assertEquals("shipping name did not match", |
608 TEST_SHIPPING_NAME, DOMUtils.getNodeValue(viewCore, "id-h-na
me")); | 609 TEST_SHIPPING_NAME, DOMUtils.getNodeValue(webContents, "id-h
-name")); |
609 assertEquals("shipping postal-code did not match", | 610 assertEquals("shipping postal-code did not match", |
610 TEST_SHIPPING_ZIP, DOMUtils.getNodeValue(viewCore, "id-h-zip
")); | 611 TEST_SHIPPING_ZIP, DOMUtils.getNodeValue(webContents, "id-h-
zip")); |
611 assertEquals("shipping address-line1 did not match", | 612 assertEquals("shipping address-line1 did not match", |
612 TEST_SHIPPING1, DOMUtils.getNodeValue(viewCore, "id-h-1")); | 613 TEST_SHIPPING1, DOMUtils.getNodeValue(webContents, "id-h-1")
); |
613 assertEquals("shipping address-line2 did not match", | 614 assertEquals("shipping address-line2 did not match", |
614 TEST_SHIPPING2, DOMUtils.getNodeValue(viewCore, "id-h-2")); | 615 TEST_SHIPPING2, DOMUtils.getNodeValue(webContents, "id-h-2")
); |
615 assertEquals("shipping street-address did not match", | 616 assertEquals("shipping street-address did not match", |
616 TEST_SHIPPING_STREET, DOMUtils.getNodeValue(viewCore, "id-h-
str")); | 617 TEST_SHIPPING_STREET, DOMUtils.getNodeValue(webContents, "id
-h-str")); |
617 assertEquals("shipping locality did not match", | 618 assertEquals("shipping locality did not match", |
618 TEST_SHIPPING_CITY, DOMUtils.getNodeValue(viewCore, "id-h-ci
ty")); | 619 TEST_SHIPPING_CITY, DOMUtils.getNodeValue(webContents, "id-h
-city")); |
619 assertEquals("shipping region did not match", | 620 assertEquals("shipping region did not match", |
620 TEST_SHIPPING_STATE, DOMUtils.getNodeValue(viewCore, "id-h-s
tate")); | 621 TEST_SHIPPING_STATE, DOMUtils.getNodeValue(webContents, "id-
h-state")); |
621 assertEquals("shipping country did not match", | 622 assertEquals("shipping country did not match", |
622 TEST_SHIPPING_COUNTRY, | 623 TEST_SHIPPING_COUNTRY, |
623 DOMUtils.getNodeValue(viewCore, "id-h-country")); | 624 DOMUtils.getNodeValue(webContents, "id-h-country")); |
624 | 625 |
625 // It is currently unspecified whether autocomplete="name" gives a S
HIPPING or | 626 // It is currently unspecified whether autocomplete="name" gives a S
HIPPING or |
626 // a BILLING name. I'm assuming here that this is a shipping name. | 627 // a BILLING name. I'm assuming here that this is a shipping name. |
627 assertEquals("name did not match", | 628 assertEquals("name did not match", |
628 TEST_SHIPPING_NAME, DOMUtils.getNodeValue(viewCore, "id-name
")); | 629 TEST_SHIPPING_NAME, DOMUtils.getNodeValue(webContents, "id-n
ame")); |
629 | 630 |
630 if (requestPhoneNumbers) { | 631 if (requestPhoneNumbers) { |
631 assertEquals("shipping tel did not match", | 632 assertEquals("shipping tel did not match", |
632 TEST_SHIPPING_PHONE_UNFORMATTED, | 633 TEST_SHIPPING_PHONE_UNFORMATTED, |
633 DOMUtils.getNodeValue(viewCore, "id-h-tel")); | 634 DOMUtils.getNodeValue(webContents, "id-h-tel")); |
634 | 635 |
635 // It is currently unspecified whether autocomplete="name" gives
a SHIPPING or | 636 // It is currently unspecified whether autocomplete="name" gives
a SHIPPING or |
636 // a BILLING phone. I'm assuming here that this is a shipping ph
one. | 637 // a BILLING phone. I'm assuming here that this is a shipping ph
one. |
637 assertEquals("tel did not match", | 638 assertEquals("tel did not match", |
638 TEST_SHIPPING_PHONE_UNFORMATTED, | 639 TEST_SHIPPING_PHONE_UNFORMATTED, |
639 DOMUtils.getNodeValue(viewCore, "id-tel")); | 640 DOMUtils.getNodeValue(webContents, "id-tel")); |
640 } | 641 } |
641 } | 642 } |
642 } | 643 } |
643 | 644 |
644 // Wait and assert helper methods ------------------------------------------
------------------- | 645 // Wait and assert helper methods ------------------------------------------
------------------- |
645 | 646 |
646 private void setUpAndRequestAutocomplete(final String url, | 647 private void setUpAndRequestAutocomplete(final String url, |
647 final boolean requestFullBilling, | 648 final boolean requestFullBilling, |
648 final boolean requestShipping, | 649 final boolean requestShipping, |
649 final boolean requestPhoneNumbers) throws InterruptedException, Time
outException { | 650 final boolean requestPhoneNumbers) throws InterruptedException, Time
outException { |
(...skipping 14 matching lines...) Expand all Loading... |
664 private void setUpAndRequestAutocompleteImpl(final String url, | 665 private void setUpAndRequestAutocompleteImpl(final String url, |
665 final boolean requestFullBilling, | 666 final boolean requestFullBilling, |
666 final boolean requestShipping, | 667 final boolean requestShipping, |
667 final boolean requestPhoneNumbers, | 668 final boolean requestPhoneNumbers, |
668 final boolean expectFailure) | 669 final boolean expectFailure) |
669 throws InterruptedException, TimeoutException { | 670 throws InterruptedException, TimeoutException { |
670 launchChromeShellWithUrl(url); | 671 launchChromeShellWithUrl(url); |
671 assertTrue(waitForActiveShellToBeDoneLoading()); | 672 assertTrue(waitForActiveShellToBeDoneLoading()); |
672 | 673 |
673 final ContentViewCore viewCore = getActivity().getActiveContentViewCore(
); | 674 final ContentViewCore viewCore = getActivity().getActiveContentViewCore(
); |
| 675 final WebContents webContents = getActivity().getActiveContentViewCore()
.getWebContents(); |
674 | 676 |
675 AutofillDialogResult.ResultWallet result = new AutofillDialogResult.Resu
ltWallet( | 677 AutofillDialogResult.ResultWallet result = new AutofillDialogResult.Resu
ltWallet( |
676 TEST_EMAIL, "Google Transaction ID", | 678 TEST_EMAIL, "Google Transaction ID", |
677 new AutofillDialogResult.ResultCard( | 679 new AutofillDialogResult.ResultCard( |
678 TEST_CC_EXP_MONTH, TEST_CC_EXP_YEAR, | 680 TEST_CC_EXP_MONTH, TEST_CC_EXP_YEAR, |
679 TEST_CC_NUMBER, TEST_CC_CSC), | 681 TEST_CC_NUMBER, TEST_CC_CSC), |
680 new AutofillDialogResult.ResultAddress( | 682 new AutofillDialogResult.ResultAddress( |
681 TEST_NAME, TEST_PHONE, | 683 TEST_NAME, TEST_PHONE, |
682 TEST_BILLING_STREET, | 684 TEST_BILLING_STREET, |
683 TEST_BILLING_CITY, TEST_BILLING_DL, TEST_BILLING_STATE, | 685 TEST_BILLING_CITY, TEST_BILLING_DL, TEST_BILLING_STATE, |
684 TEST_BILLING_ZIP, TEST_BILLING_SORTING_CODE, TEST_BILLIN
G_COUNTRY, | 686 TEST_BILLING_ZIP, TEST_BILLING_SORTING_CODE, TEST_BILLIN
G_COUNTRY, |
685 TEST_BILLING_LANGUAGE), | 687 TEST_BILLING_LANGUAGE), |
686 new AutofillDialogResult.ResultAddress( | 688 new AutofillDialogResult.ResultAddress( |
687 TEST_SHIPPING_NAME, TEST_SHIPPING_PHONE, | 689 TEST_SHIPPING_NAME, TEST_SHIPPING_PHONE, |
688 TEST_SHIPPING_STREET, | 690 TEST_SHIPPING_STREET, |
689 TEST_SHIPPING_CITY, TEST_SHIPPING_DL, TEST_SHIPPING_STAT
E, | 691 TEST_SHIPPING_CITY, TEST_SHIPPING_DL, TEST_SHIPPING_STAT
E, |
690 TEST_SHIPPING_ZIP, TEST_SHIPPING_SORTING_CODE, TEST_SHIP
PING_COUNTRY, | 692 TEST_SHIPPING_ZIP, TEST_SHIPPING_SORTING_CODE, TEST_SHIP
PING_COUNTRY, |
691 TEST_SHIPPING_LANGUAGE)); | 693 TEST_SHIPPING_LANGUAGE)); |
692 MockAutofillDialogController.installMockFactory( | 694 MockAutofillDialogController.installMockFactory( |
693 DIALOG_CALLBACK_DELAY_MILLISECONDS, | 695 DIALOG_CALLBACK_DELAY_MILLISECONDS, |
694 result, | 696 result, |
695 true, "", "", "", "", | 697 true, "", "", "", "", |
696 requestFullBilling, requestShipping, requestPhoneNumbers); | 698 requestFullBilling, requestShipping, requestPhoneNumbers); |
697 | 699 |
698 DOMUtils.clickNode(this, viewCore, "id-button"); | 700 DOMUtils.clickNode(this, viewCore, "id-button"); |
699 waitForInputFieldFill(viewCore); | 701 waitForInputFieldFill(webContents); |
700 | 702 |
701 if (!expectFailure) { | 703 if (!expectFailure) { |
702 assertEquals("requestAutocomplete failed", | 704 assertEquals("requestAutocomplete failed", |
703 "succeeded", | 705 "succeeded", |
704 DOMUtils.getNodeContents(viewCore, "was-autocompleted")); | 706 DOMUtils.getNodeContents(webContents, "was-autocompleted")); |
705 } else { | 707 } else { |
706 assertEquals("requestAutocomplete succeeded when it should be failin
g", | 708 assertEquals("requestAutocomplete succeeded when it should be failin
g", |
707 "failed", | 709 "failed", |
708 DOMUtils.getNodeContents(viewCore, "was-autocompleted")); | 710 DOMUtils.getNodeContents(webContents, "was-autocompleted")); |
709 } | 711 } |
710 } | 712 } |
711 | 713 |
712 private void waitForInputFieldFill(final ContentViewCore viewCore) throws In
terruptedException { | 714 private void waitForInputFieldFill(final WebContents webContents) throws Int
erruptedException { |
713 assertTrue("requestAutocomplete() never completed.", | 715 assertTrue("requestAutocomplete() never completed.", |
714 CriteriaHelper.pollForCriteria(new Criteria() { | 716 CriteriaHelper.pollForCriteria(new Criteria() { |
715 @Override | 717 @Override |
716 public boolean isSatisfied() { | 718 public boolean isSatisfied() { |
717 String wasAutocompleted; | 719 String wasAutocompleted; |
718 try { | 720 try { |
719 wasAutocompleted = DOMUtils.getNodeContents( | 721 wasAutocompleted = DOMUtils.getNodeContents( |
720 viewCore, "was-autocompleted"); | 722 webContents, "was-autocompleted"); |
721 } catch (InterruptedException e) { | 723 } catch (InterruptedException e) { |
722 return false; | 724 return false; |
723 } catch (TimeoutException e) { | 725 } catch (TimeoutException e) { |
724 return false; | 726 return false; |
725 } | 727 } |
726 return TextUtils.equals("succeeded", wasAutocompleted) | 728 return TextUtils.equals("succeeded", wasAutocompleted) |
727 || TextUtils.equals("failed", wasAutocompleted); | 729 || TextUtils.equals("failed", wasAutocompleted); |
728 } | 730 } |
729 })); | 731 })); |
730 } | 732 } |
731 } | 733 } |
OLD | NEW |