diff options
Diffstat (limited to '')
28 files changed, 278 insertions, 0 deletions
diff --git a/testing/web-platform/tests/document-policy/font-display/override-to-optional.tentative-ref.html b/testing/web-platform/tests/document-policy/font-display/override-to-optional.tentative-ref.html new file mode 100644 index 0000000000..78bca05b12 --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/override-to-optional.tentative-ref.html @@ -0,0 +1,30 @@ +<!DOCTYPE html> +<title>Test for no-font-display-late-swap document policy behavior</title> +<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" /> +<style> +.ahem { + font-family: 'Ahem'; +} +.arial { + font-family: 'Arial'; +} +</style> +<p>Tests if font-display is set to optional for each option except for when it is set to fallback</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> + <tr> + <td class="arial">a</td> + <td class="arial">a</td> + <td class="arial">a</td> + <td class="arial">a</td> + <td class="ahem">a</td> + <td class="arial">a</td> + </tr> +</table> diff --git a/testing/web-platform/tests/document-policy/font-display/override-to-optional.tentative.html b/testing/web-platform/tests/document-policy/font-display/override-to-optional.tentative.html new file mode 100644 index 0000000000..26927bb8c6 --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/override-to-optional.tentative.html @@ -0,0 +1,46 @@ +<!DOCTYPE html> +<html class="reftest-wait"> +<title>Test for no-font-display-late-swap document policy behavior</title> +<link rel="help" href="https://github.com/w3c/webappsec-feature-policy/blob/master/policies/font-display-late-swap.md"> +<link rel="match" href="override-to-optional.tentative-ref.html"> +<style> +</style> +<p>Tests if font-display is set to optional for each option except for when it is set to fallback</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); + const timeoutMilliSec = 1500; // After the font is loaded + setTimeout(() => { + document.documentElement.classList.remove("reftest-wait"); + }, timeoutMilliSec); +} +</script> +</html> diff --git a/testing/web-platform/tests/document-policy/font-display/override-to-optional.tentative.html.headers b/testing/web-platform/tests/document-policy/font-display/override-to-optional.tentative.html.headers new file mode 100644 index 0000000000..01b8bbccd4 --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/override-to-optional.tentative.html.headers @@ -0,0 +1 @@ +Document-Policy: font-display-late-swap=?0 diff --git a/testing/web-platform/tests/document-policy/font-display/report-only-auto.tentative.html b/testing/web-platform/tests/document-policy/font-display/report-only-auto.tentative.html new file mode 100644 index 0000000000..9eea350de4 --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/report-only-auto.tentative.html @@ -0,0 +1,9 @@ +<!DOCTYPE html> +<title>Test for font-display-late-swap document policy with font display value 'auto'</title> +<link rel="help" href="https://github.com/w3c/webappsec-permissions-policy/blob/master/policies/font-display-late-swap.md"> +<script src='/resources/testharness.js'></script> +<script src='/resources/testharnessreport.js'></script> +<script src='resources/font-display-reporting-helper.js'></script> +<script> + testFontDisplayPolicyReportOnlyGenerated('auto'); +</script> diff --git a/testing/web-platform/tests/document-policy/font-display/report-only-auto.tentative.html.headers b/testing/web-platform/tests/document-policy/font-display/report-only-auto.tentative.html.headers new file mode 100644 index 0000000000..1509127277 --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/report-only-auto.tentative.html.headers @@ -0,0 +1 @@ +Document-Policy-Report-Only: font-display-late-swap=?0
\ No newline at end of file diff --git a/testing/web-platform/tests/document-policy/font-display/report-only-blank.tentative.html b/testing/web-platform/tests/document-policy/font-display/report-only-blank.tentative.html new file mode 100644 index 0000000000..628dbccb4d --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/report-only-blank.tentative.html @@ -0,0 +1,9 @@ +<!DOCTYPE html> +<title>Test for font-display-late-swap document policy with font display value empty</title> +<link rel="help" href="https://github.com/w3c/webappsec-permissions-policy/blob/master/policies/font-display-late-swap.md"> +<script src='/resources/testharness.js'></script> +<script src='/resources/testharnessreport.js'></script> +<script src='resources/font-display-reporting-helper.js'></script> +<script> + testFontDisplayPolicyReportOnlyGenerated(''); +</script> diff --git a/testing/web-platform/tests/document-policy/font-display/report-only-blank.tentative.html.headers b/testing/web-platform/tests/document-policy/font-display/report-only-blank.tentative.html.headers new file mode 100644 index 0000000000..1509127277 --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/report-only-blank.tentative.html.headers @@ -0,0 +1 @@ +Document-Policy-Report-Only: font-display-late-swap=?0
\ No newline at end of file diff --git a/testing/web-platform/tests/document-policy/font-display/report-only-block.tentative.html b/testing/web-platform/tests/document-policy/font-display/report-only-block.tentative.html new file mode 100644 index 0000000000..a383695317 --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/report-only-block.tentative.html @@ -0,0 +1,9 @@ +<!DOCTYPE html> +<title>Test for font-display-late-swap document policy with font display value 'block'</title> +<link rel="help" href="https://github.com/w3c/webappsec-permissions-policy/blob/master/policies/font-display-late-swap.md"> +<script src='/resources/testharness.js'></script> +<script src='/resources/testharnessreport.js'></script> +<script src='resources/font-display-reporting-helper.js'></script> +<script> + testFontDisplayPolicyReportOnlyGenerated('block'); +</script> diff --git a/testing/web-platform/tests/document-policy/font-display/report-only-block.tentative.html.headers b/testing/web-platform/tests/document-policy/font-display/report-only-block.tentative.html.headers new file mode 100644 index 0000000000..1509127277 --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/report-only-block.tentative.html.headers @@ -0,0 +1 @@ +Document-Policy-Report-Only: font-display-late-swap=?0
\ No newline at end of file diff --git a/testing/web-platform/tests/document-policy/font-display/report-only-fallback.tentative.html b/testing/web-platform/tests/document-policy/font-display/report-only-fallback.tentative.html new file mode 100644 index 0000000000..a03015e47d --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/report-only-fallback.tentative.html @@ -0,0 +1,9 @@ +<!DOCTYPE html> +<title>Test for font-display-late-swap document policy with font display value 'fallback'</title> +<link rel="help" href="https://github.com/w3c/webappsec-permissions-policy/blob/master/policies/font-display-late-swap.md"> +<script src='/resources/testharness.js'></script> +<script src='/resources/testharnessreport.js'></script> +<script src='resources/font-display-reporting-helper.js'></script> +<script> + testCompliantWithFontDisplayPolicy('fallback'); +</script> diff --git a/testing/web-platform/tests/document-policy/font-display/report-only-fallback.tentative.html.headers b/testing/web-platform/tests/document-policy/font-display/report-only-fallback.tentative.html.headers new file mode 100644 index 0000000000..1509127277 --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/report-only-fallback.tentative.html.headers @@ -0,0 +1 @@ +Document-Policy-Report-Only: font-display-late-swap=?0
\ No newline at end of file diff --git a/testing/web-platform/tests/document-policy/font-display/report-only-optional.tentative.html b/testing/web-platform/tests/document-policy/font-display/report-only-optional.tentative.html new file mode 100644 index 0000000000..2a4673f153 --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/report-only-optional.tentative.html @@ -0,0 +1,9 @@ +<!DOCTYPE html> +<title>Test for font-display-late-swap document policy with font display value 'optional'</title> +<link rel="help" href="https://github.com/w3c/webappsec-permissions-policy/blob/master/policies/font-display-late-swap.md"> +<script src='/resources/testharness.js'></script> +<script src='/resources/testharnessreport.js'></script> +<script src='resources/font-display-reporting-helper.js'></script> +<script> + testCompliantWithFontDisplayPolicy('optional'); +</script> diff --git a/testing/web-platform/tests/document-policy/font-display/report-only-optional.tentative.html.headers b/testing/web-platform/tests/document-policy/font-display/report-only-optional.tentative.html.headers new file mode 100644 index 0000000000..1509127277 --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/report-only-optional.tentative.html.headers @@ -0,0 +1 @@ +Document-Policy-Report-Only: font-display-late-swap=?0
\ No newline at end of file diff --git a/testing/web-platform/tests/document-policy/font-display/report-only-swap.tentative.html b/testing/web-platform/tests/document-policy/font-display/report-only-swap.tentative.html new file mode 100644 index 0000000000..ad1f437f8c --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/report-only-swap.tentative.html @@ -0,0 +1,9 @@ +<!DOCTYPE html> +<title>Test for font-display-late-swap document policy with font display value 'swap'</title> +<link rel="help" href="https://github.com/w3c/webappsec-permissions-policy/blob/master/policies/font-display-late-swap.md"> +<script src='/resources/testharness.js'></script> +<script src='/resources/testharnessreport.js'></script> +<script src='resources/font-display-reporting-helper.js'></script> +<script> + testFontDisplayPolicyReportOnlyGenerated('swap'); +</script> diff --git a/testing/web-platform/tests/document-policy/font-display/report-only-swap.tentative.html.headers b/testing/web-platform/tests/document-policy/font-display/report-only-swap.tentative.html.headers new file mode 100644 index 0000000000..1509127277 --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/report-only-swap.tentative.html.headers @@ -0,0 +1 @@ +Document-Policy-Report-Only: font-display-late-swap=?0
\ No newline at end of file diff --git a/testing/web-platform/tests/document-policy/font-display/reporting-auto.tentative.html b/testing/web-platform/tests/document-policy/font-display/reporting-auto.tentative.html new file mode 100644 index 0000000000..01857dd90e --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/reporting-auto.tentative.html @@ -0,0 +1,9 @@ +<!DOCTYPE html> +<title>Test for font-display-late-swap document policy with font display value 'auto'</title> +<link rel="help" href="https://github.com/w3c/webappsec-permissions-policy/blob/master/policies/font-display-late-swap.md"> +<script src='/resources/testharness.js'></script> +<script src='/resources/testharnessreport.js'></script> +<script src='resources/font-display-reporting-helper.js'></script> +<script> + testFontDisplayPolicyViolationGenerated('auto'); +</script> diff --git a/testing/web-platform/tests/document-policy/font-display/reporting-auto.tentative.html.headers b/testing/web-platform/tests/document-policy/font-display/reporting-auto.tentative.html.headers new file mode 100644 index 0000000000..273ca3564d --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/reporting-auto.tentative.html.headers @@ -0,0 +1 @@ +Document-Policy: font-display-late-swap=?0
\ No newline at end of file diff --git a/testing/web-platform/tests/document-policy/font-display/reporting-blank.tentative.html b/testing/web-platform/tests/document-policy/font-display/reporting-blank.tentative.html new file mode 100644 index 0000000000..6521ae131a --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/reporting-blank.tentative.html @@ -0,0 +1,9 @@ +<!DOCTYPE html> +<title>Test for font-display-late-swap document policy with font display value empty</title> +<link rel="help" href="https://github.com/w3c/webappsec-permissions-policy/blob/master/policies/font-display-late-swap.md"> +<script src='/resources/testharness.js'></script> +<script src='/resources/testharnessreport.js'></script> +<script src='resources/font-display-reporting-helper.js'></script> +<script> + testFontDisplayPolicyViolationGenerated(''); +</script> diff --git a/testing/web-platform/tests/document-policy/font-display/reporting-blank.tentative.html.headers b/testing/web-platform/tests/document-policy/font-display/reporting-blank.tentative.html.headers new file mode 100644 index 0000000000..273ca3564d --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/reporting-blank.tentative.html.headers @@ -0,0 +1 @@ +Document-Policy: font-display-late-swap=?0
\ No newline at end of file diff --git a/testing/web-platform/tests/document-policy/font-display/reporting-block.tentative.html b/testing/web-platform/tests/document-policy/font-display/reporting-block.tentative.html new file mode 100644 index 0000000000..60403c67a4 --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/reporting-block.tentative.html @@ -0,0 +1,9 @@ +<!DOCTYPE html> +<title>Test for font-display-late-swap document policy with font display value 'block'</title> +<link rel="help" href="https://github.com/w3c/webappsec-permissions-policy/blob/master/policies/font-display-late-swap.md"> +<script src='/resources/testharness.js'></script> +<script src='/resources/testharnessreport.js'></script> +<script src='resources/font-display-reporting-helper.js'></script> +<script> + testFontDisplayPolicyViolationGenerated('block'); +</script> diff --git a/testing/web-platform/tests/document-policy/font-display/reporting-block.tentative.html.headers b/testing/web-platform/tests/document-policy/font-display/reporting-block.tentative.html.headers new file mode 100644 index 0000000000..273ca3564d --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/reporting-block.tentative.html.headers @@ -0,0 +1 @@ +Document-Policy: font-display-late-swap=?0
\ No newline at end of file diff --git a/testing/web-platform/tests/document-policy/font-display/reporting-fallback.tentative.html b/testing/web-platform/tests/document-policy/font-display/reporting-fallback.tentative.html new file mode 100644 index 0000000000..a03015e47d --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/reporting-fallback.tentative.html @@ -0,0 +1,9 @@ +<!DOCTYPE html> +<title>Test for font-display-late-swap document policy with font display value 'fallback'</title> +<link rel="help" href="https://github.com/w3c/webappsec-permissions-policy/blob/master/policies/font-display-late-swap.md"> +<script src='/resources/testharness.js'></script> +<script src='/resources/testharnessreport.js'></script> +<script src='resources/font-display-reporting-helper.js'></script> +<script> + testCompliantWithFontDisplayPolicy('fallback'); +</script> diff --git a/testing/web-platform/tests/document-policy/font-display/reporting-fallback.tentative.html.headers b/testing/web-platform/tests/document-policy/font-display/reporting-fallback.tentative.html.headers new file mode 100644 index 0000000000..273ca3564d --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/reporting-fallback.tentative.html.headers @@ -0,0 +1 @@ +Document-Policy: font-display-late-swap=?0
\ No newline at end of file diff --git a/testing/web-platform/tests/document-policy/font-display/reporting-optional.tentative.html b/testing/web-platform/tests/document-policy/font-display/reporting-optional.tentative.html new file mode 100644 index 0000000000..2a4673f153 --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/reporting-optional.tentative.html @@ -0,0 +1,9 @@ +<!DOCTYPE html> +<title>Test for font-display-late-swap document policy with font display value 'optional'</title> +<link rel="help" href="https://github.com/w3c/webappsec-permissions-policy/blob/master/policies/font-display-late-swap.md"> +<script src='/resources/testharness.js'></script> +<script src='/resources/testharnessreport.js'></script> +<script src='resources/font-display-reporting-helper.js'></script> +<script> + testCompliantWithFontDisplayPolicy('optional'); +</script> diff --git a/testing/web-platform/tests/document-policy/font-display/reporting-optional.tentative.html.headers b/testing/web-platform/tests/document-policy/font-display/reporting-optional.tentative.html.headers new file mode 100644 index 0000000000..273ca3564d --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/reporting-optional.tentative.html.headers @@ -0,0 +1 @@ +Document-Policy: font-display-late-swap=?0
\ No newline at end of file diff --git a/testing/web-platform/tests/document-policy/font-display/reporting-swap.tentative.html b/testing/web-platform/tests/document-policy/font-display/reporting-swap.tentative.html new file mode 100644 index 0000000000..53d823f178 --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/reporting-swap.tentative.html @@ -0,0 +1,9 @@ +<!DOCTYPE html> +<title>Test for font-display-late-swap document policy with font display value 'swap'</title> +<link rel="help" href="https://github.com/w3c/webappsec-permissions-policy/blob/master/policies/font-display-late-swap.md"> +<script src='/resources/testharness.js'></script> +<script src='/resources/testharnessreport.js'></script> +<script src='resources/font-display-reporting-helper.js'></script> +<script> + testFontDisplayPolicyViolationGenerated('swap'); +</script> diff --git a/testing/web-platform/tests/document-policy/font-display/reporting-swap.tentative.html.headers b/testing/web-platform/tests/document-policy/font-display/reporting-swap.tentative.html.headers new file mode 100644 index 0000000000..273ca3564d --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/reporting-swap.tentative.html.headers @@ -0,0 +1 @@ +Document-Policy: font-display-late-swap=?0
\ No newline at end of file diff --git a/testing/web-platform/tests/document-policy/font-display/resources/font-display-reporting-helper.js b/testing/web-platform/tests/document-policy/font-display/resources/font-display-reporting-helper.js new file mode 100644 index 0000000000..f3c8a22b7a --- /dev/null +++ b/testing/web-platform/tests/document-policy/font-display/resources/font-display-reporting-helper.js @@ -0,0 +1,81 @@ +function check_report_format(report, expected_url, expected_disposition) { + assert_equals(report.type, 'document-policy-violation'); + assert_equals(report.url, expected_url); + assert_equals(report.body.featureId, 'font-display-late-swap'); + assert_equals(report.body.disposition, expected_disposition); + assert_true('sourceFile' in report.body); + assert_true('lineNumber' in report.body); + assert_true('columnNumber' in report.body); +} + +function check_violation_report_format(report, expected_url) { + check_report_format(report, expected_url, 'enforce'); +} + +function check_report_only_report_format(report, expected_url) { + check_report_format(report, expected_url, 'report'); +} + +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}; }`; +} + +/** + * Run font-display test with given parameters. + * + * A violation report is expected with fontDisplayValue set to + * ['', 'auto', 'block', 'swap'] + * + * No violation report is expected with fontDisplayValue set to + * ['fallback', 'optional'] + + * @param {String} fontDisplayValue + * @param {(Report, String) => () | undefined} format_check pass a callback to + * check report format if a violation report is expected. If no report is + * expected to be generated, leave this argument undefined. + */ +function runTest(fontDisplayValue, format_check) { + window.onload = () => { + const family = fontDisplayValue + '-face'; + const rule = makeFontFaceDeclaration(family, fontDisplayValue); + + const style = document.createElement('style'); + style.innerHTML = rule; + document.body.appendChild(style); + + const div = document.createElement('div'); + div.textContent = 'a'; + div.style.fontFamily = family + ', Arial'; + document.body.appendChild(div); + }; + + const t = async_test('font-display-late-swap Report Format'); + + new ReportingObserver( + t.step_func_done((reports, _) => { + assert_equals(reports.length, 1); + assert_true(!!format_check); + format_check(reports[0], document.location.href); + }), { + types: ['document-policy-violation'], + buffered: true + } + ).observe(); + + t.step_timeout(t.step_func_done(() => { + assert_false(!!format_check, 'Expected violation report but did not get one.'); + }), 400); // 400ms should be sufficient to observe the violation report. +} + +function testFontDisplayPolicyViolationGenerated(fontDisplayValue) { + runTest(fontDisplayValue, check_violation_report_format); +} + +function testFontDisplayPolicyReportOnlyGenerated(fontDisplayValue) { + runTest(fontDisplayValue, check_report_only_report_format); +} + +function testCompliantWithFontDisplayPolicy(fontDisplayValue) { + runTest(fontDisplayValue); +}
\ No newline at end of file |