Bug 1728894 [wpt PR 30314] - [ResourceTiming]: Update cached-resources tests, a=testonly
authorTom McKee <tommckee@chromium.org>
Tue, 14 Sep 2021 09:48:29 +0000
changeset 592682 dfe1824f63e60d67a8c5ccbe2c0f88760d8a15bf
parent 592681 079657f3904df3f5e3bc5eeb5ca831b9ca956140
child 592683 d253a732e838be49741f66ab20c412e8ae2a6193
push id38811
push usernbeleuzu@mozilla.com
push dateWed, 22 Sep 2021 04:09:13 +0000
treeherdermozilla-central@b6fd43458638 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1728894, 30314, 1171767, 3138444, 918104
milestone94.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 1728894 [wpt PR 30314] - [ResourceTiming]: Update cached-resources tests, a=testonly Automatic update from web-platform-tests [ResourceTiming]: Update cached-resources tests This change updates the resource_reuse.sub.html and single-entry-per-resource.html Resource Timing WPTs. They covered the same case; when no network request is issued for a resource, there should be no associated PerformanceResourceTiming entry. The tests have been consolidated into cached-image-gets-single-entry.html and the style updated to conform to the guidelines in wpt/resource-timing/CodingConventions.md. GithubIssue: https://github.com/w3c/resource-timing/issues/254 Bug: 1171767 Change-Id: Ibdc67dcedf70b96e317ace165eed4e5ec897e996 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3138444 Reviewed-by: Yoav Weiss <yoavweiss@chromium.org> Commit-Queue: Tom McKee <tommckee@chromium.org> Cr-Commit-Position: refs/heads/main@{#918104} -- wpt-commits: 24836df509f65b6c2fb896dae46d99ec1b74d4e8 wpt-pr: 30314
testing/web-platform/tests/resource-timing/cached-image-gets-single-entry.html
testing/web-platform/tests/resource-timing/resource_reuse.sub.html
testing/web-platform/tests/resource-timing/single-entry-per-resource.html
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/resource-timing/cached-image-gets-single-entry.html
@@ -0,0 +1,67 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8" />
+<title>Resource Timing: test behavior for cached resources</title>
+<link rel="author" title="Google" href="http://www.google.com/" />
+<link rel="help" href="https://www.w3.org/TR/resource-timing-2/"/>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/observe-entry.js"></script>
+</head>
+<body>
+<h1>Description</h1>
+<p>Test that a reused resource only appears in the buffer once.</p>
+<script>
+// Need our own image loading helper because the one in resource-loaders.js
+// is desgined to always side-step the HTTP cache but this test relies on the
+// second request being resolved from the cache.
+const load_image = path => new Promise(resolve => {
+  const img = document.createElement('img');
+  img.onload = img.onerror = () => resolve();
+  img.src = path;
+  document.body.append(img);
+});
+
+promise_test(async () => {
+  const blue = "resources/blue.png";
+
+  // First request. Should appear in the timeline.
+  await load_image(blue + "?cacheable");
+
+  // Second request. Should not appear in the timeline.
+  await load_image(blue + "?cacheable");
+
+  // Third request. When this request shows up in the timeline, we know that, if
+  // the second request would generate an entry, that entry would have already
+  // shown up in the timeline. Without this, we'd need to guess at how long to
+  // wait which tends to be flaky.
+  await load_image(blue + "?avoid-cache");
+
+  const entries = await new Promise(resolve => {
+    const accumulator = [];
+    new PerformanceObserver(entry_list => {
+      entry_list.getEntries().forEach(entry => {
+        if (!entry.name.includes("blue.png")) {
+          // Ignore resources other than blue images.
+          return;
+        }
+        accumulator.push(entry);
+
+        // Once we see the 'canary' resource, we don't need to wait anymore.
+        if (entry.name.endsWith('avoid-cache')) {
+          resolve(accumulator);
+        }
+      });
+    }).observe({'type': 'resource', 'buffered': true});
+  });
+
+  assert_equals(entries.length, 2, "There must be exactly 2 entries in the " +
+    "Performance Timeline");
+  assert_true(entries[0].name.endsWith("blue.png?cacheable"));
+  assert_true(entries[1].name.endsWith("blue.png?avoid-cache"));
+}, "When a resource is resolved from cache, there must not be a " +
+  "corresponding entry in the Performance Timeline");
+</script>
+</body>
+</html>
deleted file mode 100644
--- a/testing/web-platform/tests/resource-timing/resource_reuse.sub.html
+++ /dev/null
@@ -1,91 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<meta charset="utf-8" />
-<title>Resource Timing: test behavior for reused resources</title>
-<link rel="author" title="Google" href="http://www.google.com/" />
-<link rel="help" href="http://www.w3.org/TR/resource-timing/#dom-performanceresourcetiming-initiatortype"/>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="resources/webperftestharness.js"></script>
-<script src="resources/webperftestharnessextension.js"></script>
-<script src="/common/get-host-info.sub.js"></script>
-<script>
-setup({explicit_done: true});
-let d;
-let iframe;
-let iframeBody;
-let count = 0;
-const host = get_host_info();
-const img_src = 'blue.png?id=cached';
-function onload_prep() {
-    iframe = document.getElementById('frameContext');
-    d = iframe.contentWindow.document;
-    iframeBody = d.body;
-
-    const image = d.createElement('IMG');
-    image.addEventListener('load', function() {
-        step_timeout(onload_test, 0); });
-    image.src = img_src;
-    iframeBody.appendChild(image);
-
-    const image2 = d.createElement('IMG');
-    image2.addEventListener('load', function() {
-        step_timeout(onload_test, 0); });
-    image2.src = img_src;
-    iframeBody.appendChild(image2);
-}
-
-function onload_test() {
-    ++count;
-    if (count < 2)
-        return;
-
-    const context = new PerformanceContext(iframe.contentWindow.performance);
-    const entries = context.getEntriesByType('resource');
-    test_equals(entries.length, 1, "There should be only one entry");
-
-    const index = window.location.pathname.lastIndexOf('/');
-    const pathname = window.location.pathname.substring(0, index);
-    let expected_entries = {};
-    expected_entries[pathname + '/resources/' + img_src] = 'img';
-    test_resource_entries(entries, expected_entries);
-    test_greater_than(entries[0].requestStart, 0, 'requestStart should be non-zero on the same-origin request');
-    test_greater_or_equals(entries[0].responseEnd, entries[0].startTime, 'responseEnd should not be before startTime');
-    test_greater_or_equals(entries[0].duration, 0, 'duration should not be negative');
-
-    context.clearResourceTimings();
-    start_crossorigin_test();
-}
-function start_crossorigin_test() {
-    const image3 = d.createElement('IMG');
-    image3.addEventListener("load", function() { step_timeout(finish_crossorigin_test, 0); });
-    image3.src = 'http://' + host.REMOTE_HOST + ':{{ports[http][1]}}{{location[path]}}/../resources/' + img_src;
-    iframeBody.appendChild(image3);
-}
-function finish_crossorigin_test() {
-    const context = new PerformanceContext(iframe.contentWindow.performance);
-    const entries = context.getEntriesByType('resource');
-    test_equals(entries.length, 1, 'There should be one entry in second test');
-    test_true(entries[0].name.startsWith('http://' + host.REMOTE_HOST + ':{{ports[http][1]}}'), 'Entry name should start with cross-origin domain');
-    test_true(entries[0].name.endsWith('/resources/' + img_src), 'Entry name should end with file name');
-    test_equals(entries[0].requestStart, 0, 'requestStart should be 0 on the cross-origin request');
-    done();
-}
-window.setup_iframe = () => {};
-window.addEventListener('load', onload_prep);
-</script>
-</head>
-<body>
-<h1>Description</h1>
-<p>This test validates that a reused resource appears in the buffer once.</p>
-<div id="log"></div>
-<iframe id="frameContext" src="resources/inject_resource_test.html"></iframe>
-<img src="resources/blue.png?id=cached"></img>
-<script>
-    const img = document.createElement('IMG');
-    img.src = "http://" + host.REMOTE_HOST + ":{{ports[http][1]}}{{location[path]}}/../resources/blue.png?id=cached";
-    document.currentScript.parentNode.insertBefore(img, document.currentScript);
-</script>
-</body>
-</html>
deleted file mode 100644
--- a/testing/web-platform/tests/resource-timing/single-entry-per-resource.html
+++ /dev/null
@@ -1,51 +0,0 @@
-<!DOCTYPE HTML>
-<meta charset=utf-8>
-<meta name="timeout" content="long">
-<title>One resource when reusing data</title>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<body>
-<script>
-async_test(t => {
-  var img_entries = 0;
-  var observed = 0;
-  var img_url = "resources/blue.png";
-  var observer = new PerformanceObserver(
-    function (entryList, obs) {
-      var entries = entryList.getEntriesByType("resource");
-      for (var i = 0; i < entries.length; ++i) {
-        // Ignore any entries for the test harness files if present.
-        if (/testharness(report)?\.js/.test(entries[i].name)) {
-          continue;
-        }
-
-        ++observed;
-        if (entries[i].name.indexOf(img_url) != -1)
-            ++img_entries;
-      }
-    });
-  observer.observe({entryTypes: ["resource"]});
-  window.onload = function() {
-    // A timeout is needed as PerformanceObserver is not guaranteed to run before onload triggered.
-    t.step_timeout(function() {
-        assert_equals(observed, 1);
-        assert_equals(img_entries, 1);
-        t.done();
-    }, 0);
-  };
-  // Images are added dynamically to make sure the observer is registered before their download finishes.
-  var img1 = document.createElement("img");
-  img1.src = img_url;
-  document.body.appendChild(img1);
-  var img2 = document.createElement("img");
-  img2.src = img_url;
-  document.body.appendChild(img2);
-}, "A single resource used in two elements produces a single entry.");
-</script>
-<h1>One resource when reusing data</h1>
-<p>
-If the user agent is to reuse the data from another existing or completed fetch initiated from the current document, abort the remaining steps.
-</p>
-<div id="log"></div>
-</body>
-