Import WPT preload tests
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Apr 2019 15:54:11 +0000 (15:54 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Apr 2019 15:54:11 +0000 (15:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196439

Patch by Rob Buis <rbuis@igalia.com> on 2019-04-12
Reviewed by Youenn Fablet.

* web-platform-tests/preload/avoid-delaying-onload-link-preload-expected.txt: Added.
* web-platform-tests/preload/avoid-delaying-onload-link-preload.html: Added.
* web-platform-tests/preload/delaying-onload-link-preload-after-discovery-expected.txt: Added.
* web-platform-tests/preload/delaying-onload-link-preload-after-discovery.html: Added.
* web-platform-tests/preload/dynamic-adding-preload-expected.txt: Added.
* web-platform-tests/preload/dynamic-adding-preload.html: Added.
* web-platform-tests/preload/preload-csp.sub-expected.txt: Added.
* web-platform-tests/preload/preload-csp.sub.html: Added.
* web-platform-tests/preload/preload-default-csp.sub-expected.txt: Added.
* web-platform-tests/preload/preload-default-csp.sub.html: Added.
* web-platform-tests/preload/resources/dummy.css: Added.
* web-platform-tests/preload/resources/dummy.css.sub.headers: Added.
* web-platform-tests/preload/resources/dummy.js: Added.
* web-platform-tests/preload/resources/dummy.js.sub.headers: Added.
* web-platform-tests/preload/resources/dummy.xml: Added.
* web-platform-tests/preload/resources/dummy.xml.sub.headers: Added.
* web-platform-tests/preload/resources/foo.vtt: Added.
* web-platform-tests/preload/resources/preload_helper.js: Added.
(verifyPreloadAndRTSupport):
(getAbsoluteURL):
(verifyNumberOfResourceTimingEntries):
(verifyLoadedAndNoDoubleDownload):
* web-platform-tests/preload/resources/sound_5.oga: Added.
* web-platform-tests/preload/resources/square.png: Added.
* web-platform-tests/preload/resources/white.mp4: Added.
* web-platform-tests/preload/single-download-late-used-preload-expected.txt: Added.
* web-platform-tests/preload/single-download-late-used-preload.html: Added.
* web-platform-tests/preload/single-download-preload-expected.txt: Added.
* web-platform-tests/preload/single-download-preload.html: Added.

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

26 files changed:
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/preload/avoid-delaying-onload-link-preload-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/preload/avoid-delaying-onload-link-preload.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/preload/delaying-onload-link-preload-after-discovery-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/preload/delaying-onload-link-preload-after-discovery.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/preload/dynamic-adding-preload-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/preload/dynamic-adding-preload.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/preload/preload-csp.sub-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/preload/preload-csp.sub.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/preload/preload-default-csp.sub-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/preload/preload-default-csp.sub.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/preload/resources/dummy.css [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/preload/resources/dummy.css.sub.headers [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/preload/resources/dummy.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/preload/resources/dummy.js.sub.headers [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/preload/resources/dummy.xml [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/preload/resources/dummy.xml.sub.headers [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/preload/resources/foo.vtt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/preload/resources/preload_helper.js [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/preload/resources/sound_5.oga [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/preload/resources/square.png [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/preload/resources/white.mp4 [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/preload/single-download-late-used-preload-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/preload/single-download-late-used-preload.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/preload/single-download-preload-expected.txt [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/preload/single-download-preload.html [new file with mode: 0644]

index 784a7b1..6c1f093 100644 (file)
@@ -1,3 +1,40 @@
+2019-04-12  Rob Buis  <rbuis@igalia.com>
+
+        Import WPT preload tests
+        https://bugs.webkit.org/show_bug.cgi?id=196439
+
+        Reviewed by Youenn Fablet.
+
+        * web-platform-tests/preload/avoid-delaying-onload-link-preload-expected.txt: Added.
+        * web-platform-tests/preload/avoid-delaying-onload-link-preload.html: Added.
+        * web-platform-tests/preload/delaying-onload-link-preload-after-discovery-expected.txt: Added.
+        * web-platform-tests/preload/delaying-onload-link-preload-after-discovery.html: Added.
+        * web-platform-tests/preload/dynamic-adding-preload-expected.txt: Added.
+        * web-platform-tests/preload/dynamic-adding-preload.html: Added.
+        * web-platform-tests/preload/preload-csp.sub-expected.txt: Added.
+        * web-platform-tests/preload/preload-csp.sub.html: Added.
+        * web-platform-tests/preload/preload-default-csp.sub-expected.txt: Added.
+        * web-platform-tests/preload/preload-default-csp.sub.html: Added.
+        * web-platform-tests/preload/resources/dummy.css: Added.
+        * web-platform-tests/preload/resources/dummy.css.sub.headers: Added.
+        * web-platform-tests/preload/resources/dummy.js: Added.
+        * web-platform-tests/preload/resources/dummy.js.sub.headers: Added.
+        * web-platform-tests/preload/resources/dummy.xml: Added.
+        * web-platform-tests/preload/resources/dummy.xml.sub.headers: Added.
+        * web-platform-tests/preload/resources/foo.vtt: Added.
+        * web-platform-tests/preload/resources/preload_helper.js: Added.
+        (verifyPreloadAndRTSupport):
+        (getAbsoluteURL):
+        (verifyNumberOfResourceTimingEntries):
+        (verifyLoadedAndNoDoubleDownload):
+        * web-platform-tests/preload/resources/sound_5.oga: Added.
+        * web-platform-tests/preload/resources/square.png: Added.
+        * web-platform-tests/preload/resources/white.mp4: Added.
+        * web-platform-tests/preload/single-download-late-used-preload-expected.txt: Added.
+        * web-platform-tests/preload/single-download-late-used-preload.html: Added.
+        * web-platform-tests/preload/single-download-preload-expected.txt: Added.
+        * web-platform-tests/preload/single-download-preload.html: Added.
+
 2019-04-12  Manuel Rego Casasnovas  <rego@igalia.com>
 
         [css-flex][css-grid] Fix synthesized baseline
diff --git a/LayoutTests/imported/w3c/web-platform-tests/preload/avoid-delaying-onload-link-preload-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/preload/avoid-delaying-onload-link-preload-expected.txt
new file mode 100644 (file)
index 0000000..625aad6
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Makes sure link preload preloaded resources are not delaying onload 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/preload/avoid-delaying-onload-link-preload.html b/LayoutTests/imported/w3c/web-platform-tests/preload/avoid-delaying-onload-link-preload.html
new file mode 100644 (file)
index 0000000..a1b19c8
--- /dev/null
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/preload/resources/preload_helper.js"></script>
+<script>
+    var t = async_test('Makes sure link preload preloaded resources are not delaying onload');
+</script>
+<link rel=preload href="resources/dummy.js?pipe=trickle(d5)" as=script>
+<script>
+    window.addEventListener("load", t.step_func(function() {
+        verifyPreloadAndRTSupport();
+        verifyNumberOfResourceTimingEntries("/resources/dummy.js?pipe=trickle(d5)", 0);
+        t.done();
+    }));
+</script>
diff --git a/LayoutTests/imported/w3c/web-platform-tests/preload/delaying-onload-link-preload-after-discovery-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/preload/delaying-onload-link-preload-after-discovery-expected.txt
new file mode 100644 (file)
index 0000000..961ff45
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Makes sure link preload preloaded resources are delaying onload after discovery 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/preload/delaying-onload-link-preload-after-discovery.html b/LayoutTests/imported/w3c/web-platform-tests/preload/delaying-onload-link-preload-after-discovery.html
new file mode 100644 (file)
index 0000000..1c856d1
--- /dev/null
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/preload/resources/preload_helper.js"></script>
+<script>
+    var t = async_test('Makes sure link preload preloaded resources are delaying onload after discovery');
+</script>
+<link rel=preload href="resources/dummy.js?pipe=trickle(d5)" as=script>
+<link rel=preload href="resources/square.png?pipe=trickle(d5)" as=image>
+<body>
+<script>
+    window.addEventListener("load", t.step_func(function() {
+        verifyPreloadAndRTSupport();
+        verifyLoadedAndNoDoubleDownload("resources/dummy.js?pipe=trickle(d5)");
+        verifyLoadedAndNoDoubleDownload("resources/square.png?pipe=trickle(d5)");
+        t.done();
+    }));
+    var script = document.createElement("script");
+    script.src = "resources/dummy.js?pipe=trickle(d5)";
+    document.body.appendChild(script);
+    var img = new Image();
+    img.src = "resources/square.png?pipe=trickle(d5)";
+</script>
diff --git a/LayoutTests/imported/w3c/web-platform-tests/preload/dynamic-adding-preload-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/preload/dynamic-adding-preload-expected.txt
new file mode 100644 (file)
index 0000000..a4bfb8c
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Makes sure that a dynamically added preloaded resource is downloaded 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/preload/dynamic-adding-preload.html b/LayoutTests/imported/w3c/web-platform-tests/preload/dynamic-adding-preload.html
new file mode 100644 (file)
index 0000000..0cecc19
--- /dev/null
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/preload/resources/preload_helper.js"></script>
+<script>
+    var t = async_test('Makes sure that a dynamically added preloaded resource is downloaded');
+</script>
+<body>
+<script>
+    t.step(function() {
+        verifyPreloadAndRTSupport();
+        var link = document.createElement("link");
+        link.as = "script";
+        link.rel = "preload";
+        link.href = "resources/dummy.js?dynamic-adding-preload";
+        link.onload = t.step_func(function() {
+            t.step_timeout(function() {
+                verifyNumberOfResourceTimingEntries("resources/dummy.js?dynamic-adding-preload", 1);
+                t.done();
+            }, 0);
+        });
+        document.body.appendChild(link);
+    });
+</script>
+</body>
diff --git a/LayoutTests/imported/w3c/web-platform-tests/preload/preload-csp.sub-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/preload/preload-csp.sub-expected.txt
new file mode 100644 (file)
index 0000000..f6668c7
--- /dev/null
@@ -0,0 +1,19 @@
+CONSOLE MESSAGE: Refused to load localhost:8801/preload/resources/dummy.js because it does not appear in the style-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8800/preload/resources/dummy.css because it does not appear in the style-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8800/preload/resources/square.png because it does not appear in the img-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8800/fonts/CanvasTest.ttf because it does not appear in the font-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8800/preload/resources/white.mp4 because it does not appear in the media-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8800/preload/resources/sound_5.oga because it does not appear in the media-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8800/preload/resources/foo.vtt because it does not appear in the media-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load localhost:8801/preload/resources/dummy.js because it does not appear in the style-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8800/preload/resources/dummy.css because it does not appear in the style-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8800/preload/resources/square.png because it does not appear in the img-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8800/fonts/CanvasTest.ttf because it does not appear in the font-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8800/preload/resources/white.mp4 because it does not appear in the media-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8800/preload/resources/sound_5.oga because it does not appear in the media-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8800/preload/resources/foo.vtt because it does not appear in the media-src directive of the Content Security Policy.
+CONSOLE MESSAGE: line 16: <link rel=preload> must have a valid `as` value
+CONSOLE MESSAGE: line 17: <link rel=preload> must have a valid `as` value
+
+PASS Makes sure that preload requests respect CSP 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/preload/preload-csp.sub.html b/LayoutTests/imported/w3c/web-platform-tests/preload/preload-csp.sub.html
new file mode 100644 (file)
index 0000000..7fe06eb
--- /dev/null
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'; font-src 'none'; style-src 'none'; img-src 'none'; media-src 'none'; connect-src 'none'">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/preload/resources/preload_helper.js"></script>
+<script>
+    var t = async_test('Makes sure that preload requests respect CSP');
+</script>
+<link rel=preload href="{{host}}:{{ports[http][1]}}/preload/resources/dummy.js" as=style>
+<link rel=preload href="resources/dummy.css" as=style>
+<link rel=preload href="resources/square.png" as=image>
+<link rel=preload href="/fonts/CanvasTest.ttf" as=font crossorigin>
+<link rel=preload href="resources/white.mp4" as=video>
+<link rel=preload href="resources/sound_5.oga" as=audio>
+<link rel=preload href="resources/foo.vtt" as=track>
+<link rel=preload href="resources/dummy.xml?foo=bar" as=foobarxmlthing>
+<link rel=preload href="resources/dummy.xml">
+<body>
+<script>
+    window.onload = t.step_func(function() {
+        t.step_timeout(function() {
+            verifyPreloadAndRTSupport();
+            verifyNumberOfResourceTimingEntries("{{host}}:{{ports[http][1]}}/preload/resources/dummy.js", 0);
+            verifyNumberOfResourceTimingEntries("resources/dummy.css", 0);
+            verifyNumberOfResourceTimingEntries("resources/square.png", 0);
+            verifyNumberOfResourceTimingEntries("/fonts/CanvasTest.ttf", 0);
+            verifyNumberOfResourceTimingEntries("resources/white.mp4", 0);
+            verifyNumberOfResourceTimingEntries("resources/sound_5.oga", 0);
+            verifyNumberOfResourceTimingEntries("resources/foo.vtt", 0);
+            verifyNumberOfResourceTimingEntries("resources/dummy.xml", 0);
+            t.done();
+        }, 5000);
+    });
+</script>
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/preload/preload-default-csp.sub-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/preload/preload-default-csp.sub-expected.txt
new file mode 100644 (file)
index 0000000..30cbfd5
--- /dev/null
@@ -0,0 +1,19 @@
+CONSOLE MESSAGE: Refused to load localhost:8801/preload/resources/dummy.js because it appears in neither the style-src directive nor the default-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8800/preload/resources/dummy.css because it appears in neither the style-src directive nor the default-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8800/preload/resources/square.png because it appears in neither the img-src directive nor the default-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8800/fonts/CanvasTest.ttf because it appears in neither the font-src directive nor the default-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8800/preload/resources/white.mp4 because it appears in neither the media-src directive nor the default-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8800/preload/resources/sound_5.oga because it appears in neither the media-src directive nor the default-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8800/preload/resources/foo.vtt because it appears in neither the media-src directive nor the default-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load localhost:8801/preload/resources/dummy.js because it appears in neither the style-src directive nor the default-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8800/preload/resources/dummy.css because it appears in neither the style-src directive nor the default-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8800/preload/resources/square.png because it appears in neither the img-src directive nor the default-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8800/fonts/CanvasTest.ttf because it appears in neither the font-src directive nor the default-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8800/preload/resources/white.mp4 because it appears in neither the media-src directive nor the default-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8800/preload/resources/sound_5.oga because it appears in neither the media-src directive nor the default-src directive of the Content Security Policy.
+CONSOLE MESSAGE: Refused to load http://localhost:8800/preload/resources/foo.vtt because it appears in neither the media-src directive nor the default-src directive of the Content Security Policy.
+CONSOLE MESSAGE: line 16: <link rel=preload> must have a valid `as` value
+CONSOLE MESSAGE: line 17: <link rel=preload> must have a valid `as` value
+
+PASS Makes sure that preload requests respect CSP 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/preload/preload-default-csp.sub.html b/LayoutTests/imported/w3c/web-platform-tests/preload/preload-default-csp.sub.html
new file mode 100644 (file)
index 0000000..7813e36
--- /dev/null
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'; default-src 'none'">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/preload/resources/preload_helper.js"></script>
+<script>
+    var t = async_test('Makes sure that preload requests respect CSP');
+</script>
+<link rel=preload href="{{host}}:{{ports[http][1]}}/preload/resources/dummy.js" as=style>
+<link rel=preload href="resources/dummy.css" as=style>
+<link rel=preload href="resources/square.png" as=image>
+<link rel=preload href="/fonts/CanvasTest.ttf" as=font crossorigin>
+<link rel=preload href="resources/white.mp4" as=video>
+<link rel=preload href="resources/sound_5.oga" as=audio>
+<link rel=preload href="resources/foo.vtt" as=track>
+<link rel=preload href="resources/dummy.xml?foo=bar" as=foobarxmlthing>
+<link rel=preload href="resources/dummy.xml">
+<body>
+<script>
+    window.onload = t.step_func(function() {
+        t.step_timeout(function() {
+            verifyPreloadAndRTSupport();
+            verifyNumberOfResourceTimingEntries("{{host}}:{{ports[http][1]}}/preload/resources/dummy.js", 0);
+            verifyNumberOfResourceTimingEntries("resources/dummy.css", 0);
+            verifyNumberOfResourceTimingEntries("resources/square.png", 0);
+            verifyNumberOfResourceTimingEntries("/fonts/CanvasTest.ttf", 0);
+            verifyNumberOfResourceTimingEntries("resources/white.mp4", 0);
+            verifyNumberOfResourceTimingEntries("resources/sound_5.oga", 0);
+            verifyNumberOfResourceTimingEntries("resources/foo.vtt", 0);
+            verifyNumberOfResourceTimingEntries("resources/dummy.xml", 0);
+            t.done();
+        }, 5000);
+    });
+</script>
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/preload/resources/dummy.css b/LayoutTests/imported/w3c/web-platform-tests/preload/resources/dummy.css
new file mode 100644 (file)
index 0000000..5097166
--- /dev/null
@@ -0,0 +1 @@
+/* This is just a dummy, empty CSS file */
diff --git a/LayoutTests/imported/w3c/web-platform-tests/preload/resources/dummy.css.sub.headers b/LayoutTests/imported/w3c/web-platform-tests/preload/resources/dummy.css.sub.headers
new file mode 100644 (file)
index 0000000..360e668
--- /dev/null
@@ -0,0 +1 @@
+Cache-Control: max-age=1000
diff --git a/LayoutTests/imported/w3c/web-platform-tests/preload/resources/dummy.js b/LayoutTests/imported/w3c/web-platform-tests/preload/resources/dummy.js
new file mode 100644 (file)
index 0000000..cfcb9d8
--- /dev/null
@@ -0,0 +1 @@
+// This is example JS content. Nothing to see here.
diff --git a/LayoutTests/imported/w3c/web-platform-tests/preload/resources/dummy.js.sub.headers b/LayoutTests/imported/w3c/web-platform-tests/preload/resources/dummy.js.sub.headers
new file mode 100644 (file)
index 0000000..360e668
--- /dev/null
@@ -0,0 +1 @@
+Cache-Control: max-age=1000
diff --git a/LayoutTests/imported/w3c/web-platform-tests/preload/resources/dummy.xml b/LayoutTests/imported/w3c/web-platform-tests/preload/resources/dummy.xml
new file mode 100644 (file)
index 0000000..0d88d0c
--- /dev/null
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>Text.me</root>
diff --git a/LayoutTests/imported/w3c/web-platform-tests/preload/resources/dummy.xml.sub.headers b/LayoutTests/imported/w3c/web-platform-tests/preload/resources/dummy.xml.sub.headers
new file mode 100644 (file)
index 0000000..360e668
--- /dev/null
@@ -0,0 +1 @@
+Cache-Control: max-age=1000
diff --git a/LayoutTests/imported/w3c/web-platform-tests/preload/resources/foo.vtt b/LayoutTests/imported/w3c/web-platform-tests/preload/resources/foo.vtt
new file mode 100644 (file)
index 0000000..b533895
--- /dev/null
@@ -0,0 +1,4 @@
+WEBVTT
+
+00:00:00.000 --> 00:00:05.000
+Foo
diff --git a/LayoutTests/imported/w3c/web-platform-tests/preload/resources/preload_helper.js b/LayoutTests/imported/w3c/web-platform-tests/preload/resources/preload_helper.js
new file mode 100644 (file)
index 0000000..f464908
--- /dev/null
@@ -0,0 +1,41 @@
+function verifyPreloadAndRTSupport()
+{
+    var link = window.document.createElement("link");
+    assert_true(link.relList && link.relList.supports("preload"), "Preload not supported");
+    assert_true(!!window.PerformanceResourceTiming, "ResourceTiming not supported");
+}
+
+function getAbsoluteURL(url)
+{
+    return new URL(url, location.href).href;
+}
+
+function verifyNumberOfResourceTimingEntries(url, number)
+{
+    var numEntries = performance.getEntriesByName(getAbsoluteURL(url)).length;
+    assert_equals(numEntries, number, url);
+}
+
+// Verifies that the resource is loaded, but not downloaded from network
+// more than once. This can be used to verify that a preloaded resource is
+// not downloaded again when used.
+function verifyLoadedAndNoDoubleDownload(url) {
+    var entries = performance.getEntriesByName(getAbsoluteURL(url));
+    // UA may create separate RT entries for preload and normal load,
+    // so we just check (entries.length > 0).
+    assert_greater_than(entries.length, 0, url + ' should be loaded');
+
+    var numDownloads = 0;
+    entries.forEach(entry => {
+        // transferSize is zero if the resource is loaded from cache.
+        if (entry.transferSize > 0) {
+            numDownloads++;
+        }
+    });
+    // numDownloads can be zero if the resource was already cached before running
+    // the test (for example, when the test is running repeatedly without
+    // clearing cache between runs).
+    assert_less_than_equal(
+        numDownloads, 1,
+        url + ' should be downloaded from network at most once');
+}
diff --git a/LayoutTests/imported/w3c/web-platform-tests/preload/resources/sound_5.oga b/LayoutTests/imported/w3c/web-platform-tests/preload/resources/sound_5.oga
new file mode 100644 (file)
index 0000000..239ad2b
Binary files /dev/null and b/LayoutTests/imported/w3c/web-platform-tests/preload/resources/sound_5.oga differ
diff --git a/LayoutTests/imported/w3c/web-platform-tests/preload/resources/square.png b/LayoutTests/imported/w3c/web-platform-tests/preload/resources/square.png
new file mode 100644 (file)
index 0000000..01c9666
Binary files /dev/null and b/LayoutTests/imported/w3c/web-platform-tests/preload/resources/square.png differ
diff --git a/LayoutTests/imported/w3c/web-platform-tests/preload/resources/white.mp4 b/LayoutTests/imported/w3c/web-platform-tests/preload/resources/white.mp4
new file mode 100644 (file)
index 0000000..ef609e4
Binary files /dev/null and b/LayoutTests/imported/w3c/web-platform-tests/preload/resources/white.mp4 differ
diff --git a/LayoutTests/imported/w3c/web-platform-tests/preload/single-download-late-used-preload-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/preload/single-download-late-used-preload-expected.txt
new file mode 100644 (file)
index 0000000..70c034d
--- /dev/null
@@ -0,0 +1,4 @@
+
+
+PASS Ensure preloaded resources are not downloaded again when used 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/preload/single-download-late-used-preload.html b/LayoutTests/imported/w3c/web-platform-tests/preload/single-download-late-used-preload.html
new file mode 100644 (file)
index 0000000..51533ba
--- /dev/null
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<title>Ensure preloaded resources are not downloaded again when used</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/preload/resources/preload_helper.js"></script>
+<link rel=preload href="resources/square.png?pipe=trickle(d1)" as=image>
+<script>
+    var link = document.getElementsByTagName("link")[0]
+    assert_equals(link.as, "image");
+    link.addEventListener("load", () => {
+        verifyPreloadAndRTSupport();
+        verifyNumberOfResourceTimingEntries("resources/square.png?pipe=trickle(d1)", 1);
+        var img = document.createElement("img");
+        img.src = "resources/square.png?pipe=trickle(d1)";
+        img.onload = () => {
+            verifyLoadedAndNoDoubleDownload("resources/square.png?pipe=trickle(d1)");
+            done();
+        };
+        document.body.appendChild(img);
+    });
+</script>
+<body>
diff --git a/LayoutTests/imported/w3c/web-platform-tests/preload/single-download-preload-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/preload/single-download-preload-expected.txt
new file mode 100644 (file)
index 0000000..54b2411
--- /dev/null
@@ -0,0 +1,10 @@
+CONSOLE MESSAGE: line 16: <link rel=preload> must have a valid `as` value
+CONSOLE MESSAGE: line 17: <link rel=preload> must have a valid `as` value
+CONSOLE MESSAGE: The resource http://localhost:8800/preload/resources/square.png?background&single-download-preload was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it wasn't preloaded for nothing.
+CONSOLE MESSAGE: The resource http://localhost:8800/preload/resources/white.mp4?single-download-preload was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it wasn't preloaded for nothing.
+CONSOLE MESSAGE: The resource http://localhost:8800/preload/resources/sound_5.oga?single-download-preload was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it wasn't preloaded for nothing.
+CONSOLE MESSAGE: The resource http://localhost:8800/preload/resources/foo.vtt?single-download-preload was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it wasn't preloaded for nothing.
+  PASS - this text is here just so that the browser will download the font.
+
+PASS Makes sure that preloaded resources are not downloaded again when used 
+
diff --git a/LayoutTests/imported/w3c/web-platform-tests/preload/single-download-preload.html b/LayoutTests/imported/w3c/web-platform-tests/preload/single-download-preload.html
new file mode 100644 (file)
index 0000000..16d893c
--- /dev/null
@@ -0,0 +1,60 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/preload/resources/preload_helper.js"></script>
+<script>
+    var t = async_test('Makes sure that preloaded resources are not downloaded again when used');
+</script>
+<link rel=preload href="resources/dummy.js?single-download-preload" as=script>
+<link rel=preload href="resources/dummy.css?single-download-preload" as=style>
+<link rel=preload href="resources/square.png?single-download-preload" as=image>
+<link rel=preload href="resources/square.png?background&single-download-preload" as=image>
+<link rel=preload href="/fonts/CanvasTest.ttf?single-download-preload" as=font crossorigin>
+<link rel=preload href="resources/white.mp4?single-download-preload" as=video>
+<link rel=preload href="resources/sound_5.oga?single-download-preload" as=audio>
+<link rel=preload href="resources/foo.vtt?single-download-preload" as=track>
+<link rel=preload href="resources/dummy.xml?foo=bar" as=foobarxmlthing>
+<link rel=preload href="resources/dummy.xml?single-download-preload">
+<body>
+<style>
+    #background {
+        width: 200px;
+        height: 200px;
+        background-image: url(resources/square.png?backgroundi&single-download-preload);
+    }
+    @font-face {
+      font-family:ahem;
+      src: url(/fonts/CanvasTest.ttf?single-download-preload);
+    }
+    span { font-family: ahem, Arial; }
+</style>
+<link rel="stylesheet" href="resources/dummy.css?single-download-preload">
+<script src="resources/dummy.js?single-download-preload"></script>
+<div id="background"></div>
+<img src="resources/square.png?single-download-preload">
+<video src="resources/white.mp4?single-download-preload">
+    <track kind=subtitles src="resources/foo.vtt?single-download-preload" srclang=en>
+</video>
+<audio src="resources/sound_5.oga?single-download-preload"></audio>
+<script>
+    var xhr = new XMLHttpRequest();
+    xhr.open("GET", "resources/dummy.xml?single-download-preload");
+    xhr.send();
+
+    window.addEventListener("load", t.step_func(function() {
+        verifyPreloadAndRTSupport();
+        setTimeout(t.step_func(function() {
+            verifyLoadedAndNoDoubleDownload("resources/dummy.js?single-download-preload");
+            verifyLoadedAndNoDoubleDownload("resources/dummy.css?single-download-preload");
+            verifyLoadedAndNoDoubleDownload("resources/square.png?single-download-preload");
+            verifyLoadedAndNoDoubleDownload("resources/square.png?background&single-download-preload");
+            verifyLoadedAndNoDoubleDownload("/fonts/CanvasTest.ttf?single-download-preload");
+            verifyNumberOfResourceTimingEntries("resources/dummy.xml?foobar", 0);
+            verifyLoadedAndNoDoubleDownload("resources/foo.vtt?single-download-preload");
+            verifyLoadedAndNoDoubleDownload("resources/dummy.xml?single-download-preload");
+            // FIXME: We should verify for video and audio as well, but they seem to (flakily?) trigger multiple partial requests.
+            t.done();
+        }), 3000);
+    }));
+</script>
+<span>PASS - this text is here just so that the browser will download the font.</span>