content/base/test/chrome/title_window.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/test/chrome/title_window.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,198 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
     1.6 +<window title="Mozilla Bug 481777 subwindow"
     1.7 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     1.8 +        onload="runTests()">
     1.9 +
    1.10 +  <iframe type="content" id="html1" src="data:text/html,&lt;html&gt;&lt;head&gt;&lt;title id='t'&gt;Test&lt;/title&gt;&lt;/head&gt;&lt;/html&gt;"/>
    1.11 +  <iframe type="content" id="html2" src="data:text/html,&lt;html&gt;&lt;head&gt;&lt;title id='t'&gt;Test&lt;/title&gt;&lt;title&gt;Foo&lt;/title&gt;&lt;/head&gt;&lt;/html&gt;"/>
    1.12 +  <iframe type="content" id="html3" src="data:text/html,&lt;html&gt;&lt;/html&gt;"/>
    1.13 +  <iframe type="content" id="xhtml1" src="data:text/xml,&lt;html xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;body&gt;&lt;title id='t'&gt;Test&lt;/title&gt;&lt;/body&gt;&lt;/html&gt;"/>
    1.14 +  <iframe type="content" id="xhtml2" src="data:text/xml,&lt;title xmlns='http://www.w3.org/1999/xhtml'&gt;Test&lt;/title&gt;"/>
    1.15 +  <iframe type="content" id="xhtml3" src="data:text/xml,&lt;title xmlns='http://www.w3.org/1999/xhtml'&gt;Te&lt;div&gt;bogus&lt;/div&gt;st&lt;/title&gt;"/>
    1.16 +  <iframe type="content" id="xhtml4" src="data:text/xml,&lt;html xmlns='http://www.w3.org/1999/xhtml'/>"/>
    1.17 +  <iframe type="content" id="xhtml5" src="data:text/xml,&lt;html xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;head/>&lt;/html&gt;"/>
    1.18 +  <iframe type="content" id="xhtml6" src="data:text/xml,&lt;html xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;head&gt;&lt;style/>&lt;/head&gt;&lt;/html&gt;"/>
    1.19 +  <iframe id="xul1" src="data:application/vnd.mozilla.xul+xml,&lt;window xmlns='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul' title='Test'/>"/>
    1.20 +  <iframe id="xul2" src="data:application/vnd.mozilla.xul+xml,&lt;window xmlns='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul' title='Test'/>"/>
    1.21 +  <iframe type="content" id="svg1" src="data:text/xml,&lt;svg xmlns='http://www.w3.org/2000/svg'&gt;&lt;title id='t'&gt;Test&lt;/title&gt;&lt;/svg&gt;"/>
    1.22 +  <iframe type="content" id="svg2" src="data:text/xml,&lt;svg xmlns='http://www.w3.org/2000/svg'&gt;&lt;title id='t'&gt;Test&lt;/title&gt;&lt;/svg&gt;"/>
    1.23 +
    1.24 +  <script type="application/javascript">
    1.25 +    <![CDATA[
    1.26 +    var imports = [ "SimpleTest", "is", "isnot", "ok" ];
    1.27 +    for each (var name in imports) {
    1.28 +      window[name] = window.opener.wrappedJSObject[name];
    1.29 +    }
    1.30 +
    1.31 +    function testStatics() {
    1.32 +      function testStatic(id, expect, description) {
    1.33 +        is(document.getElementById(id).contentDocument.title, expect, description);
    1.34 +      }
    1.35 +
    1.36 +      testStatic("html1", "Test", "HTML <title>");
    1.37 +      testStatic("html2", "Test", "choose the first HTML <title>");
    1.38 +      testStatic("html3", "", "No title");
    1.39 +      testStatic("xhtml1", "Test", "XHTML <title> in body");
    1.40 +      testStatic("xhtml2", "Test", "XHTML <title> as root element");
    1.41 +      testStatic("xhtml3", "Test", "XHTML <title> containing an element");
    1.42 +      testStatic("xul1", "Test", "XUL <window> title attribute");
    1.43 +      testStatic("svg1", "Test", "SVG <title>");
    1.44 +
    1.45 +      // This one does nothing and won't fire an event
    1.46 +      document.getElementById("xhtml4").contentDocument.title = "Hello";
    1.47 +      is(document.getElementById("xhtml4").contentDocument.title, "", "Setting 'title' does nothing with no <head>");
    1.48 +    }
    1.49 +
    1.50 +    function testDynamics() {
    1.51 +      var inProgress = {};
    1.52 +      var inProgressDoc = {};
    1.53 +      var inProgressWin = {};
    1.54 +      function testDynamic(id, expect, description, op, checkDOM) {
    1.55 +        inProgress[description] = true;
    1.56 +        inProgressDoc[description] = true;
    1.57 +        inProgressWin[description] = true;
    1.58 +        var frame = document.getElementById(id);
    1.59 +        var done = false;
    1.60 +
    1.61 +        function listener(ev) {
    1.62 +          inProgress[description] = false;
    1.63 +          is(frame.contentDocument.title, expect, "'title': " + description);
    1.64 +          is(frame.contentDocument, ev.target, "Unexpected target: " + description);
    1.65 +          if (typeof(checkDOM) != "undefined") {
    1.66 +            checkDOM(frame.contentDocument, "DOM: " + description);
    1.67 +          }
    1.68 +        }
    1.69 +
    1.70 +        function listener2(ev) {
    1.71 +          inProgressDoc[description] = false;
    1.72 +        }
    1.73 +        function listener3(ev) {
    1.74 +          inProgressWin[description] = false;
    1.75 +        }
    1.76 +        frame.addEventListener("DOMTitleChanged", listener, false);
    1.77 +        frame.contentDocument.addEventListener("DOMTitleChanged", listener2, false);
    1.78 +        frame.contentWindow.addEventListener("DOMTitleChanged", listener3, false);
    1.79 +
    1.80 +        op(frame.contentDocument);
    1.81 +      }
    1.82 +
    1.83 +      var dynamicTests = [
    1.84 +        [ "html1", "Hello", "Setting HTML <title> text contents",
    1.85 +          function(doc){
    1.86 +            var t = doc.getElementById("t"); t.textContent = "Hello";
    1.87 +          } ],
    1.88 +        [ "html2", "Foo", "Removing HTML <title>",
    1.89 +          function(doc){
    1.90 +            var t = doc.getElementById("t"); t.parentNode.removeChild(t);
    1.91 +          } ],
    1.92 +        [ "html3", "Hello", "Appending HTML <title> element to root element",
    1.93 +          function(doc){
    1.94 +            var t = doc.createElement("title"); t.textContent = "Hello"; doc.documentElement.appendChild(t);
    1.95 +          } ],
    1.96 +        [ "xhtml3", "Hello", "Setting 'title' clears existing <title> contents",
    1.97 +          function(doc){
    1.98 +            doc.title = "Hello";
    1.99 +          },
   1.100 +          function(doc, desc) {
   1.101 +            is(doc.documentElement.firstChild.data, "Hello", desc);
   1.102 +            is(doc.documentElement.firstChild.nextSibling, null, desc);
   1.103 +          } ],
   1.104 +        [ "xhtml5", "Hello", "Setting 'title' works with a <head>",
   1.105 +          function(doc){
   1.106 +            doc.title = "Hello";
   1.107 +          },
   1.108 +          function(doc, desc) {
   1.109 +            var head = doc.documentElement.firstChild;
   1.110 +            var title = head.firstChild;
   1.111 +            is(title.tagName.toLowerCase(), "title", desc);
   1.112 +            is(title.firstChild.data, "Hello", desc);
   1.113 +            is(title.firstChild.nextSibling, null, desc);
   1.114 +            is(title.nextSibling, null, desc);
   1.115 +          } ],
   1.116 +        [ "xhtml6", "Hello", "Setting 'title' appends to <head>",
   1.117 +          function(doc){
   1.118 +            doc.title = "Hello";
   1.119 +          },
   1.120 +          function(doc, desc) {
   1.121 +            var head = doc.documentElement.firstChild;
   1.122 +            is(head.firstChild.tagName.toLowerCase(), "style", desc);
   1.123 +            var title = head.firstChild.nextSibling;
   1.124 +            is(title.tagName.toLowerCase(), "title", desc);
   1.125 +            is(title.firstChild.data, "Hello", desc);
   1.126 +            is(title.firstChild.nextSibling, null, desc);
   1.127 +            is(title.nextSibling, null, desc);
   1.128 +          } ],
   1.129 +        [ "xul1", "Hello", "Setting XUL <window> title attribute",
   1.130 +          function(doc){
   1.131 +            doc.documentElement.setAttribute("title", "Hello");
   1.132 +          } ],
   1.133 +        [ "xul2", "Hello", "Setting 'title' in XUL",
   1.134 +          function(doc){
   1.135 +            doc.title = "Hello";
   1.136 +          },
   1.137 +          function(doc, desc) {
   1.138 +            is(doc.documentElement.getAttribute("title"), "Hello", desc);
   1.139 +            is(doc.documentElement.firstChild, null, desc);
   1.140 +          } ],
   1.141 +        [ "svg1", "Hello", "Setting SVG <title> text contents",
   1.142 +          function(doc){
   1.143 +            var t = doc.getElementById("t"); t.textContent = "Hello";
   1.144 +          } ],
   1.145 +        [ "svg2", "", "Removing SVG <title>",
   1.146 +          function(doc){
   1.147 +            var t = doc.getElementById("t"); t.parentNode.removeChild(t);
   1.148 +          } ] ];
   1.149 +
   1.150 +      var titleWindow = window;
   1.151 +
   1.152 +      function runIndividualTest(i) {
   1.153 +        if (i == dynamicTests.length) {
   1.154 +          // Closing the window will nuke the global properties, since this
   1.155 +          // function is not really running on this window... or something
   1.156 +          // like that.  Thanks, executeSoon!
   1.157 +          var tester = SimpleTest;
   1.158 +          window.close();
   1.159 +          tester.finish();
   1.160 +        } else {
   1.161 +          var parameters = dynamicTests[i];
   1.162 +          var testElementId = parameters[0];
   1.163 +          var testExpectedValue = parameters[1];
   1.164 +          var testDescription = parameters[2];
   1.165 +          var testOp = parameters[3];
   1.166 +          var testCheckDOM = parameters[4];
   1.167 +
   1.168 +          function checkTest() {
   1.169 +            ok(!inProgress[testDescription],
   1.170 +               testDescription + ": DOMTitleChange not fired");
   1.171 +            ok(inProgressDoc[testDescription],
   1.172 +               testDescription + ": DOMTitleChange fired on content document");
   1.173 +            ok(inProgressWin[testDescription],
   1.174 +               testDescription + ": DOMTitleChange fired on content window");
   1.175 +            // Run the next test in the context of the parent XUL window.
   1.176 +            titleWindow.setTimeout(runIndividualTest, 0, i+1);
   1.177 +          }
   1.178 +          function spinEventLoopOp(doc) {
   1.179 +            // Perform the test's operations.
   1.180 +            testOp(doc);
   1.181 +            // Spin the associated window's event loop to ensure we
   1.182 +            // drain any asynchronous changes and fire associated
   1.183 +            // events.
   1.184 +            doc.defaultView.setTimeout(checkTest, 0);
   1.185 +          }
   1.186 +
   1.187 +          testDynamic(testElementId, testExpectedValue, testDescription,
   1.188 +                      spinEventLoopOp, testCheckDOM);
   1.189 +        }
   1.190 +      }
   1.191 +
   1.192 +      window.setTimeout(runIndividualTest, 0, 0);
   1.193 +    }
   1.194 +
   1.195 +    function runTests() {
   1.196 +      testStatics();
   1.197 +      testDynamics();
   1.198 +    }
   1.199 +    ]]>
   1.200 +  </script>
   1.201 +</window>

mercurial