tor-browser

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

cross-origin-to-whom-part-2.window.js (2635B)


      1 async_test(t => {
      2  const frame = document.body.appendChild(document.createElement("iframe"));
      3  frame.src = "support/document-with-embedded-svg.html";
      4  const elements = {
      5    "embed": ["getSVGDocument"],
      6    "frame": ["contentDocument"],
      7    "iframe": ["getSVGDocument", "contentDocument"],
      8    "object": ["getSVGDocument", "contentDocument"]
      9  };
     10  function element_to_document(element, api) {
     11    return api === "getSVGDocument" ? element[api]() : element[api];
     12  }
     13  function assert_apis(instance, assertNull = false) {
     14    const name = instance.localName;
     15    let priorPossibleDocument = null;
     16    elements[name].forEach(api => {
     17      const assertReason = `${name}.${api}`;
     18      const possibleDocument = element_to_document(instance, api);
     19      if (assertNull) {
     20        assert_equals(possibleDocument, null, assertReason);
     21        return;
     22      } else {
     23        assert_not_equals(possibleDocument, null, assertReason);
     24 
     25        // This needs standardizing still
     26        // assert_class_string(possibleDocument, "XMLDocument");
     27      }
     28 
     29      // Ensure getSVGDocument() and contentDocument if both available return the same
     30      if (priorPossibleDocument === null) {
     31        priorPossibleDocument = possibleDocument;
     32      } else {
     33        assert_equals(priorPossibleDocument, possibleDocument);
     34      }
     35    });
     36  }
     37  frame.onload = t.step_func_done(() => {
     38    const instances = Object.keys(elements).map(element => frame.contentDocument.querySelector(element));
     39    // Everything is same origin and same origin-domain, no sweat
     40    instances.forEach(instance => assert_apis(instance));
     41    // Make the SVG cross origin-domain (its container and the current settings object are not
     42    // affected)
     43    instances.forEach(instance => {
     44      const svgDocument = element_to_document(instance, elements[instance.localName][0]);
     45      svgDocument.domain = svgDocument.domain;
     46    });
     47    instances.forEach(instance => assert_apis(instance, true));
     48    const svgContainer = frame.contentDocument;
     49    // Make the current settings object same origin-domain with the SVG and cross origin-domain with
     50    // SVG's container (SVG's container is not affected)
     51    document.domain = document.domain;
     52    assert_equals(frame.contentDocument, null);
     53    instances.forEach(instance => assert_apis(instance, true));
     54    // Make everything same origin-domain once more
     55    svgContainer.domain = svgContainer.domain;
     56    instances.forEach(instance => assert_apis(instance));
     57  });
     58  document.body.appendChild(frame);
     59 }, "Test embed/frame/iframe/object nested document APIs for same origin-domain and cross origin-domain embedder document");