Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPT: Ensure src attribute changes trigger preparation #47782

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!doctype html>
<meta charset=utf-8>
<link rel=help href=https://github.com/whatwg/html/pull/10188#discussion_r1719338657>
<title>Adding/changing src attribute does "prepare the script"</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<body>
<script>
// The "old" HTML Standard specification text around `src` attribute mutation
// for non-parser-inserted scripts *ONLY* "prepared"/run the script iff the src
// attribute "previously had no such attribute". This changed in
// https://github.com/whatwg/html/pull/10188 to align with a majority of
// browsers. This test ensures that `src` mutations on these kinds of scripts
// *where a previous valid `src` attribute existed* do indeed "prepare" the
// script.
promise_test(async () => {
window.didExecute = false;

const script = document.createElement('script');
// Invalid type, so the script won't execute upon insertion.
script.type = 'invalid';
script.src = 'resources/flag-setter.js';
document.body.append(script);
assert_false(window.didExecute);

// Make script valid, but don't immediately execute it.
script.type = '';

const scriptPromise = new Promise(resolve => {
script.onload = resolve;
});

// Mutating the `src` attribute, which has an existing valid value, triggers
// the "prepare a script" algorithm via the post-connection steps.
script.src = 'resources/flag-setter.js?different';

await scriptPromise;
assert_true(window.didExecute);
}, "Mutating `src` attribute from an already-valid value does 'prepare' the script");
</script>
</body>