Skip to content
Permalink
Browse files
[Payment Request] Implement PaymentRequest.show() and PaymentRequest.…
…hide()

https://bugs.webkit.org/show_bug.cgi?id=178043
<rdar://problem/34076639>

Reviewed by Tim Horton.

LayoutTests/imported/w3c:

* web-platform-tests/payment-request/payment-request-abort-method.https-expected.txt: Removed.
* web-platform-tests/payment-request/payment-request-show-method.https-expected.txt: Removed.

Source/WebCore:

Tests: http/tests/paymentrequest/payment-request-abort-method.https.html
       http/tests/paymentrequest/payment-request-show-method.https.html

* Modules/applepay/PaymentCoordinator.h:
* Modules/applepay/PaymentSession.h: Virtually inherited from PaymentSessionBase to
accommodate ApplePayPaymentHandler inheriting from both this and PaymentHandler.
(WebCore::PaymentSession::~PaymentSession): Deleted.
* Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
(WebCore::paymentCoordinator): Virtually inherited from PaymentSessionBase to accommodate
ApplePayPaymentHandler inheriting from both this and PaymentSession.
(WebCore::ApplePayPaymentHandler::hasActiveSession): Added. Calls PaymentCoordinator::hasActiveSession().
(WebCore::ApplePayPaymentHandler::show): Added. Calls PaymentCoordinator::beginPaymentSession().
(WebCore::ApplePayPaymentHandler::hide): Added. Calls PaymentCoordinator::abortPaymentSession().
* Modules/applepay/paymentrequest/ApplePayPaymentHandler.h: Inherited from PaymentSession in
addition to PaymentHandler so that this can be PaymentCoordinator active session.
* Modules/paymentrequest/PaymentHandler.cpp:
(WebCore::PaymentHandler::create):
(WebCore::PaymentHandler::hasActiveSession):
* Modules/paymentrequest/PaymentHandler.h:
* Modules/paymentrequest/PaymentRequest.cpp:
(WebCore::PaymentRequest::~PaymentRequest):
(WebCore::PaymentRequest::show): Rejected the promise if PaymentCoordinator has an active session.
(WebCore::PaymentRequest::abort): Called stop().
(WebCore::PaymentRequest::canSuspendForDocumentSuspension const): Returned true if state is
Interactive and there is an active handler showing.
(WebCore::PaymentRequest::stop): Hid the active session if it's showing, then set state to
Closed and rejected the show promise.
* Modules/paymentrequest/PaymentRequest.h:
* Modules/paymentrequest/PaymentSessionBase.h: Added. Inherits from
RefCounted<PaymentSessionBase> and defines a virtual destructor. This allows subclasses to
virtually inherit a single ref-count to support multiple inheritance.
* WebCore.xcodeproj/project.pbxproj:
* bindings/scripts/CodeGeneratorJS.pm:
(GetGnuVTableOffsetForType): Added ApplePaySession to the list of classes that need a vtable
offset of 3.
* page/MainFrame.cpp:
(WebCore::MainFrame::setPaymentCoordinator): Added a setter for m_paymentCoordinator.
* page/MainFrame.h:
* testing/Internals.cpp:
(WebCore::Internals::Internals): Set the main frame's payment coordinator to a new
PaymentCoordinator with MockPaymentCoordinator as its client.
* testing/MockPaymentCoordinator.cpp: Added a mock PaymentCoordinatorClient for testing.
(WebCore::MockPaymentCoordinator::supportsVersion):
(WebCore::MockPaymentCoordinator::canMakePayments):
(WebCore::MockPaymentCoordinator::canMakePaymentsWithActiveCard):
(WebCore::MockPaymentCoordinator::openPaymentSetup):
(WebCore::MockPaymentCoordinator::showPaymentUI):
(WebCore::MockPaymentCoordinator::paymentCoordinatorDestroyed):
* testing/MockPaymentCoordinator.h: Added.

LayoutTests:

Copied payment-request-abort-method.https.html and payment-request-show-method.https.html
from web-platform-tests/payment-request/ and changed the payment method from basic-card to
Apple Pay. This needs to eventually be upstreamed back to WPT.

