Title: [246056] trunk
Revision
246056
Author
[email protected]
Date
2019-06-03 23:36:05 -0700 (Mon, 03 Jun 2019)

Log Message

[Apple Pay] Disable script injection when canMakePayment APIs are called and return true
https://bugs.webkit.org/show_bug.cgi?id=198448
<rdar://problem/51323694>

Reviewed by Alex Christensen.

Source/WebCore:

Previously, only an active Apple Pay session would disable script injection in restricted
WKWebViews. However, this can result in websites rendering non-functional Apple Pay buttons
due to the race between the hosting app calling -evaluateJavaScript:completionHandler: and
the website calling canMakePayment APIs to determine whether to draw a button.

This patch makes it so that, if a website calls ApplePaySession's canMakePayments or
canMakePaymentsWithActiveCard, or PaymentRequest's canMakePayment, in a web view that has no
injected scripts, and those calls return true, future script injections from the hosting app
will be blocked.

Also, this patch removes the restrictions on the openPaymentSetup, supportsVersion, and
validatedPaymentNetwork APIs, since those APIs do not reveal transaction information and are
not used to determine whether to draw buttons.

Added new API tests.

* Modules/applepay/PaymentCoordinator.cpp:
(WebCore::PaymentCoordinator::supportsVersion const):
(WebCore::PaymentCoordinator::canMakePayments):
(WebCore::PaymentCoordinator::canMakePaymentsWithActiveCard):
(WebCore::PaymentCoordinator::openPaymentSetup):
(WebCore::PaymentCoordinator::beginPaymentSession):
(WebCore::PaymentCoordinator::validatedPaymentNetwork const):
(WebCore::PaymentCoordinator::setApplePayIsActiveIfAllowed const):
(WebCore::PaymentCoordinator::shouldAllowUserAgentScripts const):
(WebCore::PaymentCoordinator::shouldAllowApplePay const): Deleted.
* Modules/applepay/PaymentCoordinator.h:
* dom/Document.cpp:
(WebCore::Document::isApplePayActive const):
(WebCore::Document::setApplePayIsActive):
(WebCore::Document::hasStartedApplePaySession const): Deleted.
(WebCore::Document::setHasStartedApplePaySession): Deleted.
* dom/Document.h:
* testing/Internals.cpp:
(WebCore::Internals::setApplePayIsActive):
(WebCore::Internals::setHasStartedApplePaySession): Deleted.
* testing/Internals.h:
* testing/Internals.idl:

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/ApplePay.mm:
(-[TestApplePayAvailableScriptMessageHandler userContentController:didReceiveScriptMessage:]):
(-[TestApplePayActiveSessionScriptMessageHandler userContentController:didReceiveScriptMessage:]):
(TestWebKitAPI::TEST):
(TestWebKitAPI::runActiveSessionTest):
(-[TestApplePayScriptMessageHandler initWithAPIsAvailableExpectation:canMakePaymentsExpectation:]): Deleted.
(-[TestApplePayScriptMessageHandler userContentController:didReceiveScriptMessage:]): Deleted.
* TestWebKitAPI/Tests/WebKitCocoa/apple-pay-active-session.html:
* TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability-existing-object.html: Added.
* TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability-in-iframe.html:
* TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability.html:
* TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payment.html: Added.
* TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payments-with-active-card.html: Added.
* TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payments.html: Added.
* TestWebKitAPI/Tests/WebKitCocoa/apple-pay.js: Added.
(applePayRequestBase):
(applePayPaymentRequest):
(applePayMethod):
* TestWebKitAPI/cocoa/TestProtocol.mm:
(-[TestProtocol startLoading]):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (246055 => 246056)


--- trunk/Source/WebCore/ChangeLog	2019-06-04 05:05:14 UTC (rev 246055)
+++ trunk/Source/WebCore/ChangeLog	2019-06-04 06:36:05 UTC (rev 246056)
@@ -1,3 +1,50 @@
+2019-06-03  Andy Estes  <[email protected]>
+
+        [Apple Pay] Disable script injection when canMakePayment APIs are called and return true
+        https://bugs.webkit.org/show_bug.cgi?id=198448
+        <rdar://problem/51323694>
+
+        Reviewed by Alex Christensen.
+
+        Previously, only an active Apple Pay session would disable script injection in restricted
+        WKWebViews. However, this can result in websites rendering non-functional Apple Pay buttons
+        due to the race between the hosting app calling -evaluateJavaScript:completionHandler: and
+        the website calling canMakePayment APIs to determine whether to draw a button.
+
+        This patch makes it so that, if a website calls ApplePaySession's canMakePayments or
+        canMakePaymentsWithActiveCard, or PaymentRequest's canMakePayment, in a web view that has no
+        injected scripts, and those calls return true, future script injections from the hosting app
+        will be blocked.
+
+        Also, this patch removes the restrictions on the openPaymentSetup, supportsVersion, and
+        validatedPaymentNetwork APIs, since those APIs do not reveal transaction information and are
+        not used to determine whether to draw buttons.
+
+        Added new API tests.
+
+        * Modules/applepay/PaymentCoordinator.cpp:
+        (WebCore::PaymentCoordinator::supportsVersion const):
+        (WebCore::PaymentCoordinator::canMakePayments):
+        (WebCore::PaymentCoordinator::canMakePaymentsWithActiveCard):
+        (WebCore::PaymentCoordinator::openPaymentSetup):
+        (WebCore::PaymentCoordinator::beginPaymentSession):
+        (WebCore::PaymentCoordinator::validatedPaymentNetwork const):
+        (WebCore::PaymentCoordinator::setApplePayIsActiveIfAllowed const):
+        (WebCore::PaymentCoordinator::shouldAllowUserAgentScripts const):
+        (WebCore::PaymentCoordinator::shouldAllowApplePay const): Deleted.
+        * Modules/applepay/PaymentCoordinator.h:
+        * dom/Document.cpp:
+        (WebCore::Document::isApplePayActive const):
+        (WebCore::Document::setApplePayIsActive):
+        (WebCore::Document::hasStartedApplePaySession const): Deleted.
+        (WebCore::Document::setHasStartedApplePaySession): Deleted.
+        * dom/Document.h:
+        * testing/Internals.cpp:
+        (WebCore::Internals::setApplePayIsActive):
+        (WebCore::Internals::setHasStartedApplePaySession): Deleted.
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2019-06-03  Robin Morisset  <[email protected]>
 
         [WHLSL] Parsing and lexing the standard library is slow

