summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-font-loading/fontfaceset-load-var.html
blob: 1d74f8ed2a91e38cb5900be98e6455671be8b333 (plain)
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
<!DOCTYPE html>
<title>SyntaxError thrown when matching loading values with var()</title>
<link rel="help" href="https://drafts.csswg.org/css-font-loading/#font-face-set-load">
<link rel="help" href="https://drafts.csswg.org/css-font-loading/#find-the-matching-font-faces">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>

  function load_on_worker(keyword) {
    return new Promise((resolve, reject) =>{
      var blob = new Blob([`
        self.fonts.load('${keyword}').then(
          ()=>{ self.postMessage('success') },
          (e)=>{ self.postMessage(e) }
        );
      `]);
      var blob_url = window.URL.createObjectURL(blob);
      let worker = new Worker(blob_url);
      worker.onmessage = msg => {
        if (msg === 'success')
          resolve(msg.data)
        else
          reject(msg.data)
      }
    });
  }

  promise_test(test => {
    return promise_rejects_dom(test, 'SyntaxError', document.fonts.load('var(--x) serif'));
  }, 'Loading "var(--x) serif" causes SyntaxError (document)')

  promise_test(test => {
    return promise_rejects_dom(test, 'SyntaxError', document.fonts.load('var(--x, 10px) serif'));
  }, 'Loading "var(--x, 10px) serif" causes SyntaxError (document)')

  promise_test(test => {
    return promise_rejects_dom(test, 'SyntaxError', load_on_worker('var(--x) serif'));
  }, 'Loading "var(--x) serif" causes SyntaxError (worker)')

  promise_test(test => {
    return promise_rejects_dom(test, 'SyntaxError', load_on_worker('var(--x, 10px) serif'));
  }, 'Loading "var(--x, 10px) serif" causes SyntaxError (worker)')

</script>