Bug 1526643 [wpt PR 15129] - Fix remaining preload tests flaking on wpt.fyi, a=testonly
authorKunihiko Sakamoto <ksakamoto@chromium.org>
Tue, 19 Feb 2019 14:38:42 +0000
changeset 519230 8b67c6a2fd48ee4d3604e9973564c681e08a8e0d
parent 519229 8d84d8255986a0b1e5a3abe604d60557307fa2f6
child 519231 c4da5566b9663c79809d741bc7ca21ff28653ec9
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1526643, 15129, 15075, 1436777, 922343, 1442020, 629029
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1526643 [wpt PR 15129] - Fix remaining preload tests flaking on wpt.fyi, a=testonly Automatic update from web-platform-tests Fix remaining preload tests flaking on wpt.fyi This is a follow-up to https://github.com/web-platform-tests/wpt/pull/15075. https://crrev.com/c/1436777 successfully fixed the wpt.fyi flakiness for link-header-preload-srcset.tentative.html and link-header-preload-nonce.html. This patch fixes that for the remaining preload tests. - Use step_timeout instead of dummy.js?pipe=trickle, because dummy.js?pipe=trickle may be loaded from cache with no delay. - Replace verifyNumberOfDownloads() with - verifyNumberOfResourceTimingEntries() if possible - A new helper function verifyLoadedAndNoDoubleDownload() that doesn't fail if the resource was already cached before running the test. Bug: 922343 Change-Id: Ia9b7c4bd49dd76463df4607349fe4f935e5410d0 Reviewed-on: https://chromium-review.googlesource.com/c/1442020 Reviewed-by: Kinuko Yasuda <kinuko@chromium.org> Commit-Queue: Kunihiko Sakamoto <ksakamoto@chromium.org> Cr-Commit-Position: refs/heads/master@{#629029} -- wpt-commits: eb5aa0038ee7a938beabbe4c732a685af2581dbc wpt-pr: 15129
testing/web-platform/tests/mixed-content/imageset.https.sub.html
testing/web-platform/tests/preload/avoid-delaying-onload-link-preload.html
testing/web-platform/tests/preload/delaying-onload-link-preload-after-discovery.html
testing/web-platform/tests/preload/download-resources.html
testing/web-platform/tests/preload/dynamic-adding-preload-imagesrcset.tentative.html
testing/web-platform/tests/preload/dynamic-adding-preload-nonce.html
testing/web-platform/tests/preload/dynamic-adding-preload.html
testing/web-platform/tests/preload/link-header-on-subresource.html
testing/web-platform/tests/preload/link-header-preload-delay-onload.html
testing/web-platform/tests/preload/link-header-preload-nonce.html
testing/web-platform/tests/preload/link-header-preload-srcset.tentative.html
testing/web-platform/tests/preload/link-header-preload.html
testing/web-platform/tests/preload/onerror-event.html
testing/web-platform/tests/preload/onload-event.html
testing/web-platform/tests/preload/preload-csp.sub.html
testing/web-platform/tests/preload/preload-default-csp.sub.html
testing/web-platform/tests/preload/preload-with-type.html
testing/web-platform/tests/preload/resources/preload_helper.js
testing/web-platform/tests/preload/single-download-late-used-preload.html
testing/web-platform/tests/preload/single-download-preload.html
--- a/testing/web-platform/tests/mixed-content/imageset.https.sub.html
+++ b/testing/web-platform/tests/mixed-content/imageset.https.sub.html
@@ -16,16 +16,16 @@
   <img src="http://{{domains[]}}:{{ports[http][0]}}/images/smiley.png?img_src">
   <picture>
     <source srcset="http://{{domains[]}}:{{ports[http][0]}}/images/smiley.png?picture">
     <img>
   </picture>
   <img srcset="http://{{domains[]}}:{{ports[http][0]}}/images/smiley.png?img_srcset">
   <script>
     window.addEventListener("load", t.step_func(function() {
-        verifyNumberOfDownloads("http://{{domains[]}}:{{ports[http][0]}}/images/smiley.png?img_src", 1);
-        verifyNumberOfDownloads("http://{{domains[]}}:{{ports[http][0]}}/images/smiley.png?picture", 0);
-        verifyNumberOfDownloads("http://{{domains[]}}:{{ports[http][0]}}/images/smiley.png?img_srcset", 0);
+        verifyNumberOfResourceTimingEntries("http://{{domains[]}}:{{ports[http][0]}}/images/smiley.png?img_src", 1);
+        verifyNumberOfResourceTimingEntries("http://{{domains[]}}:{{ports[http][0]}}/images/smiley.png?picture", 0);
+        verifyNumberOfResourceTimingEntries("http://{{domains[]}}:{{ports[http][0]}}/images/smiley.png?img_srcset", 0);
         t.done();
     }));
   </script>
   </body>
 </html>
