tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

propagation-sameorigin.html (4331B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4  <script src="/resources/testharness.js"></script>
      5  <script src="/resources/testharnessreport.js"></script>
      6  <script src="/resources/testdriver.js"></script>
      7  <script src="/resources/testdriver-vendor.js"></script>
      8  <script>
      9    // Frame layout:
     10    // top=this-file [
     11    //   child1=child-one.html,
     12    //   child-so=propagation-sameorigin-child.html [
     13    //     gchild=child-two.html
     14    //   ]
     15    // ]
     16    let propagation_test = async_test("Propagation test");
     17 
     18    let num_children_to_load = 3;
     19    let num_children_to_report = 3;
     20 
     21    function finishLoadPhase() {
     22        assert_equals(num_children_to_load, 0);
     23 
     24        test(() => {
     25            assert_false(navigator.userActivation.isActive);
     26            assert_false(navigator.userActivation.hasBeenActive);
     27        }, "Parent frame initial state");
     28 
     29        test_driver.click(document.getElementById("child-so"));
     30    }
     31 
     32    function finishReportPhase() {
     33        assert_equals(num_children_to_report, 0);
     34 
     35        test(() => {
     36            assert_true(navigator.userActivation.isActive);
     37            assert_true(navigator.userActivation.hasBeenActive);
     38        }, "Parent frame final state");
     39 
     40        propagation_test.done();
     41    }
     42 
     43    window.addEventListener("message", event => {
     44        // Test driver can send messages too...
     45        if (typeof event.data !== "string") return;
     46 
     47        var msg = JSON.parse(event.data);
     48 
     49        if (msg.type == 'child-one-loaded') {
     50            test(() => {
     51                assert_false(msg.isActive);
     52                assert_false(msg.hasBeenActive);
     53            }, "Child1 frame initial state");
     54        } else if (msg.type == 'child-sameorigin-loaded') {
     55            test(() => {
     56                assert_false(msg.isActive);
     57                assert_false(msg.hasBeenActive);
     58            }, "Child2 frame initial state");
     59        } else if (msg.type == 'child-two-loaded') {
     60            test(() => {
     61                assert_false(msg.isActive);
     62                assert_false(msg.hasBeenActive);
     63            }, "Grandchild frame initial state");
     64        } else if (msg.type == 'child-one-report') {
     65            // Siblings (same or cross origin) should not be activated per spec
     66            // Spec issue discussing: https://github.com/whatwg/html/issues/9831
     67            test(() => {
     68                assert_false(msg.isActive);
     69                assert_false(msg.hasBeenActive);
     70            }, "Child1 frame final state");
     71        } else if (msg.type == 'child-sameorigin-report') {
     72            // This msg was triggered by a user click.
     73            test(() => {
     74                assert_true(msg.isActive);
     75                assert_true(msg.hasBeenActive);
     76            }, "Child2 frame final state");
     77 
     78            // Ask remaining frames to report states.
     79            let ask_report = JSON.stringify({"type": "report"});
     80            frames[0].postMessage(ask_report, "*");
     81            frames[1].frames[0].postMessage(ask_report, "*");
     82        } else if (msg.type == 'child-two-report') {
     83            test(() => {
     84                assert_true(msg.isActive);
     85                assert_true(msg.hasBeenActive);
     86            }, "Grand child frame final state");
     87        }
     88 
     89        // Phase switching.
     90        if (msg.type.endsWith("-loaded")) {
     91            if (--num_children_to_load == 0)
     92                finishLoadPhase();
     93        } else if (msg.type.endsWith("-report")) {
     94            if (--num_children_to_report == 0)
     95                finishReportPhase();
     96        }
     97    });
     98    async function createIframes() {
     99        const child1 = document.createElement("iframe");
    100        child1.src = "resources/child-one.html";
    101        child1.id = "child1";
    102        await new Promise((resolve) => {
    103            child1.onload = resolve;
    104            document.body.appendChild(child1);
    105        });
    106        const childSO = document.createElement("iframe");
    107        childSO.id = "child-so";
    108        childSO.src = "resources/propagation-sameorigin-child.html";
    109        document.body.appendChild(childSO);
    110    }
    111  </script>
    112 </head>
    113 <body onload="createIframes()">
    114  <h1>User activation propagation across same-origin frame boundary</h1>
    115  <p>Tests that user activation propagates across same-origin frame boundary.</p>
    116  <ol id="instructions">
    117    <li>Click anywhere on the green area (child frame).
    118  </ol>
    119 </body>
    120 </html>