Modified: trunk/Source/WebCore/Modules/applepay/PaymentCoordinator.cpp (246055 => 246056)


--- trunk/Source/WebCore/Modules/applepay/PaymentCoordinator.cpp	2019-06-04 05:05:14 UTC (rev 246055)
+++ trunk/Source/WebCore/Modules/applepay/PaymentCoordinator.cpp	2019-06-04 06:36:05 UTC (rev 246056)
@@ -56,11 +56,8 @@
     m_client.paymentCoordinatorDestroyed();
 }
 
-bool PaymentCoordinator::supportsVersion(Document& document, unsigned version) const
+bool PaymentCoordinator::supportsVersion(Document&, unsigned version) const
 {
-    if (!shouldAllowApplePay(document))
-        return false;
-
     auto supportsVersion = m_client.supportsVersion(version);
     RELEASE_LOG_IF_ALLOWED("supportsVersion(%d) -> %d", version, supportsVersion);
     return supportsVersion;
@@ -68,28 +65,38 @@
 
 bool PaymentCoordinator::canMakePayments(Document& document)
 {
-    if (!shouldAllowApplePay(document))
+    auto canMakePayments = m_client.canMakePayments();
+    RELEASE_LOG_IF_ALLOWED("canMakePayments() -> %d", canMakePayments);
+
+    if (!canMakePayments)
         return false;
 
-    auto canMakePayments = m_client.canMakePayments();
-    RELEASE_LOG_IF_ALLOWED("canMakePayments() -> %d", canMakePayments);
-    return canMakePayments;
+    if (!setApplePayIsActiveIfAllowed(document))
+        return false;
+
+    return true;
 }
 
 void PaymentCoordinator::canMakePaymentsWithActiveCard(Document& document, const String& merchantIdentifier, WTF::Function<void(bool)>&& completionHandler)
 {
-    if (!shouldAllowApplePay(document))
-        return completionHandler(false);
+    m_client.canMakePaymentsWithActiveCard(merchantIdentifier, document.domain(), [this, weakThis = makeWeakPtr(*this), document = makeWeakPtr(document), completionHandler = WTFMove(completionHandler)](bool canMakePayments) {
+        if (!weakThis)
+            return completionHandler(false);
 
-    RELEASE_LOG_IF_ALLOWED("canMakePaymentsWithActiveCard()");
-    m_client.canMakePaymentsWithActiveCard(merchantIdentifier, document.domain(), WTFMove(completionHandler));
+        RELEASE_LOG_IF_ALLOWED("canMakePaymentsWithActiveCard() -> %d", canMakePayments);
+
+        if (!canMakePayments)
+            return completionHandler(false);
+
+        if (!document || !setApplePayIsActiveIfAllowed(*document))
+            return completionHandler(false);
+
+        completionHandler(true);
+    });
 }
 
 void PaymentCoordinator::openPaymentSetup(Document& document, const String& merchantIdentifier, WTF::Function<void(bool)>&& completionHandler)
 {
-    if (!shouldAllowApplePay(document))
-        return completionHandler(false);
-
     RELEASE_LOG_IF_ALLOWED("openPaymentSetup()");
     m_client.openPaymentSetup(merchantIdentifier, document.domain(), WTFMove(completionHandler));
 }
@@ -98,7 +105,7 @@
 {
     ASSERT(!m_activeSession);
 
-    if (!shouldAllowApplePay(document))
+    if (!setApplePayIsActiveIfAllowed(document))
         return false;
 
     Vector<URL> linkIconURLs;
@@ -111,7 +118,6 @@
         return false;
 
     m_activeSession = &paymentSession;
-    document.setHasStartedApplePaySession();
     return true;
 }
 
@@ -239,11 +245,8 @@
     m_activeSession = nullptr;
 }
 
-Optional<String> PaymentCoordinator::validatedPaymentNetwork(Document& document, unsigned version, const String& paymentNetwork) const
+Optional<String> PaymentCoordinator::validatedPaymentNetwork(Document&, unsigned version, const String& paymentNetwork) const
 {
-    if (!shouldAllowApplePay(document))
-        return WTF::nullopt;
-
     if (version < 2 && equalIgnoringASCIICase(paymentNetwork, "jcb"))
         return WTF::nullopt;
 
@@ -269,37 +272,32 @@
     return shouldEnableAPIs;
 }
 