--- a/testing/web-platform/tests/preload/avoid-delaying-onload-link-preload.html
+++ b/testing/web-platform/tests/preload/avoid-delaying-onload-link-preload.html
@@ -4,12 +4,12 @@
 <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();
-        verifyNumberOfDownloads("/resources/dummy.js?pipe=trickle(d5)", 0);
+        verifyNumberOfResourceTimingEntries("/resources/dummy.js?pipe=trickle(d5)", 0);
         t.done();
     }));
 </script>
--- a/testing/web-platform/tests/preload/delaying-onload-link-preload-after-discovery.html
+++ b/testing/web-platform/tests/preload/delaying-onload-link-preload-after-discovery.html
@@ -6,18 +6,18 @@
     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();
-        verifyNumberOfDownloads("resources/dummy.js?pipe=trickle(d5)", 1);
-        verifyNumberOfDownloads("resources/square.png?pipe=trickle(d5)", 1);
+        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>
--- a/testing/web-platform/tests/preload/download-resources.html
+++ b/testing/web-platform/tests/preload/download-resources.html
@@ -11,25 +11,26 @@
 <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?novalue">
 <link rel=preload href="resources/dummy.xml" as="fetch">
 <body>
-<script src="resources/dummy.js?pipe=trickle(d5)&download-resources"></script>
 <script>
     window.addEventListener("load", t.step_func(function() {
-        verifyPreloadAndRTSupport()
-        verifyNumberOfDownloads("resources/dummy.js", 1);
-        verifyNumberOfDownloads("resources/dummy.css", 1);
-        verifyNumberOfDownloads("/fonts/CanvasTest.ttf", 1);
-        verifyNumberOfDownloads("resources/white.mp4", 1);
-        verifyNumberOfDownloads("resources/sound_5.oga", 1);
-        verifyNumberOfDownloads("resources/foo.vtt", 1);
-        verifyNumberOfDownloads("resources/dummy.xml?foo=bar", 0);
-        verifyNumberOfDownloads("resources/dummy.xml?novalue", 0);
-        verifyNumberOfDownloads("resources/dummy.xml", 1);
-        t.done();
+        t.step_timeout(function() {
+            verifyPreloadAndRTSupport()
+            verifyNumberOfResourceTimingEntries("resources/dummy.js", 1);
+            verifyNumberOfResourceTimingEntries("resources/dummy.css", 1);
+            verifyNumberOfResourceTimingEntries("/fonts/CanvasTest.ttf", 1);
+            verifyNumberOfResourceTimingEntries("resources/white.mp4", 1);
+            verifyNumberOfResourceTimingEntries("resources/sound_5.oga", 1);
+            verifyNumberOfResourceTimingEntries("resources/foo.vtt", 1);
+            verifyNumberOfResourceTimingEntries("resources/dummy.xml?foo=bar", 0);
+            verifyNumberOfResourceTimingEntries("resources/dummy.xml?novalue", 0);
+            verifyNumberOfResourceTimingEntries("resources/dummy.xml", 1);
+            t.done();
+        }, 5000);
     }));
 </script>
 </body>
