Added web platform tests for priority hints
This adds web platform tests for all of the DOM attributes and fetch
api touch points for the priority hints API.
The IFrame and request.priority interfaces are not implemented in
Chromium yet so the tests are added but marked as expected to fail.
Bug: 821464
Change-Id: I910d2e3df24aa1e0324519c5ec505207f4069c03
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4008682
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Commit-Queue: Patrick Meenan <pmeenan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1070296}
diff --git a/third_party/blink/web_tests/TestExpectations b/third_party/blink/web_tests/TestExpectations
index 1888dec..16e662a 100644
--- a/third_party/blink/web_tests/TestExpectations
+++ b/third_party/blink/web_tests/TestExpectations
@@ -7420,3 +7420,7 @@
crbug.com/1382865 virtual/storage-access-api/external/wpt/storage-access-api/requestStorageAccess-cross-origin-iframe.sub.https.window.html [ Failure Pass ]
crbug.com/1382865 external/wpt/storage-access-api/requestStorageAccess-nested-cross-origin-iframe.sub.https.window.html [ Failure Pass ]
crbug.com/1382865 virtual/storage-access-api/external/wpt/storage-access-api/requestStorageAccess-nested-cross-origin-iframe.sub.https.window.html [ Failure Pass ]
+
+# Missing priority hints interfaces.
+crbug.com/1345601 external/wpt/priority-hints/iframe-attr-fetchpriority.tentative.html [ Failure ]
+crbug.com/1301942 external/wpt/priority-hints/service-worker-fetch-request-priority.tentative.https.html [ Failure ]
diff --git a/third_party/blink/web_tests/external/wpt/priority-hints/fetch-api-request.tentative.any.js b/third_party/blink/web_tests/external/wpt/priority-hints/fetch-api-request.tentative.any.js
index 668bdb7..1b576e5 100644
--- a/third_party/blink/web_tests/external/wpt/priority-hints/fetch-api-request.tentative.any.js
+++ b/third_party/blink/web_tests/external/wpt/priority-hints/fetch-api-request.tentative.any.js
@@ -3,3 +3,7 @@
new Request("", {priority: 'invalid'});
}, "a new Request() must throw a TypeError if RequestInit's priority is an invalid value");
}, "new Request() throws a TypeError if any of RequestInit's members' values are invalid");
+
+promise_test(function(t) {
+ return promise_rejects_js(t, TypeError, fetch('resources/blank.html', { priority: 'invalid' }));
+}, "fetch() with an invalid priority returns a rejected promise with a TypeError");
\ No newline at end of file
diff --git a/third_party/blink/web_tests/external/wpt/priority-hints/iframe-attr-fetchpriority.tentative.html b/third_party/blink/web_tests/external/wpt/priority-hints/iframe-attr-fetchpriority.tentative.html
new file mode 100644
index 0000000..3865776
--- /dev/null
+++ b/third_party/blink/web_tests/external/wpt/priority-hints/iframe-attr-fetchpriority.tentative.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<title>Priority Hints - iFrame element</title>
+<meta name="author" title="Patrick Meenan" href="mailto:patmeenan@gmail.com">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<iframe id=iframe1 src="/common/blank.html" fetchpriority=high></iframe>
+<iframe id=iframe2 src="/common/blank.html" fetchpriority=low></iframe>
+<iframe id=iframe3 src="/common/blank.html" fetchpriority=auto></iframe>
+<iframe id=iframe4 src="/common/blank.html" fetchpriority=xyz></iframe>
+<iframe id=iframe5 src="/common/blank.html"></iframe>
+
+<script>
+ test(() => {
+ assert_equals(iframe1.fetchPriority, "high", "high fetchPriority is a valid IDL value on the script element");
+ assert_equals(iframe2.fetchPriority, "low", "low fetchPriority is a valid IDL value on the script element");
+ assert_equals(iframe3.fetchPriority, "auto", "auto fetchPriority is a valid IDL value on the script element");
+ assert_equals(iframe4.fetchPriority, "auto", "invalid fetchPriority reflects as 'auto' IDL attribute on the script element");
+ assert_equals(iframe5.fetchPriority, "auto", "missing fetchPriority reflects as 'auto' IDL attribute on the script element");
+ }, "fetchpriority attribute on <iframe> elements should reflect valid IDL values");
+
+ test(() => {
+ const iframe = document.createElement("iframe");
+ assert_equals(iframe.fetchPriority, "auto");
+ }, "default fetchpriority attribute on <iframe> elements should be 'auto'");
+</script>
diff --git a/third_party/blink/web_tests/external/wpt/priority-hints/img-attr-named-constructor.tentative.html b/third_party/blink/web_tests/external/wpt/priority-hints/img-attr-fetchpriority.tentative.html
similarity index 91%
rename from third_party/blink/web_tests/external/wpt/priority-hints/img-attr-named-constructor.tentative.html
rename to third_party/blink/web_tests/external/wpt/priority-hints/img-attr-fetchpriority.tentative.html
index a6a62905..996aa4d1 100644
--- a/third_party/blink/web_tests/external/wpt/priority-hints/img-attr-named-constructor.tentative.html
+++ b/third_party/blink/web_tests/external/wpt/priority-hints/img-attr-fetchpriority.tentative.html
@@ -13,7 +13,7 @@
<script>
test(() => {
assert_equals(img1.fetchPriority, "high", "high fetchPriority is a valid IDL value on the image element");
- assert_equals(img2.fetchPriority, "low", "high fetchPriority is a valid IDL value on the image element");
+ assert_equals(img2.fetchPriority, "low", "low fetchPriority is a valid IDL value on the image element");
assert_equals(img3.fetchPriority, "auto", "auto fetchPriority is a valid IDL value on the image element");
assert_equals(img4.fetchPriority, "auto", "invalid fetchPriority reflects as 'auto' IDL attribute on the image element");
assert_equals(img5.fetchPriority, "auto", "missing fetchPriority reflects as 'auto' IDL attribute on the image element");
diff --git a/third_party/blink/web_tests/external/wpt/priority-hints/link-attr.tentative.html b/third_party/blink/web_tests/external/wpt/priority-hints/link-attr-fetchpriority.tentative.html
similarity index 79%
rename from third_party/blink/web_tests/external/wpt/priority-hints/link-attr.tentative.html
rename to third_party/blink/web_tests/external/wpt/priority-hints/link-attr-fetchpriority.tentative.html
index 0190a611..32c318b 100644
--- a/third_party/blink/web_tests/external/wpt/priority-hints/link-attr.tentative.html
+++ b/third_party/blink/web_tests/external/wpt/priority-hints/link-attr-fetchpriority.tentative.html
@@ -13,12 +13,14 @@
<script>
test(() => {
assert_equals(link1.fetchPriority, "high", "high fetchPriority is a valid IDL value on the link element");
- assert_equals(link2.fetchPriority, "low", "high fetchPriority is a valid IDL value on the link element");
+ assert_equals(link2.fetchPriority, "low", "low fetchPriority is a valid IDL value on the link element");
assert_equals(link3.fetchPriority, "auto", "auto fetchPriority is a valid IDL value on the link element");
assert_equals(link4.fetchPriority, "auto", "invalid fetchPriority reflects as 'auto' IDL attribute on the link element");
assert_equals(link5.fetchPriority, "auto", "missing fetchPriority reflects as 'auto' IDL attribute on the link element");
}, "fetchpriority attribute on <link> elements should reflect valid IDL values");
- const link = document.createElement("link");
- assert_equals(link.fetchPriority, "auto");
+ test(() => {
+ const link = document.createElement("link");
+ assert_equals(link.fetchPriority, "auto");
+ }, "default fetchpriority attribute on <link> elements should be 'auto'");
</script>
diff --git a/third_party/blink/web_tests/external/wpt/priority-hints/resources/blank.html b/third_party/blink/web_tests/external/wpt/priority-hints/resources/blank.html
new file mode 100644
index 0000000..0e76edd6
--- /dev/null
+++ b/third_party/blink/web_tests/external/wpt/priority-hints/resources/blank.html
@@ -0,0 +1 @@
+<!DOCTYPE html>
diff --git a/third_party/blink/web_tests/external/wpt/priority-hints/resources/script.js b/third_party/blink/web_tests/external/wpt/priority-hints/resources/script.js
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/third_party/blink/web_tests/external/wpt/priority-hints/resources/script.js
diff --git a/third_party/blink/web_tests/external/wpt/priority-hints/resources/service-worker-fetch-request-priority.js b/third_party/blink/web_tests/external/wpt/priority-hints/resources/service-worker-fetch-request-priority.js
new file mode 100644
index 0000000..6d115c8d
--- /dev/null
+++ b/third_party/blink/web_tests/external/wpt/priority-hints/resources/service-worker-fetch-request-priority.js
@@ -0,0 +1,17 @@
+// This worker echos back the priority of FetchEvent.request.priority
+
+self.addEventListener('message', function(event) {
+ self.port = event.data.port;
+});
+
+self.addEventListener('fetch', function(event) {
+ const search = new URL(event.request.url).search;
+ if (search.startsWith('?priority')) {
+ try {
+ self.port.postMessage(event.request.priority);
+ } catch (e) {
+ self.port.postMessage('EXCEPTION');
+ }
+ event.respondWith(new Response(null, {"status": 200}))
+ }
+});
diff --git a/third_party/blink/web_tests/external/wpt/priority-hints/script-attr-fetchpriority.tentative.html b/third_party/blink/web_tests/external/wpt/priority-hints/script-attr-fetchpriority.tentative.html
new file mode 100644
index 0000000..8639d04d
--- /dev/null
+++ b/third_party/blink/web_tests/external/wpt/priority-hints/script-attr-fetchpriority.tentative.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<title>Priority Hints - Script element</title>
+<meta name="author" title="Patrick Meenan" href="mailto:patmeenan@gmail.com">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<script id=script1 src="resources/script.js" fetchpriority=high></script>
+<script id=script2 src="resources/script.js" fetchpriority=low></script>
+<script id=script3 src="resources/script.js" fetchpriority=auto></script>
+<script id=script4 src="resources/script.js" fetchpriority=xyz></script>
+<script id=script5 src="resources/script.js"></script>
+
+<script>
+ test(() => {
+ assert_equals(script1.fetchPriority, "high", "high fetchPriority is a valid IDL value on the script element");
+ assert_equals(script2.fetchPriority, "low", "low fetchPriority is a valid IDL value on the script element");
+ assert_equals(script3.fetchPriority, "auto", "auto fetchPriority is a valid IDL value on the script element");
+ assert_equals(script4.fetchPriority, "auto", "invalid fetchPriority reflects as 'auto' IDL attribute on the script element");
+ assert_equals(script5.fetchPriority, "auto", "missing fetchPriority reflects as 'auto' IDL attribute on the script element");
+ }, "fetchpriority attribute on <script> elements should reflect valid IDL values");
+
+ test(() => {
+ const script = document.createElement("script");
+ assert_equals(script.fetchPriority, "auto");
+ }, "default fetchpriority attribute on <script> elements should be 'auto'");
+</script>
diff --git a/third_party/blink/web_tests/external/wpt/priority-hints/service-worker-fetch-request-priority.tentative.https.html b/third_party/blink/web_tests/external/wpt/priority-hints/service-worker-fetch-request-priority.tentative.https.html
new file mode 100644
index 0000000..3bf6757
--- /dev/null
+++ b/third_party/blink/web_tests/external/wpt/priority-hints/service-worker-fetch-request-priority.tentative.https.html
@@ -0,0 +1,157 @@
+<!DOCTYPE html>
+<html>
+<title>Priority Hints: Service Worker Fetch Request Priority</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
+<script>
+
+let frame = null;
+let worker = null;
+const script = 'resources/service-worker-fetch-request-priority.js';
+const scope = 'resources/blank.html';
+const channel = new MessageChannel();
+
+// Wait for a message from the service worker and removes the message handler.
+function wait_for_message_from_worker() {
+ return new Promise((resolve) => channel.port2.onmessage = (event) => resolve(event.data));
+}
+
+// Global setup: this must be the first promise_test.
+promise_test(async (t) => {
+ const registration =
+ await service_worker_unregister_and_register(t, script, scope);
+ worker = registration.installing;
+ if (!worker)
+ worker = registration.active;
+ worker.postMessage({port:channel.port1}, [channel.port1]);
+ await wait_for_state(t, worker, 'activated');
+ frame = await with_iframe(scope);
+}, 'global setup');
+
+promise_test(async (t) => {
+ frame.contentWindow.fetch('blank.html?priority', {priority: 'high'});
+ const message = await wait_for_message_from_worker();
+ assert_equals(message, 'high');
+}, "'high' fetch priority is reflected in service worker fetch handler's "+
+ " request object's priority as 'high'");
+
+promise_test(async (t) => {
+ frame.contentWindow.fetch('blank.html?priority', {priority: 'low'});
+ const message = await wait_for_message_from_worker();
+ assert_equals(message, 'low');
+}, "'low' fetch priority is reflected in service worker fetch handler's "+
+ " request object's priority as 'low'");
+
+promise_test(async (t) => {
+ frame.contentWindow.fetch('blank.html?priority', {priority: 'auto'});
+ const message = await wait_for_message_from_worker();
+ assert_equals(message, 'auto');
+}, "'auto' fetch priority is reflected in service worker fetch handler's "+
+ " request object's priority as 'auto'");
+
+promise_test(async (t) => {
+ frame.contentWindow.fetch('blank.html?priority');
+ const message = await wait_for_message_from_worker();
+ assert_equals(message, 'auto');
+}, "default fetch priority is reflected in service worker fetch handler's "+
+ " request object's priority as 'auto'");
+
+promise_test(async (t) => {
+ const doc = frame.contentDocument;
+ const node = doc.createElement("img");
+ node.src = "img-auto?priority";
+ doc.body.appendChild(node);
+ const message = await wait_for_message_from_worker();
+ assert_equals(message, 'auto');
+}, "img element with default fetchpriority is reflected in service worker" +
+ " fetch handler's request object's priority as 'auto'");
+
+promise_test(async (t) => {
+ const doc = frame.contentDocument;
+ const node = doc.createElement("img");
+ node.fetchPriority = "high";
+ node.src = "img-high?priority";
+ doc.body.appendChild(node);
+ const message = await wait_for_message_from_worker();
+ assert_equals(message, 'high');
+}, "img element with fetchpriority of high is reflected in service worker" +
+ " fetch handler's request object's priority as 'high'");
+
+promise_test(async (t) => {
+ const doc = frame.contentDocument;
+ const node = doc.createElement("script");
+ node.src = "script-auto?priority";
+ doc.body.appendChild(node);
+ const message = await wait_for_message_from_worker();
+ assert_equals(message, 'auto');
+}, "script element with default fetchpriority is reflected in service worker" +
+ " fetch handler's request object's priority as 'auto'");
+
+promise_test(async (t) => {
+ const doc = frame.contentDocument;
+ const node = doc.createElement("script");
+ node.fetchPriority = "high";
+ node.src = "script-high?priority";
+ doc.body.appendChild(node);
+ const message = await wait_for_message_from_worker();
+ assert_equals(message, 'high');
+}, "script element with fetchpriority of high is reflected in service worker" +
+ " fetch handler's request object's priority as 'high'");
+
+promise_test(async (t) => {
+ const doc = frame.contentDocument;
+ const node = doc.createElement("link");
+ node.rel = "stylesheet";
+ node.type = "text/css";
+ node.href = "link-auto?priority";
+ doc.body.appendChild(node);
+ const message = await wait_for_message_from_worker();
+ assert_equals(message, 'auto');
+}, "link element with default fetchpriority is reflected in service worker" +
+ " fetch handler's request object's priority as 'auto'");
+
+promise_test(async (t) => {
+ const doc = frame.contentDocument;
+ const node = doc.createElement("link");
+ node.rel = "stylesheet";
+ node.type = "text/css";
+ node.fetchPriority = "high";
+ node.href = "link-high?priority";
+ doc.body.appendChild(node);
+ const message = await wait_for_message_from_worker();
+ assert_equals(message, 'high');
+}, "link element with fetchpriority of high is reflected in service worker" +
+ " fetch handler's request object's priority as 'high'");
+
+promise_test(async (t) => {
+ const frame = document.createElement('iframe');
+ frame.src = scope + '?priority-default';
+ frame.style.position = 'absolute';
+ document.body.appendChild(frame);
+ const message = await wait_for_message_from_worker();
+ assert_equals(message, 'auto');
+ frame.parentNode.removeChild(frame);
+}, "iframe element with default fetchpriority is reflected in service worker" +
+ " fetch handler's request object's priority as 'auto'");
+
+promise_test(async (t) => {
+ const frame = document.createElement('iframe');
+ frame.fetchPriority = 'high';
+ frame.src = scope + '?priority-high';
+ frame.style.position = 'absolute';
+ document.body.appendChild(frame);
+ const message = await wait_for_message_from_worker();
+ assert_equals(message, 'high');
+ frame.parentNode.removeChild(frame);
+}, "iframe element with fetchpriority of high is reflected in service worker" +
+ " fetch handler's request object's priority as 'high'");
+
+// Global cleanup: the final promise_test.
+promise_test(async (t) => {
+ if (frame)
+ frame.remove();
+ await service_worker_unregister(t, scope);
+}, 'global cleanup');
+</script>
+</html>