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

[WebLayer] Create structural hooks for show-ui, trigger-ui-skip

This CL causes no behavioural change.

Motivation:
This CL adds structural hooks to encapsulate the following methods:
- ensureHasSupportedPaymentMethods
- showAppSelector
- triggerPaymentAppUiSkipIfApplicable

Changes:
* Added two structural hooks:
 - OnShowCalledAndAppsQueried(), for ensureHasSupportedPaymentMethods,
   showAppSelector
 - OnShowCalledAndAppsQueriedAndDetailsFinalized(), for
   triggerPaymentAppUiSkipIfApplicable

Bug: 1153353
Change-Id: I12f4996a48d0110d7bf858151530694204d59acf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2563020
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#832338}
parent 8f68600e
...@@ -262,7 +262,7 @@ public class ChromePaymentRequestService ...@@ -262,7 +262,7 @@ public class ChromePaymentRequestService
// Implements BrowserPaymentRequest: // Implements BrowserPaymentRequest:
@Override @Override
public String triggerPaymentAppUiSkipIfApplicable(boolean isUserGestureShow) { public String onShowCalledAndAppsQueriedAndDetailsFinalized(boolean isUserGestureShow) {
// If we are skipping showing the Payment Request UI, we should call into the payment app // If we are skipping showing the Payment Request UI, we should call into the payment app
// immediately after we determine the apps are ready and UI is shown. // immediately after we determine the apps are ready and UI is shown.
if (mShouldSkipShowingPaymentRequestUi || mSkipToGPayHelper != null) { if (mShouldSkipShowingPaymentRequestUi || mSkipToGPayHelper != null) {
......
...@@ -143,13 +143,13 @@ public interface BrowserPaymentRequest { ...@@ -143,13 +143,13 @@ public interface BrowserPaymentRequest {
void notifyPaymentUiOfPendingApps(List<PaymentApp> pendingApps); void notifyPaymentUiOfPendingApps(List<PaymentApp> pendingApps);
/** /**
* Skips the app selector UI whether it is currently opened or not, and if applicable, invokes a * Called when these conditions are satisfied: (1) show() has been called, (2) payment apps
* payment app. * are all queried, and (3) PaymentDetails is finalized.
* @return The error if it fails; null otherwise. * @return The error if it fails; null otherwise.
* @param isUserGestureShow Whether PaymentRequest.show() was invoked with a user gesture. * @param isUserGestureShow Whether PaymentRequest.show() was invoked with a user gesture.
*/ */
@Nullable @Nullable
default String triggerPaymentAppUiSkipIfApplicable(boolean isUserGestureShow) { default String onShowCalledAndAppsQueriedAndDetailsFinalized(boolean isUserGestureShow) {
return null; return null;
} }
......
...@@ -749,23 +749,11 @@ public class PaymentRequestService ...@@ -749,23 +749,11 @@ public class PaymentRequestService
mBrowserPaymentRequest.notifyPaymentUiOfPendingApps(mPendingApps); mBrowserPaymentRequest.notifyPaymentUiOfPendingApps(mPendingApps);
mPendingApps.clear(); mPendingApps.clear();
if (mIsShowCalled) { if (mIsShowCalled) {
PaymentNotShownError notShownError = ensureHasSupportedPaymentMethods(); PaymentNotShownError notShownError = onShowCalledAndAppsQueried();
if (notShownError != null) { if (notShownError != null) {
onShowFailed(notShownError); onShowFailed(notShownError);
return; return;
} }
String error = mBrowserPaymentRequest.showAppSelector(mIsShowWaitingForUpdatedDetails,
mSpec.getRawTotal(), mSpec.getPaymentOptions(), mIsUserGestureShow);
if (error != null) {
onShowFailed(error);
return;
}
}
String error = triggerPaymentAppUiSkipIfApplicable();
if (error != null) {
onShowFailed(error);
return;
} }
if (mIsCanMakePaymentResponsePending) { if (mIsCanMakePaymentResponsePending) {
...@@ -777,6 +765,33 @@ public class PaymentRequestService ...@@ -777,6 +765,33 @@ public class PaymentRequestService
} }
} }
@Nullable
private PaymentNotShownError onShowCalledAndAppsQueried() {
assert mIsShowCalled;
assert mIsFinishedQueryingPaymentApps;
assert mBrowserPaymentRequest != null;
PaymentNotShownError ensureError = ensureHasSupportedPaymentMethods();
if (ensureError != null) return ensureError;
String showError = mBrowserPaymentRequest.showAppSelector(mIsShowWaitingForUpdatedDetails,
mSpec.getRawTotal(), mSpec.getPaymentOptions(), mIsUserGestureShow);
if (showError != null) {
return new PaymentNotShownError(
NotShownReason.OTHER, showError, PaymentErrorReason.NOT_SUPPORTED);
}
if (mIsShowWaitingForUpdatedDetails) return null;
String error = mBrowserPaymentRequest.onShowCalledAndAppsQueriedAndDetailsFinalized(
mIsUserGestureShow);
if (error != null) {
return new PaymentNotShownError(
NotShownReason.OTHER, error, PaymentErrorReason.NOT_SUPPORTED);
}
return null;
}
private void onShowFailed(String error) { private void onShowFailed(String error) {
onShowFailed(NotShownReason.OTHER, error, PaymentErrorReason.USER_CANCEL); onShowFailed(NotShownReason.OTHER, error, PaymentErrorReason.USER_CANCEL);
} }
...@@ -1035,34 +1050,12 @@ public class PaymentRequestService ...@@ -1035,34 +1050,12 @@ public class PaymentRequestService
mJourneyLogger.setTriggerTime(); mJourneyLogger.setTriggerTime();
if (mIsFinishedQueryingPaymentApps) { if (mIsFinishedQueryingPaymentApps) {
PaymentNotShownError notShownError = ensureHasSupportedPaymentMethods(); PaymentNotShownError notShownError = onShowCalledAndAppsQueried();
if (notShownError != null) { if (notShownError != null) {
onShowFailed(notShownError); onShowFailed(notShownError);
return; return;
} }
String error = mBrowserPaymentRequest.showAppSelector(mIsShowWaitingForUpdatedDetails,
mSpec.getRawTotal(), mSpec.getPaymentOptions(), mIsUserGestureShow);
if (error != null) {
onShowFailed(error);
return;
}
} }
String error = triggerPaymentAppUiSkipIfApplicable();
if (error != null) {
onShowFailed(error);
return;
}
}
// Return the error if failed, null if success.
@Nullable
private String triggerPaymentAppUiSkipIfApplicable() {
if (mHasClosed || !mIsFinishedQueryingPaymentApps || !mIsShowCalled
|| mIsShowWaitingForUpdatedDetails) {
return null;
}
return mBrowserPaymentRequest.triggerPaymentAppUiSkipIfApplicable(mIsUserGestureShow);
} }
/** /**
...@@ -1158,6 +1151,7 @@ public class PaymentRequestService ...@@ -1158,6 +1151,7 @@ public class PaymentRequestService
private String continueShow(@Nullable PaymentDetails details) { private String continueShow(@Nullable PaymentDetails details) {
assert mIsShowWaitingForUpdatedDetails; assert mIsShowWaitingForUpdatedDetails;
assert mBrowserPaymentRequest != null;
// mSpec.updateWith() can be used only when mSpec has not been destroyed. // mSpec.updateWith() can be used only when mSpec has not been destroyed.
assert !mSpec.isDestroyed(); assert !mSpec.isDestroyed();
...@@ -1173,7 +1167,10 @@ public class PaymentRequestService ...@@ -1173,7 +1167,10 @@ public class PaymentRequestService
mIsShowWaitingForUpdatedDetails = false; mIsShowWaitingForUpdatedDetails = false;
String error = mBrowserPaymentRequest.continueShow(mIsFinishedQueryingPaymentApps); String error = mBrowserPaymentRequest.continueShow(mIsFinishedQueryingPaymentApps);
if (error != null) return error; if (error != null) return error;
return triggerPaymentAppUiSkipIfApplicable();
if (!mIsFinishedQueryingPaymentApps) return null;
return mBrowserPaymentRequest.onShowCalledAndAppsQueriedAndDetailsFinalized(
mIsUserGestureShow);
} }
/** /**
......
...@@ -540,10 +540,10 @@ public class PaymentRequestServiceTest implements PaymentRequestClient { ...@@ -540,10 +540,10 @@ public class PaymentRequestServiceTest implements PaymentRequestClient {
PaymentRequestService service = defaultBuilder().build(); PaymentRequestService service = defaultBuilder().build();
show(service); show(service);
Mockito.verify(mBrowserPaymentRequest, Mockito.never()) Mockito.verify(mBrowserPaymentRequest, Mockito.never())
.triggerPaymentAppUiSkipIfApplicable(Mockito.anyBoolean()); .onShowCalledAndAppsQueriedAndDetailsFinalized(Mockito.anyBoolean());
queryPaymentApps(); queryPaymentApps();
Mockito.verify(mBrowserPaymentRequest, Mockito.times(1)) Mockito.verify(mBrowserPaymentRequest, Mockito.times(1))
.triggerPaymentAppUiSkipIfApplicable(Mockito.anyBoolean()); .onShowCalledAndAppsQueriedAndDetailsFinalized(Mockito.anyBoolean());
} }
@Test @Test
...@@ -552,13 +552,28 @@ public class PaymentRequestServiceTest implements PaymentRequestClient { ...@@ -552,13 +552,28 @@ public class PaymentRequestServiceTest implements PaymentRequestClient {
PaymentRequestService service = defaultBuilder().build(); PaymentRequestService service = defaultBuilder().build();
service.show(mIsUserGestureDefaultValue, true); service.show(mIsUserGestureDefaultValue, true);
Mockito.verify(mBrowserPaymentRequest, Mockito.never()) Mockito.verify(mBrowserPaymentRequest, Mockito.never())
.triggerPaymentAppUiSkipIfApplicable(Mockito.anyBoolean()); .onShowCalledAndAppsQueriedAndDetailsFinalized(Mockito.anyBoolean());
queryPaymentApps(); queryPaymentApps();
Mockito.verify(mBrowserPaymentRequest, Mockito.never()) Mockito.verify(mBrowserPaymentRequest, Mockito.never())
.triggerPaymentAppUiSkipIfApplicable(Mockito.anyBoolean()); .onShowCalledAndAppsQueriedAndDetailsFinalized(Mockito.anyBoolean());
service.updateWith(getDefaultPaymentDetailsUpdate()); updateWith(service);
Mockito.verify(mBrowserPaymentRequest, Mockito.times(1))
.onShowCalledAndAppsQueriedAndDetailsFinalized(Mockito.anyBoolean());
}
@Test
@Feature({"Payments"})
public void testQueryFinishCanTriggerUiSkipped() {
PaymentRequestService service = defaultBuilder().build();
service.show(mIsUserGestureDefaultValue, true);
Mockito.verify(mBrowserPaymentRequest, Mockito.never())
.onShowCalledAndAppsQueriedAndDetailsFinalized(Mockito.anyBoolean());
updateWith(service);
Mockito.verify(mBrowserPaymentRequest, Mockito.never())
.onShowCalledAndAppsQueriedAndDetailsFinalized(Mockito.anyBoolean());
queryPaymentApps();
Mockito.verify(mBrowserPaymentRequest, Mockito.times(1)) Mockito.verify(mBrowserPaymentRequest, Mockito.times(1))
.triggerPaymentAppUiSkipIfApplicable(Mockito.anyBoolean()); .onShowCalledAndAppsQueriedAndDetailsFinalized(Mockito.anyBoolean());
} }
@Test @Test
......
...@@ -129,7 +129,7 @@ public class WebLayerPaymentRequestService implements BrowserPaymentRequest { ...@@ -129,7 +129,7 @@ public class WebLayerPaymentRequestService implements BrowserPaymentRequest {
// Implements BrowserPaymentRequest: // Implements BrowserPaymentRequest:
@Override @Override
@Nullable @Nullable
public String triggerPaymentAppUiSkipIfApplicable(boolean isUserGestureShow) { public String onShowCalledAndAppsQueriedAndDetailsFinalized(boolean isUserGestureShow) {
assert !mAvailableApps.isEmpty() assert !mAvailableApps.isEmpty()
: "triggerPaymentAppUiSkipIfApplicable() should be called only when there is any " : "triggerPaymentAppUiSkipIfApplicable() should be called only when there is any "
+ "available app."; + "available app.";
......
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