tor-browser

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

test_recursive_frames.html (9234B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test for Recursive Loads</title>
      5  <meta charset="utf-8">
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
      8 </head>
      9 <body>
     10 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1597427">Mozilla Bug 1597427</a>
     11 <p id="display"></p>
     12 <div id="content" style="display: none">
     13 
     14 </div>
     15 <pre id="test">
     16  <script type="application/javascript">
     17  const TEST_CASES = [
     18    { // too many recursive iframes
     19      frameId: "recursiveFrame",
     20      expectedLocations: [
     21        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     22        "http://example.com/tests/docshell/test/navigation/frame_recursive.html",
     23        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     24        "http://example.com/tests/docshell/test/navigation/frame_recursive.html",
     25        "about:blank",
     26      ],
     27    },
     28    { // too many recursive iframes
     29      frameId: "twoRecursiveIframes",
     30      expectedLocations: [
     31        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     32        "http://example.com/tests/docshell/test/navigation/frame_load_as_example_com.html",
     33        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     34        "http://example.org/tests/docshell/test/navigation/frame_load_as_example_org.html",
     35        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     36        "http://example.com/tests/docshell/test/navigation/frame_load_as_example_com.html",
     37        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     38        "http://example.org/tests/docshell/test/navigation/frame_load_as_example_org.html",
     39        "about:blank",
     40      ],
     41    },
     42    { // too many recursive iframes
     43      frameId: "threeRecursiveIframes",
     44      expectedLocations: [
     45        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     46        "http://sub1.test1.mochi.test:8888/tests/docshell/test/navigation/frame_load_as_host1.html",
     47        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     48        "http://example.com/tests/docshell/test/navigation/frame_load_as_host2.html",
     49        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     50        "http://test1.mochi.test:8888/tests/docshell/test/navigation/frame_load_as_host3.html",
     51        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     52        "http://sub1.test1.mochi.test:8888/tests/docshell/test/navigation/frame_load_as_host1.html",
     53        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     54        "http://example.com/tests/docshell/test/navigation/frame_load_as_host2.html",
     55        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     56        "http://test1.mochi.test:8888/tests/docshell/test/navigation/frame_load_as_host3.html",
     57        "about:blank",
     58      ],
     59    },
     60    { // too many nested iframes
     61      frameId: "sixRecursiveIframes",
     62      expectedLocations: [
     63        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     64        "http://example.com/tests/docshell/test/navigation/frame_1_out_of_6.html",
     65        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     66        "http://test1.mochi.test:8888/tests/docshell/test/navigation/frame_2_out_of_6.html",
     67        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     68        "http://sub1.test1.mochi.test:8888/tests/docshell/test/navigation/frame_3_out_of_6.html",
     69        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     70        "http://sub2.xn--lt-uia.mochi.test:8888/tests/docshell/test/navigation/frame_4_out_of_6.html",
     71        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     72        "http://test2.mochi.test:8888/tests/docshell/test/navigation/frame_5_out_of_6.html",
     73        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     74        "http://example.org/tests/docshell/test/navigation/frame_6_out_of_6.html",
     75        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     76        "http://example.com/tests/docshell/test/navigation/frame_1_out_of_6.html",
     77        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     78        "http://test1.mochi.test:8888/tests/docshell/test/navigation/frame_2_out_of_6.html",
     79        "about:blank",
     80      ],
     81    },
     82    { // too many recursive objects
     83      frameId: "recursiveObject",
     84      expectedLocations: [
     85        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     86        "http://sub2.xn--lt-uia.mochi.test:8888/tests/docshell/test/navigation/object_recursive_load.html",
     87        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     88        "http://sub2.xn--lt-uia.mochi.test:8888/tests/docshell/test/navigation/object_recursive_load.html",
     89      ],
     90    },
     91    { // 3 nested srcdocs, should show all of them
     92      frameId: "nestedSrcdoc",
     93      expectedLocations: [
     94        "about:srcdoc",
     95        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     96        "http://example.com/tests/docshell/test/navigation/file_nested_srcdoc.html",
     97        "about:srcdoc",
     98        "about:srcdoc",
     99      ],
    100    },
    101    { // too many recursive dynamically created iframes
    102      frameId: "dynamicrecursive",
    103      expectedLocations: [
    104        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
    105        "http://example.com/tests/docshell/test/navigation/frame_recursive_dynamic.html",
    106        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
    107        "http://example.com/tests/docshell/test/navigation/frame_recursive_dynamic.html",
    108        "about:blank"
    109      ],
    110    },
    111    { // navigating shouldn't be blocked by recursion check
    112      frameId: "navigationIsNotRecursive",
    113      expectedLocations: [
    114        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
    115        "http://example.com/tests/docshell/test/navigation/frame_recursive_target.html",
    116        "http://example.com/tests/docshell/test/navigation/frame_recursive_target.html",
    117        "http://example.com/tests/docshell/test/navigation/frame_recursive_target.html",
    118        "about:blank"
    119      ],
    120    },
    121  ];
    122 
    123  async function checkRecursiveLoad(level) {
    124    let el = content.document.getElementById("static") || content.document.getElementById("dynamic");
    125    let documentURI = await SpecialPowers.spawn(
    126      el,
    127      [],
    128      () => this.content.document.documentURI
    129    );
    130    if (documentURI == "about:blank") {
    131      // If we had too many recursive frames, the most inner iframe's uri will be about:blank
    132      return [documentURI];
    133    }
    134    if (documentURI == "about:srcdoc" && level == 3) {
    135      // Check that we have the correct most inner srcdoc iframe
    136      let innerText = await SpecialPowers.spawn(
    137        el,
    138        [],
    139        () => this.content.document.body.innerText
    140      );
    141      is(innerText, "Third nested srcdoc", "correct most inner srcdoc iframe");
    142    }
    143    let nestedIfrOrObjectURI = [];
    144    try {
    145      // Throws an error when we have too many nested frames/objects, because we
    146      // claim to have no content window for the inner most frame/object.
    147      nestedIfrOrObjectURI = await SpecialPowers.spawn(
    148        el,
    149        [level + 1],
    150        checkRecursiveLoad
    151      );
    152    } catch (err) {
    153      info(
    154        `Tried to spawn another task in the iframe/object, but got err: ${err}, must have had too many nested iframes/objects\n`
    155      );
    156    }
    157    return [documentURI, ...nestedIfrOrObjectURI];
    158  }
    159 
    160  add_task(async () => {
    161    for (const testCase of TEST_CASES) {
    162      let el = document.getElementById(testCase.frameId);
    163      let loc = await SpecialPowers.spawn(
    164        el,
    165        [],
    166        () => this.content.location.href
    167      );
    168      let locations = await SpecialPowers.spawn(el, [1], checkRecursiveLoad);
    169      isDeeply(
    170        [loc, ...locations],
    171        testCase.expectedLocations,
    172        "iframes/object loaded in correct order"
    173      );
    174    }
    175  });
    176  </script>
    177 </pre>
    178 <div>
    179  <iframe style="height: 100vh; width:25%;" id="recursiveFrame" src="http://example.com/tests/docshell/test/navigation/frame_recursive.html"></iframe>
    180  <iframe style="height: 100vh; width:25%;" id="twoRecursiveIframes" src="http://example.com/tests/docshell/test/navigation/frame_load_as_example_com.html"></iframe>
    181  <iframe style="height: 100vh; width:25%;" id="threeRecursiveIframes" src="http://sub1.test1.mochi.test:8888/tests/docshell/test/navigation/frame_load_as_host1.html"></iframe>
    182  <iframe style="height: 100vh; width:25%;" id="sixRecursiveIframes" src="http://example.com/tests/docshell/test/navigation/frame_1_out_of_6.html"></iframe>
    183  <object width="400" height="300" id="recursiveObject" data="http://sub2.xn--lt-uia.mochi.test:8888/tests/docshell/test/navigation/object_recursive_load.html"></object>
    184  <iframe id="nestedSrcdoc" srcdoc="Srcdoc that will embed an iframe &lt;iframe id=&quot;static&quot; src=&quot;http://example.com/tests/docshell/test/navigation/file_nested_srcdoc.html&quot;&gt;&lt;/iframe&gt;"></iframe>
    185  <iframe style="height: 100vh; width:25%;" id="dynamicrecursive" src="http://example.com/tests/docshell/test/navigation/frame_recursive_dynamic.html"></iframe>
    186  <iframe style="height: 100vh; width:25%;" id="navigationIsNotRecursive" src="http://example.com/tests/docshell/test/navigation/frame_recursive_target.html"></iframe>
    187 </div>
    188 </body>
    189 </html>