--- a/testing/web-platform/tests/preload/dynamic-adding-preload-imagesrcset.tentative.html
+++ b/testing/web-platform/tests/preload/dynamic-adding-preload-imagesrcset.tentative.html
@@ -12,20 +12,19 @@
         var link = document.createElement("link");
         link.as = "image";
         link.rel = "preload";
         link.href = "resources/square.png?default";
         link.imageSrcset = "resources/square.png?200 200w, resources/square.png?400 400w, resources/square.png?800 800w";
         link.imageSizes = "400px";
         link.onload = t.step_func(function() {
             t.step_timeout(function() {
-                verifyNumberOfDownloads("resources/square.png?default", 0);
-                verifyNumberOfDownloads("resources/square.png?200", 0);
-                verifyNumberOfDownloads("resources/square.png?400", 1);
-                verifyNumberOfDownloads("resources/square.png?800", 0);
+                verifyNumberOfResourceTimingEntries("resources/square.png?default", 0);
+                verifyNumberOfResourceTimingEntries("resources/square.png?200", 0);
+                verifyNumberOfResourceTimingEntries("resources/square.png?400", 1);
+                verifyNumberOfResourceTimingEntries("resources/square.png?800", 0);
                 t.done();
             }, 0);
         });
         document.body.appendChild(link);
     });
 </script>
-<script src="resources/dummy.js?pipe=trickle(d5)&dynamic-adding-preload"></script>
 </body>
--- a/testing/web-platform/tests/preload/dynamic-adding-preload-nonce.html
+++ b/testing/web-platform/tests/preload/dynamic-adding-preload-nonce.html
@@ -9,32 +9,32 @@ async_test(function(t) {
     verifyPreloadAndRTSupport();
     var link = document.createElement("link");
     link.as = "script";
     link.rel = "preload";
     link.href = "resources/dummy.js?with-nonce";
     link.nonce = "abc";
     link.onload = link.onerror = t.step_func(function() {
         t.step_timeout(function() {
-            verifyNumberOfDownloads("resources/dummy.js?with-nonce", 1);
+            verifyNumberOfResourceTimingEntries("resources/dummy.js?with-nonce", 1);
             t.done();
         }, 0);
     });
     document.body.appendChild(link);
 }, "link preload with nonce attribute");
 
 async_test(function(t) {
     verifyPreloadAndRTSupport();
     var link = document.createElement("link");
     link.as = "script";
     link.rel = "preload";
     link.href = "resources/dummy.js?without-nonce";
     link.onload = link.onerror = t.step_func(function() {
         t.step_timeout(function() {
-            verifyNumberOfDownloads("resources/dummy.js?without-nonce", 0);
+            verifyNumberOfResourceTimingEntries("resources/dummy.js?without-nonce", 0);
             t.done();
         }, 0);
     });
     document.body.appendChild(link);
 }, "link preload without nonce attribute");
 
 </script>
 </body>
--- a/testing/web-platform/tests/preload/dynamic-adding-preload.html
+++ b/testing/web-platform/tests/preload/dynamic-adding-preload.html
@@ -10,17 +10,16 @@
     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() {
-                verifyNumberOfDownloads("resources/dummy.js?dynamic-adding-preload", 1);
+                verifyNumberOfResourceTimingEntries("resources/dummy.js?dynamic-adding-preload", 1);
                 t.done();
             }, 0);
         });
         document.body.appendChild(link);
     });
 </script>
-<script src="resources/dummy.js?pipe=trickle(d5)&dynamic-adding-preload"></script>
 </body>
--- a/testing/web-platform/tests/preload/link-header-on-subresource.html
+++ b/testing/web-platform/tests/preload/link-header-on-subresource.html
@@ -1,17 +1,18 @@
 <!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 Link headers on subresources preload resources');
 </script>
 <link rel=stylesheet href="resources/dummy-preloads-subresource.css?link-header-on-subresource">
