Skip to content

Commit e9fb562

Browse files
domfarolinomoz-wptsync-bot
authored andcommitted
Bug 1914829 [wpt PR 47782] - WPT: Ensure src attribute changes trigger preparation, a=testonly
Automatic update from web-platform-tests WPT: Ensure `src` attribute changes trigger preparation See this HTML Standard PR thread: whatwg/html#10188 (comment). R=domenic Bug: N/A Change-Id: I31065f76e324f71d2b4ae52813b3b37d3b4467c0 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5809759 Reviewed-by: Domenic Denicola <[email protected]> Commit-Queue: Dominic Farolino <[email protected]> Cr-Commit-Position: refs/heads/main@{#1346661} -- wpt-commits: cab88353d0991229e6d81f8fb6b0862fe9495de8 wpt-pr: 47782
1 parent 1557078 commit e9fb562

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!doctype html>
2+
<meta charset=utf-8>
3+
<link rel=help href=https://github.com/whatwg/html/pull/10188#discussion_r1719338657>
4+
<title>Adding/changing src attribute does "prepare the script"</title>
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
8+
<body>
9+
<script>
10+
// The "old" HTML Standard specification text around `src` attribute mutation
11+
// for non-parser-inserted scripts *ONLY* "prepared"/run the script iff the src
12+
// attribute "previously had no such attribute". This changed in
13+
// https://github.com/whatwg/html/pull/10188 to align with a majority of
14+
// browsers. This test ensures that `src` mutations on these kinds of scripts
15+
// *where a previous valid `src` attribute existed* do indeed "prepare" the
16+
// script.
17+
promise_test(async () => {
18+
window.didExecute = false;
19+
20+
const script = document.createElement('script');
21+
// Invalid type, so the script won't execute upon insertion.
22+
script.type = 'invalid';
23+
script.src = 'resources/flag-setter.js';
24+
document.body.append(script);
25+
assert_false(window.didExecute);
26+
27+
// Make script valid, but don't immediately execute it.
28+
script.type = '';
29+
30+
const scriptPromise = new Promise(resolve => {
31+
script.onload = resolve;
32+
});
33+
34+
// Mutating the `src` attribute, which has an existing valid value, triggers
35+
// the "prepare a script" algorithm via the post-connection steps.
36+
script.src = 'resources/flag-setter.js?different';
37+
38+
await scriptPromise;
39+
assert_true(window.didExecute);
40+
}, "Mutating `src` attribute from an already-valid value does 'prepare' the script");
41+
</script>
42+
</body>

0 commit comments

Comments
 (0)