Title: [235003] trunk/LayoutTests
Revision
235003
Author
[email protected]
Date
2018-08-17 17:25:01 -0700 (Fri, 17 Aug 2018)

Log Message

Resource Load Statistics: Add layout test for web workers importing cross-site scripts
https://bugs.webkit.org/show_bug.cgi?id=188706
<rdar://problem/43437050>

Reviewed by Alex Christensen.

* http/tests/resourceLoadStatistics/blocking-in-web-worker-script-import-expected.txt: Added.
* http/tests/resourceLoadStatistics/blocking-in-web-worker-script-import.html: Added.
* http/tests/resourceLoadStatistics/resources/iframe-report-back-loaded.html:
    Fixed typo in URL.
* http/tests/resourceLoadStatistics/resources/script-revealing-cookies.php: Added.
* http/tests/resourceLoadStatistics/resources/worker-importing-localhost-script.js: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (235002 => 235003)


--- trunk/LayoutTests/ChangeLog	2018-08-18 00:20:18 UTC (rev 235002)
+++ trunk/LayoutTests/ChangeLog	2018-08-18 00:25:01 UTC (rev 235003)
@@ -1,3 +1,18 @@
+2018-08-17  John Wilander  <[email protected]>
+
+        Resource Load Statistics: Add layout test for web workers importing cross-site scripts
+        https://bugs.webkit.org/show_bug.cgi?id=188706
+        <rdar://problem/43437050>
+
+        Reviewed by Alex Christensen.
+
+        * http/tests/resourceLoadStatistics/blocking-in-web-worker-script-import-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/blocking-in-web-worker-script-import.html: Added.
+        * http/tests/resourceLoadStatistics/resources/iframe-report-back-loaded.html:
+            Fixed typo in URL.
+        * http/tests/resourceLoadStatistics/resources/script-revealing-cookies.php: Added.
+        * http/tests/resourceLoadStatistics/resources/worker-importing-localhost-script.js: Added.
+
 2018-08-17  Devin Rousso  <[email protected]>
 
         Marked inspector/dom-debugger/event-breakpoint-with-navigation.html as flaky.

Added: trunk/LayoutTests/http/tests/resourceLoadStatistics/blocking-in-web-worker-script-import-expected.txt (0 => 235003)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/blocking-in-web-worker-script-import-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/blocking-in-web-worker-script-import-expected.txt	2018-08-18 00:25:01 UTC (rev 235003)
@@ -0,0 +1,18 @@
+Test for cookie blocking when web workers import cross-site scripts.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Did receive firstPartyCookie == value
+PASS Did not receive cookie named firstPartyCookie
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
+
+--------
+Frame: '<!--frame1-->'
+--------
+Should receive first-party cookie.
+Received cookie named 'firstPartyCookie'.
+Client-side document.cookie: firstPartyCookie=value

