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

Fix mistakes in trusted-types*reporting tests. #50098

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
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
Expand Up @@ -45,7 +45,8 @@
// Like assert_throws_*, but we don't care about the exact error. We just want
// to run the code and continue.
function expect_throws(fn) {
try { fn(); assert_unreached(); } catch (err) { /* ignore */ }
try { fn(); } catch (err) { return; /* ignore */ }
assert_unreached();
}

// A sample policy we use to test trustedTypes.createPolicy behaviour.
Expand Down
3 changes: 2 additions & 1 deletion trusted-types/trusted-types-eval-reporting-report-only.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
// Like assert_throws_*, but we don't care about the exact error. We just want
// to run the code and continue.
function expect_throws(fn) {
try { fn(); assert_unreached(); } catch (err) { /* ignore */ }
try { fn(); } catch (err) { return; /* ignore */ }
assert_unreached();
}

// A sample policy we use to test trustedTypes.createPolicy behaviour.
Expand Down
3 changes: 2 additions & 1 deletion trusted-types/trusted-types-eval-reporting.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
// Like assert_throws_*, but we don't care about the exact error. We just want
// to run the code and continue.
function expect_throws(fn) {
try { fn(); assert_unreached(); } catch (err) { /* ignore */ }
try { fn(); } catch (err) { return; /* ignore */ }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current behavior is broken, see commit message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah apologies yeah that makes sense.

assert_unreached();
}

// A sample policy we use to test trustedTypes.createPolicy behaviour.
Expand Down
17 changes: 7 additions & 10 deletions trusted-types/trusted-types-reporting.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
<script src="/content-security-policy/support/testharness-helper.js"></script>
</head>
<body>
<!-- Some elements for the tests to act on. -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this cause a problem when running them? LGTM either way, just trying to understand the why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, I noticed some flakiness in firefox after implementing svg href due to that. actually it seems there used to be a flakiness in chromium too (will remove that comment)

<div id="div"></div>
<script id="script"></script>
<script id="customscript" is="custom-script" src="a"></script>
<svg><script id="svgscript"></script></svg>
<script>
// CSP insists the "trusted-types: ..." directives are delivered as headers
// (rather than as "<meta http-equiv" tags). This test assumes the following
Expand Down Expand Up @@ -52,7 +57,8 @@
// Like assert_throws_*, but we don't care about the exact error. We just want
// to run the code and continue.
function expect_throws(fn) {
try { fn(); assert_unreached(); } catch (err) { /* ignore */ }
try { fn(); } catch (err) { return; /* ignore */ }
assert_unreached();
}

// Test the "sample" field of the event.
Expand Down Expand Up @@ -198,9 +204,6 @@
return p;
}, "Trusted Type violation report: sample for script innerText assignment");

// TODO(lyf): https://crbug.com/1066791 Following tests which related to svg
// script element cause a flaky timeout in `linux-blink-rel`, following tests
// should be added back after the bug fix.
promise_test(t => {
let p = Promise.resolve()
.then(promise_violation("require-trusted-types-for 'script'"))
Expand Down Expand Up @@ -281,10 +284,4 @@
}, "Trusted Type violation report: Worker constructor");

</script>

<!-- Some elements for the tests to act on. -->
<div id="div"></div>
<script id="script"></script>
<script id="customscript" is="custom-script" src="a"></script>
<svg><script id="svgscript"></script></svg>
</body>
Loading