-<script src="resources/dummy.js?pipe=trickle(d5)&link-header-on-subresources"></script>
 <script>
     window.addEventListener("load", t.step_func(function() {
-        verifyPreloadAndRTSupport();
-        verifyNumberOfDownloads("/fonts/CanvasTest.ttf?link-header-on-subresource", 1);
-        t.done();
+        t.step_timeout(function() {
+            verifyPreloadAndRTSupport();
+            verifyNumberOfResourceTimingEntries("/fonts/CanvasTest.ttf?link-header-on-subresource", 1);
+            t.done();
+        }, 5000);
     }));
 </script>
 
--- a/testing/web-platform/tests/preload/link-header-preload-delay-onload.html
+++ b/testing/web-platform/tests/preload/link-header-preload-delay-onload.html
@@ -26,15 +26,15 @@
             var entry = entries[i];
             if (entry.name.indexOf("square") != -1) {
                 if (entry.name.indexOf("background") != -1)
                     found_background_first = true;
                 break;
             }
         }
         assert_true(found_background_first);
-        verifyNumberOfDownloads("resources/square.png?link-header-preload-delay-onload", 1);
-        verifyNumberOfDownloads("resources/square.png?background", 1);
-        verifyNumberOfDownloads("resources/dummy.js?link-header-preload-delay-onload", 1);
-        verifyNumberOfDownloads("resources/dummy.css?link-header-preload-delay-onload", 1);
+        verifyLoadedAndNoDoubleDownload("resources/square.png?link-header-preload-delay-onload");
+        verifyLoadedAndNoDoubleDownload("resources/square.png?background");
+        verifyLoadedAndNoDoubleDownload("resources/dummy.js?link-header-preload-delay-onload");
+        verifyLoadedAndNoDoubleDownload("resources/dummy.css?link-header-preload-delay-onload");
         t.done();
     }));
 </script>
--- a/testing/web-platform/tests/preload/link-header-preload-nonce.html
+++ b/testing/web-platform/tests/preload/link-header-preload-nonce.html
@@ -1,16 +1,17 @@
 <!DOCTYPE html>
 <script nonce="abc" src="/resources/testharness.js"></script>
 <script nonce="abc" src="/resources/testharnessreport.js"></script>
 <script nonce="abc" src="/preload/resources/preload_helper.js"></script>
 <script nonce="abc">
     var t = async_test('Makes sure that Link headers preload resources with CSP nonce');
 </script>
-<script nonce="abc" src="resources/dummy.js?pipe=trickle(d5)&link-header-preload-nonce"></script>
 <script nonce="abc">
     window.addEventListener('load', t.step_func(function() {
-        verifyPreloadAndRTSupport();
-        verifyNumberOfResourceTimingEntries("resources/dummy.js?from-header&without-nonce", 0);
-        verifyNumberOfResourceTimingEntries("resources/dummy.js?from-header&with-nonce", 1);
-        t.done();
+        t.step_timeout(function() {
+            verifyPreloadAndRTSupport();
+            verifyNumberOfResourceTimingEntries("resources/dummy.js?from-header&without-nonce", 0);
+            verifyNumberOfResourceTimingEntries("resources/dummy.js?from-header&with-nonce", 1);
+            t.done();
+        }, 5000);
     }));
 </script>
--- a/testing/web-platform/tests/preload/link-header-preload-srcset.tentative.html
+++ b/testing/web-platform/tests/preload/link-header-preload-srcset.tentative.html
@@ -2,26 +2,27 @@
 <link rel="help" href="https://github.com/w3c/preload/issues/120">
 <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 Link headers preload images with (experimental) imagesrcset/imagesizes attributes.');
 </script>
 <body>
