File: font-display-feature-policy-reporting.tentative.html

package info (click to toggle)
thunderbird 1%3A68.10.0-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,754,812 kB
  • sloc: cpp: 5,411,679; javascript: 4,161,772; ansic: 2,639,702; python: 763,064; java: 346,606; xml: 266,623; asm: 265,884; sh: 117,270; lisp: 41,340; makefile: 23,560; perl: 18,042; objc: 5,277; yacc: 1,778; ada: 1,681; pascal: 1,673; lex: 1,417; cs: 879; exp: 527; awk: 495; php: 436; ruby: 221; sed: 69; csh: 27
file content (72 lines) | stat: -rw-r--r-- 2,597 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE html>
<html>
  <head>
    <title>Test for font-display-late-swap feature policy set to reporting</title>
    <link rel="help" href="https://w3c.github.io/webappsec-feature-policy/#reporting">
    <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, 'feature-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, 'enforce');
    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: ['feature-policy-violation'], buffered: true}).observe();
    </script>
  </body>
</html>