Skip to content

Commit

Permalink
Add WPT test for Document-Policy: expect-no-linked-resources
Browse files Browse the repository at this point in the history
This PR adds a tentative and optional test case for
whatwg/html#10718
  • Loading branch information
alexnj committed Dec 10, 2024
1 parent d8cdb54 commit 81775b0
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Speculative parsing, expect-no-linked-resources Document-Policy</title>
<meta name="timeout" content="long">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/common/utils.js"></script>
<script src="stash.js"></script>
<script>
promise_test(t => new Promise((resolve, reject) => {
const uuid = token();
async function on_load_test_document() {
resolve(await get_results(uuid));
}

test_driver.bless('Open a URL with expect-no-linked-resources Document-Policy', () => {
const popup = window.open(`/html/syntax/speculative-parsing/expect-no-linked-resources/no-speculative-fetch.tentative.optional.sub.html?pipe=sub&uuid=${uuid}`, '_blank');
popup.addEventListener('load', on_load_test_document, false);
});
}).then(result => {
assert_equals(result, '', 'speculative case fetched');
}), `no-linked-resources speculative hint was ignored`);

</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!doctype html>
<title>Navigating to a page with expect-no-linked-resources</title>

<body>
<script>
document.write('<plaintext>');
</script>
<img
src="/html/syntax/speculative-parsing/expect-no-linked-resources/stash.py?action=put&uuid={{GET[uuid]}}&encodingcheck=&Gbreve;">
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Document-Policy: expect-no-linked-resources
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Fetch test results from the Stash
async function get_results(uuid) {
const response = await fetch(`/html/syntax/speculative-parsing/expect-no-linked-resources/stash.py?action=get&uuid=${uuid}`);
const text = await response.text();
return text;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import time

def main(request, response):
if request.GET[b"action"] == b"put":
# Received result data from target page
request.server.stash.put(request.GET[b"uuid"], request.GET[b"uuid"], u'/expect-no-linked-resources/')
return u"ok"
else:
# Request for result data from test page
value = request.server.stash.take(request.GET[b"uuid"], u'/expect-no-linked-resources/')
return value

0 comments on commit 81775b0

Please sign in to comment.