* TestExpectations:
* http/tests/paymentrequest/payment-request-abort-method.https-expected.txt: Added.
* http/tests/paymentrequest/payment-request-abort-method.https.html: Added.
* http/tests/paymentrequest/payment-request-show-method.https-expected.txt: Added.
* http/tests/paymentrequest/payment-request-show-method.https.html: Added.
* platform/ios-wk2/TestExpectations:
* platform/mac-wk2/TestExpectations:


Canonical link: https://commits.webkit.org/194345@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223076 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
aestes committed Oct 9, 2017
1 parent 0822a2c commit 5aab31cd0e177c2cc2e7ae5cf0a78e9d8b8d9395
Showing 28 changed files with 579 additions and 60 deletions.
@@ -1,3 +1,23 @@
2017-10-09 Andy Estes <aestes@apple.com>

[Payment Request] Implement PaymentRequest.show() and PaymentRequest.hide()
https://bugs.webkit.org/show_bug.cgi?id=178043
<rdar://problem/34076639>

Reviewed by Tim Horton.

Copied payment-request-abort-method.https.html and payment-request-show-method.https.html
from web-platform-tests/payment-request/ and changed the payment method from basic-card to
Apple Pay. This needs to eventually be upstreamed back to WPT.

* TestExpectations:
* http/tests/paymentrequest/payment-request-abort-method.https-expected.txt: Added.
* http/tests/paymentrequest/payment-request-abort-method.https.html: Added.
* http/tests/paymentrequest/payment-request-show-method.https-expected.txt: Added.
* http/tests/paymentrequest/payment-request-show-method.https.html: Added.
* platform/ios-wk2/TestExpectations:
* platform/mac-wk2/TestExpectations:

2017-10-09 Youenn Fablet <youenn@apple.com>

Add quota to cache API
@@ -148,6 +148,7 @@ fast/text/accessibility-bold-system-font-2.html [ Skip ]
fast/text/font-lookup-dot-prefix-case-sensitive.html [ Skip ]

# Payment Request is only enabled on Cocoa platforms.
http/tests/paymentrequest [ Skip ]
imported/w3c/web-platform-tests/payment-request [ Skip ]

imported/w3c/web-platform-tests/2dcontext/transformations/canvas_transformations_reset_001.html [ ImageOnlyFailure ]
@@ -0,0 +1,5 @@

PASS Throws if the promise [[state]] is not "interactive"
PASS Calling abort must not change the [[state]] until after "interactive"
PASS calling .abort() causes acceptPromise to reject and closes the request.

@@ -0,0 +1,76 @@
<!DOCTYPE html>
<!-- Copyright © 2017 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
<!-- Copyright (C) 2017 Apple Inc. All rights reserved. -->
<!-- FIXME: Upstream this test to web-platform-tests/payment-request/. -->
<meta charset="utf-8">
<title>Test for PaymentRequest.abort() method</title>
<link rel="help" href="https://w3c.github.io/browser-payment-api/#abort-method">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
"use strict";
setup(() => {}, {
// Ignore unhandled rejections resulting from .show()'s acceptPromise
// not being explicitly handled.
allow_uncaught_exception: true,
});
const applePay = Object.freeze({
supportedMethods: "https://apple.com/apple-pay",
data: {
version: 2,
merchantCapabilities: ['supports3DS'],
supportedNetworks: ['visa', 'masterCard'],
countryCode: 'US',
currencyCode: 'USD',
},
});
const defaultMethods = Object.freeze([applePay]);
const defaultDetails = Object.freeze({
total: {
label: "Total",
amount: {
currency: "USD",
value: "1.00",
},
},
});

promise_test(async t => {
// request is in "created" state
const request = new PaymentRequest(defaultMethods, defaultDetails);
await promise_rejects(t, "InvalidStateError", request.abort());
}, `Throws if the promise [[state]] is not "interactive"`);

promise_test(async t => {
// request is in "created" state.
const request = new PaymentRequest(defaultMethods, defaultDetails);
await promise_rejects(t, "InvalidStateError", request.abort());
// Call it again, for good measure.
await promise_rejects(t, "InvalidStateError", request.abort());
// The request's state is "created", so let's show it
// which changes the state to "interactive.".
request.show();
// Let's set request the state to "closed" by calling .abort()
try {
await request.abort();
} catch (err) {
assert_true(false, "Unexpected promise rejection: " + err.message);
}
// The request is now "closed", so...
await promise_rejects(t, "InvalidStateError", request.abort());
}, `Calling abort must not change the [[state]] until after "interactive"`);

