| 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.support.test.filters.MediumTest; | 7 import android.support.test.filters.MediumTest; |
| 8 | 8 |
| 9 import org.chromium.base.test.util.Feature; | 9 import org.chromium.base.test.util.Feature; |
| 10 import org.chromium.content_public.browser.WebContents; | 10 import org.chromium.content_public.browser.WebContents; |
| 11 | 11 |
| 12 import java.util.ArrayList; |
| 12 import java.util.Arrays; | 13 import java.util.Arrays; |
| 14 import java.util.HashSet; |
| 15 import java.util.List; |
| 13 import java.util.Set; | 16 import java.util.Set; |
| 14 import java.util.concurrent.ExecutionException; | 17 import java.util.concurrent.ExecutionException; |
| 15 import java.util.concurrent.TimeoutException; | 18 import java.util.concurrent.TimeoutException; |
| 16 | 19 |
| 17 /** | 20 /** |
| 18 * A payment integration test for service worker based payment apps. | 21 * A payment integration test for service worker based payment apps. |
| 19 */ | 22 */ |
| 20 public class PaymentRequestServiceWorkerPaymentAppTest extends PaymentRequestTes
tBase { | 23 public class PaymentRequestServiceWorkerPaymentAppTest extends PaymentRequestTes
tBase { |
| 21 /** Flag for installing a service worker payment app without any payment opt
ions. */ | 24 /** Flag for installing a service worker payment app without any payment opt
ions. */ |
| 22 private static final int NO_OPTIONS = 0; | 25 private static final int NO_OPTIONS = 0; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 36 * | 39 * |
| 37 * @param instrumentPresence Whether the manifest has any payment options. E
ither NO_OPTIONS | 40 * @param instrumentPresence Whether the manifest has any payment options. E
ither NO_OPTIONS |
| 38 * ONE_OPTION or TWO_OPTIONS | 41 * ONE_OPTION or TWO_OPTIONS |
| 39 */ | 42 */ |
| 40 private void installMockServiceWorkerPaymentApp(final int instrumentPresence
) { | 43 private void installMockServiceWorkerPaymentApp(final int instrumentPresence
) { |
| 41 PaymentAppFactory.getInstance().addAdditionalFactory( | 44 PaymentAppFactory.getInstance().addAdditionalFactory( |
| 42 new PaymentAppFactory.PaymentAppFactoryAddition() { | 45 new PaymentAppFactory.PaymentAppFactoryAddition() { |
| 43 @Override | 46 @Override |
| 44 public void create(WebContents webContents, Set<String> meth
odNames, | 47 public void create(WebContents webContents, Set<String> meth
odNames, |
| 45 PaymentAppFactory.PaymentAppCreatedCallback callback
) { | 48 PaymentAppFactory.PaymentAppCreatedCallback callback
) { |
| 46 ServiceWorkerPaymentAppBridge.Manifest testManifest = | 49 List<PaymentInstrument> instruments = new ArrayList<Paym
entInstrument>(); |
| 47 new ServiceWorkerPaymentAppBridge.Manifest(); | |
| 48 testManifest.registrationId = 0; | |
| 49 testManifest.label = "BobPay"; | |
| 50 | 50 |
| 51 if (instrumentPresence != NO_OPTIONS) { | 51 if (instrumentPresence != NO_OPTIONS) { |
| 52 ServiceWorkerPaymentAppBridge.Option testOption = | 52 instruments.add(new ServiceWorkerPaymentInstrument(w
ebContents, |
| 53 new ServiceWorkerPaymentAppBridge.Option(); | 53 0 /* swRegistrationId */, "new" /* instrumen
tId */, |
| 54 testOption.id = "new"; | 54 "Create BobPay account" /* label */, |
| 55 testOption.label = "Create BobPay account"; | 55 new HashSet<String>(Arrays.asList("https://b
obpay.com", |
| 56 testOption.enabledMethods = | 56 "basic-card")) /* methodNames */)); |
| 57 Arrays.asList("https://bobpay.com", "basic-card"
); | |
| 58 testManifest.options.add(testOption); | |
| 59 } | 57 } |
| 60 | 58 |
| 61 if (instrumentPresence == TWO_OPTIONS) { | 59 if (instrumentPresence == TWO_OPTIONS) { |
| 62 ServiceWorkerPaymentAppBridge.Option testOption = | 60 instruments.add(new ServiceWorkerPaymentInstrument(w
ebContents, |
| 63 new ServiceWorkerPaymentAppBridge.Option(); | 61 0 /* swRegistrationId */, "existing" /* inst
rumentId */, |
| 64 testOption.id = "existing"; | 62 "Existing BobPay account" /* label */, |
| 65 testOption.label = "Existing BobPay account"; | 63 new HashSet<String>(Arrays.asList("https://b
obpay.com", |
| 66 testOption.enabledMethods = | 64 "basic-card")) /* methodNames */)); |
| 67 Arrays.asList("https://bobpay.com", "basic-card"
); | |
| 68 testManifest.options.add(testOption); | |
| 69 } | 65 } |
| 70 | 66 |
| 71 callback.onPaymentAppCreated( | 67 callback.onPaymentAppCreated( |
| 72 new ServiceWorkerPaymentApp(webContents, testMan
ifest)); | 68 new ServiceWorkerPaymentApp(webContents, instrum
ents)); |
| 73 callback.onAllPaymentAppsCreated(); | 69 callback.onAllPaymentAppsCreated(); |
| 74 } | 70 } |
| 75 }); | 71 }); |
| 76 } | 72 } |
| 77 | 73 |
| 78 @Override | 74 @Override |
| 79 public void onMainActivityStarted() throws InterruptedException, ExecutionEx
ception, | 75 public void onMainActivityStarted() throws InterruptedException, ExecutionEx
ception, |
| 80 TimeoutException {} | 76 TimeoutException {} |
| 81 | 77 |
| 82 @MediumTest | 78 @MediumTest |
| (...skipping 19 matching lines...) Expand all Loading... |
| 102 @MediumTest | 98 @MediumTest |
| 103 @Feature({"Payments"}) | 99 @Feature({"Payments"}) |
| 104 public void testTwoOptions() throws InterruptedException, ExecutionException
, | 100 public void testTwoOptions() throws InterruptedException, ExecutionException
, |
| 105 TimeoutException { | 101 TimeoutException { |
| 106 installMockServiceWorkerPaymentApp(TWO_OPTIONS); | 102 installMockServiceWorkerPaymentApp(TWO_OPTIONS); |
| 107 triggerUIAndWait(mReadyForInput); | 103 triggerUIAndWait(mReadyForInput); |
| 108 // TODO(tommyt): crbug.com/669876. Expand this test as we implement more | 104 // TODO(tommyt): crbug.com/669876. Expand this test as we implement more |
| 109 // service worker based payment app functionality. | 105 // service worker based payment app functionality. |
| 110 } | 106 } |
| 111 } | 107 } |
| OLD | NEW |