-bool PaymentCoordinator::shouldAllowApplePay(Document& document) const
+bool PaymentCoordinator::setApplePayIsActiveIfAllowed(Document& document) const
 {
-    if (m_client.supportsUnrestrictedApplePay()) {
-        RELEASE_LOG_IF_ALLOWED("shouldAllowApplePay() -> true (unrestricted client)");
-        return true;
-    }
-
     auto hasEvaluatedUserAgentScripts = document.hasEvaluatedUserAgentScripts();
     auto isRunningUserScripts = document.isRunningUserScripts();
-    if (hasEvaluatedUserAgentScripts || isRunningUserScripts) {
-        ASSERT(shouldAllowUserAgentScripts(document));
-        RELEASE_LOG_IF_ALLOWED("shouldAllowApplePay() -> false (hasEvaluatedUserAgentScripts: %d, isRunningUserScripts: %d)", hasEvaluatedUserAgentScripts, isRunningUserScripts);
+    auto supportsUnrestrictedApplePay = m_client.supportsUnrestrictedApplePay();
+
+    if (!supportsUnrestrictedApplePay && (hasEvaluatedUserAgentScripts || isRunningUserScripts)) {
+        ASSERT(!document.isApplePayActive());
+        RELEASE_LOG_IF_ALLOWED("setApplePayIsActiveIfAllowed() -> false (hasEvaluatedUserAgentScripts: %d, isRunningUserScripts: %d)", hasEvaluatedUserAgentScripts, isRunningUserScripts);
         return false;
     }
 
-    RELEASE_LOG_IF_ALLOWED("shouldAllowApplePay() -> true");
+    RELEASE_LOG_IF_ALLOWED("setApplePayIsActiveIfAllowed() -> true (supportsUnrestrictedApplePay: %d)", supportsUnrestrictedApplePay);
+    document.setApplePayIsActive();
     return true;
 }
 
 bool PaymentCoordinator::shouldAllowUserAgentScripts(Document& document) const
 {
-    if (m_client.supportsUnrestrictedApplePay())
+    if (m_client.supportsUnrestrictedApplePay() || !document.isApplePayActive())
         return true;
 
-    if (document.hasStartedApplePaySession()) {
-        ASSERT(shouldAllowApplePay(document));
-        RELEASE_LOG_ERROR_IF_ALLOWED("shouldAllowUserAgentScripts() -> false (active session)");
-        return false;
-    }
-
-    return true;
+    ASSERT(!document.hasEvaluatedUserAgentScripts());
+    ASSERT(!document.isRunningUserScripts());
+    RELEASE_LOG_ERROR_IF_ALLOWED("shouldAllowUserAgentScripts() -> false (active session)");
+    return false;
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/applepay/PaymentCoordinator.h (246055 => 246056)


--- trunk/Source/WebCore/Modules/applepay/PaymentCoordinator.h	2019-06-04 05:05:14 UTC (rev 246055)
+++ trunk/Source/WebCore/Modules/applepay/PaymentCoordinator.h	2019-06-04 06:36:05 UTC (rev 246056)
@@ -29,6 +29,7 @@
 
 #include "ApplePaySessionPaymentRequest.h"
 #include <wtf/Function.h>
+#include <wtf/WeakPtr.h>
 
 namespace WebCore {
 
@@ -45,7 +46,7 @@
 struct ShippingContactUpdate;
 struct ShippingMethodUpdate;
 
-class PaymentCoordinator {
+class PaymentCoordinator : public CanMakeWeakPtr<PaymentCoordinator> {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     WEBCORE_EXPORT explicit PaymentCoordinator(PaymentCoordinatorClient&);
@@ -79,12 +80,12 @@
     Optional<String> validatedPaymentNetwork(Document&, unsigned version, const String&) const;
 
     bool shouldEnableApplePayAPIs(Document&) const;
-    WEBCORE_EXPORT bool shouldAllowApplePay(Document&) const;
     WEBCORE_EXPORT bool shouldAllowUserAgentScripts(Document&) const;
 
 private:
+    bool setApplePayIsActiveIfAllowed(Document&) const;
+
     PaymentCoordinatorClient& m_client;
-
     RefPtr<PaymentSession> m_activeSession;
 };
 

Modified: trunk/Source/WebCore/dom/Document.cpp (246055 => 246056)


--- trunk/Source/WebCore/dom/Document.cpp	2019-06-04 05:05:14 UTC (rev 246055)
+++ trunk/Source/WebCore/dom/Document.cpp	2019-06-04 06:36:05 UTC (rev 246056)
@@ -8249,19 +8249,19 @@
 
 #if ENABLE(APPLE_PAY)
 
-bool Document::hasStartedApplePaySession() const
+bool Document::isApplePayActive() const
 {
     auto& top = topDocument();
-    return this == &top ? m_hasStartedApplePaySession : top.hasStartedApplePaySession();
+    return this == &top ? m_hasStartedApplePaySession : top.isApplePayActive();
 }
 
-void Document::setHasStartedApplePaySession()
+void Document::setApplePayIsActive()
 {
     auto& top = topDocument();
     if (this == &top)
         m_hasStartedApplePaySession = true;
     else
-        top.setHasStartedApplePaySession();
+        top.setApplePayIsActive();
 }
 
 #endif

Modified: trunk/Source/WebCore/dom/Document.h (246055 => 246056)


--- trunk/Source/WebCore/dom/Document.h	2019-06-04 05:05:14 UTC (rev 246055)
+++ trunk/Source/WebCore/dom/Document.h	2019-06-04 06:36:05 UTC (rev 246056)
@@ -1522,8 +1522,8 @@
     WEBCORE_EXPORT void setAsRunningUserScripts();
     void setHasEvaluatedUserAgentScripts();
 #if ENABLE(APPLE_PAY)
-    WEBCORE_EXPORT bool hasStartedApplePaySession() const;
-    WEBCORE_EXPORT void setHasStartedApplePaySession();
+    WEBCORE_EXPORT bool isApplePayActive() const;
+    WEBCORE_EXPORT void setApplePayIsActive();
 #endif
 
     void frameWasDisconnectedFromOwner();

Modified: trunk/Source/WebCore/testing/Internals.cpp (246055 => 246056)


--- trunk/Source/WebCore/testing/Internals.cpp	2019-06-04 05:05:14 UTC (rev 246055)
+++ trunk/Source/WebCore/testing/Internals.cpp	2019-06-04 06:36:05 UTC (rev 246056)
@@ -4603,9 +4603,9 @@
 }
 
 #if ENABLE(APPLE_PAY)
-void Internals::setHasStartedApplePaySession(Document& document)
+void Internals::setApplePayIsActive(Document& document)
 {
-    document.setHasStartedApplePaySession();
+    document.setApplePayIsActive();
 }
 #endif
 

Modified: trunk/Source/WebCore/testing/Internals.h (246055 => 246056)


--- trunk/Source/WebCore/testing/Internals.h	2019-06-04 05:05:14 UTC (rev 246055)
+++ trunk/Source/WebCore/testing/Internals.h	2019-06-04 06:36:05 UTC (rev 246056)
@@ -681,7 +681,7 @@
 
     void setAsRunningUserScripts(Document&);
 #if ENABLE(APPLE_PAY)
-    void setHasStartedApplePaySession(Document&);
+    void setApplePayIsActive(Document&);
 #endif
 
 #if ENABLE(WEBGL)

Modified: trunk/Source/WebCore/testing/Internals.idl (246055 => 246056)


--- trunk/Source/WebCore/testing/Internals.idl	2019-06-04 05:05:14 UTC (rev 246055)
+++ trunk/Source/WebCore/testing/Internals.idl	2019-06-04 06:36:05 UTC (rev 246056)
@@ -657,7 +657,7 @@
     void setQuickLookPassword(DOMString password);
 
     [CallWith=Document] void setAsRunningUserScripts();
-    [CallWith=Document, Conditional=APPLE_PAY] void setHasStartedApplePaySession();
+    [CallWith=Document, Conditional=APPLE_PAY] void setApplePayIsActive();
 
     void disableTileSizeUpdateDelay();
     void setSpeculativeTilingDelayDisabledForTesting(boolean disabled);

Modified: trunk/Tools/ChangeLog (246055 => 246056)


--- trunk/Tools/ChangeLog	2019-06-04 05:05:14 UTC (rev 246055)
+++ trunk/Tools/ChangeLog	2019-06-04 06:36:05 UTC (rev 246056)
@@ -1,3 +1,33 @@
+2019-06-03  Andy Estes  <[email protected]>
+
+        [Apple Pay] Disable script injection when canMakePayment APIs are called and return true
+        https://bugs.webkit.org/show_bug.cgi?id=198448
+        <rdar://problem/51323694>
+
+        Reviewed by Alex Christensen.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/ApplePay.mm:
+        (-[TestApplePayAvailableScriptMessageHandler userContentController:didReceiveScriptMessage:]):
+        (-[TestApplePayActiveSessionScriptMessageHandler userContentController:didReceiveScriptMessage:]):
+        (TestWebKitAPI::TEST):
+        (TestWebKitAPI::runActiveSessionTest):
+        (-[TestApplePayScriptMessageHandler initWithAPIsAvailableExpectation:canMakePaymentsExpectation:]): Deleted.
+        (-[TestApplePayScriptMessageHandler userContentController:didReceiveScriptMessage:]): Deleted.
+        * TestWebKitAPI/Tests/WebKitCocoa/apple-pay-active-session.html:
+        * TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability-existing-object.html: Added.
+        * TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability-in-iframe.html:
+        * TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability.html:
+        * TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payment.html: Added.
+        * TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payments-with-active-card.html: Added.
+        * TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payments.html: Added.
+        * TestWebKitAPI/Tests/WebKitCocoa/apple-pay.js: Added.
+        (applePayRequestBase):
+        (applePayPaymentRequest):
+        (applePayMethod):
+        * TestWebKitAPI/cocoa/TestProtocol.mm:
+        (-[TestProtocol startLoading]):
+
 2019-06-03  Sihui Liu  <[email protected]>
 
         [ Mac WK2 ] TestWebKitAPI.WKWebView.LocalStorageProcessCrashes is a flaky timeout when run locally.

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (246055 => 246056)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-06-04 05:05:14 UTC (rev 246055)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-06-04 06:36:05 UTC (rev 246056)
@@ -730,6 +730,11 @@
 		A1C4FB731BACD1CA003742D0 /* pages.pages in Copy Resources */ = {isa = PBXBuildFile; fileRef = A1C4FB721BACD1B7003742D0 /* pages.pages */; };
 		A1DF74321C41B65800A2F4D0 /* AlwaysRevalidatedURLSchemes.mm in Sources */ = {isa = PBXBuildFile; fileRef = A1DF74301C41B65800A2F4D0 /* AlwaysRevalidatedURLSchemes.mm */; };
 		A1EC11881F42541200D0146E /* PreviewConverter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1EC11871F42541200D0146E /* PreviewConverter.cpp */; };
+		A1FB503D22A1CBE200D4D979 /* apple-pay-availability-existing-object.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = A1FB503C22A1C24400D4D979 /* apple-pay-availability-existing-object.html */; };
+		A1FB503F22A20F6400D4D979 /* apple-pay-can-make-payments.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = A1FB503E22A1E3B300D4D979 /* apple-pay-can-make-payments.html */; };
+		A1FB504122A212A900D4D979 /* apple-pay-can-make-payments-with-active-card.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = A1FB504022A2128400D4D979 /* apple-pay-can-make-payments-with-active-card.html */; };
+		A1FB504322A213A300D4D979 /* apple-pay-can-make-payment.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = A1FB504222A2138F00D4D979 /* apple-pay-can-make-payment.html */; };
+		A1FB504522A2157100D4D979 /* apple-pay.js in Copy Resources */ = {isa = PBXBuildFile; fileRef = A1FB504422A2154B00D4D979 /* apple-pay.js */; };
 		A310827221F296FF00C28B97 /* FileSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A310827121F296EC00C28B97 /* FileSystem.cpp */; };
 		A57A34F216AF6B2B00C2501F /* PageVisibilityStateWithWindowChanges.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = A57A34F116AF69E200C2501F /* PageVisibilityStateWithWindowChanges.html */; };
 		A57D54F31F338C3600A97AA7 /* NeverDestroyed.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A57D54F21F338C3600A97AA7 /* NeverDestroyed.cpp */; };
@@ -1049,8 +1054,13 @@
 				C25CCA0D1E5141840026CB8A /* AllAhem.svg in Copy Resources */,
 				F4A9202F1FEE34E900F59590 /* apple-data-url.html in Copy Resources */,
 				A1798B8B224361A4000764BD /* apple-pay-active-session.html in Copy Resources */,
+				A1FB503D22A1CBE200D4D979 /* apple-pay-availability-existing-object.html in Copy Resources */,
 				A1798B8922435E29000764BD /* apple-pay-availability-in-iframe.html in Copy Resources */,
 				A1798B872243449B000764BD /* apple-pay-availability.html in Copy Resources */,
+				A1FB504322A213A300D4D979 /* apple-pay-can-make-payment.html in Copy Resources */,
+				A1FB504122A212A900D4D979 /* apple-pay-can-make-payments-with-active-card.html in Copy Resources */,
+				A1FB503F22A20F6400D4D979 /* apple-pay-can-make-payments.html in Copy Resources */,
+				A1FB504522A2157100D4D979 /* apple-pay.js in Copy Resources */,
 				F46A095A1ED8A6E600D4AA55 /* apple.gif in Copy Resources */,
 				5C9E59411D3EB5AC00E3C62E /* ApplicationCache.db in Copy Resources */,
 				5C9E59421D3EB5AC00E3C62E /* ApplicationCache.db-shm in Copy Resources */,
@@ -2028,6 +2038,11 @@
 		A1C4FB721BACD1B7003742D0 /* pages.pages */ = {isa = PBXFileReference; lastKnownFileType = file; name = pages.pages; path = ios/pages.pages; sourceTree = SOURCE_ROOT; };
 		A1DF74301C41B65800A2F4D0 /* AlwaysRevalidatedURLSchemes.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AlwaysRevalidatedURLSchemes.mm; sourceTree = "<group>"; };
 		A1EC11871F42541200D0146E /* PreviewConverter.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = PreviewConverter.cpp; sourceTree = "<group>"; };
+		A1FB503C22A1C24400D4D979 /* apple-pay-availability-existing-object.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "apple-pay-availability-existing-object.html"; sourceTree = "<group>"; };
+		A1FB503E22A1E3B300D4D979 /* apple-pay-can-make-payments.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "apple-pay-can-make-payments.html"; sourceTree = "<group>"; };
+		A1FB504022A2128400D4D979 /* apple-pay-can-make-payments-with-active-card.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "apple-pay-can-make-payments-with-active-card.html"; sourceTree = "<group>"; };
+		A1FB504222A2138F00D4D979 /* apple-pay-can-make-payment.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "apple-pay-can-make-payment.html"; sourceTree = "<group>"; };
+		A1FB504422A2154B00D4D979 /* apple-pay.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode._javascript_; path = "apple-pay.js"; sourceTree = "<group>"; };
 		A1FDFD2E19C288BB005148A4 /* WKImageCreateCGImageCrash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKImageCreateCGImageCrash.cpp; sourceTree = "<group>"; };
 		A310827121F296EC00C28B97 /* FileSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FileSystem.cpp; sourceTree = "<group>"; };
 		A57A34EF16AF677200C2501F /* PageVisibilityStateWithWindowChanges.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PageVisibilityStateWithWindowChanges.mm; sourceTree = "<group>"; };
@@ -2959,8 +2974,13 @@
 				C25CCA0C1E5140E50026CB8A /* AllAhem.svg */,
 				F4A9202E1FEE34C800F59590 /* apple-data-url.html */,
 				A1798B8A2243611A000764BD /* apple-pay-active-session.html */,
+				A1FB503C22A1C24400D4D979 /* apple-pay-availability-existing-object.html */,
 				A1798B8822435D2E000764BD /* apple-pay-availability-in-iframe.html */,
 				A1798B862243446B000764BD /* apple-pay-availability.html */,
+				A1FB504222A2138F00D4D979 /* apple-pay-can-make-payment.html */,
+				A1FB504022A2128400D4D979 /* apple-pay-can-make-payments-with-active-card.html */,
+				A1FB503E22A1E3B300D4D979 /* apple-pay-can-make-payments.html */,
+				A1FB504422A2154B00D4D979 /* apple-pay.js */,
 				F47D30EB1ED28619000482E1 /* apple.gif */,
 				5C9E593E1D3EB1DE00E3C62E /* ApplicationCache.db */,
 				5C9E593F1D3EB1DE00E3C62E /* ApplicationCache.db-shm */,

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ApplePay.mm (246055 => 246056)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ApplePay.mm	2019-06-04 05:05:14 UTC (rev 246055)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ApplePay.mm	2019-06-04 06:36:05 UTC (rev 246056)
@@ -37,8 +37,9 @@
 #import <WebKit/WebKit.h>
 
 static bool isDone;
+static NSString * const userScriptSource = @"window.wkUserScriptInjected = true";
 
-@interface TestApplePayScriptMessageHandler : NSObject <WKScriptMessageHandler>
+@interface TestApplePayAvailableScriptMessageHandler : NSObject <WKScriptMessageHandler>
 
 - (instancetype)init NS_UNAVAILABLE;
 - (instancetype)initWithAPIsAvailableExpectation:(BOOL)apisAvailableExpectation canMakePaymentsExpectation:(BOOL)canMakePaymentsExpectation;
@@ -48,7 +49,7 @@
 
 @end
 
-@implementation TestApplePayScriptMessageHandler
+@implementation TestApplePayAvailableScriptMessageHandler
 
 - (instancetype)initWithAPIsAvailableExpectation:(BOOL)apisAvailableExpectation canMakePaymentsExpectation:(BOOL)canMakePaymentsExpectation
 {
@@ -64,7 +65,7 @@
 {
     EXPECT_EQ(_apisAvailableExpectation, [[message.body objectForKey:@"applePaySessionAvailable"] boolValue]);
     EXPECT_EQ(_apisAvailableExpectation, [[message.body objectForKey:@"paymentRequestAvailable"] boolValue]);
-    EXPECT_EQ(_canMakePaymentsExpectation, [[message.body objectForKey:@"supportsVersion"] boolValue]);
+    EXPECT_EQ(_apisAvailableExpectation, [[message.body objectForKey:@"supportsVersion"] boolValue]);
     EXPECT_EQ(_canMakePaymentsExpectation, [[message.body objectForKey:@"canMakePayments"] boolValue]);
     EXPECT_EQ(_canMakePaymentsExpectation, [[message.body objectForKey:@"canMakePaymentsWithActiveCard"] boolValue]);
     EXPECT_EQ(_canMakePaymentsExpectation, [[message.body objectForKey:@"canMakePayment"] boolValue]);
@@ -73,6 +74,18 @@
 
 @end
 
+@interface TestApplePayActiveSessionScriptMessageHandler : NSObject <WKScriptMessageHandler>
+@end
+
+@implementation TestApplePayActiveSessionScriptMessageHandler
+
+- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
+{
+    isDone = true;
+}
+
+@end
+
 namespace TestWebKitAPI {
     
 TEST(ApplePay, ApplePayAvailableByDefault)
@@ -79,13 +92,13 @@
 {
     [TestProtocol registerWithScheme:@"https"];
 
-    auto messageHandler = adoptNS([[TestApplePayScriptMessageHandler alloc] initWithAPIsAvailableExpectation:YES canMakePaymentsExpectation:YES]);
+    auto messageHandler = adoptNS([[TestApplePayAvailableScriptMessageHandler alloc] initWithAPIsAvailableExpectation:YES canMakePaymentsExpectation:YES]);
 
     WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals"];
     [configuration.userContentController addScriptMessageHandler:messageHandler.get() name:@"testApplePay"];
 
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
-    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://bundle-html-file/apple-pay-availability"]]];
+    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://bundle-file/apple-pay-availability.html"]]];
 
     Util::run(&isDone);
 
@@ -92,12 +105,35 @@
     [TestProtocol unregister];
 }
 
+TEST(ApplePay, ApplePayAvailableInUnrestrictedClients)
+{
+    [TestProtocol registerWithScheme:@"https"];
+
+    auto messageHandler = adoptNS([[TestApplePayAvailableScriptMessageHandler alloc] initWithAPIsAvailableExpectation:YES canMakePaymentsExpectation:YES]);
+    auto userScript = adoptNS([[WKUserScript alloc] initWithSource:userScriptSource injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]);
+
+    WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals"];
+    [configuration.userContentController addUserScript:userScript.get()];
+    [configuration.userContentController addScriptMessageHandler:messageHandler.get() name:@"testApplePay"];
+
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
+    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://bundle-file/apple-pay-availability-in-iframe.html?unrestricted"]]];
+    [webView _test_waitForDidFinishNavigation];
+    [webView evaluateJavaScript:@"loadApplePayFrame();" completionHandler:nil];
+
+    Util::run(&isDone);
+
+    EXPECT_EQ(YES, [[webView objectByEvaluatingJavaScript:@"window.wkUserScriptInjected"] boolValue]);
+
+    [TestProtocol unregister];
+}
+
 TEST(ApplePay, UserScriptAtDocumentStartDisablesApplePay)
 {
     [TestProtocol registerWithScheme:@"https"];
 
-    auto messageHandler = adoptNS([[TestApplePayScriptMessageHandler alloc] initWithAPIsAvailableExpectation:NO canMakePaymentsExpectation:NO]);
-    auto userScript = adoptNS([[WKUserScript alloc] initWithSource:@"window.wkUserScriptInjected = true" injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]);
+    auto messageHandler = adoptNS([[TestApplePayAvailableScriptMessageHandler alloc] initWithAPIsAvailableExpectation:NO canMakePaymentsExpectation:NO]);
+    auto userScript = adoptNS([[WKUserScript alloc] initWithSource:userScriptSource injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]);
 
     WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals"];
     [configuration.userContentController addUserScript:userScript.get()];
@@ -104,7 +140,7 @@
     [configuration.userContentController addScriptMessageHandler:messageHandler.get() name:@"testApplePay"];
 
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
-    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://bundle-html-file/apple-pay-availability"]]];
+    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://bundle-file/apple-pay-availability.html"]]];
 
     Util::run(&isDone);
 
@@ -117,8 +153,8 @@
 {
     [TestProtocol registerWithScheme:@"https"];
     
-    auto messageHandler = adoptNS([[TestApplePayScriptMessageHandler alloc] initWithAPIsAvailableExpectation:NO canMakePaymentsExpectation:NO]);
-    auto userScript = adoptNS([[WKUserScript alloc] initWithSource:@"window.wkUserScriptInjected = true" injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES]);
+    auto messageHandler = adoptNS([[TestApplePayAvailableScriptMessageHandler alloc] initWithAPIsAvailableExpectation:NO canMakePaymentsExpectation:NO]);
+    auto userScript = adoptNS([[WKUserScript alloc] initWithSource:userScriptSource injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES]);
     
     WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals"];
     [configuration.userContentController addUserScript:userScript.get()];
@@ -125,7 +161,7 @@
     [configuration.userContentController addScriptMessageHandler:messageHandler.get() name:@"testApplePay"];
     
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
-    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://bundle-html-file/apple-pay-availability"]]];
+    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://bundle-file/apple-pay-availability.html"]]];
     
     Util::run(&isDone);
     
@@ -138,13 +174,13 @@
 {
     [TestProtocol registerWithScheme:@"https"];
 
-    auto messageHandler = adoptNS([[TestApplePayScriptMessageHandler alloc] initWithAPIsAvailableExpectation:YES canMakePaymentsExpectation:NO]);
+    auto messageHandler = adoptNS([[TestApplePayAvailableScriptMessageHandler alloc] initWithAPIsAvailableExpectation:YES canMakePaymentsExpectation:NO]);
 
     WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals"];
     [configuration.userContentController addScriptMessageHandler:messageHandler.get() name:@"testApplePay"];
 
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
-    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://bundle-html-file/apple-pay-availability-in-iframe"]]];
+    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://bundle-file/apple-pay-availability-in-iframe.html"]]];
     [webView _test_waitForDidFinishNavigation];
     [webView evaluateJavaScript:@"window.wkScriptEvaluated = true; loadApplePayFrame();" completionHandler:nil];
 
@@ -159,13 +195,13 @@
 {
     [TestProtocol registerWithScheme:@"https"];
 
-    auto messageHandler = adoptNS([[TestApplePayScriptMessageHandler alloc] initWithAPIsAvailableExpectation:YES canMakePaymentsExpectation:YES]);
+    auto messageHandler = adoptNS([[TestApplePayAvailableScriptMessageHandler alloc] initWithAPIsAvailableExpectation:YES canMakePaymentsExpectation:NO]);
 
     WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals"];
     [configuration.userContentController addScriptMessageHandler:messageHandler.get() name:@"testApplePay"];
 
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
-    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://bundle-html-file/apple-pay-availability"]]];
+    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://bundle-file/apple-pay-availability-existing-object.html"]]];
 
     Util::run(&isDone);
 
@@ -178,29 +214,68 @@
     [TestProtocol unregister];
 }
 
-TEST(ApplePay, ActiveSessionBlocksUserAgentScripts)
+static void runActiveSessionTest(NSURL *url, BOOL shouldBlockScripts)
 {
     [TestProtocol registerWithScheme:@"https"];
 
-    auto userScript = adoptNS([[WKUserScript alloc] initWithSource:@"window.wkUserScriptInjected = true" injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]);
+    auto messageHandler = adoptNS([[TestApplePayActiveSessionScriptMessageHandler alloc] init]);
+    auto userScript = adoptNS([[WKUserScript alloc] initWithSource:userScriptSource injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]);
 
     WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals"];
+    [configuration.userContentController addScriptMessageHandler:messageHandler.get() name:@"testApplePay"];
 
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
-    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://bundle-html-file/apple-pay-active-session"]]];
-    [webView _test_waitForDidFinishNavigation];
+    [webView loadRequest:[NSURLRequest requestWithURL:url]];
+    Util::run(&isDone);
 
     [configuration.userContentController _addUserScriptImmediately:userScript.get()];
     [webView evaluateJavaScript:@"window.wkUserScriptInjected" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
-        EXPECT_NULL(result);
-        EXPECT_NOT_NULL(error);
+        EXPECT_EQ(shouldBlockScripts, !result);
+        EXPECT_EQ(shouldBlockScripts, !!error);
         isDone = true;
     }];
+
+    isDone = false;
     Util::run(&isDone);
 
     [TestProtocol unregister];
 }
 
+TEST(ApplePay, ActiveSessionBlocksUserAgentScripts)
+{
+    runActiveSessionTest([NSURL URLWithString:@"https://bundle-file/apple-pay-active-session.html"], YES);
+}
+
+TEST(ApplePay, CanMakePaymentsBlocksUserAgentScripts)
+{
+    runActiveSessionTest([NSURL URLWithString:@"https://bundle-file/apple-pay-can-make-payments.html"], YES);
+}
+
+TEST(ApplePay, CanMakePaymentsFalseDoesNotBlockUserAgentScripts)
+{
+    runActiveSessionTest([NSURL URLWithString:@"https://bundle-file/apple-pay-can-make-payments.html?false"], NO);
+}
+
+TEST(ApplePay, CanMakePaymentsWithActiveCardBlocksUserAgentScripts)
+{
+    runActiveSessionTest([NSURL URLWithString:@"https://bundle-file/apple-pay-can-make-payments-with-active-card.html"], YES);
+}
+
+TEST(ApplePay, CanMakePaymentsWithActiveCardFalseDoesNotBlockUserAgentScripts)
+{
+    runActiveSessionTest([NSURL URLWithString:@"https://bundle-file/apple-pay-can-make-payments-with-active-card.html?false"], NO);
+}
+
+TEST(ApplePay, CanMakePaymentBlocksUserAgentScripts)
+{
+    runActiveSessionTest([NSURL URLWithString:@"https://bundle-file/apple-pay-can-make-payment.html"], YES);
+}
+
+TEST(ApplePay, CanMakePaymentFalseDoesNotBlockUserAgentScripts)
+{
+    runActiveSessionTest([NSURL URLWithString:@"https://bundle-file/apple-pay-can-make-payment.html?false"], NO);
+}
+
 } // namespace TestWebKitAPI
 
 #endif // ENABLE(APPLE_PAY_REMOTE_UI)

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Download.mm (246055 => 246056)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Download.mm	2019-06-04 05:05:14 UTC (rev 246055)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Download.mm	2019-06-04 06:36:05 UTC (rev 246056)
@@ -973,7 +973,7 @@
     [webView setNavigationDelegate:delegate.get()];
     [webView configuration].processPool._downloadDelegate = delegate.get();
 
-    NSURL *firstURL = [NSURL URLWithString:@"http://bundle-html-file/simple"];
+    NSURL *firstURL = [NSURL URLWithString:@"http://bundle-file/simple.html"];
     [delegate setResponsePolicy:WKNavigationResponsePolicyAllow];
     [webView loadRequest:[NSURLRequest requestWithURL:firstURL]];
     isDone = false;
@@ -983,7 +983,7 @@
     EXPECT_TRUE([delegate didFinishNavigation]);
     EXPECT_WK_STREQ(firstURL.absoluteString, [webView URL].absoluteString);
 
-    NSURL *secondURL = [NSURL URLWithString:@"http://bundle-html-file/simple2"];
+    NSURL *secondURL = [NSURL URLWithString:@"http://bundle-file/simple2.html"];
     [delegate setResponsePolicy:_WKNavigationResponsePolicyBecomeDownload];
     [webView loadRequest:[NSURLRequest requestWithURL:secondURL]];
     isDone = false;

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-active-session.html (246055 => 246056)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-active-session.html	2019-06-04 05:05:14 UTC (rev 246055)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-active-session.html	2019-06-04 06:36:05 UTC (rev 246056)
@@ -2,5 +2,6 @@
 <body>
 <script>
     internals.mockPaymentCoordinator.supportsUnrestrictedApplePay = false;
-    internals.setHasStartedApplePaySession();
+    internals.setApplePayIsActive();
+    window.webkit.messageHandlers.testApplePay.postMessage("done");
 </script>

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability-existing-object.html (0 => 246056)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability-existing-object.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability-existing-object.html	2019-06-04 06:36:05 UTC (rev 246056)
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<body>
+<script src=""
+<script>
+    const eventListener = async () => {
+        internals.mockPaymentCoordinator.supportsUnrestrictedApplePay = false;
+
+        const applePaySessionAvailable = !!window.ApplePaySession;
+        const paymentRequestAvailable = !!window.PaymentRequest;
+        const supportsVersion = ApplePaySession.supportsVersion(1);
+
+        if (!window.wkPaymentRequest) {
+            wkPaymentRequest = new PaymentRequest([applePayMethod()], applePayDetails);
+
+            window.webkit.messageHandlers.testApplePay.postMessage({
+                applePaySessionAvailable,
+                paymentRequestAvailable,
+                supportsVersion,
+            });
+
+            return;
+        }
+
+        const canMakePayment = await wkPaymentRequest.canMakePayment();
+
+        window.webkit.messageHandlers.testApplePay.postMessage({
+            applePaySessionAvailable,
+            paymentRequestAvailable,
+            supportsVersion,
+            canMakePayment,
+        });
+    };
+
+    window.addEventListener('hashchange', eventListener);
+    window.addEventListener('load', eventListener);
+</script>

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability-in-iframe.html (246055 => 246056)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability-in-iframe.html	2019-06-04 05:05:14 UTC (rev 246055)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability-in-iframe.html	2019-06-04 06:36:05 UTC (rev 246056)
@@ -1,9 +1,10 @@
 <!DOCTYPE html>
 <body>
 <script>
+    internals.mockPaymentCoordinator.supportsUnrestrictedApplePay = window.location.search === "?unrestricted" ? true : false;
     loadApplePayFrame = () => {
         const iframe = document.createElement('iframe');
-        iframe.src = '';
+        iframe.src = '' + window.location.search;
         document.body.appendChild(iframe);
     };
 </script>

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability.html (246055 => 246056)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability.html	2019-06-04 05:05:14 UTC (rev 246055)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability.html	2019-06-04 06:36:05 UTC (rev 246056)
@@ -1,34 +1,10 @@
 <!DOCTYPE html>
 <body>
+<script src=""
 <script>
-    const applePayRequestBase = () => {
-        return {
-            merchantCapabilities: ['supports3DS'],
-            supportedNetworks: ['visa'],
-            countryCode: 'US',
-        };
-    };
+    window.addEventListener('load', async () => {
+        internals.mockPaymentCoordinator.supportsUnrestrictedApplePay = window.location.search === "?unrestricted" ? true : false;
 
-    const applePayPaymentRequest = () => {
-        const request = applePayRequestBase();
-        request.total = { label: 'total', amount: '0.00' };
-        request.currencyCode = 'USD';
-        return request;
-    };
-
-    const applePayMethod = () => {
-        const request = applePayRequestBase();
-        request.version = 1;
-        request.merchantIdentifier = '';
-        return {
-            supportedMethods: 'https://apple.com/apple-pay',
-            data: request,
-        };
-    };
-
-    const eventListener = async () => {
-        internals.mockPaymentCoordinator.supportsUnrestrictedApplePay = false;
-
         const applePaySessionAvailable = !!window.ApplePaySession;
         const paymentRequestAvailable = !!window.PaymentRequest;
         if (!applePaySessionAvailable || !paymentRequestAvailable) {
@@ -40,17 +16,9 @@
         const canMakePayments = ApplePaySession.canMakePayments();
         const canMakePaymentsWithActiveCard = await ApplePaySession.canMakePaymentsWithActiveCard('');
 
-        if (!window.wkPaymentRequest) {
-            wkPaymentRequest = new PaymentRequest([applePayMethod()], {
-                total: {
-                    label: 'total',
-                    amount: { currency: 'USD', value: '0.00' },
-                },
-            });
-        }
+        const paymentRequest = new PaymentRequest([applePayMethod()], applePayDetails);
+        const canMakePayment = await paymentRequest.canMakePayment();
 
-        const canMakePayment = await wkPaymentRequest.canMakePayment();
-
         window.webkit.messageHandlers.testApplePay.postMessage({
             applePaySessionAvailable,
             paymentRequestAvailable,
@@ -59,8 +27,5 @@
             canMakePaymentsWithActiveCard,
             canMakePayment,
         });
-    };
-
-    window.addEventListener('load', eventListener);
-    window.addEventListener('hashchange', eventListener);
+    });
 </script>

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payment.html (0 => 246056)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payment.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payment.html	2019-06-04 06:36:05 UTC (rev 246056)
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<body>
+<script src=""
+<script>
+    internals.mockPaymentCoordinator.supportsUnrestrictedApplePay = false;
+    internals.mockPaymentCoordinator.setCanMakePayments(window.location.search === "?false" ? false : true);
+
+    const paymentRequest = new PaymentRequest([applePayMethod()], applePayDetails);
+    paymentRequest.canMakePayment().then(() => {
+        window.webkit.messageHandlers.testApplePay.postMessage("done");
+    });
+</script>

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payments-with-active-card.html (0 => 246056)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payments-with-active-card.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payments-with-active-card.html	2019-06-04 06:36:05 UTC (rev 246056)
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<body>
+<script>
+    internals.mockPaymentCoordinator.supportsUnrestrictedApplePay = false;
+    internals.mockPaymentCoordinator.setCanMakePaymentsWithActiveCard(window.location.search === "?false" ? false : true);
+    ApplePaySession.canMakePaymentsWithActiveCard("").then(() => {
+        window.webkit.messageHandlers.testApplePay.postMessage("done");
+    });
+</script>

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payments.html (0 => 246056)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payments.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payments.html	2019-06-04 06:36:05 UTC (rev 246056)
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<body>
+<script>
+    internals.mockPaymentCoordinator.supportsUnrestrictedApplePay = false;
+    internals.mockPaymentCoordinator.setCanMakePayments(window.location.search === "?false" ? false : true);
+    ApplePaySession.canMakePayments();
+    window.webkit.messageHandlers.testApplePay.postMessage("done");
+</script>

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay.js (0 => 246056)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay.js	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay.js	2019-06-04 06:36:05 UTC (rev 246056)
@@ -0,0 +1,33 @@
+(() => {
+    applePayRequestBase = () => {
+        return {
+            merchantCapabilities: ['supports3DS'],
+            supportedNetworks: ['visa'],
+            countryCode: 'US',
+        };
+    };
+
+    applePayPaymentRequest = () => {
+        const request = applePayRequestBase();
+        request.total = { label: 'total', amount: '0.00' };
+        request.currencyCode = 'USD';
+        return request;
+     };
+
+    applePayMethod = () => {
+        const request = applePayRequestBase();
+        request.version = 1;
+        request.merchantIdentifier = '';
+        return {
+            supportedMethods: 'https://apple.com/apple-pay',
+            data: request,
+        };
+    };
+
+    applePayDetails = {
+        total: {
+            label: 'total',
+            amount: { currency: 'USD', value: '0.00' },
+        },
+    };
+})();

Modified: trunk/Tools/TestWebKitAPI/cocoa/TestProtocol.mm (246055 => 246056)


--- trunk/Tools/TestWebKitAPI/cocoa/TestProtocol.mm	2019-06-04 05:05:14 UTC (rev 246055)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestProtocol.mm	2019-06-04 06:36:05 UTC (rev 246056)
@@ -29,6 +29,10 @@
 #import <WebKit/WKBrowsingContextController.h>
 #import <wtf/RetainPtr.h>
 
+#if PLATFORM(IOS_FAMILY)
+#include <MobileCoreServices/MobileCoreServices.h>
+#endif
+
 static NSString *testScheme;
 
 @implementation TestProtocol
@@ -86,6 +90,13 @@
     return [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@", testScheme, query]];
 }
 
+static NSString *contentTypeForFileExtension(NSString *fileExtension)
+{
+    auto identifier = adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExtension, nullptr));
+    auto mimeType = adoptCF(UTTypeCopyPreferredTagWithClass(identifier.get(), kUTTagClassMIMEType));
+    return (__bridge NSString *)mimeType.autorelease();
+}
+
 - (void)startLoading
 {
     NSURL *requestURL = self.request.URL;
@@ -106,14 +117,20 @@
         return;
     }
 
+    NSString *contentType;
     NSData *data;
-    if ([requestURL.host isEqualToString:@"bundle-html-file"])
-        data = "" dataWithContentsOfURL:[NSBundle.mainBundle URLForResource:requestURL.lastPathComponent.stringByDeletingPathExtension withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
-    else
+    if ([requestURL.host isEqualToString:@"bundle-file"]) {
+        NSString *fileName = requestURL.lastPathComponent;
+        NSString *fileExtension = fileName.pathExtension;
+        contentType = contentTypeForFileExtension(fileExtension);
+        data = "" dataWithContentsOfURL:[NSBundle.mainBundle URLForResource:fileName.stringByDeletingPathExtension withExtension:fileExtension subdirectory:@"TestWebKitAPI.resources"]];
+    } else {
+        contentType = @"text/html";
         data = "" dataUsingEncoding:NSASCIIStringEncoding];
+    }
 
     NSMutableDictionary *responseHeaders = [NSMutableDictionary dictionaryWithCapacity:2];
-    responseHeaders[@"Content-Type"] = @"text/html";
+    responseHeaders[@"Content-Type"] = contentType;
     responseHeaders[@"Content-Length"] = [NSString stringWithFormat:@"%tu", data.length];
     if (additionalResponseHeaders)
         [responseHeaders addEntriesFromDictionary:additionalResponseHeaders];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to