Skip to content

Commit

Permalink
Split LoAF sourceLocation to 3 attributes
Browse files Browse the repository at this point in the history
As per spec, sourceURL / sourceFunctionName / sourceCharPosition
Amended existing test.

Bug: 1523675
Change-Id: Ic3bb8df05bb822fa8b56990e2696d67324b4763f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5250540
Reviewed-by: Ian Clelland <[email protected]>
Reviewed-by: Rick Byers <[email protected]>
Reviewed-by: Michal Mocny <[email protected]>
Commit-Queue: Noam Rosenthal <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1256409}
  • Loading branch information
noamr authored and chromium-wpt-export-bot committed Feb 5, 2024
1 parent 81c06c7 commit 3c54afa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,20 @@ <h1>Long Animation Frame: source location with cross-origin redirects</h1>
}, script => script.duration >= VERY_LONG_FRAME_DURATION - 5, t);

const result =
script.sourceLocation.startsWith(postRedirectURL) ? "post-redirect" :
script.sourceLocation.startsWith(preRedirectURL) ? "pre-redirect" :
script.sourceLocation === "" ?
script.sourceURL.startsWith(postRedirectURL) ? "post-redirect" :
script.sourceURL.startsWith(preRedirectURL) ? "pre-redirect" :
script.sourceURL === "" ?
"empty" : "other";

assert_not_equals(result, "other", `Unexpected source location ${script.sourceLocation}`);
assert_not_equals(result, "other", `Unexpected source location ${script.sourceURL}`);
if (!cors)
assert_equals(script.executionStart, script.startTime, "Opaque scripts should hide execution start time");

if (cors) {
assert_not_equals(result, "empty", "CORS-ok scripts should expose sourceLocation");
} else {
const char_index = result === "empty" ? 0 :
parseInt(script.sourceLocation.match(/\:(\d+)$/)?.[1] ?? "0");
assert_not_equals(result, "post-redirect", "No-CORS classic scripts should not expose post-redirect URL");
assert_equals(char_index, 0, "No-CORS classic scripts should not expose character index");
assert_equals(script.sourceCharPosition, type === "script-block" ? 0 : -1, "No-CORS classic scripts should not expose character index");
}
}, `Test ${type} with ${scriptType}`);
}
Expand Down
19 changes: 9 additions & 10 deletions long-animation-frame/tentative/loaf-source-location.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ <h1>Long Animation Frame: source location extraction</h1>
<div id="log"></div>
<script>

const source_location_regex = /^([^@]+\@)?https?\:\/\/[^\/]+[^\:]+\:\d*$/;

promise_test(async t => {
const [entry, script] = await expect_long_frame_with_script(() => {
requestAnimationFrame(function non_bound_function() {
busy_wait();
});
}, script => script.invoker === "FrameRequestCallback", t);
assert_true(script.sourceLocation?.startsWith("non_bound_function"));
assert_regexp_match(script.sourceLocation, source_location_regex);
assert_equals(script.sourceURL, location.href);
assert_equals(script.sourceFunctionName, "non_bound_function");
assert_greater_than(script.sourceCharPosition, 0);
}, "Source location should be extracted from non-bound functions");

promise_test(async t => {
Expand All @@ -30,18 +29,18 @@ <h1>Long Animation Frame: source location extraction</h1>
busy_wait();
}).bind(object));
}, script => script.invoker === "FrameRequestCallback", t);
assert_true(script.sourceLocation?.startsWith("my_bound_function"));
assert_regexp_match(script.sourceLocation, source_location_regex);
assert_equals(script.sourceURL, location.href);
assert_equals(script.sourceFunctionName, "my_bound_function");
assert_greater_than(script.sourceCharPosition, 0);
}, "Source location should be extracted from bound functions");

promise_test(async t => {
const [entry, script] = await expect_long_frame_with_script(() => {
t.step_timeout(function my_timeout() {
busy_wait();
});
}, script => script.invoker === "TimerHandler:setTimeout" && script.sourceLocation, t );
assert_true(script.sourceLocation.includes("testharness.js"));
assert_regexp_match(script.sourceLocation, source_location_regex);
}, script => script.invoker === "TimerHandler:setTimeout" && script.sourceURL, t );
assert_true(script.sourceURL.includes("testharness.js"));
}, "Source location should be extracted for setTimeout");

promise_test(async t => {
Expand All @@ -51,7 +50,7 @@ <h1>Long Animation Frame: source location extraction</h1>
scriptElement.src = scriptLocation;
document.body.appendChild(scriptElement);
}, script => script.invoker === "Window.fetch.then", t);
assert_true(script.sourceLocation?.includes("promise-generates-loaf.js"));
assert_true(script.sourceURL.includes("promise-generates-loaf.js"));
}, "Source location should be extracted for promises");

</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ <h1>Long Animation Frame: source location extraction for streams</h1>
<div id="log"></div>
<script>

const source_location_regex = /^([^@]+\@)?https?\:\/\/[^\/]+[^\:]+\:\d*$/;

promise_test(async t => {
const scriptLocation = new URL("resources/stream-promise-generates-loaf.js", location.href);
const [entry, script] = await expect_long_frame_with_script(() => {
Expand All @@ -21,7 +19,7 @@ <h1>Long Animation Frame: source location extraction for streams</h1>
document.body.appendChild(scriptElement);
}, script => script.invoker === "StreamPromise.resolve.then", t);

assert_true(script.sourceLocation?.includes("stream-promise-generates-loaf.js"));
assert_true(script.sourceURL.includes("stream-promise-generates-loaf.js"));
}, "Source location should be extracted for stream promises");

</script>
Expand Down

0 comments on commit 3c54afa

Please sign in to comment.