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.Context; |
7 import android.test.suitebuilder.annotation.MediumTest; | 8 import android.test.suitebuilder.annotation.MediumTest; |
8 | 9 |
9 import org.chromium.base.test.util.Feature; | 10 import org.chromium.base.test.util.Feature; |
| 11 import org.chromium.content_public.browser.WebContents; |
10 | 12 |
11 import java.util.Arrays; | 13 import java.util.Arrays; |
12 import java.util.List; | |
13 import java.util.concurrent.ExecutionException; | 14 import java.util.concurrent.ExecutionException; |
14 import java.util.concurrent.TimeoutException; | 15 import java.util.concurrent.TimeoutException; |
15 | 16 |
16 /** | 17 /** |
17 * A payment integration test for service worker based payment apps. | 18 * A payment integration test for service worker based payment apps. |
18 */ | 19 */ |
19 public class PaymentRequestServiceWorkerPaymentAppTest extends PaymentRequestTes
tBase { | 20 public class PaymentRequestServiceWorkerPaymentAppTest extends PaymentRequestTes
tBase { |
20 /** Flag for installing a service worker payment app without any payment opt
ions. */ | 21 /** Flag for installing a service worker payment app without any payment opt
ions. */ |
21 private static final int NO_OPTIONS = 0; | 22 private static final int NO_OPTIONS = 0; |
22 | 23 |
23 /** Flag for installing a service worker payment app with one payment option
. */ | 24 /** Flag for installing a service worker payment app with one payment option
. */ |
24 private static final int ONE_OPTION = 1; | 25 private static final int ONE_OPTION = 1; |
25 | 26 |
26 /** Flag for installing a service worker payment app with two options. */ | 27 /** Flag for installing a service worker payment app with two options. */ |
27 private static final int TWO_OPTIONS = 2; | 28 private static final int TWO_OPTIONS = 2; |
28 | 29 |
29 public PaymentRequestServiceWorkerPaymentAppTest() { | 30 public PaymentRequestServiceWorkerPaymentAppTest() { |
30 super("payment_request_bobpay_test.html"); | 31 super("payment_request_bobpay_test.html"); |
31 } | 32 } |
32 | 33 |
33 /** | 34 /** |
34 * Installs a service worker based payment app for testing. | 35 * Installs a mock service worker based payment app for testing. |
35 * | 36 * |
36 * @param optionPresence Whether the manifest has any payment options. Eithe
r NO_OPTIONS | 37 * @param optionPresence Whether the manifest has any payment options. Eithe
r NO_OPTIONS |
37 * ONE_OPTION or TWO_OPTIONS | 38 * ONE_OPTION or TWO_OPTIONS |
38 */ | 39 */ |
39 private void installServiceWorkerPaymentApp(final int instrumentPresence) { | 40 private void installMockServiceWorkerPaymentApp(final int instrumentPresence
) { |
40 PaymentAppFactory.getInstance().addAdditionalFactory( | 41 PaymentAppFactory.getInstance().addAdditionalFactory( |
41 new ServiceWorkerPaymentAppBridge() { | 42 new PaymentAppFactory.PaymentAppFactoryAddition() { |
42 @Override | 43 @Override |
43 public List<Manifest> getAllAppManifests() { | 44 public void create(Context context, WebContents webContents, |
| 45 PaymentAppFactory.PaymentAppCreatedCallback callback
) { |
44 ServiceWorkerPaymentAppBridge.Manifest testManifest = | 46 ServiceWorkerPaymentAppBridge.Manifest testManifest = |
45 new ServiceWorkerPaymentAppBridge.Manifest(); | 47 new ServiceWorkerPaymentAppBridge.Manifest(); |
46 testManifest.scopeUrl = "https://bobpay.com/app"; | 48 testManifest.registrationId = 0; |
47 testManifest.label = "BobPay"; | 49 testManifest.label = "BobPay"; |
48 | 50 |
49 if (instrumentPresence != NO_OPTIONS) { | 51 if (instrumentPresence != NO_OPTIONS) { |
50 ServiceWorkerPaymentAppBridge.Option testOption = | 52 ServiceWorkerPaymentAppBridge.Option testOption = |
51 new ServiceWorkerPaymentAppBridge.Option(); | 53 new ServiceWorkerPaymentAppBridge.Option(); |
52 testOption.id = "new"; | 54 testOption.id = "new"; |
53 testOption.label = "Create BobPay account"; | 55 testOption.label = "Create BobPay account"; |
54 testOption.enabledMethods = | 56 testOption.enabledMethods = |
55 Arrays.asList("https://bobpay.com", "basic-card"
); | 57 Arrays.asList("https://bobpay.com", "basic-card"
); |
56 testManifest.options.add(testOption); | 58 testManifest.options.add(testOption); |
57 } | 59 } |
58 | 60 |
59 if (instrumentPresence == TWO_OPTIONS) { | 61 if (instrumentPresence == TWO_OPTIONS) { |
60 ServiceWorkerPaymentAppBridge.Option testOption = | 62 ServiceWorkerPaymentAppBridge.Option testOption = |
61 new ServiceWorkerPaymentAppBridge.Option(); | 63 new ServiceWorkerPaymentAppBridge.Option(); |
62 testOption.id = "existing"; | 64 testOption.id = "existing"; |
63 testOption.label = "Existing BobPay account"; | 65 testOption.label = "Existing BobPay account"; |
64 testOption.enabledMethods = | 66 testOption.enabledMethods = |
65 Arrays.asList("https://bobpay.com", "basic-card"
); | 67 Arrays.asList("https://bobpay.com", "basic-card"
); |
66 testManifest.options.add(testOption); | 68 testManifest.options.add(testOption); |
67 } | 69 } |
68 | 70 |
69 return Arrays.asList(testManifest); | 71 callback.onPaymentAppCreated( |
| 72 new ServiceWorkerPaymentApp(webContents, testMan
ifest)); |
| 73 callback.onAllPaymentAppsCreated(); |
70 } | 74 } |
71 }); | 75 }); |
72 } | 76 } |
73 | 77 |
74 @Override | 78 @Override |
75 public void onMainActivityStarted() throws InterruptedException, ExecutionEx
ception, | 79 public void onMainActivityStarted() throws InterruptedException, ExecutionEx
ception, |
76 TimeoutException {} | 80 TimeoutException {} |
77 | 81 |
78 @MediumTest | 82 @MediumTest |
79 @Feature({"Payments"}) | 83 @Feature({"Payments"}) |
80 public void testNoOptions() throws InterruptedException, ExecutionException, | 84 public void testNoOptions() throws InterruptedException, ExecutionException, |
81 TimeoutException { | 85 TimeoutException { |
82 installServiceWorkerPaymentApp(NO_OPTIONS); | 86 installMockServiceWorkerPaymentApp(NO_OPTIONS); |
83 openPageAndClickBuyAndWait(mShowFailed); | 87 openPageAndClickBuyAndWait(mShowFailed); |
84 expectResultContains( | 88 expectResultContains( |
85 new String[]{"show() rejected", "The payment method is not suppo
rted"}); | 89 new String[]{"show() rejected", "The payment method is not suppo
rted"}); |
86 } | 90 } |
87 | 91 |
88 @MediumTest | 92 @MediumTest |
89 @Feature({"Payments"}) | 93 @Feature({"Payments"}) |
90 public void testOneOption() throws InterruptedException, ExecutionException, | 94 public void testOneOption() throws InterruptedException, ExecutionException, |
91 TimeoutException { | 95 TimeoutException { |
92 installServiceWorkerPaymentApp(ONE_OPTION); | 96 installMockServiceWorkerPaymentApp(ONE_OPTION); |
93 triggerUIAndWait(mReadyForInput); | 97 triggerUIAndWait(mReadyForInput); |
94 // TODO(tommyt): crbug.com/669876. Expand this test as we implement more | 98 // TODO(tommyt): crbug.com/669876. Expand this test as we implement more |
95 // service worker based payment app functionality. | 99 // service worker based payment app functionality. |
96 } | 100 } |
97 | 101 |
98 @MediumTest | 102 @MediumTest |
99 @Feature({"Payments"}) | 103 @Feature({"Payments"}) |
100 public void testTwoOptions() throws InterruptedException, ExecutionException
, | 104 public void testTwoOptions() throws InterruptedException, ExecutionException
, |
101 TimeoutException { | 105 TimeoutException { |
102 installServiceWorkerPaymentApp(TWO_OPTIONS); | 106 installMockServiceWorkerPaymentApp(TWO_OPTIONS); |
103 triggerUIAndWait(mReadyForInput); | 107 triggerUIAndWait(mReadyForInput); |
104 // TODO(tommyt): crbug.com/669876. Expand this test as we implement more | 108 // TODO(tommyt): crbug.com/669876. Expand this test as we implement more |
105 // service worker based payment app functionality. | 109 // service worker based payment app functionality. |
106 } | 110 } |
107 } | 111 } |
OLD | NEW |