Added: trunk/LayoutTests/http/tests/resourceLoadStatistics/blocking-in-web-worker-script-import.html (0 => 235003)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/blocking-in-web-worker-script-import.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/blocking-in-web-worker-script-import.html	2018-08-18 00:25:01 UTC (rev 235003)
@@ -0,0 +1,87 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <script src=""
+    <script src=""
+</head>
+<body>
+<script>
+    description("Test for cookie blocking when web workers import cross-site scripts.");
+    jsTestIsAsync = true;
+
+    const partitionHost = "127.0.0.1:8000";
+    const thirdPartyOrigin = "http://localhost:8000";
+    const thirdPartyBaseUrl = thirdPartyOrigin + "/resourceLoadStatistics/resources";
+    const firstPartyCookieName = "firstPartyCookie";
+    const subPathToSetFirstPartyCookie = "/set-cookie.php?name=" + firstPartyCookieName + "&value=value";
+    const returnUrl = "http://127.0.0.1:8000/resourceLoadStatistics/blocking-in-web-worker-script-import.html";
+    const subPathToGetCookies = "/get-cookies.php?name1=" + firstPartyCookieName;
+
+    function openIframe(url, onLoadHandler) {
+        const element = document.createElement("iframe");
+        element.src = ""
+        if (onLoadHandler) {
+            element._onload_ = onLoadHandler;
+        }
+        document.body.appendChild(element);
+    }
+
+    let receivedMessages = 0;
+    function receiveMessage(event) {
+        if (event.data.indexOf("PASS") === -1)
+            testFailed(event.data.replace("FAIL ", ""));
+        else
+            testPassed(event.data.replace("PASS ", ""));
+
+        ++receivedMessages;
+        if (receivedMessages >= 2)
+            setEnableFeature(false, finishJSTest);
+        else
+            runTest();
+    }
+
+    function runTest() {
+        switch (document.location.hash) {
+            case "#step1":
+                document.location.href = "" + subPathToSetFirstPartyCookie + "#" + returnUrl + "#step2";
+                break;
+            case "#step2":
+                document.location.hash = "step3";
+                openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive first-party cookie.", runTest);
+                break;
+            case "#step3":
+                document.location.hash = "step4";
+                let w1 = new Worker("resources/worker-importing-localhost-script.js");
+                w1._onmessage_ = receiveMessage;
+                w1.postMessage("shouldReceiveCookies=true");
+                break;
+            case "#step4":
+                document.location.hash = "step5";
+                testRunner.setStatisticsPrevalentResource(thirdPartyOrigin, true, function() {
+                    if (!testRunner.isStatisticsPrevalentResource(thirdPartyOrigin))
+                        testFailed("Host did not get set as prevalent resource.");
+                    testRunner.statisticsUpdateCookieBlocking(runTest);
+                });
+                break;
+            case "#step5":
+                let w2 = new Worker("resources/worker-importing-localhost-script.js");
+                w2._onmessage_ = receiveMessage;
+                w2.postMessage("shouldNotReceiveCookies");
+                break;
+        }
+    }
+
+    if (document.location.host === partitionHost && document.location.hash === "" && window.testRunner && window.internals) {
+        setEnableFeature(true, function() {
+            document.location.hash = "step1";
+            testRunner.dumpChildFramesAsText();
+            if (testRunner.isStatisticsPrevalentResource(thirdPartyOrigin))
+                testFailed("Localhost was classified as prevalent resource before the test starts.");
+            runTest();
+        });
+    } else {
+        runTest();
+    }
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/http/tests/resourceLoadStatistics/resources/iframe-report-back-loaded.html (235002 => 235003)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/resources/iframe-report-back-loaded.html	2018-08-18 00:20:18 UTC (rev 235002)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/resources/iframe-report-back-loaded.html	2018-08-18 00:25:01 UTC (rev 235003)
@@ -5,7 +5,7 @@
 <body _onload_="reportBackLoadedToTopFrame()">
 <script>
     function reportBackLoadedToTopFrame() {
-        top.postMessage("PASS Frame loaded.", "http:127.0.0.1:8000");
+        top.postMessage("PASS Frame loaded.", "http://127.0.0.1:8000");
     }
 </script>
 </body>

Added: trunk/LayoutTests/http/tests/resourceLoadStatistics/resources/script-revealing-cookies.php (0 => 235003)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/resources/script-revealing-cookies.php	                        (rev 0)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/resources/script-revealing-cookies.php	2018-08-18 00:25:01 UTC (rev 235003)
@@ -0,0 +1,9 @@
+<?php
+$shouldReceiveCookies = $_GET["shouldReceiveCookies"];
+if(isset($_COOKIE["firstPartyCookie"])) {
+    echo "let cookieResult = '". ($shouldReceiveCookies ? "PASS " : "FAIL ") . "Did receive firstPartyCookie == " . $_COOKIE["firstPartyCookie"] . "';";
+} else {
+    echo "let cookieResult = '". ($shouldReceiveCookies ? "FAIL " : "PASS ") . "Did not receive cookie named firstPartyCookie';";
+}
+?>
+postMessage(cookieResult);

Added: trunk/LayoutTests/http/tests/resourceLoadStatistics/resources/worker-importing-localhost-script.js (0 => 235003)


--- trunk/LayoutTests/http/tests/resourceLoadStatistics/resources/worker-importing-localhost-script.js	                        (rev 0)
+++ trunk/LayoutTests/http/tests/resourceLoadStatistics/resources/worker-importing-localhost-script.js	2018-08-18 00:25:01 UTC (rev 235003)
@@ -0,0 +1,3 @@
+_onmessage_ = function(e) {
+    importScripts("//localhost:8000/resourceLoadStatistics/resources/script-revealing-cookies.php?" + e.data);
+};
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to