-<script src="resources/dummy.js?pipe=trickle(d3)&link-header-preload-srcset"></script>
 <script>
     window.addEventListener("load", t.step_func(function() {
-        verifyPreloadAndRTSupport();
-        verifyNumberOfResourceTimingEntries('resources/square.png?from-header&1x', 1);
-        verifyNumberOfResourceTimingEntries('resources/square.png?from-header&2x', 0);
-        verifyNumberOfResourceTimingEntries('resources/square.png?from-header&3x', 0);
-        verifyNumberOfResourceTimingEntries('resources/square.png?from-header&base', 0);
-        verifyNumberOfResourceTimingEntries('resources/square.png?from-header&200', 0);
-        verifyNumberOfResourceTimingEntries('resources/square.png?from-header&400', 1);
-        verifyNumberOfResourceTimingEntries('resources/square.png?from-header&800', 0);
-        verifyNumberOfResourceTimingEntries('resources/square.png?from-header&150', 0);
-        verifyNumberOfResourceTimingEntries('resources/square.png?from-header&300', 1);
-        verifyNumberOfResourceTimingEntries('resources/square.png?from-header&600', 0);
-        t.done();
+        t.step_timeout(function() {
+            verifyPreloadAndRTSupport();
+            verifyNumberOfResourceTimingEntries('resources/square.png?from-header&1x', 1);
+            verifyNumberOfResourceTimingEntries('resources/square.png?from-header&2x', 0);
+            verifyNumberOfResourceTimingEntries('resources/square.png?from-header&3x', 0);
+            verifyNumberOfResourceTimingEntries('resources/square.png?from-header&base', 0);
+            verifyNumberOfResourceTimingEntries('resources/square.png?from-header&200', 0);
+            verifyNumberOfResourceTimingEntries('resources/square.png?from-header&400', 1);
+            verifyNumberOfResourceTimingEntries('resources/square.png?from-header&800', 0);
+            verifyNumberOfResourceTimingEntries('resources/square.png?from-header&150', 0);
+            verifyNumberOfResourceTimingEntries('resources/square.png?from-header&300', 1);
+            verifyNumberOfResourceTimingEntries('resources/square.png?from-header&600', 0);
+            t.done();
+        }, 3000);
     }));
 </script>
 </body>
--- a/testing/web-platform/tests/preload/link-header-preload.html
+++ b/testing/web-platform/tests/preload/link-header-preload.html
@@ -1,19 +1,20 @@
 <!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 Link headers preload resources');
 </script>
 <body>
-<script src="resources/dummy.js?pipe=trickle(d5)&link-header-preload"></script>
 <script>
     window.addEventListener("load", t.step_func(function() {
-        verifyPreloadAndRTSupport();
-        verifyNumberOfDownloads("resources/square.png?link-header-preload", 1);
-        verifyNumberOfDownloads("resources/dummy.js?link-header-preload", 1);
-        verifyNumberOfDownloads("resources/dummy.css?link-header-preload", 1);
-        t.done();
+        t.step_timeout(function() {
+            verifyPreloadAndRTSupport();
+            verifyNumberOfResourceTimingEntries("resources/square.png?link-header-preload", 1);
+            verifyNumberOfResourceTimingEntries("resources/dummy.js?link-header-preload", 1);
+            verifyNumberOfResourceTimingEntries("resources/dummy.css?link-header-preload", 1);
+            t.done();
+        }, 5000);
     }));
 </script>
 </body>
--- a/testing/web-platform/tests/preload/onerror-event.html
+++ b/testing/web-platform/tests/preload/onerror-event.html
@@ -23,27 +23,28 @@
 <link rel=preload href="non-existent/square.png" as=image onerror="imageFailed = true;">
 <link rel=preload href="non-existent/Ahem.ttf" as=font crossorigin onerror="fontFailed = true;">
 <link rel=preload href="non-existent/test.mp4" as=video onerror="videoFailed = true;">
 <link rel=preload href="non-existent/test.oga" as=audio onerror="audioFailed = true;">
 <link rel=preload href="non-existent/security/captions.vtt" as=track onerror="trackFailed = true;">
 <link rel=preload href="non-existent/dummy.xml?foo" as=foobarxmlthing onerror="gibberishFailed = true;">
 <link rel=preload href="non-existent/dummy.xml?fetch" as=fetch onerror="fetchFailed = true;">
 <link rel=preload href="non-existent/dummy.xml?empty" onerror="emptyFailed = true;">
