WebKit Bugzilla
Attachment 371104 Details for
Bug 198448
: [Apple Pay] Disable script injection when canMakePayment APIs are called and return true
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-198448-20190531200846.patch (text/plain), 45.72 KB, created by
Andy Estes
on 2019-05-31 20:08:47 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Andy Estes
Created:
2019-05-31 20:08:47 PDT
Size:
45.72 KB
patch
obsolete
>Subversion Revision: 245853 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 9fb761ba875db93d9cc593f20dac47686e04809c..3a3deb58400e6f6b60a51a63e37f88ecdbf0188d 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,50 @@ >+2019-05-31 Andy Estes <aestes@apple.com> >+ >+ [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 NOBODY (OOPS!). >+ >+ 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-05-29 Ludovico de Nittis <ludovico.denittis@collabora.com> > > Prepend KEY_ to the last key alias in PlatformEventKeyboardGtk >diff --git a/Source/WebCore/Modules/applepay/PaymentCoordinator.cpp b/Source/WebCore/Modules/applepay/PaymentCoordinator.cpp >index d559948d0a6faa63e205ba09fcf192b1b0bb02c7..651419851e8e5a737c179f31efc04e86b6731cf1 100644 >--- a/Source/WebCore/Modules/applepay/PaymentCoordinator.cpp >+++ b/Source/WebCore/Modules/applepay/PaymentCoordinator.cpp >@@ -56,11 +56,8 @@ PaymentCoordinator::~PaymentCoordinator() > 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::supportsVersion(Document& document, unsigned version) c > > bool PaymentCoordinator::canMakePayments(Document& document) > { >- if (!shouldAllowApplePay(document)) >- return false; >- > auto canMakePayments = m_client.canMakePayments(); > RELEASE_LOG_IF_ALLOWED("canMakePayments() -> %d", canMakePayments); >- return canMakePayments; >+ >+ if (!canMakePayments) >+ return false; >+ >+ 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() -> %d", canMakePayments); >+ >+ if (!canMakePayments) >+ return completionHandler(false); >+ >+ if (!document || !setApplePayIsActiveIfAllowed(*document)) >+ return completionHandler(false); > >- RELEASE_LOG_IF_ALLOWED("canMakePaymentsWithActiveCard()"); >- m_client.canMakePaymentsWithActiveCard(merchantIdentifier, document.domain(), WTFMove(completionHandler)); >+ 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 @@ bool PaymentCoordinator::beginPaymentSession(Document& document, PaymentSession& > { > ASSERT(!m_activeSession); > >- if (!shouldAllowApplePay(document)) >+ if (!setApplePayIsActiveIfAllowed(document)) > return false; > > Vector<URL> linkIconURLs; >@@ -111,7 +118,6 @@ bool PaymentCoordinator::beginPaymentSession(Document& document, PaymentSession& > return false; > > m_activeSession = &paymentSession; >- document.setHasStartedApplePaySession(); > return true; > } > >@@ -239,11 +245,8 @@ void PaymentCoordinator::didCancelPaymentSession() > 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 @@ bool PaymentCoordinator::shouldEnableApplePayAPIs(Document& document) const > 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 >diff --git a/Source/WebCore/Modules/applepay/PaymentCoordinator.h b/Source/WebCore/Modules/applepay/PaymentCoordinator.h >index 260a3e2811626e7e48dcb00c22e0763c9b2a6e98..edda85487ef3aecc36a06704d98933c90bc451a9 100644 >--- a/Source/WebCore/Modules/applepay/PaymentCoordinator.h >+++ b/Source/WebCore/Modules/applepay/PaymentCoordinator.h >@@ -29,6 +29,7 @@ > > #include "ApplePaySessionPaymentRequest.h" > #include <wtf/Function.h> >+#include <wtf/WeakPtr.h> > > namespace WebCore { > >@@ -45,7 +46,7 @@ struct PaymentMethodUpdate; > 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 @@ public: > 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: >- PaymentCoordinatorClient& m_client; >+ bool setApplePayIsActiveIfAllowed(Document&) const; > >+ PaymentCoordinatorClient& m_client; > RefPtr<PaymentSession> m_activeSession; > }; > >diff --git a/Source/WebCore/dom/Document.cpp b/Source/WebCore/dom/Document.cpp >index d8f3a7a09980fe2a9516a436d427848273ffb04d..f906f203c4b0c3edc41555b8d3ca1c594e371669 100644 >--- a/Source/WebCore/dom/Document.cpp >+++ b/Source/WebCore/dom/Document.cpp >@@ -8234,19 +8234,19 @@ void Document::setHasEvaluatedUserAgentScripts() > > #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 >diff --git a/Source/WebCore/dom/Document.h b/Source/WebCore/dom/Document.h >index 16d0410bb67d4d99f04567ef016b62ea16eb17cb..81f4289a8e73e04fb76a1ab6aa9d77cf84c99442 100644 >--- a/Source/WebCore/dom/Document.h >+++ b/Source/WebCore/dom/Document.h >@@ -1522,8 +1522,8 @@ public: > 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(); >diff --git a/Source/WebCore/testing/Internals.cpp b/Source/WebCore/testing/Internals.cpp >index 510ef0d31b6ea420e4ab09bfe81f415a318f2efe..ac4795e1d269a8f9d8b24bc45d088ce7fd843ae6 100644 >--- a/Source/WebCore/testing/Internals.cpp >+++ b/Source/WebCore/testing/Internals.cpp >@@ -4594,9 +4594,9 @@ void Internals::setAsRunningUserScripts(Document& document) > } > > #if ENABLE(APPLE_PAY) >-void Internals::setHasStartedApplePaySession(Document& document) >+void Internals::setApplePayIsActive(Document& document) > { >- document.setHasStartedApplePaySession(); >+ document.setApplePayIsActive(); > } > #endif > >diff --git a/Source/WebCore/testing/Internals.h b/Source/WebCore/testing/Internals.h >index 3ac66f72598030c089f71202b4481308379f7946..8d8486d11a2590253b9d74de61b0fa0dc07324f1 100644 >--- a/Source/WebCore/testing/Internals.h >+++ b/Source/WebCore/testing/Internals.h >@@ -680,7 +680,7 @@ public: > > void setAsRunningUserScripts(Document&); > #if ENABLE(APPLE_PAY) >- void setHasStartedApplePaySession(Document&); >+ void setApplePayIsActive(Document&); > #endif > > #if ENABLE(WEBGL) >diff --git a/Source/WebCore/testing/Internals.idl b/Source/WebCore/testing/Internals.idl >index ca2bc545b3e04a7868c3d48940ae077249d147a7..103291b811f8d6497d5ca47707d2afedcaf2dfd5 100644 >--- a/Source/WebCore/testing/Internals.idl >+++ b/Source/WebCore/testing/Internals.idl >@@ -657,7 +657,7 @@ enum CompositingPolicy { > 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); >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index d33b8af7c62cc8ccf1ce1ff2fd74a3ecfa27e5ea..3cc52e8cb1caab6bd7891fb94cbe5310a2b70397 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,33 @@ >+2019-05-31 Andy Estes <aestes@apple.com> >+ >+ [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 NOBODY (OOPS!). >+ >+ * 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-05-29 Aakash Jain <aakash_jain@apple.com> > > Disable Flaky API Test TestWebKitAPI._WKDownload.DownloadMonitorCancel >diff --git a/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj >index 57aa7d182e8fcf005390e22b654f306045e9c37f..ed87ea32300efc260543d28e6ae993570f79ea31 100644 >--- a/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj >+++ b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj >@@ -726,6 +726,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 */; }; >@@ -1044,8 +1049,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 */, >@@ -2017,6 +2027,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>"; }; >@@ -2937,8 +2952,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 */, >diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/ApplePay.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/ApplePay.mm >index 061b331a15676b3379f36961854703eee6913a0c..17a1ae0b11487cf87b1302980ba821760605c14e 100644 >--- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/ApplePay.mm >+++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/ApplePay.mm >@@ -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 @@ @property (nonatomic) BOOL canMakePaymentsExpectation; > > @end > >-@implementation TestApplePayScriptMessageHandler >+@implementation TestApplePayAvailableScriptMessageHandler > > - (instancetype)initWithAPIsAvailableExpectation:(BOOL)apisAvailableExpectation canMakePaymentsExpectation:(BOOL)canMakePaymentsExpectation > { >@@ -64,7 +65,7 @@ - (void)userContentController:(WKUserContentController *)userContentController d > { > 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,22 +74,57 @@ - (void)userContentController:(WKUserContentController *)userContentController d > > @end > >+@interface TestApplePayActiveSessionScriptMessageHandler : NSObject <WKScriptMessageHandler> >+@end >+ >+@implementation TestApplePayActiveSessionScriptMessageHandler >+ >+- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message >+{ >+ isDone = true; >+} >+ >+@end >+ > namespace TestWebKitAPI { > > TEST(ApplePay, ApplePayAvailableByDefault) > { > [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-file/apple-pay-availability.html"]]]; >+ >+ Util::run(&isDone); >+ >+ [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-html-file/apple-pay-availability"]]]; >+ [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]; > } > >@@ -96,15 +132,15 @@ 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()]; > [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,15 +153,15 @@ TEST(ApplePay, UserScriptAtDocumentEndDisablesApplePay) > { > [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()]; > [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 @@ TEST(ApplePay, UserAgentScriptEvaluationDisablesApplePay) > { > [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 @@ TEST(ApplePay, UserAgentScriptEvaluationDisablesApplePayInExistingObjects) > { > [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 @@ TEST(ApplePay, UserAgentScriptEvaluationDisablesApplePayInExistingObjects) > [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) >diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-active-session.html b/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-active-session.html >index 1bd9f6f7458646684295a4fed155a46964d407f9..1f9660c559585c3c21e2bf012e4c8b5ba27bdb5f 100644 >--- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-active-session.html >+++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-active-session.html >@@ -2,5 +2,6 @@ > <body> > <script> > internals.mockPaymentCoordinator.supportsUnrestrictedApplePay = false; >- internals.setHasStartedApplePaySession(); >+ internals.setApplePayIsActive(); >+ window.webkit.messageHandlers.testApplePay.postMessage("done"); > </script> >diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability-existing-object.html b/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability-existing-object.html >new file mode 100644 >index 0000000000000000000000000000000000000000..e359207b9573a397dc4ee929c1b0c59e2537f2af >--- /dev/null >+++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability-existing-object.html >@@ -0,0 +1,36 @@ >+<!DOCTYPE html> >+<body> >+<script src="apple-pay.js"></script> >+<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> >diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability-in-iframe.html b/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability-in-iframe.html >index a3fae1ac6709f9c1a91523bd52f3ecf1ff8bc2f0..f90a6f6c7353bfec87512da398fe1ecdd828e7c6 100644 >--- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability-in-iframe.html >+++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability-in-iframe.html >@@ -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 = 'https://bundle-html-file/apple-pay-availability'; >+ iframe.src = 'apple-pay-availability.html' + window.location.search; > document.body.appendChild(iframe); > }; > </script> >diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability.html b/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability.html >index 6a8bc5a45eb238c1eae838178fe21cb5450c4daa..182c62fca744e0ec38c89f6a04238c4d78a54f3e 100644 >--- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability.html >+++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability.html >@@ -1,33 +1,9 @@ > <!DOCTYPE html> > <body> >+<script src="apple-pay.js"></script> > <script> >- const applePayRequestBase = () => { >- return { >- merchantCapabilities: ['supports3DS'], >- supportedNetworks: ['visa'], >- countryCode: 'US', >- }; >- }; >- >- 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; >+ window.addEventListener('load', async () => { >+ internals.mockPaymentCoordinator.supportsUnrestrictedApplePay = window.location.search === "?unrestricted" ? true : false; > > const applePaySessionAvailable = !!window.ApplePaySession; > const paymentRequestAvailable = !!window.PaymentRequest; >@@ -40,16 +16,8 @@ > 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 canMakePayment = await wkPaymentRequest.canMakePayment(); >+ const paymentRequest = new PaymentRequest([applePayMethod()], applePayDetails); >+ const canMakePayment = await paymentRequest.canMakePayment(); > > window.webkit.messageHandlers.testApplePay.postMessage({ > applePaySessionAvailable, >@@ -59,8 +27,5 @@ > canMakePaymentsWithActiveCard, > canMakePayment, > }); >- }; >- >- window.addEventListener('load', eventListener); >- window.addEventListener('hashchange', eventListener); >+ }); > </script> >diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payment.html b/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payment.html >new file mode 100644 >index 0000000000000000000000000000000000000000..9893021b3ddf1355416d2b70e1cffca3619ca4ca >--- /dev/null >+++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payment.html >@@ -0,0 +1,12 @@ >+<!DOCTYPE html> >+<body> >+<script src="apple-pay.js"></script> >+<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> >diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payments-with-active-card.html b/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payments-with-active-card.html >new file mode 100644 >index 0000000000000000000000000000000000000000..c47c3fac5f3b55c55fb499fcf68bca777e662db7 >--- /dev/null >+++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payments-with-active-card.html >@@ -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> >diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payments.html b/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payments.html >new file mode 100644 >index 0000000000000000000000000000000000000000..2aea1d8b42a8eb4a8705e68e0771ab636f6795a7 >--- /dev/null >+++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payments.html >@@ -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> >diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay.js b/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay.js >new file mode 100644 >index 0000000000000000000000000000000000000000..13cbc97b0b97318f0deb1b2fd378d91def505c64 >--- /dev/null >+++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay.js >@@ -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' }, >+ }, >+ }; >+})(); >diff --git a/Tools/TestWebKitAPI/cocoa/TestProtocol.mm b/Tools/TestWebKitAPI/cocoa/TestProtocol.mm >index d949c6fe5fa541fc75d3c778a67bdc5a591fc885..7cebb92e1c0d320136a26e6a8516142d9e82bc8e 100644 >--- a/Tools/TestWebKitAPI/cocoa/TestProtocol.mm >+++ b/Tools/TestWebKitAPI/cocoa/TestProtocol.mm >@@ -87,9 +87,10 @@ - (void)startLoading > } > > NSData *data; >- if ([requestURL.host isEqualToString:@"bundle-html-file"]) >- data = [NSData dataWithContentsOfURL:[NSBundle.mainBundle URLForResource:requestURL.lastPathComponent.stringByDeletingPathExtension withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; >- else >+ if ([requestURL.host isEqualToString:@"bundle-file"]) { >+ NSString *fileName = requestURL.lastPathComponent; >+ data = [NSData dataWithContentsOfURL:[NSBundle.mainBundle URLForResource:fileName.stringByDeletingPathExtension withExtension:fileName.pathExtension subdirectory:@"TestWebKitAPI.resources"]]; >+ } else > data = [@"PASS" dataUsingEncoding:NSASCIIStringEncoding]; > > RetainPtr<NSURLResponse> response = adoptNS([[NSURLResponse alloc] initWithURL:requestURL MIMEType:@"text/html" expectedContentLength:data.length textEncodingName:nil]);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 198448
:
371104
|
371247