| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.payments; | 5 package org.chromium.chrome.browser.payments; |
| 6 | 6 |
| 7 import android.content.DialogInterface; | 7 import android.content.DialogInterface; |
| 8 import android.test.suitebuilder.annotation.MediumTest; | 8 import android.test.suitebuilder.annotation.MediumTest; |
| 9 | 9 |
| 10 import org.chromium.base.metrics.RecordHistogram; | 10 import org.chromium.base.metrics.RecordHistogram; |
| 11 import org.chromium.base.test.util.Feature; | 11 import org.chromium.base.test.util.Feature; |
| 12 import org.chromium.chrome.R; | 12 import org.chromium.chrome.R; |
| 13 import org.chromium.chrome.browser.autofill.AutofillTestHelper; | 13 import org.chromium.chrome.browser.autofill.AutofillTestHelper; |
| 14 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; | 14 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; |
| 15 import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; | 15 import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; |
| 16 | 16 |
| 17 import java.util.concurrent.ExecutionException; | 17 import java.util.concurrent.ExecutionException; |
| 18 import java.util.concurrent.TimeoutException; | 18 import java.util.concurrent.TimeoutException; |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * A payment integration test for a merchant that requests email address. | 21 * A payment integration test for a merchant that requests payer name. |
| 22 */ | 22 */ |
| 23 public class PaymentRequestEmailTest extends PaymentRequestTestBase { | 23 public class PaymentRequestNameTest extends PaymentRequestTestBase { |
| 24 public PaymentRequestEmailTest() { | 24 public PaymentRequestNameTest() { |
| 25 // This merchant request an email address. | 25 // This merchant request an payer name. |
| 26 super("payment_request_email_test.html"); | 26 super("payment_request_name_test.html"); |
| 27 } | 27 } |
| 28 | 28 |
| 29 @Override | 29 @Override |
| 30 public void onMainActivityStarted() | 30 public void onMainActivityStarted() |
| 31 throws InterruptedException, ExecutionException, TimeoutException { | 31 throws InterruptedException, ExecutionException, TimeoutException { |
| 32 AutofillTestHelper helper = new AutofillTestHelper(); | 32 AutofillTestHelper helper = new AutofillTestHelper(); |
| 33 // The user has a valid email address on disk. | 33 // The user has a valid payer name on disk. |
| 34 String billingAddressId = helper.setProfile(new AutofillProfile("", "htt
ps://example.com", | 34 String billingAddressId = helper.setProfile(new AutofillProfile("", "htt
ps://example.com", |
| 35 true, "Jon Doe", "Google", "340 Main St", "CA", "Los Angeles", "
", "90291", "", | 35 true, "Jon Doe", "Google", "340 Main St", "CA", "Los Angeles", "
", "90291", "", |
| 36 "US", "555-555-5555", "jon.doe@google.com", "en-US")); | 36 "US", "555-555-5555", "jon.doe@google.com", "en-US")); |
| 37 helper.setCreditCard(new CreditCard("", "https://example.com", true, tru
e, "Jon Doe", | 37 helper.setCreditCard(new CreditCard("", "https://example.com", true, tru
e, "Jon Doe", |
| 38 "4111111111111111", "1111", "12", "2050", "visa", R.drawable.pr_
visa, | 38 "4111111111111111", "1111", "12", "2050", "visa", R.drawable.pr_
visa, |
| 39 billingAddressId, "" /* serverId */)); | 39 billingAddressId, "" /* serverId */)); |
| 40 } | 40 } |
| 41 | 41 |
| 42 /** Provide the existing valid email address to the merchant. */ | 42 /** Provide the existing valid payer name to the merchant. */ |
| 43 @MediumTest | 43 @MediumTest |
| 44 @Feature({"Payments"}) | 44 @Feature({"Payments"}) |
| 45 public void testPay() throws InterruptedException, ExecutionException, Timeo
utException { | 45 public void testPay() throws InterruptedException, ExecutionException, Timeo
utException { |
| 46 triggerUIAndWait(mReadyToPay); | 46 triggerUIAndWait(mReadyToPay); |
| 47 clickAndWait(R.id.button_primary, mReadyForUnmaskInput); | 47 clickAndWait(R.id.button_primary, mReadyForUnmaskInput); |
| 48 setTextInCardUnmaskDialogAndWait(R.id.card_unmask_input, "123", mReadyTo
Unmask); | 48 setTextInCardUnmaskDialogAndWait(R.id.card_unmask_input, "123", mReadyTo
Unmask); |
| 49 clickCardUnmaskButtonAndWait(DialogInterface.BUTTON_POSITIVE, mDismissed
); | 49 clickCardUnmaskButtonAndWait(DialogInterface.BUTTON_POSITIVE, mDismissed
); |
| 50 expectResultContains(new String[] {"jon.doe@google.com"}); | 50 expectResultContains(new String[] {"Jon Doe"}); |
| 51 } | 51 } |
| 52 | 52 |
| 53 /** Attempt to add an invalid email address and cancel the transaction. */ | 53 /** Attempt to add an invalid payer name and cancel the transaction. */ |
| 54 @MediumTest | 54 @MediumTest |
| 55 @Feature({"Payments"}) | 55 @Feature({"Payments"}) |
| 56 public void testAddInvalidEmailAndCancel() | 56 public void testAddInvalidNameAndCancel() |
| 57 throws InterruptedException, ExecutionException, TimeoutException { | 57 throws InterruptedException, ExecutionException, TimeoutException { |
| 58 triggerUIAndWait(mReadyToPay); | 58 triggerUIAndWait(mReadyToPay); |
| 59 clickInContactInfoAndWait(R.id.payments_section, mReadyForInput); | 59 clickInPayerInfoAndWait(R.id.payments_section, mReadyForInput); |
| 60 clickInContactInfoAndWait(R.id.payments_add_option_button, mReadyToEdit)
; | 60 clickInPayerInfoAndWait(R.id.payments_add_option_button, mReadyToEdit); |
| 61 setTextInEditorAndWait(new String[] {"jane.jones"}, mEditorTextUpdate); | 61 setTextInEditorAndWait(new String[] {""}, mEditorTextUpdate); |
| 62 clickInEditorAndWait(R.id.payments_edit_done_button, mEditorValidationEr
ror); | 62 clickInEditorAndWait(R.id.payments_edit_done_button, mEditorValidationEr
ror); |
| 63 clickInEditorAndWait(R.id.payments_edit_cancel_button, mReadyForInput); | 63 clickInEditorAndWait(R.id.payments_edit_cancel_button, mReadyForInput); |
| 64 clickAndWait(R.id.close_button, mDismissed); | 64 clickAndWait(R.id.close_button, mDismissed); |
| 65 expectResultContains(new String[] {"Request cancelled"}); | 65 expectResultContains(new String[] {"Request cancelled"}); |
| 66 } | 66 } |
| 67 | 67 |
| 68 /** Add a new email address and provide that to the merchant. */ | 68 /** Add a new payer name and provide that to the merchant. */ |
| 69 @MediumTest | 69 @MediumTest |
| 70 @Feature({"Payments"}) | 70 @Feature({"Payments"}) |
| 71 public void testAddEmailAndPay() | 71 public void testAddEmailAndPay() |
| 72 throws InterruptedException, ExecutionException, TimeoutException { | 72 throws InterruptedException, ExecutionException, TimeoutException { |
| 73 triggerUIAndWait(mReadyToPay); | 73 triggerUIAndWait(mReadyToPay); |
| 74 clickInContactInfoAndWait(R.id.payments_section, mReadyForInput); | 74 clickInPayerInfoAndWait(R.id.payments_section, mReadyForInput); |
| 75 clickInContactInfoAndWait(R.id.payments_add_option_button, mReadyToEdit)
; | 75 clickInPayerInfoAndWait(R.id.payments_add_option_button, mReadyToEdit); |
| 76 setTextInEditorAndWait(new String[] {"jane.jones@google.com"}, mEditorTe
xtUpdate); | 76 setTextInEditorAndWait(new String[] {"Jane Jones"}, mEditorTextUpdate); |
| 77 clickInEditorAndWait(R.id.payments_edit_done_button, mReadyToPay); | 77 clickInEditorAndWait(R.id.payments_edit_done_button, mReadyToPay); |
| 78 clickAndWait(R.id.button_primary, mReadyForUnmaskInput); | 78 clickAndWait(R.id.button_primary, mReadyForUnmaskInput); |
| 79 setTextInCardUnmaskDialogAndWait(R.id.card_unmask_input, "123", mReadyTo
Unmask); | 79 setTextInCardUnmaskDialogAndWait(R.id.card_unmask_input, "123", mReadyTo
Unmask); |
| 80 clickCardUnmaskButtonAndWait(DialogInterface.BUTTON_POSITIVE, mDismissed
); | 80 clickCardUnmaskButtonAndWait(DialogInterface.BUTTON_POSITIVE, mDismissed
); |
| 81 expectResultContains(new String[] {"jane.jones@google.com"}); | 81 expectResultContains(new String[] {"Jane Jones"}); |
| 82 } | 82 } |
| 83 | 83 |
| 84 /** | 84 /** |
| 85 * Test that starting a payment request that requires only the user's email
address results in | 85 * Test that starting a payment request that requires only the user's payer
name results in |
| 86 * the appropriate metric being logged in the PaymentRequest.RequestedInform
ation histogram. | 86 * the appropriate metric being logged in the PaymentRequest.RequestedInform
ation histogram. |
| 87 */ | 87 */ |
| 88 @MediumTest | 88 @MediumTest |
| 89 @Feature({"Payments"}) | 89 @Feature({"Payments"}) |
| 90 public void testRequestedInformationMetric() throws InterruptedException, Ex
ecutionException, | 90 public void testRequestedInformationMetric() throws InterruptedException, Ex
ecutionException, |
| 91 TimeoutException { | 91 TimeoutException { |
| 92 // Start the Payment Request. | 92 // Start the Payment Request. |
| 93 triggerUIAndWait(mReadyToPay); | 93 triggerUIAndWait(mReadyToPay); |
| 94 | 94 |
| 95 // Make sure that only the appropriate enum value was logged. | 95 // Make sure that only the appropriate enum value was logged. |
| 96 for (int i = 0; i < PaymentRequestMetrics.REQUESTED_INFORMATION_MAX; ++i
) { | 96 for (int i = 0; i < PaymentRequestMetrics.REQUESTED_INFORMATION_MAX; ++i
) { |
| 97 assertEquals((i == PaymentRequestMetrics.REQUESTED_INFORMATION_EMAIL
? 1 : 0), | 97 assertEquals((i == PaymentRequestMetrics.REQUESTED_INFORMATION_EMAIL
? 1 : 0), |
| 98 RecordHistogram.getHistogramValueCountForTesting( | 98 RecordHistogram.getHistogramValueCountForTesting( |
| 99 "PaymentRequest.RequestedInformation", i)); | 99 "PaymentRequest.RequestedInformation", i)); |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 } | 102 } |
| OLD | NEW |