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