summaryrefslogtreecommitdiffstats
path: root/dom/xul/test/test_import_xul_to_content.xhtml
blob: 32db06e5649883af7264b79eedcf6ca067928b55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<window title="Mozilla Importing XUL into Content"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>

  <!-- test results are displayed in the html:body -->
  <body xmlns="http://www.w3.org/1999/xhtml">
  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1027299"
     target="_blank">Mozilla Bug 1027299</a>
  </body>

  <browser id="browserelt" src="about:blank" type="content"/>

  <!-- test code goes here -->
  <script type="application/javascript">
  <![CDATA[

  SimpleTest.waitForExplicitFinish();

  function expectWarning(expected, when, f) {
    Services.console.reset();

    f();

    var sawWarning = false;
    var msgs = Services.console.getMessageArray();
    for (var i = 0; i < msgs.length; i++) {
      var msg = msgs[i];
      if (!msg || !(msg instanceof Ci.nsIScriptError)) {
        continue;
      }

      if (msg.category.includes("DOM") && msg.errorMessage.includes("Importing XUL")) {
        sawWarning = true;
      }
    }

    ok(sawWarning == expected, "correct warning condition when " + when);
  }

  var browser = document.getElementById("browserelt");
  browser.addEventListener("load", function() {
    var doc = browser.contentDocument;

    // We add a <video> element, which contains anonymous XUL content. This should not warn.
    var video = doc.createElement("video");
    expectWarning(false, "appending video", function() {
      doc.documentElement.appendChild(video);
      // Force a layout flush to make sure the anonymous content is added.
      // eslint-disable-next-line no-unused-vars
      let dummy = doc.documentElement.offsetLeft;
    });

    // We add some XUL to a content document. This should generate a warning.
    var elt = document.createXULElement("scrollbar");
    var newElt = doc.importNode(elt, false);
    expectWarning(true, "appending XUL", function() {
      doc.documentElement.appendChild(newElt);
    });

    SimpleTest.finish();
  });

  ]]>
  </script>
</window>