Skip to content

Commit

Permalink
Add WPT for permissions policy report-only mode
Browse files Browse the repository at this point in the history
Change-Id: Ifb7aadc82992db73385676b92fc576cdcd1b7077
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4915362
Reviewed-by: Ari Chivukula <arichiv@chromium.org>
Commit-Queue: Ian Clelland <iclelland@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1206551}
  • Loading branch information
clelland authored and chromium-wpt-export-bot committed Oct 6, 2023
1 parent 2e73f41 commit 0a366a4
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>
<script src='/resources/testdriver.js'></script>
<script src='/resources/testdriver-vendor.js'></script>
<script src='../../mediacapture-streams/permission-helper.js'></script>
<script src='/reporting/resources/report-helper.js'></script>
</head>
<body>
<script>
const base_url = `${location.protocol}//${location.host}`;
const endpoint = `${base_url}/reporting/resources/report.py`;
const enforcing_id = '69c90b97-8b7c-4439-b5d2-ff03f237b2b2';
const report_only_id = '9d095a14-6b1c-40e1-be19-55a1fec97d11';

promise_test(async t => {
await setMediaPermission("granted", ["camera","microphone"]);
await promise_rejects_dom(
t, "NotAllowedError", navigator.mediaDevices.getUserMedia({video: true}),
"UserMedia camera access should not be allowed in this document.");
while(true) {
await wait(100);
const reports = await pollReports(endpoint, enforcing_id);
if (reports.length) {
checkReportExists(reports, 'permissions-policy-violation', location.href);
break;
}
}
const report_only_reports = await pollReports(endpoint, report_only_id);
assert_equals(report_only_reports.length, 0, "Report-only endpoint should not receive report.");
}, "Enforcing policy receives reports when both enforcing and report-only policies are set.");
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Permissions-Policy: camera=();report-to=enforcing-endpoint
Permissions-Policy-Report-Only: camera=();report-to=report-only-endpoint
Reporting-Endpoints: enforcing-endpoint="https://{{host}}:{{ports[https][0]}}/reporting/resources/report.py?reportID=69c90b97-8b7c-4439-b5d2-ff03f237b2b2", report-only-endpoint="https://{{host}}:{{ports[https][0]}}/reporting/resources/report.py?reportID=9d095a14-6b1c-40e1-be19-55a1fec97d11"
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<head>
<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>
<script src='/resources/testdriver.js'></script>
<script src='/resources/testdriver-vendor.js'></script>
<script src='../../mediacapture-streams/permission-helper.js'></script>
<script src='/reporting/resources/report-helper.js'></script>
</head>
<body>
<script>
const base_url = `${location.protocol}//${location.host}`;
const endpoint = `${base_url}/reporting/resources/report.py`;
const id = 'c3841a1a-e750-4801-a50b-c4222d386515';

promise_test(async t => {
await setMediaPermission("granted", ["camera","microphone"]);
// This should not throw, as the enforcing policy does not block it.
await navigator.mediaDevices.getUserMedia({video: true});
while(true) {
await wait(100);
const reports = await pollReports(endpoint, id);
if (reports.length) {
checkReportExists(reports, 'permissions-policy-violation', location.href);
break;
}
}
}, "Reporting-Endpoints defined endpoint received reports in report-only mode.");
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Permissions-Policy-Report-Only: camera=();report-to=camera-endpoint
Reporting-Endpoints: camera-endpoint="https://{{host}}:{{ports[https][0]}}/reporting/resources/report.py?reportID=c3841a1a-e750-4801-a50b-c4222d386515"

0 comments on commit 0a366a4

Please sign in to comment.