servo/tests/wpt/web-platform-tests/document-policy/font-display/font-display-document-policy-report-only.tentative.html

72 lines
No EOL
2.6 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>Test for font-display-late-swap feature policy set to report-only</title>
<link rel="help" href="https://github.com/w3c/webappsec-feature-policy/blob/master/policies/font-display-late-swap.md">
<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>
<style>
</style>
</head>
<body>
<p>
Tests if the correct number of violation reports are generated and each report corresponds to this feature.
4 reports should be created out of the 6 options below (reports for all except for 'fallback' and 'optional').
</p>
<table id="container">
<tr>
<th>not-set</th>
<th>auto</th>
<th>block</th>
<th>swap</th>
<th>fallback</th>
<th>optional</th>
</tr>
</table>
<script>
const fontDisplayValues = ['', 'auto', 'block', 'swap', 'fallback', 'optional'];
const table = document.getElementById('container');
function makeFontFaceDeclaration(family, display) {
url = '/fonts/Ahem.ttf?pipe=trickle(d1)'; // Before the swap period is over
return '@font-face { font-family: ' + family + '; src: url("' + url + '"); font-display: ' + display + '; }';
}
window.onload = () => {
let tr = document.createElement('tr');
for (let display of fontDisplayValues) {
const family = display + '-face';
const rule = makeFontFaceDeclaration(family, display);
document.styleSheets[0].insertRule(rule, 0);
let td = document.createElement('td');
td.textContent = 'a';
td.style.fontFamily = family + ', Arial';
tr.appendChild(td);
}
table.appendChild(tr);
}
let reportCounter = 4;
let t = async_test('font-display-late-swap Report Format');
let check_report_format = (reports, observer) => {
reportCounter -= reports.length;
for (let report of reports) {
assert_equals(report.type, 'document-policy-violation');
assert_equals(report.url, document.location.href, 'Report URL');
assert_equals(report.body.featureId, 'font-display-late-swap');
assert_equals(report.body.disposition, 'report');
assert_true('sourceFile' in report.body);
assert_true('lineNumber' in report.body);
assert_true('columnNumber' in report.body);
}
// Test is done when we have exactly 4 reports for the following
// font-display values: not set, 'auto', 'block', 'swap'
if (reportCounter == 0) t.done();
};
new ReportingObserver(t.step_func(check_report_format),
{types: ['document-policy-violation'], buffered: true}).observe();
</script>
</body>
</html>