tor-browser

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

test_import_xul_to_content.xhtml (2243B)


      1 <?xml version="1.0"?>
      2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
      3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
      4 <window title="Mozilla Importing XUL into Content"
      5        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
      6  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
      7 
      8  <!-- test results are displayed in the html:body -->
      9  <body xmlns="http://www.w3.org/1999/xhtml">
     10  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1027299"
     11     target="_blank">Mozilla Bug 1027299</a>
     12  </body>
     13 
     14  <browser id="browserelt" src="about:blank" type="content"/>
     15 
     16  <!-- test code goes here -->
     17  <script type="application/javascript">
     18  <![CDATA[
     19 
     20  SimpleTest.waitForExplicitFinish();
     21 
     22  function expectWarning(expected, when, f) {
     23    Services.console.reset();
     24 
     25    f();
     26 
     27    var sawWarning = false;
     28    var msgs = Services.console.getMessageArray();
     29    for (var i = 0; i < msgs.length; i++) {
     30      var msg = msgs[i];
     31      if (!msg || !(msg instanceof Ci.nsIScriptError)) {
     32        continue;
     33      }
     34 
     35      if (msg.category.includes("DOM") && msg.errorMessage.includes("Importing XUL")) {
     36        sawWarning = true;
     37      }
     38    }
     39 
     40    ok(sawWarning == expected, "correct warning condition when " + when);
     41  }
     42 
     43  var browser = document.getElementById("browserelt");
     44  browser.addEventListener("load", function() {
     45    var doc = browser.contentDocument;
     46 
     47    // We add a <video> element, which contains anonymous XUL content. This should not warn.
     48    var video = doc.createElement("video");
     49    expectWarning(false, "appending video", function() {
     50      doc.documentElement.appendChild(video);
     51      // Force a layout flush to make sure the anonymous content is added.
     52      // eslint-disable-next-line no-unused-vars
     53      let dummy = doc.documentElement.offsetLeft;
     54    });
     55 
     56    // We add some XUL to a content document. This should generate a warning.
     57    var elt = document.createXULElement("scrollbar");
     58    var newElt = doc.importNode(elt, false);
     59    expectWarning(true, "appending XUL", function() {
     60      doc.documentElement.appendChild(newElt);
     61    });
     62 
     63    SimpleTest.finish();
     64  });
     65 
     66  ]]>
     67  </script>
     68 </window>