-<script src="resources/dummy.js?pipe=trickle(d5)&onerror-event"></script>
 <script>
     window.onload = t.step_func(function() {
-        verifyPreloadAndRTSupport();
-        assert_true(styleFailed, "style triggered error event");
-        assert_true(scriptFailed, "script triggered error event");
-        assert_true(imageFailed, "image triggered error event");
-        assert_true(fontFailed, "font triggered error event");
-        assert_true(videoFailed, "video triggered error event");
-        assert_true(audioFailed, "audio triggered error event");
-        assert_true(trackFailed, "track triggered error event");
-        assert_false(gibberishFailed, "gibberish as value did not trigger error event");
-        assert_true(fetchFailed, "fetch as triggered error event");
-        assert_false(emptyFailed, "empty as triggered error event");
-        t.done();
+        t.step_timeout(function() {
+            verifyPreloadAndRTSupport();
+            assert_true(styleFailed, "style triggered error event");
+            assert_true(scriptFailed, "script triggered error event");
+            assert_true(imageFailed, "image triggered error event");
+            assert_true(fontFailed, "font triggered error event");
+            assert_true(videoFailed, "video triggered error event");
+            assert_true(audioFailed, "audio triggered error event");
+            assert_true(trackFailed, "track triggered error event");
+            assert_false(gibberishFailed, "gibberish as value did not trigger error event");
+            assert_true(fetchFailed, "fetch as triggered error event");
+            assert_false(emptyFailed, "empty as triggered error event");
+            t.done();
+        }, 5000);
     });
 </script>
 </body>
 </html>
--- a/testing/web-platform/tests/preload/onload-event.html
+++ b/testing/web-platform/tests/preload/onload-event.html
@@ -22,27 +22,28 @@
 <link rel=preload href="/fonts/CanvasTest.ttf" as=font crossorigin onload="fontLoaded = true;">
 <link rel=preload href="resources/white.mp4" as=video onload="videoLoaded = true;">
 <link rel=preload href="resources/sound_5.oga" as=audio onload="audioLoaded = true;">
 <link rel=preload href="resources/foo.vtt" as=track onload="trackLoaded = true;">
 <link rel=preload href="resources/dummy.xml?foo=bar" as=foobarxmlthing onload="gibberishLoaded = true;" onerror="gibberishErrored = true;">
 <link rel=preload href="resources/dummy.xml?fetch" as=fetch onload="fetchLoaded = true;">
 <link rel=preload href="resources/dummy.xml" onload="noTypeLoaded = true;">
 <body>
-<script src="resources/dummy.js?pipe=trickle(d5)&onload-event"></script>
 <script>
     window.onload = t.step_func(function() {
-        verifyPreloadAndRTSupport();
-        assert_true(styleLoaded, "style triggered load event");
-        assert_true(scriptLoaded, "script triggered load event");
-        assert_true(imageLoaded, "image triggered load event");
-        assert_true(fontLoaded, "font triggered load event");
-        assert_true(videoLoaded, "video triggered load event");
-        assert_true(audioLoaded, "audio triggered load event");
-        assert_true(trackLoaded, "track triggered load event");
-        assert_false(gibberishLoaded, "gibberish as value triggered load event");
-        assert_false(gibberishErrored, "gibberish as value triggered error event");
-        assert_true(fetchLoaded, "fetch as value triggered load event");
-        assert_false(noTypeLoaded, "empty as triggered load event");
-        t.done();
+        t.step_timeout(function() {
+            verifyPreloadAndRTSupport();
+            assert_true(styleLoaded, "style triggered load event");
+            assert_true(scriptLoaded, "script triggered load event");
+            assert_true(imageLoaded, "image triggered load event");
+            assert_true(fontLoaded, "font triggered load event");
+            assert_true(videoLoaded, "video triggered load event");
+            assert_true(audioLoaded, "audio triggered load event");
+            assert_true(trackLoaded, "track triggered load event");
+            assert_false(gibberishLoaded, "gibberish as value triggered load event");
+            assert_false(gibberishErrored, "gibberish as value triggered error event");
+            assert_true(fetchLoaded, "fetch as value triggered load event");
+            assert_false(noTypeLoaded, "empty as triggered load event");
+            t.done();
+        }, 5000);
     });
 </script>
 </body>
--- a/testing/web-platform/tests/preload/preload-csp.sub.html
+++ b/testing/web-platform/tests/preload/preload-csp.sub.html
@@ -11,24 +11,25 @@
 <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 src="resources/dummy.js?pipe=trickle(d5)&preload-csp"></script>
 <script>
     window.onload = t.step_func(function() {
-        verifyPreloadAndRTSupport();
-        verifyNumberOfDownloads("{{host}}:{{ports[http][1]}}/preload/resources/dummy.js", 0);
-        verifyNumberOfDownloads("resources/dummy.css", 0);
-        verifyNumberOfDownloads("resources/square.png", 0);
-        verifyNumberOfDownloads("/fonts/CanvasTest.ttf", 0);
-        verifyNumberOfDownloads("resources/white.mp4", 0);
-        verifyNumberOfDownloads("resources/sound_5.oga", 0);
-        verifyNumberOfDownloads("resources/foo.vtt", 0);
-        verifyNumberOfDownloads("resources/dummy.xml", 0);
-        t.done();
+        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>
 
--- a/testing/web-platform/tests/preload/preload-default-csp.sub.html
+++ b/testing/web-platform/tests/preload/preload-default-csp.sub.html
@@ -11,24 +11,25 @@
 <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 src="resources/dummy.js?pipe=trickle(d5)&preload-default-csp"></script>
 <script>
     window.onload = t.step_func(function() {
-        verifyPreloadAndRTSupport();
-        verifyNumberOfDownloads("{{host}}:{{ports[http][1]}}/preload/resources/dummy.js", 0);
-        verifyNumberOfDownloads("resources/dummy.css", 0);
-        verifyNumberOfDownloads("resources/square.png", 0);
-        verifyNumberOfDownloads("/fonts/CanvasTest.ttf", 0);
-        verifyNumberOfDownloads("resources/white.mp4", 0);
-        verifyNumberOfDownloads("resources/sound_5.oga", 0);
-        verifyNumberOfDownloads("resources/foo.vtt", 0);
-        verifyNumberOfDownloads("resources/dummy.xml", 0);
-        t.done();
+        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>
 
--- a/testing/web-platform/tests/preload/preload-with-type.html
+++ b/testing/web-platform/tests/preload/preload-with-type.html
@@ -42,25 +42,26 @@
 <link rel=preload href="resources/square.png" as=image type="image/foobar" onload="gibberishLoaded++;">
 <link rel=preload href="/fonts/CanvasTest.ttf" as=font type="font/foobar" crossorigin onload="gibberishLoaded++;">
 <script>
     document.write('<link rel=preload href="' + videoURL + '" as=video type="video/foobar" onload="gibberishLoaded++;">');
     document.write('<link rel=preload href="' + audioURL + '" as=audio type="audio/foobar" onload="gibberishLoaded++;">');
 </script>
 <link rel=preload href="resources/foo.vtt" as=track type="text/foobar" onload="gibberishLoaded++;">
 <body>
-<script src="resources/dummy.js?pipe=trickle(d5)&preload-with-type"></script>
 <script>
     window.onload = t.step_func(function() {
-        verifyPreloadAndRTSupport();
-        assert_true(styleLoaded, "style triggered load event");
-        assert_true(scriptLoaded, "script triggered load event");
-        assert_true(imageLoaded, "image triggered load event");
-        assert_true(fontLoaded, "font triggered load event");
-        assert_true(videoLoaded, "video triggered load event");
-        assert_true(audioLoaded, "audio triggered load event");
-        assert_true(trackLoaded, "track triggered load event");
-        assert_equals(gibberishLoaded, 0, "resources with gibberish type should not be loaded");
-        t.done();
+        t.step_timeout(function() {
+            verifyPreloadAndRTSupport();
+            assert_true(styleLoaded, "style triggered load event");
+            assert_true(scriptLoaded, "script triggered load event");
+            assert_true(imageLoaded, "image triggered load event");
+            assert_true(fontLoaded, "font triggered load event");
+            assert_true(videoLoaded, "video triggered load event");
+            assert_true(audioLoaded, "audio triggered load event");
+            assert_true(trackLoaded, "track triggered load event");
+            assert_equals(gibberishLoaded, 0, "resources with gibberish type should not be loaded");
+            t.done();
+        }, 5000);
     });
 </script>
 </body>
 </html>
--- a/testing/web-platform/tests/preload/resources/preload_helper.js
+++ b/testing/web-platform/tests/preload/resources/preload_helper.js
@@ -5,24 +5,37 @@ function verifyPreloadAndRTSupport()
     assert_true(!!window.PerformanceResourceTiming, "ResourceTiming not supported");
 }
 
 function getAbsoluteURL(url)
 {
     return new URL(url, location.href).href;
 }
 
-function verifyNumberOfDownloads(url, number)
-{
-    var numDownloads = 0;
-    performance.getEntriesByName(getAbsoluteURL(url)).forEach(entry => {
-        if (entry.transferSize > 0) {
-            numDownloads++;
-        }
-    });
-    assert_equals(numDownloads, number, url);
-}
-
 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');
+}
--- a/testing/web-platform/tests/preload/single-download-late-used-preload.html
+++ b/testing/web-platform/tests/preload/single-download-late-used-preload.html
@@ -4,19 +4,19 @@
 <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();
-        verifyNumberOfDownloads("resources/square.png?pipe=trickle(d1)", 1);
+        verifyNumberOfResourceTimingEntries("resources/square.png?pipe=trickle(d1)", 1);
         var img = document.createElement("img");
         img.src = "resources/square.png?pipe=trickle(d1)";
         img.onload = () => {
-            verifyNumberOfDownloads("resources/square.png?pipe=trickle(d1)", 1);
+            verifyLoadedAndNoDoubleDownload("resources/square.png?pipe=trickle(d1)");
             done();
         };
         document.body.appendChild(img);
     });
 </script>
 <body>
