[ResourceTiming] Add cache busting to ResourceTiming WPTs

In order to reliably force loading a given resource, the helper
functions in resource-loaders.js now add a "cache_bust" search
parameter to URLs before loading them. This way, cache state
won't leak into and interfere with running multiple ResourceTiming
tests.

Bug: 1171767
Change-Id: I9927963b0c467122c478cb6b137b7113487219d9
GithubIssue: https://github.com/w3c/resource-timing/issues/254
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2826596
Reviewed-by: Yoav Weiss <yoavweiss@chromium.org>
Reviewed-by: Nicolás Peña Moreno <npm@chromium.org>
Commit-Queue: Tom McKee <tommckee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#877940}
diff --git a/resource-timing/resources/resource-loaders.js b/resource-timing/resources/resource-loaders.js
index c5754d1..a02de4f 100644
--- a/resource-timing/resources/resource-loaders.js
+++ b/resource-timing/resources/resource-loaders.js
@@ -1,11 +1,18 @@
 const load = {
+  _cache_bust_value: Math.random().toString().substr(2),
+  cache_bust: path => {
+    let url = new URL(path, location.origin);
+    url.hash += `cache_bust=${load._cache_bust_value++}`;
+    return url.href;
+  },
+
   // Returns a promise that settles once the given path has been fetched as an
   // image resource.
   image: path => {
     return new Promise(resolve => {
       const img = new Image();
       img.onload = img.onerror = resolve;
-      img.src = path;
+      img.src = load.cache_bust(path);
     });
   },
 
@@ -17,7 +24,7 @@
       <style>
       @font-face {
           font-family: ahem;
-          src: url('${path}');
+          src: url('${load.cache_bust(path)}');
       }
       </style>
       <div style="font-family: ahem;">This fetches ahem font.</div>
@@ -34,7 +41,7 @@
     const link = document.createElement("link");
     link.rel = "stylesheet";
     link.type = "text/css";
-    link.href = path;
+    link.href = load.cache_bust(path);
 
     const loaded = new Promise(resolve => {
       link.onload = link.onerror = resolve;
@@ -52,7 +59,7 @@
     const loaded = new Promise(resolve => {
       frame.onload = frame.onerror = resolve;
     });
-    frame.src = path;
+    frame.src = load.cache_bust(path);
     document.body.appendChild(frame);
     await loaded;
     document.body.removeChild(frame);
@@ -65,7 +72,7 @@
     const loaded = new Promise(resolve => {
       script.onload = script.onerror = resolve;
     });
-    script.src = path;
+    script.src = load.cache_bust(path);
     document.body.appendChild(script);
     await loaded;
     document.body.removeChild(script);