promise_test(async t => {
const request = new PaymentRequest(defaultMethods, defaultDetails);
const acceptPromise = request.show();
try {
await request.abort();
} catch (err) {
assert_true(false, "Unexpected promise rejection: " + err.message);
}
await promise_rejects(t, "AbortError", acceptPromise);
// As request is now "closed", trying to show it will fail
await promise_rejects(t, "InvalidStateError", request.show());
}, "calling .abort() causes acceptPromise to reject and closes the request.");

</script>
@@ -0,0 +1,6 @@

PASS Must be possible to construct a payment request
PASS Throws if the promise [[state]] is not "created"
PASS If the user agent's "payment request is showing" boolean is true, then return a promise rejected with an "AbortError" DOMException.
PASS If payment method consultation produces no supported method of payment, then return a promise rejected with a "NotSupportedError" DOMException.

@@ -0,0 +1,68 @@
<!DOCTYPE html>
<!-- Copyright © 2017 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
<!-- Copyright (C) 2017 Apple Inc. All rights reserved. -->
<!-- FIXME: Upstream this test to web-platform-tests/payment-request/. -->
<meta charset="utf-8">
<title>Test for PaymentRequest.show() method</title>
<link rel="help" href="https://w3c.github.io/browser-payment-api/#show-method">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
'use strict';
const applePay = Object.freeze({
supportedMethods: "https://apple.com/apple-pay",
data: {
version: 2,
merchantCapabilities: ['supports3DS'],
supportedNetworks: ['visa', 'masterCard'],
countryCode: 'US',
currencyCode: 'USD',
},
});
const defaultMethods = Object.freeze([applePay]);
const defaultDetails = Object.freeze({
total: {
label: "Total",
amount: {
currency: "USD",
value: "1.00",
},
},
});

test(() => {
try {
new PaymentRequest(defaultMethods, defaultDetails);
} catch (err) {
done();
throw err;
}
}, "Must be possible to construct a payment request");


promise_test(async t => {
const request = new PaymentRequest(defaultMethods, defaultDetails);
const acceptPromise = request.show(); // Sets state to "interactive"
await promise_rejects(t, "InvalidStateError", request.show());
await request.abort();
await promise_rejects(t, "AbortError", acceptPromise);
}, `Throws if the promise [[state]] is not "created"`);

promise_test(async t => {
const request1 = new PaymentRequest(defaultMethods, defaultDetails);
const request2 = new PaymentRequest(defaultMethods, defaultDetails);
const acceptPromise1 = request1.show();
const acceptPromise2 = request2.show();
await promise_rejects(t, "AbortError", acceptPromise2);
await request1.abort();
await promise_rejects(t, "AbortError", acceptPromise1);
}, `If the user agent's "payment request is showing" boolean is true, then return a promise rejected with an "AbortError" DOMException.`);

promise_test(async t => {
const request = new PaymentRequest(
[{ supportedMethods: "this-is-not-supported" }],
defaultDetails);
const acceptPromise = request.show();
await promise_rejects(t, "NotSupportedError", acceptPromise);
}, `If payment method consultation produces no supported method of payment, then return a promise rejected with a "NotSupportedError" DOMException.`);
</script>
@@ -1,3 +1,14 @@
2017-10-09 Andy Estes <aestes@apple.com>

[Payment Request] Implement PaymentRequest.show() and PaymentRequest.hide()
https://bugs.webkit.org/show_bug.cgi?id=178043
<rdar://problem/34076639>

Reviewed by Tim Horton.

* web-platform-tests/payment-request/payment-request-abort-method.https-expected.txt: Removed.
* web-platform-tests/payment-request/payment-request-show-method.https-expected.txt: Removed.

2017-10-09 Youenn Fablet <youenn@apple.com>

REGRESSION: Some bots fail to run LayoutTests due to a WPT Server error

This file was deleted.

This file was deleted.

@@ -28,14 +28,17 @@ fast/viewport/ios/viewport-fit-contain.html [ Skip ]
fast/viewport/ios/viewport-fit-cover.html [ Skip ]
fast/viewport/ios/viewport-fit-auto.html [ Skip ]

