Skip to content

Commit

Permalink
Report synchronous script violations
Browse files Browse the repository at this point in the history
Use the ReportingAPI to report violations of the
"sync-script" document policy.

Bug: 1314475
Change-Id: I554625e1b88170c999d52ad23f7c7a4dbefc3a68
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3573257
Reviewed-by: Hiroshige Hayashizaki <hiroshige@chromium.org>
Commit-Queue: Ian Clelland <iclelland@chromium.org>
Cr-Commit-Position: refs/heads/main@{#991516}
  • Loading branch information
clelland authored and chromium-wpt-export-bot committed Apr 12, 2022
1 parent 4fa22e3 commit 458b046
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
20 changes: 20 additions & 0 deletions document-policy/reporting/resources/sync-script.js
@@ -0,0 +1,20 @@
// This is deliberately split from sync-script-reporting.html so that it will
// not be blocked by policy, and can actuall be executed.

var t = async_test("Sync-script Report Format");

var check_report_format = (reports, observer) => {
let report = reports[0];
assert_equals(report.type, "document-policy-violation");
assert_equals(report.url, document.location.href);
assert_equals(report.body.featureId, "sync-script");
assert_equals(report.body.sourceFile, null);
assert_equals(report.body.lineNumber, null);
assert_equals(report.body.columnNumber, null);
assert_equals(report.body.disposition, "enforce");
check_report_json(report);
};

new ReportingObserver(t.step_func_done(check_report_format),
{ types: ['document-policy-violation'],
buffered: true}).observe();
14 changes: 14 additions & 0 deletions document-policy/reporting/sync-script-reporting.html
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<script defer src='/resources/testharness.js'></script>
<script defer src='/resources/testharnessreport.js'></script>
<script defer src='../resources/document-policy-report-json.js'></script>
<script defer src="resources/sync-script.js"></script>
</head>
<body>
<!-- The presence of this script will violate the sync-script policy,
and will trigger a report. -->
<script>var newGlobal = true;</script>
</body>
</html>
@@ -0,0 +1 @@
Document-Policy: sync-script=?0

0 comments on commit 458b046

Please sign in to comment.