tor-browser

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

navigated-named-objects.window.js (2453B)


      1 // META: script=/common/get-host-info.sub.js
      2 
      3 function echoURL(content) {
      4  return `/common/echo.py?content=${encodeURIComponent(content)}`;
      5 }
      6 
      7 function setSrc(frame, type, content) {
      8  if (type === "same-origin") {
      9    frame.src = echoURL(content);
     10  } else if (type === "cross-site") {
     11    frame.src = `${get_host_info().HTTP_NOTSAMESITE_ORIGIN}${echoURL(content)}`;
     12  } else {
     13    frame.srcdoc = content;
     14  }
     15 }
     16 
     17 ["srcdoc", "same-origin", "cross-site"].forEach(type => {
     18  const initialType = type === "srcdoc" ? type : "same-origin";
     19 
     20  [
     21    {
     22      "namedObject": "<div id=abc></div>",
     23      "namedObjectLocalName": "div"
     24    },
     25    {
     26      "namedObject": "<object name=abc></object>",
     27      "namedObjectLocalName": "object"
     28    },
     29    {
     30      "namedObject": "<iframe id=abc></iframe>",
     31      "namedObjectLocalName": "iframe"
     32    }
     33  ].forEach(testData => {
     34    async_test(t => {
     35      const frame = document.createElement("iframe");
     36      t.add_cleanup(() => frame.remove());
     37      setSrc(frame, initialType, `<script>function f() { return abc }</script>${testData.namedObject}`);
     38      frame.onload = t.step_func(() => {
     39        const f = frame.contentWindow.f,
     40              associatedAbc = f();
     41        frame.onload = t.step_func_done(() => {
     42          assert_equals(f(), associatedAbc);
     43          assert_equals(associatedAbc.localName, testData.namedObjectLocalName);
     44        });
     45        setSrc(frame, type, "<span id=abc></span>");
     46      });
     47      document.body.append(frame);
     48    }, `Window's associated Document object is used for finding named objects (<${testData.namedObjectLocalName}> via ${type} <iframe>)`);
     49  });
     50 
     51  async_test(t => {
     52    const frame = document.createElement("iframe");
     53    t.add_cleanup(() => frame.remove());
     54    setSrc(frame, initialType, "<script>function f() { return abc }</script><object name=abc data='about:blank'></object>");
     55    frame.onload = t.step_func(() => {
     56      const f = frame.contentWindow.f,
     57            associatedAbc = f(),
     58            associatedAbcContainer = associatedAbc.frameElement;
     59      frame.onload = t.step_func_done(() => {
     60        assert_equals(f(), associatedAbcContainer);
     61        assert_equals(associatedAbcContainer.contentWindow, null);
     62      });
     63      setSrc(frame, type, "<span id=abc></span>");
     64    });
     65    document.body.append(frame);
     66  }, `Window's associated Document object is used for finding named objects (<object> with browsing ccontext via ${type} <iframe)>`);
     67 });