http/tests/paymentrequest [ Pass ]
imported/w3c/web-platform-tests/payment-request [ Pass ]
webkit.org/b/175611 imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/allowpaymentrequest-attribute-cross-origin-bc-containers.https.html [ Skip ]
webkit.org/b/175611 imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/no-attribute-cross-origin-bc-containers.https.html [ Skip ]
webkit.org/b/175611 imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/removing-allowpaymentrequest.https.sub.html [ Skip ]
webkit.org/b/175611 imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/setting-allowpaymentrequest-timing.https.sub.html [ Skip ]
webkit.org/b/175611 imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/setting-allowpaymentrequest.https.sub.html [ Skip ]
webkit.org/b/177391 imported/w3c/web-platform-tests/payment-request/payment-request-show-method.https.html [ Pass Failure ]
webkit.org/b/177391 imported/w3c/web-platform-tests/payment-request/payment-request-abort-method.https.html [ Pass Failure ]

# skip in favor of tests in http/tests/paymentrequest
imported/w3c/web-platform-tests/payment-request/payment-request-show-method.https.html [ WontFix ]
imported/w3c/web-platform-tests/payment-request/payment-request-abort-method.https.html [ WontFix ]

# skip manual payment-request tests
imported/w3c/web-platform-tests/payment-request/algorithms-manual.https.html [ Skip ]
@@ -25,15 +25,18 @@ fast/media/mq-prefers-reduced-motion-live-update.html [ Pass ]
fast/visual-viewport/rubberbanding-viewport-rects.html [ Pass ]
fast/visual-viewport/rubberbanding-viewport-rects-header-footer.html [ Pass ]

imported/w3c/web-platform-tests/payment-request [ Pass ]
[ Sierra+ ] http/tests/paymentrequest [ Pass ]
[ Sierra+ ] imported/w3c/web-platform-tests/payment-request [ Pass ]
webkit.org/b/175611 imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/allowpaymentrequest-attribute-cross-origin-bc-containers.https.html [ Skip ]
webkit.org/b/175611 imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/no-attribute-cross-origin-bc-containers.https.html [ Skip ]
webkit.org/b/175611 imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/removing-allowpaymentrequest.https.sub.html [ Skip ]
webkit.org/b/175611 imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/setting-allowpaymentrequest-timing.https.sub.html [ Skip ]
webkit.org/b/175611 imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/setting-allowpaymentrequest.https.sub.html [ Skip ]
webkit.org/b/177783 imported/w3c/web-platform-tests/payment-request/rejects_if_not_active.https.html [ Skip ]
webkit.org/b/177391 imported/w3c/web-platform-tests/payment-request/payment-request-show-method.https.html [ Pass Failure ]
webkit.org/b/177391 imported/w3c/web-platform-tests/payment-request/payment-request-abort-method.https.html [ Pass Failure ]

# skip in favor of tests in http/tests/paymentrequest
imported/w3c/web-platform-tests/payment-request/payment-request-show-method.https.html [ WontFix ]
imported/w3c/web-platform-tests/payment-request/payment-request-abort-method.https.html [ WontFix ]

# skip manual payment-request tests
imported/w3c/web-platform-tests/payment-request/algorithms-manual.https.html [ Skip ]
@@ -1,3 +1,61 @@
2017-10-09 Andy Estes <aestes@apple.com>

[Payment Request] Implement PaymentRequest.show() and PaymentRequest.hide()
https://bugs.webkit.org/show_bug.cgi?id=178043
<rdar://problem/34076639>

Reviewed by Tim Horton.

Tests: http/tests/paymentrequest/payment-request-abort-method.https.html
http/tests/paymentrequest/payment-request-show-method.https.html

