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

Conversation

fred-wang
Copy link
Contributor

  • expect_throws(): move out assert_unreached() out of the try scope. assert_unreached() throws [1] [2] so expect_throws() will not throw in case of failure.

  • trusted-types-reporting.html: Move the elements before the script to make sure they are already in the DOM when the tests are run.

[1]

function assert_unreached(description) {

[2]
throw new AssertionError(msg);

* expect_throws(): move out assert_unreached() out of the try scope.
  assert_unreached() throws [1] [2] so expect_throws() will not throw
  in case of failure.

* trusted-types-reporting.html: Move the elements before the script
  to make sure they are already in the DOM when the tests are run.

[1] https://github.com/web-platform-tests/wpt/blob/070a67f19da0b454068bc38ef40904403e5edca0/resources/testharness.js#L2391
[2] https://github.com/web-platform-tests/wpt/blob/070a67f19da0b454068bc38ef40904403e5edca0/resources/testharness.js#L4544
@@ -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.

@@ -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)

Copy link
Member

@lukewarlow lukewarlow left a comment

Choose a reason for hiding this comment

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

LGTM

@fred-wang fred-wang merged commit a87e05c into master Jan 15, 2025
13 of 16 checks passed
@fred-wang fred-wang deleted the reporting-tests branch January 15, 2025 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants