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.test.util.CommandLineFlags; |
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.browser.ChromeActivity; |
| 15 import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
15 import org.chromium.content.browser.ContentViewCore; | 16 import org.chromium.content.browser.ContentViewCore; |
16 import org.chromium.content.browser.test.util.Criteria; | 17 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.CriteriaHelper; |
18 import org.chromium.content.browser.test.util.DOMUtils; | 19 import org.chromium.content.browser.test.util.DOMUtils; |
19 import org.chromium.content_public.browser.WebContents; | 20 import org.chromium.content_public.browser.WebContents; |
20 | 21 |
21 import java.util.concurrent.TimeoutException; | 22 import java.util.concurrent.TimeoutException; |
22 | 23 |
23 /** | 24 /** |
24 * Integration tests for the AutofillPopup. | 25 * Integration tests for the AutofillPopup. |
25 */ | 26 */ |
26 public class AutofillDialogControllerTest extends ChromeShellTestBase { | 27 @CommandLineFlags.Add("reduce-security-for-testing") |
27 private static final String SWITCH_REDUCE_SECURITY_FOR_TESTING = "reduce-sec
urity-for-testing"; | 28 public class AutofillDialogControllerTest extends ChromeActivityTestCaseBase<Chr
omeActivity> { |
28 private static final long DIALOG_CALLBACK_DELAY_MILLISECONDS = 50; | 29 private static final long DIALOG_CALLBACK_DELAY_MILLISECONDS = 50; |
29 | 30 |
30 private static final String TEST_NAME = "Joe Doe"; | 31 private static final String TEST_NAME = "Joe Doe"; |
31 private static final String TEST_PHONE = "(415)413-0703"; | 32 private static final String TEST_PHONE = "(415)413-0703"; |
32 private static final String TEST_PHONE_UNFORMATTED = "4154130703"; | 33 private static final String TEST_PHONE_UNFORMATTED = "4154130703"; |
33 private static final String TEST_EMAIL = "email@server.com"; | 34 private static final String TEST_EMAIL = "email@server.com"; |
34 | 35 |
35 private static final String TEST_CC_NUMBER = "4111111111111111"; | 36 private static final String TEST_CC_NUMBER = "4111111111111111"; |
36 private static final String TEST_CC_CSC = "123"; | 37 private static final String TEST_CC_CSC = "123"; |
37 private static final int TEST_CC_EXP_MONTH = 11; | 38 private static final int TEST_CC_EXP_MONTH = 11; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 if (requestShipping) { | 168 if (requestShipping) { |
168 sb.append("<input id=\"id-h-tel\" autocomplete=\"shipping tel\"
value=\"W\">" | 169 sb.append("<input id=\"id-h-tel\" autocomplete=\"shipping tel\"
value=\"W\">" |
169 + "<input id=\"id-tel\" autocomplete=\"tel\" value=\"W\"
>"); | 170 + "<input id=\"id-tel\" autocomplete=\"tel\" value=\"W\"
>"); |
170 } | 171 } |
171 sb.append("</fieldset>"); | 172 sb.append("</fieldset>"); |
172 } | 173 } |
173 sb.append(HTML_POSTLUDE); | 174 sb.append(HTML_POSTLUDE); |
174 return UrlUtils.encodeHtmlDataUri(sb.toString()); | 175 return UrlUtils.encodeHtmlDataUri(sb.toString()); |
175 } | 176 } |
176 | 177 |
| 178 public AutofillDialogControllerTest() { |
| 179 super(ChromeActivity.class); |
| 180 } |
| 181 |
177 @Override | 182 @Override |
178 public void setUp() throws Exception { | 183 public void startMainActivity() throws InterruptedException { |
179 super.setUp(); | 184 // Don't launch activity automatically. |
180 clearAppData(); | |
181 CommandLine.init(new String[]{}); | |
182 CommandLine.getInstance().appendSwitch(SWITCH_REDUCE_SECURITY_FOR_TESTIN
G); | |
183 } | 185 } |
184 | 186 |
185 @MediumTest | 187 @MediumTest |
186 @Feature({"autofill"}) | 188 @Feature({"autofill"}) |
187 public void testFieldsAreFilledMinimal() throws InterruptedException, Timeou
tException { | 189 public void testFieldsAreFilledMinimal() throws InterruptedException, Timeou
tException { |
188 final boolean requestFullBilling = false; | 190 final boolean requestFullBilling = false; |
189 final boolean requestShipping = false; | 191 final boolean requestShipping = false; |
190 final boolean requestPhoneNumbers = false; | 192 final boolean requestPhoneNumbers = false; |
191 verifyFieldsAreFilled(requestFullBilling, requestShipping, requestPhoneN
umbers); | 193 verifyFieldsAreFilled(requestFullBilling, requestShipping, requestPhoneN
umbers); |
192 } | 194 } |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 ? "<input id=\"id-opt-cc-csc\" autocomplete=\"cc-csc\">" | 532 ? "<input id=\"id-opt-cc-csc\" autocomplete=\"cc-csc\">" |
531 : ""; | 533 : ""; |
532 final String url = UrlUtils.encodeHtmlDataUri( | 534 final String url = UrlUtils.encodeHtmlDataUri( |
533 HTML_PRELUDE | 535 HTML_PRELUDE |
534 + htmlFragment | 536 + htmlFragment |
535 + optionalCcFragment | 537 + optionalCcFragment |
536 + HTML_POSTLUDE); | 538 + HTML_POSTLUDE); |
537 | 539 |
538 setUpAndRequestAutocomplete(url, requestFullBilling, requestShipping, re
questPhoneNumbers); | 540 setUpAndRequestAutocomplete(url, requestFullBilling, requestShipping, re
questPhoneNumbers); |
539 | 541 |
540 final WebContents webContents = getActivity().getActiveContentViewCore()
.getWebContents(); | 542 final WebContents webContents = getActivity().getCurrentContentViewCore(
).getWebContents(); |
541 | 543 |
542 assertEquals(actualId + " did not match", | 544 assertEquals(actualId + " did not match", |
543 expected, DOMUtils.getNodeValue(webContents, actualId)); | 545 expected, DOMUtils.getNodeValue(webContents, actualId)); |
544 if (requestCcInfo) { | 546 if (requestCcInfo) { |
545 assertEquals("cc-csc did not match", | 547 assertEquals("cc-csc did not match", |
546 TEST_CC_CSC, DOMUtils.getNodeValue(webContents, "id-opt-cc-c
sc")); | 548 TEST_CC_CSC, DOMUtils.getNodeValue(webContents, "id-opt-cc-c
sc")); |
547 } | 549 } |
548 } | 550 } |
549 | 551 |
550 private void verifyFieldsAreFilled(final boolean requestFullBilling, | 552 private void verifyFieldsAreFilled(final boolean requestFullBilling, |
551 final boolean requestShipping, final boolean requestPhoneNumbers) | 553 final boolean requestShipping, final boolean requestPhoneNumbers) |
552 throws InterruptedException, TimeoutException { | 554 throws InterruptedException, TimeoutException { |
553 setUpAndRequestAutocomplete( | 555 setUpAndRequestAutocomplete( |
554 generatePage(requestFullBilling, requestShipping, requestPhoneNu
mbers), | 556 generatePage(requestFullBilling, requestShipping, requestPhoneNu
mbers), |
555 requestFullBilling, requestShipping, requestPhoneNumbers); | 557 requestFullBilling, requestShipping, requestPhoneNumbers); |
556 | 558 |
557 final WebContents webContents = getActivity().getActiveContentViewCore()
.getWebContents(); | 559 final WebContents webContents = getActivity().getCurrentContentViewCore(
).getWebContents(); |
558 | 560 |
559 assertEquals("billing name did not match", | 561 assertEquals("billing name did not match", |
560 TEST_NAME, DOMUtils.getNodeValue(webContents, "id-billing-name")
); | 562 TEST_NAME, DOMUtils.getNodeValue(webContents, "id-billing-name")
); |
561 assertEquals("email did not match", | 563 assertEquals("email did not match", |
562 TEST_EMAIL, DOMUtils.getNodeValue(webContents, "id-email")); | 564 TEST_EMAIL, DOMUtils.getNodeValue(webContents, "id-email")); |
563 | 565 |
564 assertEquals("cc-name did not match", | 566 assertEquals("cc-name did not match", |
565 TEST_NAME, DOMUtils.getNodeValue(webContents, "id-cc-name")); | 567 TEST_NAME, DOMUtils.getNodeValue(webContents, "id-cc-name")); |
566 | 568 |
567 assertEquals("cc-number did not match", | 569 assertEquals("cc-number did not match", |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 requestFullBilling, requestShipping, requestPhoneNumbers, | 663 requestFullBilling, requestShipping, requestPhoneNumbers, |
662 true); | 664 true); |
663 } | 665 } |
664 | 666 |
665 private void setUpAndRequestAutocompleteImpl(final String url, | 667 private void setUpAndRequestAutocompleteImpl(final String url, |
666 final boolean requestFullBilling, | 668 final boolean requestFullBilling, |
667 final boolean requestShipping, | 669 final boolean requestShipping, |
668 final boolean requestPhoneNumbers, | 670 final boolean requestPhoneNumbers, |
669 final boolean expectFailure) | 671 final boolean expectFailure) |
670 throws InterruptedException, TimeoutException { | 672 throws InterruptedException, TimeoutException { |
671 launchChromeShellWithUrl(url); | 673 startMainActivityWithURL(url); |
672 assertTrue(waitForActiveShellToBeDoneLoading()); | |
673 | 674 |
674 final ContentViewCore viewCore = getActivity().getActiveContentViewCore(
); | 675 final ContentViewCore viewCore = getActivity().getCurrentContentViewCore
(); |
675 final WebContents webContents = getActivity().getActiveContentViewCore()
.getWebContents(); | 676 final WebContents webContents = getActivity().getCurrentContentViewCore(
).getWebContents(); |
676 | 677 |
677 AutofillDialogResult.ResultWallet result = new AutofillDialogResult.Resu
ltWallet( | 678 AutofillDialogResult.ResultWallet result = new AutofillDialogResult.Resu
ltWallet( |
678 TEST_EMAIL, "Google Transaction ID", | 679 TEST_EMAIL, "Google Transaction ID", |
679 new AutofillDialogResult.ResultCard( | 680 new AutofillDialogResult.ResultCard( |
680 TEST_CC_EXP_MONTH, TEST_CC_EXP_YEAR, | 681 TEST_CC_EXP_MONTH, TEST_CC_EXP_YEAR, |
681 TEST_CC_NUMBER, TEST_CC_CSC), | 682 TEST_CC_NUMBER, TEST_CC_CSC), |
682 new AutofillDialogResult.ResultAddress( | 683 new AutofillDialogResult.ResultAddress( |
683 TEST_NAME, TEST_PHONE, | 684 TEST_NAME, TEST_PHONE, |
684 TEST_BILLING_STREET, | 685 TEST_BILLING_STREET, |
685 TEST_BILLING_CITY, TEST_BILLING_DL, TEST_BILLING_STATE, | 686 TEST_BILLING_CITY, TEST_BILLING_DL, TEST_BILLING_STATE, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 return false; | 725 return false; |
725 } catch (TimeoutException e) { | 726 } catch (TimeoutException e) { |
726 return false; | 727 return false; |
727 } | 728 } |
728 return TextUtils.equals("succeeded", wasAutocompleted) | 729 return TextUtils.equals("succeeded", wasAutocompleted) |
729 || TextUtils.equals("failed", wasAutocompleted); | 730 || TextUtils.equals("failed", wasAutocompleted); |
730 } | 731 } |
731 })); | 732 })); |
732 } | 733 } |
733 } | 734 } |
OLD | NEW |