Skip to content

Commit 8fbd359

Browse files
noamrchromium-wpt-export-bot
authored andcommitted
LoAF: Use document character position for inline scripts
This applies to classic/module script blocks and event content attributes. Bug: 328209286 Change-Id: Id11e0a9324c529925b11b950d73ed4491410f96d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5425010 Reviewed-by: Michal Mocny <[email protected]> Reviewed-by: Kouhei Ueno <[email protected]> Commit-Queue: Noam Rosenthal <[email protected]> Cr-Commit-Position: refs/heads/main@{#1291353}
1 parent ec57fe8 commit 8fbd359

File tree

4 files changed

+77
-5
lines changed

4 files changed

+77
-5
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE HTML>
2+
<meta charset=utf-8>
3+
<title>Long Animation Frame Timing: source location for inline classic scripts</title>
4+
<meta name="timeout" content="long">
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
<script src="resources/utils.js"></script>
8+
9+
<body>
10+
<script>
11+
busy_wait();
12+
</script>
13+
<script>
14+
promise_test(async () => {
15+
const script = await loaf_with_inline_script("classic-script");
16+
assert_equals(script.sourceURL, location.href);
17+
assert_greater_than(script.sourceCharPosition, 0);
18+
}, "Source location should be available for inline classic scripts");
19+
</script>
20+
</body>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE HTML>
2+
<meta charset=utf-8>
3+
<title>Long Animation Frame Timing: source location for inline scripts</title>
4+
<meta name="timeout" content="long">
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
<script src="resources/utils.js"></script>
8+
9+
<body>
10+
<img id=image onload="busy_wait()">
11+
<script>
12+
promise_test(async () => {
13+
document.querySelector("#image").src = "/images/green.png";
14+
const script = await loaf_with_inline_script("event-listener");
15+
assert_equals(script.sourceURL, location.href);
16+
assert_equals(script.sourceFunctionName, "onload");
17+
assert_greater_than(script.sourceCharPosition, 0);
18+
}, "Source location should be available for event handlers");
19+
</script>
20+
</body>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE HTML>
2+
<meta charset=utf-8>
3+
<title>Long Animation Frame Timing: source location for inline module scripts</title>
4+
<meta name="timeout" content="long">
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
<script src="resources/utils.js"></script>
8+
9+
<body>
10+
<script type=module>
11+
busy_wait();
12+
</script>
13+
<script>
14+
promise_test(async () => {
15+
const script = await loaf_with_inline_script("module-script");
16+
assert_equals(script.sourceURL, location.href);
17+
assert_greater_than(script.sourceCharPosition, 0);
18+
}, "Source location should be available for inline classic scripts");
19+
</script>
20+
</body>

long-animation-frame/tentative/resources/utils.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const very_long_frame_duration = 360;
77
const no_long_frame_timeout = very_long_frame_duration * 2;
88
const waiting_for_long_frame_timeout = very_long_frame_duration * 10;
99

10-
function loaf_promise(t) {
10+
function loaf_promise(t, options = {}) {
1111
return new Promise(resolve => {
1212
const observer = new PerformanceObserver(entries => {
1313
const entry = entries.getEntries()[0];
@@ -20,7 +20,7 @@ function loaf_promise(t) {
2020

2121
t.add_cleanup(() => observer.disconnect());
2222

23-
observer.observe({entryTypes: ['long-animation-frame']});
23+
observer.observe({type: 'long-animation-frame', ...options});
2424
});
2525
}
2626

@@ -29,7 +29,7 @@ function busy_wait(ms_delay = very_long_frame_duration) {
2929
while (performance.now() < deadline) {}
3030
}
3131

32-
async function expect_long_frame(cb, t) {
32+
async function expect_long_frame(cb, t, opt = {}) {
3333
await windowLoaded;
3434
await new Promise(resolve => t.step_timeout(resolve, 0));
3535
const timeout = new Promise((resolve, reject) =>
@@ -43,9 +43,9 @@ async function expect_long_frame(cb, t) {
4343
return entry;
4444
}
4545

46-
async function expect_long_frame_with_script(cb, predicate, t) {
46+
async function expect_long_frame_with_script(cb, predicate, t, opt = {}) {
4747
for (let i = 0; i < 10; ++i) {
48-
const entry = await expect_long_frame(cb, t);
48+
const entry = await expect_long_frame(cb, t, opt);
4949
if (entry === "timeout" || !entry.scripts.length)
5050
continue;
5151
for (const script of entry.scripts) {
@@ -129,3 +129,15 @@ function test_promise_script(cb, resolve_or_reject, invoker, label) {
129129
function test_self_script_block(cb, invoker, type) {
130130
test_loaf_script(cb, invoker, type);
131131
}
132+
133+
function loaf_with_inline_script(type) {
134+
return new Promise(resolve => new PerformanceObserver(entries => {
135+
for (const e of entries.getEntries()) {
136+
if (e.duration < very_long_frame_duration - 5)
137+
return;
138+
const script = e.scripts.find(s => s.invokerType === type && s.sourceURL === location.href);
139+
if (script)
140+
resolve(script);
141+
}
142+
}).observe({ type: "long-animation-frame", buffered: true }));
143+
}

0 commit comments

Comments
 (0)