File: permissions-policy-frame-policy-timing.https.sub.html

package info (click to toggle)
firefox 143.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,617,328 kB
  • sloc: cpp: 7,478,492; javascript: 6,417,157; ansic: 3,720,058; python: 1,396,372; xml: 627,523; asm: 438,677; java: 186,156; sh: 63,477; makefile: 19,171; objc: 13,059; perl: 12,983; yacc: 4,583; cs: 3,846; pascal: 3,405; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (70 lines) | stat: -rw-r--r-- 3,094 bytes parent folder | download | duplicates (14)
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
<!doctype html>
<html>
  <header>
    <title>allow/sandbox attr changed after document creation, before response</title>
    <script src=/resources/testharness.js></script>
    <script src=/resources/testharnessreport.js></script>
    <script>
        let lastCallbackId = 0;
        const callbacks = {};

        function postMessageToFrame(frame, cb, id) {
          callbacks[id] = cb;
          frame.contentWindow.postMessage('test', '*');
          step_timeout(() => {
            if (id in callbacks) {
              callbacks[id]('timeout');
              delete callbacks[id];
            }
          }, 1000);
        }

        window.onmessage = function(e) {
          const message = e.data;
          const id = message['id'];
          const callback = callbacks[id];
          delete callbacks[id];
          callback(message.result);
        };
        // @param {string} url
        // @param {Function} iframe_pre_nav_callback - a callback with signature (iframe) => () which gets
        //                                            triggered before setting src attribute.
        // @param {Function} iframe_post_nav_callback - a callback with signature (iframe) => () which gets
        //                                             triggered after setting src attribute but before commit
        //                                             of navigation.
        // @param {Function} result_handler - a callback that handles the result posted back from iframe.
        // @param {string} test_name
        function timing_test(url,
          iframe_pre_nav_callback,
          iframe_post_nav_callback,
          result_handler, test_name) {
          async_test((t) => {
            var id = ++lastCallbackId;
            const iframe = document.createElement('iframe');
            document.body.appendChild(iframe);
            callbacks[id] = t.step_func((result) => {
              assert_equals(result, 'ready');
              iframe_post_nav_callback(iframe);
              postMessageToFrame(iframe, t.step_func_done(result_handler), id);
            });
            iframe_pre_nav_callback(iframe);
            iframe.src = url + '?id=' + id;
          }, test_name);
        }

        const path = location.pathname.substring(0, location.pathname.lastIndexOf('/') + 1);
        const same_origin = path;
        const cross_origin = "https://{{domains[www1]}}:{{ports[https][0]}}" + path;

        const cameraUrl = 'permissions-policy-frame-policy-timing-iframe-camera.https.sub.html';
        function disallowCamera(iframe) { iframe.allow = "camera 'none'"; }
        function allowCamera(iframe) { iframe.allow = 'camera *'; }
        function verifyCamera(result) { assert_equals(result, 'NotAllowedError'); }
        timing_test(same_origin + cameraUrl, disallowCamera, allowCamera, verifyCamera, 'allow attr timing test same origin');
        timing_test(cross_origin + cameraUrl, disallowCamera, allowCamera, verifyCamera, 'allow attr timing test diff origin');
        </script>
  </header>
  <body>
    <div id="log"></div>
  </body>
</html>