Skip to content

Commit

Permalink
Bug 1914829 [wpt PR 47782] - WPT: Ensure src attribute changes trig…
Browse files Browse the repository at this point in the history
…ger 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
  • Loading branch information
domfarolino authored and moz-wptsync-bot committed Aug 28, 2024
1 parent 1557078 commit e9fb562
Showing 1 changed file with 42 additions and 0 deletions.
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>

0 comments on commit e9fb562

Please sign in to comment.