OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.chrome.browser.payments; | |
6 | |
7 import android.content.DialogInterface; | |
8 import android.test.suitebuilder.annotation.MediumTest; | |
9 | |
10 import org.chromium.base.metrics.RecordHistogram; | |
11 import org.chromium.base.test.util.Feature; | |
12 import org.chromium.chrome.R; | |
13 import org.chromium.chrome.browser.autofill.AutofillTestHelper; | |
14 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; | |
15 import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; | |
16 | |
17 import java.util.concurrent.ExecutionException; | |
18 import java.util.concurrent.TimeoutException; | |
19 | |
20 /** | |
21 * A payment integration test for a merchant that requests an email address and
a phone number and | |
22 * provides free shipping regardless of address. | |
23 */ | |
24 public class PaymentRequestContactDetailsAndFreeShippingTest extends PaymentRequ
estTestBase { | |
25 public PaymentRequestContactDetailsAndFreeShippingTest() { | |
26 // This merchant requests an email address and a phone number and provid
es free shipping | |
27 // worldwide. | |
28 super("payment_request_contact_details_and_free_shipping_test.html"); | |
29 } | |
30 | |
31 @Override | |
32 public void onMainActivityStarted() | |
33 throws InterruptedException, ExecutionException, TimeoutException { | |
34 AutofillTestHelper helper = new AutofillTestHelper(); | |
35 // The user has a shipping address with a valid email address and a vali
d phone number on | |
36 // disk. | |
37 String billingAddressId = helper.setProfile(new AutofillProfile("", "htt
ps://example.com", | |
38 true, "Jon Doe", "Google", "340 Main St", "CA", "Los Angeles", "
", "90291", "", | |
39 "US", "555-555-5555", "jon.doe@google.com", "en-US")); | |
40 helper.setCreditCard(new CreditCard("", "https://example.com", true, tru
e, "Jon Doe", | |
41 "4111111111111111", "1111", "12", "2050", "visa", R.drawable.pr_
visa, | |
42 billingAddressId, "" /* serverId */)); | |
43 } | |
44 | |
45 /** | |
46 * Submit the email address, phone number and shipping address to the mercha
nt when the user | |
47 * clicks "Pay." | |
48 */ | |
49 @MediumTest | |
50 @Feature({"Payments"}) | |
51 public void testPay() throws InterruptedException, ExecutionException, Timeo
utException { | |
52 triggerUIAndWait(mReadyToPay); | |
53 clickAndWait(R.id.button_primary, mReadyForUnmaskInput); | |
54 setTextInCardUnmaskDialogAndWait(R.id.card_unmask_input, "123", mReadyTo
Unmask); | |
55 clickCardUnmaskButtonAndWait(DialogInterface.BUTTON_POSITIVE, mDismissed
); | |
56 expectResultContains(new String[] {"jon.doe@google.com", "555-555-5555",
"Jon Doe", | |
57 "4111111111111111", "12", "2050", "visa", "123", "Google", "340
Main St", "CA", | |
58 "Los Angeles", "90291", "US", "en", "freeShippingOption"}); | |
59 } | |
60 | |
61 /** | |
62 * Test that starting a payment request that requires an email address, a ph
one number and a | |
63 * shipping address results in the appropriate metric being logged in the | |
64 * PaymentRequest.RequestedInformation histogram. | |
65 */ | |
66 @MediumTest | |
67 @Feature({"Payments"}) | |
68 public void testRequestedInformationMetric() throws InterruptedException, Ex
ecutionException, | |
69 TimeoutException { | |
70 // Start the Payment Request. | |
71 triggerUIAndWait(mReadyToPay); | |
72 | |
73 // Make sure that only the appropriate enum value was logged. | |
74 for (int i = 0; i < PaymentRequestMetrics.REQUESTED_INFORMATION_MAX; ++i
) { | |
75 assertEquals((i == (PaymentRequestMetrics.REQUESTED_INFORMATION_EMAI
L | |
76 | PaymentRequestMetrics.REQUESTED_INFORMATION_PHONE | |
77 | PaymentRequestMetrics.REQUESTED_INFORMATION_SHIPPING) ? 1
: 0), | |
78 RecordHistogram.getHistogramValueCountForTesting( | |
79 "PaymentRequest.RequestedInformation", i)); | |
80 } | |
81 } | |
82 } | |
OLD | NEW |