Changeset 237594 in webkit


Ignore:
Timestamp:
Oct 30, 2018, 11:12:21 AM (6 years ago)
Author:
aestes@apple.com
Message:

[Apple Pay] PaymentRequest.canMakePayment() should resolve to true whenever Apple Pay is available
https://bugs.webkit.org/show_bug.cgi?id=191039

Reviewed by Megan Gardner.

Source/WebCore:

During a recent Web Payments WG F2F, we decided that canMakePayment() should return true
whenever the user agent supports one or more of the specified payment methods, even if those
payment methods do not have active instruments.

Change WebKit's implementation of canMakePayment() for Apple Pay to resolve with the value
of ApplePaySession.canMakePayments() rather than ApplePaySession.canMakePaymentsWithActiveCard().

Added a test case to http/tests/paymentrequest/payment-request-canmakepayment-method.https.html.

  • Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:

(WebCore::ApplePayPaymentHandler::canMakePayment):
(WebCore::shouldDiscloseApplePayCapability): Deleted.

  • testing/MockPaymentCoordinator.cpp:

(WebCore::MockPaymentCoordinator::canMakePayments):
(WebCore::MockPaymentCoordinator::canMakePaymentsWithActiveCard):

  • testing/MockPaymentCoordinator.h:
  • testing/MockPaymentCoordinator.idl:

LayoutTests:

  • http/tests/paymentrequest/payment-request-canmakepayment-method.https-expected.txt:
  • http/tests/paymentrequest/payment-request-canmakepayment-method.https.html:
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r237592 r237594  
     12018-10-30  Andy Estes  <aestes@apple.com>
     2
     3        [Apple Pay] PaymentRequest.canMakePayment() should resolve to true whenever Apple Pay is available
     4        https://bugs.webkit.org/show_bug.cgi?id=191039
     5
     6        Reviewed by Megan Gardner.
     7
     8        * http/tests/paymentrequest/payment-request-canmakepayment-method.https-expected.txt:
     9        * http/tests/paymentrequest/payment-request-canmakepayment-method.https.html:
     10
    1112018-10-30  Dawei Fenton  <realdawei@apple.com>
    212
  • trunk/LayoutTests/http/tests/paymentrequest/payment-request-canmakepayment-method.https-expected.txt

    r228331 r237594  
    77PASS If payment method identifier is unknown, resolve promise with false.
    88PASS Optionally, at the user agent's discretion, return a promise rejected with a "NotAllowedError" DOMException.
     9PASS Return a promise that resolves to true when Apple Pay is available, even if there isn't an active card.
    910
  • trunk/LayoutTests/http/tests/paymentrequest/payment-request-canmakepayment-method.https.html

    r228331 r237594  
    1010<script src="/resources/testharness.js"></script>
    1111<script src="/resources/testharnessreport.js"></script>
     12<body>
    1213<script>
    1314const applePay = Object.freeze({
     
    183184  }
    184185}, `Optionally, at the user agent's discretion, return a promise rejected with a "NotAllowedError" DOMException.`);
     186
     187promise_test(async t => {
     188  internals.mockPaymentCoordinator.setCanMakePaymentsWithActiveCard(false);
     189  const request = new PaymentRequest(defaultMethods, defaultDetails);
     190  assert_true(
     191    await request.canMakePayment(),
     192    `canMakePaymentPromise should be true`
     193  );
     194  internals.mockPaymentCoordinator.setCanMakePaymentsWithActiveCard(true);
     195}, `Return a promise that resolves to true when Apple Pay is available, even if there isn't an active card.`);
    185196</script>
  • trunk/Source/WebCore/ChangeLog

    r237591 r237594  
     12018-10-30  Andy Estes  <aestes@apple.com>
     2
     3        [Apple Pay] PaymentRequest.canMakePayment() should resolve to true whenever Apple Pay is available
     4        https://bugs.webkit.org/show_bug.cgi?id=191039
     5
     6        Reviewed by Megan Gardner.
     7
     8        During a recent Web Payments WG F2F, we decided that canMakePayment() should return true
     9        whenever the user agent supports one or more of the specified payment methods, even if those
     10        payment methods do not have active instruments.
     11
     12        Change WebKit's implementation of canMakePayment() for Apple Pay to resolve with the value
     13        of ApplePaySession.canMakePayments() rather than ApplePaySession.canMakePaymentsWithActiveCard().
     14
     15        Added a test case to http/tests/paymentrequest/payment-request-canmakepayment-method.https.html.
     16
     17        * Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
     18        (WebCore::ApplePayPaymentHandler::canMakePayment):
     19        (WebCore::shouldDiscloseApplePayCapability): Deleted.
     20        * testing/MockPaymentCoordinator.cpp:
     21        (WebCore::MockPaymentCoordinator::canMakePayments):
     22        (WebCore::MockPaymentCoordinator::canMakePaymentsWithActiveCard):
     23        * testing/MockPaymentCoordinator.h:
     24        * testing/MockPaymentCoordinator.idl:
     25
    1262018-10-30  Sihui Liu  <sihui_liu@apple.com>
    227
  • trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp

    r237521 r237594  
    226226}
    227227
    228 static bool shouldDiscloseApplePayCapability(Document& document)
    229 {
    230     auto* page = document.page();
    231     if (!page || page->usesEphemeralSession())
    232         return false;
    233 
    234     return document.settings().applePayCapabilityDisclosureAllowed();
    235 }
    236 
    237228void ApplePayPaymentHandler::canMakePayment(Function<void(bool)>&& completionHandler)
    238229{
    239     if (!shouldDiscloseApplePayCapability(document())) {
    240         completionHandler(paymentCoordinator().canMakePayments());
    241         return;
    242     }
    243 
    244     paymentCoordinator().canMakePaymentsWithActiveCard(m_applePayRequest->merchantIdentifier, document().domain(), WTFMove(completionHandler));
    245 }
    246    
     230    completionHandler(paymentCoordinator().canMakePayments());
     231}
     232
    247233ExceptionOr<Vector<ApplePaySessionPaymentRequest::ShippingMethod>> ApplePayPaymentHandler::computeShippingMethods()
    248234{
  • trunk/Source/WebCore/testing/MockPaymentCoordinator.cpp

    r237238 r237594  
    7878bool MockPaymentCoordinator::canMakePayments()
    7979{
    80     return true;
     80    return m_canMakePayments;
    8181}
    8282
    8383void MockPaymentCoordinator::canMakePaymentsWithActiveCard(const String&, const String&, Function<void(bool)>&& completionHandler)
    8484{
    85     RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler)] {
    86         completionHandler(true);
     85    RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler), canMakePaymentsWithActiveCard = m_canMakePaymentsWithActiveCard] {
     86        completionHandler(canMakePaymentsWithActiveCard);
    8787    });
    8888}
  • trunk/Source/WebCore/testing/MockPaymentCoordinator.h

    r237142 r237594  
    4545    explicit MockPaymentCoordinator(Page&);
    4646
     47    void setCanMakePayments(bool canMakePayments) { m_canMakePayments = canMakePayments; }
     48    void setCanMakePaymentsWithActiveCard(bool canMakePaymentsWithActiveCard) { m_canMakePaymentsWithActiveCard = canMakePaymentsWithActiveCard; }
    4749    void setShippingAddress(MockPaymentAddress&& shippingAddress) { m_shippingAddress = WTFMove(shippingAddress); }
    4850    void changeShippingOption(String&& shippingOption);
     
    7880
    7981    Page& m_page;
     82    bool m_canMakePayments { true };
     83    bool m_canMakePaymentsWithActiveCard { true };
    8084    ApplePayPaymentContact m_shippingAddress;
    8185    ApplePayLineItem m_total;
  • trunk/Source/WebCore/testing/MockPaymentCoordinator.idl

    r237142 r237594  
    2828    NoInterfaceObject,
    2929] interface MockPaymentCoordinator {
     30    void setCanMakePayments(boolean canMakePayments);
     31    void setCanMakePaymentsWithActiveCard(boolean canMakePaymentsWithActiveCard);
    3032    void setShippingAddress(MockPaymentAddress shippingAddress);
    3133    void changeShippingOption(DOMString shippingOption);
Note: See TracChangeset for help on using the changeset viewer.