* Modules/applepay/PaymentCoordinator.h:
* Modules/applepay/PaymentSession.h: Virtually inherited from PaymentSessionBase to
accommodate ApplePayPaymentHandler inheriting from both this and PaymentHandler.
(WebCore::PaymentSession::~PaymentSession): Deleted.
* Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
(WebCore::paymentCoordinator): Virtually inherited from PaymentSessionBase to accommodate
ApplePayPaymentHandler inheriting from both this and PaymentSession.
(WebCore::ApplePayPaymentHandler::hasActiveSession): Added. Calls PaymentCoordinator::hasActiveSession().
(WebCore::ApplePayPaymentHandler::show): Added. Calls PaymentCoordinator::beginPaymentSession().
(WebCore::ApplePayPaymentHandler::hide): Added. Calls PaymentCoordinator::abortPaymentSession().
* Modules/applepay/paymentrequest/ApplePayPaymentHandler.h: Inherited from PaymentSession in
addition to PaymentHandler so that this can be PaymentCoordinator active session.
* Modules/paymentrequest/PaymentHandler.cpp:
(WebCore::PaymentHandler::create):
(WebCore::PaymentHandler::hasActiveSession):
* Modules/paymentrequest/PaymentHandler.h:
* Modules/paymentrequest/PaymentRequest.cpp:
(WebCore::PaymentRequest::~PaymentRequest):
(WebCore::PaymentRequest::show): Rejected the promise if PaymentCoordinator has an active session.
(WebCore::PaymentRequest::abort): Called stop().
(WebCore::PaymentRequest::canSuspendForDocumentSuspension const): Returned true if state is
Interactive and there is an active handler showing.
(WebCore::PaymentRequest::stop): Hid the active session if it's showing, then set state to
Closed and rejected the show promise.
* Modules/paymentrequest/PaymentRequest.h:
* Modules/paymentrequest/PaymentSessionBase.h: Added. Inherits from
RefCounted<PaymentSessionBase> and defines a virtual destructor. This allows subclasses to
virtually inherit a single ref-count to support multiple inheritance.
* WebCore.xcodeproj/project.pbxproj:
* bindings/scripts/CodeGeneratorJS.pm:
(GetGnuVTableOffsetForType): Added ApplePaySession to the list of classes that need a vtable
offset of 3.
* page/MainFrame.cpp:
(WebCore::MainFrame::setPaymentCoordinator): Added a setter for m_paymentCoordinator.
* page/MainFrame.h:
* testing/Internals.cpp:
(WebCore::Internals::Internals): Set the main frame's payment coordinator to a new
PaymentCoordinator with MockPaymentCoordinator as its client.
* testing/MockPaymentCoordinator.cpp: Added a mock PaymentCoordinatorClient for testing.
(WebCore::MockPaymentCoordinator::supportsVersion):
(WebCore::MockPaymentCoordinator::canMakePayments):
(WebCore::MockPaymentCoordinator::canMakePaymentsWithActiveCard):
(WebCore::MockPaymentCoordinator::openPaymentSetup):
(WebCore::MockPaymentCoordinator::showPaymentUI):
(WebCore::MockPaymentCoordinator::paymentCoordinatorDestroyed):
* testing/MockPaymentCoordinator.h: Added.

2017-10-09 Youenn Fablet <youenn@apple.com>

Add quota to cache API
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015, 2016 Apple Inc. All rights reserved.
* Copyright (C) 2015-2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -47,8 +47,8 @@ struct ShippingMethodUpdate;

class PaymentCoordinator {
public:
explicit PaymentCoordinator(PaymentCoordinatorClient&);
~PaymentCoordinator();
WEBCORE_EXPORT explicit PaymentCoordinator(PaymentCoordinatorClient&);
WEBCORE_EXPORT ~PaymentCoordinator();

bool supportsVersion(unsigned version);
bool canMakePayments();
@@ -28,7 +28,7 @@
#if ENABLE(APPLE_PAY)

#include "ApplePaySessionPaymentRequest.h"
#include <wtf/RefCounted.h>
#include "PaymentSessionBase.h"

namespace WebCore {

@@ -37,10 +37,8 @@ class PaymentContact;
class PaymentMethod;
class URL;

class PaymentSession : public RefCounted<PaymentSession> {
class PaymentSession : public virtual PaymentSessionBase {
public:
virtual ~PaymentSession() { }

virtual void validateMerchant(const URL&) = 0;
virtual void didAuthorizePayment(const Payment&) = 0;
virtual void didSelectShippingMethod(const ApplePaySessionPaymentRequest::ShippingMethod&) = 0;

0 comments on commit 5aab31c

Please sign in to comment.