Commit dc54ae55 authored by Yoland Yan's avatar Yoland Yan Committed by Commit Bot

Convert the rest of Payment tests to JUnit4

For more on JUnit4 migration, please check
src/testing/android/docs/junit4.md

Bug: 640116
Change-Id: I0270db03b98377e50bcbd45ccbc972fe28e4c918
Reviewed-on: https://chromium-review.googlesource.com/699794
Commit-Queue: Yoland Yan <yolandyan@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#506812}
parent da4ce848
......@@ -1650,7 +1650,6 @@ chrome_test_java_sources = [
"javatests/src/org/chromium/chrome/browser/payments/PaymentRequestShippingAddressChangeTest.java",
"javatests/src/org/chromium/chrome/browser/payments/PaymentRequestShowTwiceTest.java",
"javatests/src/org/chromium/chrome/browser/payments/PaymentRequestTabTest.java",
"javatests/src/org/chromium/chrome/browser/payments/PaymentRequestTestBase.java",
"javatests/src/org/chromium/chrome/browser/payments/PaymentRequestTestCommon.java",
"javatests/src/org/chromium/chrome/browser/payments/PaymentRequestTestRule.java",
"javatests/src/org/chromium/chrome/browser/payments/PaymentRequestUseStatsTest.java",
......
......@@ -6,11 +6,21 @@ package org.chromium.chrome.browser.payments;
import android.support.test.filters.MediumTest;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.autofill.AutofillTestHelper;
import org.chromium.chrome.browser.autofill.CardType;
import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard;
import org.chromium.chrome.browser.payments.PaymentRequestTestRule.MainActivityStartCallback;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
......@@ -19,9 +29,18 @@ import java.util.concurrent.TimeoutException;
* A payment integration test for checking whether user can make a payment via a credit card. This
* user has a valid credit card without a billing address on file.
*/
public class PaymentRequestCcCanMakePaymentQueryTest extends PaymentRequestTestBase {
public PaymentRequestCcCanMakePaymentQueryTest() {
super("payment_request_can_make_payment_query_cc_test.html");
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({
ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG,
})
public class PaymentRequestCcCanMakePaymentQueryTest implements MainActivityStartCallback {
@Rule
public PaymentRequestTestRule mPaymentRequestTestRule =
new PaymentRequestTestRule("payment_request_can_make_payment_query_cc_test.html", this);
@Before
public void setUp() {
PaymentRequestImpl.setIsLocalCanMakePaymentQueryQuotaEnforcedForTest();
}
......@@ -35,26 +54,33 @@ public class PaymentRequestCcCanMakePaymentQueryTest extends PaymentRequestTestB
CardType.UNKNOWN, "" /* billingAddressId */, "" /* serverId */));
}
@Test
@MediumTest
@Feature({"Payments"})
public void testCanMakePayment() throws InterruptedException, ExecutionException,
TimeoutException {
openPageAndClickBuyAndWait(getCanMakePaymentQueryResponded());
expectResultContains(new String[]{"true"});
public void testCanMakePayment()
throws InterruptedException, ExecutionException, TimeoutException {
mPaymentRequestTestRule.openPageAndClickBuyAndWait(
mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"true"});
// Repeating a query does not count against the quota.
clickNodeAndWait("buy", getCanMakePaymentQueryResponded());
expectResultContains(new String[]{"true"});
mPaymentRequestTestRule.clickNodeAndWait(
"buy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"true"});
clickNodeAndWait("buy", getCanMakePaymentQueryResponded());
expectResultContains(new String[]{"true"});
mPaymentRequestTestRule.clickNodeAndWait(
"buy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"true"});
// Different queries are throttled for a period of time.
clickNodeAndWait("other-buy", getCanMakePaymentQueryResponded());
expectResultContains(new String[] {"Not allowed to check whether can make payment"});
mPaymentRequestTestRule.clickNodeAndWait(
"other-buy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(
new String[] {"Not allowed to check whether can make payment"});
// Repeating the same query again does not count against the quota.
clickNodeAndWait("buy", getCanMakePaymentQueryResponded());
expectResultContains(new String[]{"true"});
mPaymentRequestTestRule.clickNodeAndWait(
"buy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"true"});
}
}
......@@ -6,34 +6,51 @@ package org.chromium.chrome.browser.payments;
import android.support.test.filters.MediumTest;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.payments.PaymentRequestTestRule.MainActivityStartCallback;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
/** Web payments test for data URL. */
public class PaymentRequestDataUrlTest extends PaymentRequestTestBase {
public PaymentRequestDataUrlTest() {
super("data:text/html,<html><head>"
+ "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, "
+ "maximum-scale=1\"></head><body><button id=\"buy\" onclick=\"try { "
+ "(new PaymentRequest([{supportedMethods: ['basic-card']}], "
+ "{total: {label: 'Total', "
+ " amount: {currency: 'USD', value: '1.00'}}})).show(); "
+ "} catch(e) { "
+ "document.getElementById('result').innerHTML = e; "
+ "}\">Data URL Test</button><div id='result'></div></body></html>");
}
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({
ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG,
})
public class PaymentRequestDataUrlTest implements MainActivityStartCallback {
@Rule
public PaymentRequestTestRule mPaymentRequestTestRule = new PaymentRequestTestRule(
"data:text/html,<html><head>"
+ "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, "
+ "maximum-scale=1\"></head><body><button id=\"buy\" onclick=\"try { "
+ "(new PaymentRequest([{supportedMethods: ['basic-card']}], "
+ "{total: {label: 'Total', "
+ " amount: {currency: 'USD', value: '1.00'}}})).show(); "
+ "} catch(e) { "
+ "document.getElementById('result').innerHTML = e; "
+ "}\">Data URL Test</button><div id='result'></div></body></html>",
this);
@Override
public void onMainActivityStarted()
throws InterruptedException, ExecutionException, TimeoutException {}
@Test
@MediumTest
@Feature({"Payments"})
public void test() throws InterruptedException, ExecutionException, TimeoutException {
openPageAndClickNode("buy");
expectResultContains(new String[] {"SecurityError: Failed to construct 'PaymentRequest': "
+ "Must be in a secure context"});
mPaymentRequestTestRule.openPageAndClickNode("buy");
mPaymentRequestTestRule.expectResultContains(
new String[] {"SecurityError: Failed to construct 'PaymentRequest': "
+ "Must be in a secure context"});
}
}
......@@ -4,9 +4,24 @@
package org.chromium.chrome.browser.payments;
import static org.chromium.chrome.browser.payments.PaymentRequestTestRule.DELAYED_RESPONSE;
import static org.chromium.chrome.browser.payments.PaymentRequestTestRule.HAVE_INSTRUMENTS;
import static org.chromium.chrome.browser.payments.PaymentRequestTestRule.IMMEDIATE_RESPONSE;
import static org.chromium.chrome.browser.payments.PaymentRequestTestRule.NO_INSTRUMENTS;
import android.support.test.filters.MediumTest;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.payments.PaymentRequestTestRule.MainActivityStartCallback;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
......@@ -14,85 +29,114 @@ import java.util.concurrent.TimeoutException;
/**
* A payment integration test for checking whether user can make a payment using a payment app.
*/
public class PaymentRequestPaymentAppCanMakePaymentQueryTest extends PaymentRequestTestBase {
public PaymentRequestPaymentAppCanMakePaymentQueryTest() {
super("payment_request_can_make_payment_query_bobpay_test.html");
PaymentRequestImpl.setIsLocalCanMakePaymentQueryQuotaEnforcedForTest();
}
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({
ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG,
})
public class PaymentRequestPaymentAppCanMakePaymentQueryTest implements MainActivityStartCallback {
@Rule
public PaymentRequestTestRule mPaymentRequestTestRule = new PaymentRequestTestRule(
"payment_request_can_make_payment_query_bobpay_test.html", this);
@Override
public void onMainActivityStarted() throws InterruptedException, ExecutionException,
TimeoutException {}
@Before
public void setUp() {
PaymentRequestImpl.setIsLocalCanMakePaymentQueryQuotaEnforcedForTest();
}
@Test
@MediumTest
@Feature({"Payments"})
public void testNoBobPayInstalled() throws InterruptedException, ExecutionException,
TimeoutException {
openPageAndClickBuyAndWait(getCanMakePaymentQueryResponded());
expectResultContains(new String[] {"false, false"});
public void testNoBobPayInstalled()
throws InterruptedException, ExecutionException, TimeoutException {
mPaymentRequestTestRule.openPageAndClickBuyAndWait(
mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"false, false"});
clickNodeAndWait("otherBuy", getCanMakePaymentQueryResponded());
expectResultContains(new String[] {"false, NotAllowedError"});
mPaymentRequestTestRule.clickNodeAndWait(
"otherBuy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"false, NotAllowedError"});
}
@Test
@MediumTest
@Feature({"Payments"})
public void testBobPayInstalledLater()
throws InterruptedException, ExecutionException, TimeoutException {
openPageAndClickBuyAndWait(getCanMakePaymentQueryResponded());
expectResultContains(new String[] {"false, false"});
mPaymentRequestTestRule.openPageAndClickBuyAndWait(
mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"false, false"});
installPaymentApp(HAVE_INSTRUMENTS, IMMEDIATE_RESPONSE);
mPaymentRequestTestRule.installPaymentApp(HAVE_INSTRUMENTS, IMMEDIATE_RESPONSE);
clickNodeAndWait("otherBuy", getCanMakePaymentQueryResponded());
expectResultContains(new String[] {"true, NotAllowedError"});
Thread.sleep(10000);
mPaymentRequestTestRule.clickNodeAndWait(
"otherBuy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
Thread.sleep(10000);
mPaymentRequestTestRule.expectResultContains(new String[] {"true, NotAllowedError"});
}
@Test
@MediumTest
@Feature({"Payments"})
public void testNoInstrumentsInFastBobPay() throws InterruptedException, ExecutionException,
TimeoutException {
installPaymentApp(NO_INSTRUMENTS, IMMEDIATE_RESPONSE);
openPageAndClickBuyAndWait(getCanMakePaymentQueryResponded());
expectResultContains(new String[] {"false, false"});
clickNodeAndWait("otherBuy", getCanMakePaymentQueryResponded());
expectResultContains(new String[] {"false, NotAllowedError"});
public void testNoInstrumentsInFastBobPay()
throws InterruptedException, ExecutionException, TimeoutException {
mPaymentRequestTestRule.installPaymentApp(NO_INSTRUMENTS, IMMEDIATE_RESPONSE);
mPaymentRequestTestRule.openPageAndClickBuyAndWait(
mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"false, false"});
mPaymentRequestTestRule.clickNodeAndWait(
"otherBuy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"false, NotAllowedError"});
}
@Test
@MediumTest
@Feature({"Payments"})
public void testNoInstrumentsInSlowBobPay() throws InterruptedException, ExecutionException,
TimeoutException {
installPaymentApp(NO_INSTRUMENTS, DELAYED_RESPONSE);
openPageAndClickBuyAndWait(getCanMakePaymentQueryResponded());
expectResultContains(new String[] {"false, false"});
clickNodeAndWait("otherBuy", getCanMakePaymentQueryResponded());
expectResultContains(new String[] {"false, NotAllowedError"});
public void testNoInstrumentsInSlowBobPay()
throws InterruptedException, ExecutionException, TimeoutException {
mPaymentRequestTestRule.installPaymentApp(NO_INSTRUMENTS, DELAYED_RESPONSE);
mPaymentRequestTestRule.openPageAndClickBuyAndWait(
mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"false, false"});
mPaymentRequestTestRule.clickNodeAndWait(
"otherBuy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"false, NotAllowedError"});
}
@Test
@MediumTest
@Feature({"Payments"})
public void testPayViaFastBobPay() throws InterruptedException, ExecutionException,
TimeoutException {
installPaymentApp(HAVE_INSTRUMENTS, IMMEDIATE_RESPONSE);
openPageAndClickBuyAndWait(getCanMakePaymentQueryResponded());
expectResultContains(new String[] {"true, true"});
clickNodeAndWait("otherBuy", getCanMakePaymentQueryResponded());
expectResultContains(new String[] {"true, NotAllowedError"});
public void testPayViaFastBobPay()
throws InterruptedException, ExecutionException, TimeoutException {
mPaymentRequestTestRule.installPaymentApp(HAVE_INSTRUMENTS, IMMEDIATE_RESPONSE);
mPaymentRequestTestRule.openPageAndClickBuyAndWait(
mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"true, true"});
mPaymentRequestTestRule.clickNodeAndWait(
"otherBuy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"true, NotAllowedError"});
}
@Test
@MediumTest
@Feature({"Payments"})
public void testPayViaSlowBobPay() throws InterruptedException, ExecutionException,
TimeoutException {
installPaymentApp(HAVE_INSTRUMENTS, DELAYED_RESPONSE);
openPageAndClickBuyAndWait(getCanMakePaymentQueryResponded());
expectResultContains(new String[] {"true, true"});
clickNodeAndWait("otherBuy", getCanMakePaymentQueryResponded());
expectResultContains(new String[] {"true, NotAllowedError"});
public void testPayViaSlowBobPay()
throws InterruptedException, ExecutionException, TimeoutException {
mPaymentRequestTestRule.installPaymentApp(HAVE_INSTRUMENTS, DELAYED_RESPONSE);
mPaymentRequestTestRule.openPageAndClickBuyAndWait(
mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"true, true"});
mPaymentRequestTestRule.clickNodeAndWait(
"otherBuy", mPaymentRequestTestRule.getCanMakePaymentQueryResponded());
mPaymentRequestTestRule.expectResultContains(new String[] {"true, NotAllowedError"});
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment