Override the session configuration for cookieAcceptPolicy
authorryanhaddad@apple.com <ryanhaddad@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Jan 2019 17:57:22 +0000 (17:57 +0000)
committerryanhaddad@apple.com <ryanhaddad@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Jan 2019 17:57:22 +0000 (17:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=190925
<rdar://problem/45497382>

Patch by John Wilander <wilander@apple.com> on 2019-01-10
Reviewed by Alexey Proskuryakov and Alex Christensen.

Source/WebCore/PAL:

* pal/spi/cf/CFNetworkSPI.h:
    Declaration of _overrideSessionCookieAcceptPolicy on NSHTTPCookieStorage.

Source/WebKit:

* NetworkProcess/cocoa/NetworkSessionCocoa.mm:
(WebKit::NetworkSessionCocoa::NetworkSessionCocoa):
    Now sets cookieStorage._overrideSessionCookieAcceptPolicy to YES.

Source/WTF:

* wtf/Platform.h:
    Definition of HAVE_CFNETWORK_OVERRIDE_SESSION_COOKIE_ACCEPT_POLICY.

Tools:

Test infrastructure for setting a first-party-only cookie policy.

* DumpRenderTree/TestRunner.cpp:
(setOnlyAcceptFirstPartyCookiesCallback):
(TestRunner::staticFunctions):
* DumpRenderTree/TestRunner.h:
* DumpRenderTree/mac/TestRunnerMac.mm:
(TestRunner::setOnlyAcceptFirstPartyCookies):
* DumpRenderTree/win/TestRunnerWin.cpp:
(TestRunner::setOnlyAcceptFirstPartyCookies):
* WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::setOnlyAcceptFirstPartyCookies):
* WebKitTestRunner/InjectedBundle/TestRunner.h:
* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):

LayoutTests:

* TestExpectations:
    Skipped since this cookie policy is only supported on Cocoa platforms.
* http/tests/cookies/only-accept-first-party-cookies-expected.txt: Added.
* http/tests/cookies/only-accept-first-party-cookies.html: Added.
* http/tests/cookies/resources/reset-cookies.html: Added.
    To support reset of third-party cookies in an iframe.
* http/tests/cookies/resources/set-cookie-and-redirect-back.php: Added.
    A simple bounce to set a cookie.
* platform/ios/TestExpectations:
    Skipped for now. Will be fixed in <rdar://problem/47165939>.
* platform/mac/TestExpectations:
    Skipped for now. Will be fixed in <rdar://problem/47165939>.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239832 268f45cc-cd09-0410-ab3c-d52691b4dbfc

23 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/http/tests/cookies/only-accept-first-party-cookies-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/cookies/only-accept-first-party-cookies.html [new file with mode: 0644]
LayoutTests/http/tests/cookies/resources/reset-cookies.html [new file with mode: 0644]
LayoutTests/http/tests/cookies/resources/set-cookie-and-redirect-back.php [new file with mode: 0644]
LayoutTests/platform/ios/TestExpectations
LayoutTests/platform/mac/TestExpectations
Source/WTF/ChangeLog
Source/WTF/wtf/Platform.h
Source/WebCore/PAL/ChangeLog
Source/WebCore/PAL/pal/spi/cf/CFNetworkSPI.h
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm
Tools/ChangeLog
Tools/DumpRenderTree/TestRunner.cpp
Tools/DumpRenderTree/TestRunner.h
Tools/DumpRenderTree/mac/TestRunnerMac.mm
Tools/DumpRenderTree/win/TestRunnerWin.cpp
Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl
Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp
Tools/WebKitTestRunner/InjectedBundle/TestRunner.h
Tools/WebKitTestRunner/TestInvocation.cpp

index 9ba6837..0a817ce 100644 (file)
@@ -1,3 +1,24 @@
+2019-01-10  John Wilander  <wilander@apple.com>
+
+        Override the session configuration for cookieAcceptPolicy
+        https://bugs.webkit.org/show_bug.cgi?id=190925
+        <rdar://problem/45497382>
+
+        Reviewed by Alexey Proskuryakov and Alex Christensen.
+
+        * TestExpectations:
+            Skipped since this cookie policy is only supported on Cocoa platforms.
+        * http/tests/cookies/only-accept-first-party-cookies-expected.txt: Added.
+        * http/tests/cookies/only-accept-first-party-cookies.html: Added.
+        * http/tests/cookies/resources/reset-cookies.html: Added.
+            To support reset of third-party cookies in an iframe.
+        * http/tests/cookies/resources/set-cookie-and-redirect-back.php: Added.
+            A simple bounce to set a cookie.
+        * platform/ios/TestExpectations:
+            Skipped for now. Will be fixed in <rdar://problem/47165939>.
+        * platform/mac/TestExpectations:
+            Skipped for now. Will be fixed in <rdar://problem/47165939>.
+
 2019-01-10  Miguel Gomez  <magomez@igalia.com>
 
         Unreviewed GTK+ gardening after r239824.
index fe575d2..ddf324e 100644 (file)
@@ -1990,6 +1990,9 @@ webkit.org/b/3652 fast/dom/HTMLLinkElement/subresource.html [ Skip ]
 webkit.org/b/3652 http/tests/misc/link-rel-prefetch-and-subresource.html [ Skip ]
 webkit.org/b/3652 http/tests/misc/prefetch-purpose.html [ Skip ]
 
+# First-party-only cookie policy only supported on Cocoa platforms.
+http/tests/cookies/only-accept-first-party-cookies.html [ Skip ]
+
 # Disabled WPT tests
 webkit.org/b/185939 imported/w3c/web-platform-tests/css/WOFF2 [ Skip ]
 
diff --git a/LayoutTests/http/tests/cookies/only-accept-first-party-cookies-expected.txt b/LayoutTests/http/tests/cookies/only-accept-first-party-cookies-expected.txt
new file mode 100644 (file)
index 0000000..583d813
--- /dev/null
@@ -0,0 +1,29 @@
+Tests the first-party-only cookie policy.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
+
+--------
+Frame: '<!--frame1-->'
+--------
+Cookies are: test_cookie = 1
+
+--------
+Frame: '<!--frame2-->'
+--------
+Cookies are:
+
+--------
+Frame: '<!--frame3-->'
+--------
+Cookies are: test_cookie = 1
+
+--------
+Frame: '<!--frame4-->'
+--------
+
diff --git a/LayoutTests/http/tests/cookies/only-accept-first-party-cookies.html b/LayoutTests/http/tests/cookies/only-accept-first-party-cookies.html
new file mode 100644 (file)
index 0000000..bf01d6b
--- /dev/null
@@ -0,0 +1,73 @@
+<html>
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/resetCookies.js"></script>
+    <script>
+        description("Tests the first-party-only cookie policy.");
+        jsTestIsAsync = true;
+
+        const iframeUrls = {
+            echoCookies : "http://localhost:8000/cookies/resources/echo-cookies.php",
+            resetCookies : "http://localhost:8000/cookies/resources/reset-cookies.html"
+        };
+
+        function injectThirdPartyIframe(url) {
+            let iframeElement = document.createElement("iframe");
+            iframeElement.src = url;
+            iframeElement.onload = runNextTestOrFinish;
+            document.body.appendChild(iframeElement);
+        }
+
+        function setCookieInRedirect(hashValue) {
+            document.location.href = "http://localhost:8000/cookies/resources/set-cookie-and-redirect-back.php?redirectBackTo=http://127.0.0.1:8000/cookies/only-accept-first-party-cookies.html#" + hashValue;
+        }
+
+        function runNextTestOrFinish() {
+            if (!window.testRunner) {
+                testFailed("No testRunner.");
+                finishJSTest();
+            }
+
+            switch (document.location.hash) {
+                case "":
+                    testRunner.dumpChildFramesAsText();
+                    document.location.hash = "1";
+                    injectThirdPartyIframe(iframeUrls.resetCookies);
+                    break;
+                case "#1":
+                    setCookieInRedirect(2);
+                    break;
+                case "#2":
+                    document.location.hash = "3";
+                    // Should see one cookie.
+                    injectThirdPartyIframe(iframeUrls.echoCookies);
+                    break;
+                case "#3":
+                    document.location.hash = "4";
+                    testRunner.setOnlyAcceptFirstPartyCookies(true);
+                    // Should not see any cookies.
+                    injectThirdPartyIframe(iframeUrls.echoCookies);
+                    break;
+                case "#4":
+                    document.location.hash = "5";
+                    // Should see one cookie.
+                    testRunner.setOnlyAcceptFirstPartyCookies(false);
+                    injectThirdPartyIframe(iframeUrls.echoCookies);
+                    break;
+                case "#5":
+                    document.location.hash = "6";
+                    injectThirdPartyIframe(iframeUrls.resetCookies);
+                    break;
+                case "#6":
+                    finishJSTest();
+                    break;
+                default:
+                    testFailed("Unknown location hash value.");
+                    finishJSTest();
+            }
+        }
+    </script>
+</head>
+<body onload="runNextTestOrFinish()">
+</body>
+</html>
diff --git a/LayoutTests/http/tests/cookies/resources/reset-cookies.html b/LayoutTests/http/tests/cookies/resources/reset-cookies.html
new file mode 100644 (file)
index 0000000..d827185
--- /dev/null
@@ -0,0 +1,10 @@
+<html>
+<head>
+    <script src="resetCookies.js"></script>
+</head>
+<body>
+    <script>
+        resetCookies();
+    </script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/cookies/resources/set-cookie-and-redirect-back.php b/LayoutTests/http/tests/cookies/resources/set-cookie-and-redirect-back.php
new file mode 100644 (file)
index 0000000..5333567
--- /dev/null
@@ -0,0 +1,10 @@
+<?php
+if ($_GET['redirectBackTo']) {
+  header("HTTP/1.0 302 Found");
+  setcookie("test_cookie", "1", time() + 86400);
+  header('Location: ' . $_GET['redirectBackTo']);
+} else {
+  header("HTTP/1.0 200 OK");
+  echo "FAILED: No redirectBackTo parameter found.\n";
+}
+?>
index 77ca55c..d5c4f17 100644 (file)
@@ -3170,6 +3170,9 @@ webkit.org/b/190032 animations/stop-animation-on-suspend.html [ Failure ]
 
 http/tests/cookies/same-site [ Pass ]
 
+# FIXME: Mark as Pass once <rdar://problem/47165939> is fixed.
+http/tests/cookies/only-accept-first-party-cookies.html [ Skip ]
+
 system-preview [ Pass ]
 
 editing/selection/character-granularity-rect.html [ Pass ]
index afc578c..efcda9f 100644 (file)
@@ -1726,6 +1726,9 @@ webkit.org/b/187393 imported/w3c/web-platform-tests/2dcontext/imagebitmap/create
 
 [ Mojave+ ] http/tests/cookies/same-site [ Pass ]
 
+# FIXME: Mark as Pass once <rdar://problem/47165939> is fixed.
+[ Mojave+ ] http/tests/cookies/only-accept-first-party-cookies.html [ Skip ]
+
 # FIXME: Mark as Pass once the fix for <rdar://problem/42255251> is shipped.
 [ Mojave+ ] http/tests/cookies/same-site/set-first-party-cross-site-cookies.php [ Skip ]
 [ Mojave+ ] http/tests/cookies/same-site/set-first-party-same-site-cookies.php [ Skip ]
index 8423843..786ba97 100644 (file)
@@ -1,3 +1,14 @@
+2019-01-10  John Wilander  <wilander@apple.com>
+
+        Override the session configuration for cookieAcceptPolicy
+        https://bugs.webkit.org/show_bug.cgi?id=190925
+        <rdar://problem/45497382>
+
+        Reviewed by Alexey Proskuryakov and Alex Christensen.
+
+        * wtf/Platform.h:
+            Definition of HAVE_CFNETWORK_OVERRIDE_SESSION_COOKIE_ACCEPT_POLICY.
+
 2019-01-10  Dominik Infuehr  <dinfuehr@igalia.com>
 
         Enable DFG on ARM/Linux again
index 4fdfb3d..a574b04 100644 (file)
 #if PLATFORM(IOS_FAMILY) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400)
 #define HAVE_AUTHORIZATION_STATUS_FOR_MEDIA_TYPE 1
 #endif
+
+#if (PLATFORM(MAC) && (__MAC_OS_X_VERSION_MIN_REQUIRED == 101200 || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101400 && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101404))) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000 && __IPHONE_OS_VERSION_MAX_ALLOWED >= 120200) || (PLATFORM(WATCHOS) && __WATCH_OS_VERSION_MIN_REQUIRED >= 50000 && __WATCH_OS_VERSION_MAX_ALLOWED >= 50200) || (PLATFORM(APPLETV) && __TV_OS_VERSION_MIN_REQUIRED >= 120000 && __TV_OS_VERSION_MAX_ALLOWED >= 120200)
+#define HAVE_CFNETWORK_OVERRIDE_SESSION_COOKIE_ACCEPT_POLICY 1
+#endif
index dcff5ff..5a10d74 100644 (file)
@@ -1,3 +1,14 @@
+2019-01-10  John Wilander  <wilander@apple.com>
+
+        Override the session configuration for cookieAcceptPolicy
+        https://bugs.webkit.org/show_bug.cgi?id=190925
+        <rdar://problem/45497382>
+
+        Reviewed by Alexey Proskuryakov and Alex Christensen.
+
+        * pal/spi/cf/CFNetworkSPI.h:
+            Declaration of _overrideSessionCookieAcceptPolicy on NSHTTPCookieStorage.
+
 2019-01-07  Devin Rousso  <drousso@apple.com>
 
         Web Inspector: Network: show secure connection details per-request
index fe4476f..2cf3dc3 100644 (file)
@@ -126,6 +126,9 @@ typedef void (^CFCachedURLResponseCallBackBlock)(CFCachedURLResponseRef);
 #if HAVE(FOUNDATION_WITH_SAVE_COOKIES_WITH_COMPLETION_HANDLER)
 - (void)_saveCookies:(dispatch_block_t) completionHandler;
 #endif
+#if HAVE(CFNETWORK_OVERRIDE_SESSION_COOKIE_ACCEPT_POLICY)
+@property (nonatomic, readwrite) BOOL _overrideSessionCookieAcceptPolicy;
+#endif
 @end
 
 @interface NSURLConnection ()
index 9e87978..8675a02 100644 (file)
@@ -1,3 +1,15 @@
+2019-01-10  John Wilander  <wilander@apple.com>
+
+        Override the session configuration for cookieAcceptPolicy
+        https://bugs.webkit.org/show_bug.cgi?id=190925
+        <rdar://problem/45497382>
+
+        Reviewed by Alexey Proskuryakov and Alex Christensen.
+
+        * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
+        (WebKit::NetworkSessionCocoa::NetworkSessionCocoa):
+            Now sets cookieStorage._overrideSessionCookieAcceptPolicy to YES.
+
 2019-01-09  Matt Rajca  <mrajca@apple.com>
 
         Put per-document autoplay behavior behind runtime website policies quirk instead of a compile time flag
index 4404dac..f856ff5 100644 (file)
@@ -916,8 +916,20 @@ NetworkSessionCocoa::NetworkSessionCocoa(NetworkProcess& networkProcess, Network
 
     auto* storageSession = WebCore::NetworkStorageSession::storageSession(parameters.sessionID);
     RELEASE_ASSERT(storageSession);
-    if (CFHTTPCookieStorageRef storage = storageSession->cookieStorage().get())
-        configuration.HTTPCookieStorage = [[[NSHTTPCookieStorage alloc] _initWithCFHTTPCookieStorage:storage] autorelease];
+
+    NSHTTPCookieStorage* cookieStorage;
+    if (CFHTTPCookieStorageRef storage = storageSession->cookieStorage().get()) {
+        cookieStorage = [[[NSHTTPCookieStorage alloc] _initWithCFHTTPCookieStorage:storage] autorelease];
+        configuration.HTTPCookieStorage = cookieStorage;
+    } else
+        cookieStorage = storageSession->nsCookieStorage();
+
+#if HAVE(CFNETWORK_OVERRIDE_SESSION_COOKIE_ACCEPT_POLICY)
+    // We still need to check the selector since CFNetwork updates and WebKit updates are separate
+    // on older macOS.
+    if ([cookieStorage respondsToSelector:@selector(_overrideSessionCookieAcceptPolicy)])
+        cookieStorage._overrideSessionCookieAcceptPolicy = YES;
+#endif
 
     m_sessionWithCredentialStorageDelegate = adoptNS([[WKNetworkSessionDelegate alloc] initWithNetworkSession:*this withCredentials:true]);
     m_sessionWithCredentialStorage = [NSURLSession sessionWithConfiguration:configuration delegate:static_cast<id>(m_sessionWithCredentialStorageDelegate.get()) delegateQueue:[NSOperationQueue mainQueue]];
index c98759b..381b9b5 100644 (file)
@@ -1,3 +1,28 @@
+2019-01-10  John Wilander  <wilander@apple.com>
+
+        Override the session configuration for cookieAcceptPolicy
+        https://bugs.webkit.org/show_bug.cgi?id=190925
+        <rdar://problem/45497382>
+
+        Reviewed by Alexey Proskuryakov and Alex Christensen.
+
+        Test infrastructure for setting a first-party-only cookie policy.
+
+        * DumpRenderTree/TestRunner.cpp:
+        (setOnlyAcceptFirstPartyCookiesCallback):
+        (TestRunner::staticFunctions):
+        * DumpRenderTree/TestRunner.h:
+        * DumpRenderTree/mac/TestRunnerMac.mm:
+        (TestRunner::setOnlyAcceptFirstPartyCookies):
+        * DumpRenderTree/win/TestRunnerWin.cpp:
+        (TestRunner::setOnlyAcceptFirstPartyCookies):
+        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
+        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
+        (WTR::TestRunner::setOnlyAcceptFirstPartyCookies):
+        * WebKitTestRunner/InjectedBundle/TestRunner.h:
+        * WebKitTestRunner/TestInvocation.cpp:
+        (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):
+
 2019-01-09  Matt Rajca  <mrajca@apple.com>
 
         Put per-document autoplay behavior behind runtime website policies quirk instead of a compile time flag
index 3f4a289..6222242 100644 (file)
@@ -810,6 +810,17 @@ static JSValueRef setAlwaysAcceptCookiesCallback(JSContextRef context, JSObjectR
     return JSValueMakeUndefined(context);
 }
 
+static JSValueRef setOnlyAcceptFirstPartyCookiesCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    if (argumentCount < 1)
+        return JSValueMakeUndefined(context);
+
+    TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
+    controller->setOnlyAcceptFirstPartyCookies(JSValueToBoolean(context, arguments[0]));
+
+    return JSValueMakeUndefined(context);
+}
+
 static JSValueRef setAppCacheMaximumSizeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
     // Has mac implementation
@@ -2195,6 +2206,7 @@ JSStaticFunction* TestRunner::staticFunctions()
         { "setNeedsStorageAccessFromFileURLsQuirk", setNeedsStorageAccessFromFileURLsQuirkCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "setAllowsAnySSLCertificate", setAllowsAnySSLCertificateCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "setAlwaysAcceptCookies", setAlwaysAcceptCookiesCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+        { "setOnlyAcceptFirstPartyCookies", setOnlyAcceptFirstPartyCookiesCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "setAppCacheMaximumSize", setAppCacheMaximumSizeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "setAudioResult", setAudioResultCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "setAuthenticationPassword", setAuthenticationPasswordCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
index 1dc16f1..4209190 100644 (file)
@@ -272,7 +272,8 @@ public:
 
     bool alwaysAcceptCookies() const { return m_alwaysAcceptCookies; }
     void setAlwaysAcceptCookies(bool);
-    
+    void setOnlyAcceptFirstPartyCookies(bool);
+
     bool rejectsProtectionSpaceAndContinueForAuthenticationChallenges() const { return m_rejectsProtectionSpaceAndContinueForAuthenticationChallenges; }
     void setRejectsProtectionSpaceAndContinueForAuthenticationChallenges(bool value) { m_rejectsProtectionSpaceAndContinueForAuthenticationChallenges = value; }
     
index ce8728e..c1378d9 100644 (file)
@@ -72,6 +72,7 @@
 #import <WebKit/WebStorageManagerPrivate.h>
 #import <WebKit/WebView.h>
 #import <WebKit/WebViewPrivate.h>
+#import <pal/spi/cf/CFNetworkSPI.h>
 #import <wtf/HashMap.h>
 #import <wtf/RetainPtr.h>
 #import <wtf/WallTime.h>
@@ -400,6 +401,15 @@ void TestRunner::setAlwaysAcceptCookies(bool alwaysAcceptCookies)
     [WebPreferences _setCurrentNetworkLoaderSessionCookieAcceptPolicy:cookieAcceptPolicy];
 }
 
+void TestRunner::setOnlyAcceptFirstPartyCookies(bool onlyAcceptFirstPartyCookies)
+{
+    if (onlyAcceptFirstPartyCookies)
+        m_alwaysAcceptCookies = NO;
+
+    NSHTTPCookieAcceptPolicy cookieAcceptPolicy = onlyAcceptFirstPartyCookies ? static_cast<NSHTTPCookieAcceptPolicy>(NSHTTPCookieAcceptPolicyExclusivelyFromMainDocumentDomain) : NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain;
+    [WebPreferences _setCurrentNetworkLoaderSessionCookieAcceptPolicy:cookieAcceptPolicy];
+}
+
 void TestRunner::setAppCacheMaximumSize(unsigned long long size)
 {
     [WebApplicationCache setMaximumSize:size];
index 1072532..6061aa1 100644 (file)
@@ -397,6 +397,12 @@ void TestRunner::setAlwaysAcceptCookies(bool alwaysAcceptCookies)
     m_alwaysAcceptCookies = alwaysAcceptCookies;
 }
 
+void TestRunner::setOnlyAcceptFirstPartyCookies(bool onlyAcceptFirstPartyCookies)
+{
+    // FIXME: Implement.
+    fprintf(testResult, "ERROR: TestRunner::setOnlyAcceptFirstPartyCookies() not implemented\n");
+}
+
 void TestRunner::setAppCacheMaximumSize(unsigned long long size)
 {
     COMPtr<IWebApplicationCache> applicationCache;
index da022c4..67fc93e 100644 (file)
@@ -187,6 +187,7 @@ interface TestRunner {
 
     // Cookies testing
     void setAlwaysAcceptCookies(boolean accept);
+    void setOnlyAcceptFirstPartyCookies(boolean accept);
 
     void overridePreference(DOMString preference, DOMString value);
 
index 24d340f..f97ae47 100644 (file)
@@ -926,6 +926,15 @@ void TestRunner::setAlwaysAcceptCookies(bool accept)
     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr);
 }
 
+void TestRunner::setOnlyAcceptFirstPartyCookies(bool accept)
+{
+    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetOnlyAcceptFirstPartyCookies"));
+    
+    WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(accept));
+    
+    WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr);
+}
+
 double TestRunner::preciseTime()
 {
     return WallTime::now().secondsSinceEpoch().seconds();
index 120efc8..2214d77 100644 (file)
@@ -294,6 +294,7 @@ public:
 
     // Cookies testing
     void setAlwaysAcceptCookies(bool);
+    void setOnlyAcceptFirstPartyCookies(bool);
 
     // Custom full screen behavior.
     void setHasCustomFullScreenBehavior(bool value) { m_customFullScreenBehavior = value; }
index 1a91eb2..0c6c877 100644 (file)
@@ -874,6 +874,14 @@ WKRetainPtr<WKTypeRef> TestInvocation::didReceiveSynchronousMessageFromInjectedB
         return nullptr;
     }
 
+    if (WKStringIsEqualToUTF8CString(messageName, "SetOnlyAcceptFirstPartyCookies")) {
+        WKBooleanRef accept = static_cast<WKBooleanRef>(messageBody);
+        WKHTTPCookieAcceptPolicy policy = WKBooleanGetValue(accept) ? kWKHTTPCookieAcceptPolicyExclusivelyFromMainDocumentDomain : kWKHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain;
+        // FIXME: This updates the policy in WebProcess and in NetworkProcess asynchronously, which might break some tests' expectations.
+        WKCookieManagerSetHTTPCookieAcceptPolicy(WKContextGetCookieManager(TestController::singleton().context()), policy);
+        return nullptr;
+    }
+    
     if (WKStringIsEqualToUTF8CString(messageName, "SetCustomUserAgent")) {
         WKStringRef userAgent = static_cast<WKStringRef>(messageBody);
         WKPageSetCustomUserAgent(TestController::singleton().mainWebView()->page(), userAgent);