Commit bcc96ac8 authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Chromium LUCI CQ

[Payments] Add test coverage to updateWith, OnConnectionError, etc

According to test coverage report[1], the error handling
branches of PRService#updateWith(), OnConnectionError(),
OnPaymentDetailsNotUpdated() has no test coverage. This
CL adds the tests to cover these cases.

[1] https://analysis.chromium.org/p/chromium/coverage/file?host=chromium.googlesource.com&project=chromium/src&ref=refs/heads/master&revision=5089ddb0638765b738ce9690ee00be44d2e19a9c&path=//components/payments/content/android/java/src/org/chromium/components/payments/PaymentRequestService.java&platform=android-java#1213

Bug: 1093971
Change-Id: I555d46796f1b570a49fb0861328effbb8226bd09
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2584463
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835730}
parent 69a7cd3b
...@@ -30,6 +30,7 @@ import org.chromium.payments.mojom.PaymentAddress; ...@@ -30,6 +30,7 @@ import org.chromium.payments.mojom.PaymentAddress;
import org.chromium.payments.mojom.PaymentDetails; import org.chromium.payments.mojom.PaymentDetails;
import org.chromium.payments.mojom.PaymentErrorReason; import org.chromium.payments.mojom.PaymentErrorReason;
import org.chromium.payments.mojom.PaymentMethodData; import org.chromium.payments.mojom.PaymentMethodData;
import org.chromium.payments.mojom.PaymentOptions;
import org.chromium.payments.mojom.PaymentRequestClient; import org.chromium.payments.mojom.PaymentRequestClient;
import org.chromium.payments.mojom.PaymentResponse; import org.chromium.payments.mojom.PaymentResponse;
...@@ -434,6 +435,51 @@ public class PaymentRequestServiceTest implements PaymentRequestClient { ...@@ -434,6 +435,51 @@ public class PaymentRequestServiceTest implements PaymentRequestClient {
Mockito.verify(mBrowserPaymentRequest, Mockito.times(1)).continueShow(Mockito.anyBoolean()); Mockito.verify(mBrowserPaymentRequest, Mockito.times(1)).continueShow(Mockito.anyBoolean());
} }
@Test
@Feature({"Payments"})
public void testCallUpdateWithBeforeShowFailsPayment() {
PaymentRequestService service = defaultBuilder().build();
assertNoError();
updateWith(service);
assertErrorAndReason(
ErrorStrings.CANNOT_UPDATE_WITHOUT_SHOW, PaymentErrorReason.USER_CANCEL);
}
@Test
@Feature({"Payments"})
public void testCallUpdateWithWithoutRequestingAnyInfoFailsPayment() {
PaymentRequestService service = defaultBuilder().setOptions(new PaymentOptions()).build();
assertNoError();
show(service);
assertNoError();
updateWith(service);
assertErrorAndReason(ErrorStrings.INVALID_STATE, PaymentErrorReason.USER_CANCEL);
}
@Test
@Feature({"Payments"})
public void testCallOnPaymentDetailsNotUpdatedBeforeShowFailsPayment() {
PaymentRequestService service = defaultBuilder().build();
assertNoError();
service.onPaymentDetailsNotUpdated();
assertErrorAndReason(
ErrorStrings.CANNOT_UPDATE_WITHOUT_SHOW, PaymentErrorReason.USER_CANCEL);
}
@Test
@Feature({"Payments"})
public void testOnConnectionErrorFailsPayment() {
PaymentRequestService service = defaultBuilder().build();
Assert.assertFalse(mIsOnCloseListenerInvoked);
service.onConnectionError(null);
Assert.assertTrue(mIsOnCloseListenerInvoked);
}
@Test @Test
@Feature({"Payments"}) @Feature({"Payments"})
public void testNullOptionsFailsCreation() { public void testNullOptionsFailsCreation() {
......
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