--- a/testing/web-platform/tests/preload/single-download-preload.html
+++ b/testing/web-platform/tests/preload/single-download-preload.html
@@ -11,17 +11,16 @@
 <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>
-<script src="resources/dummy.js?pipe=trickle(d3)&single-download-preload"></script>
 <style>
     #background {
         width: 200px;
         height: 200px;
         background-image: url(resources/square.png?backgroundi&single-download-preload);
     }
     @font-face {
       font-family:ahem;
@@ -40,22 +39,22 @@
 <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() {
-            verifyNumberOfDownloads("resources/dummy.js?single-download-preload", 1);
-            verifyNumberOfDownloads("resources/dummy.css?single-download-preload", 1);
-            verifyNumberOfDownloads("resources/square.png?single-download-preload", 1);
-            verifyNumberOfDownloads("resources/square.png?background&single-download-preload", 1);
-            verifyNumberOfDownloads("/fonts/CanvasTest.ttf?single-download-preload", 1);
-            verifyNumberOfDownloads("resources/dummy.xml?foobar", 0);
-            verifyNumberOfDownloads("resources/foo.vtt?single-download-preload", 1);
-            verifyNumberOfDownloads("resources/dummy.xml?single-download-preload", 1);
+            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();
-        }), 0);
+        }), 3000);
     }));
 </script>
 <span>PASS - this text is here just so that the browser will download the font.</span>