tor-browser

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

title_window.xhtml (8861B)


      1 <?xml version="1.0"?>
      2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
      3 <window title="Mozilla Bug 481777 subwindow"
      4        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
      5        onload="runTests()">
      6 
      7  <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;"/>
      8  <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;"/>
      9  <iframe type="content" id="html3" src="data:text/html,&lt;html&gt;&lt;/html&gt;"/>
     10  <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;"/>
     11  <iframe type="content" id="xhtml2" src="data:text/xml,&lt;title xmlns='http://www.w3.org/1999/xhtml'&gt;Test&lt;/title&gt;"/>
     12  <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;"/>
     13  <iframe type="content" id="xhtml4" src="data:text/xml,&lt;html xmlns='http://www.w3.org/1999/xhtml'/>"/>
     14  <iframe type="content" id="xhtml5" src="data:text/xml,&lt;html xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;head/>&lt;/html&gt;"/>
     15  <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;"/>
     16  <iframe id="xul1" src="file_title.xhtml"/>
     17  <iframe id="xul2" src="file_title.xhtml"/>
     18  <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;"/>
     19  <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;"/>
     20 
     21  <script type="application/javascript">
     22    <![CDATA[
     23    var imports = [ "SimpleTest", "is", "isnot", "ok" ];
     24    for (var name of imports) {
     25      window[name] = window.arguments[0][name];
     26    }
     27 
     28    function testStatics() {
     29      function testStatic(id, expect, description) {
     30        is(document.getElementById(id).contentDocument.title, expect, description);
     31      }
     32 
     33      testStatic("html1", "Test", "HTML <title>");
     34      testStatic("html2", "Test", "choose the first HTML <title>");
     35      testStatic("html3", "", "No title");
     36      testStatic("xhtml1", "Test", "XHTML <title> in body");
     37      testStatic("xhtml2", "Test", "XHTML <title> as root element");
     38      testStatic("xhtml3", "Test", "XHTML <title> containing an element");
     39      testStatic("xul1", "Test", "XUL <window> title attribute");
     40      testStatic("svg1", "Test", "SVG <title>");
     41 
     42      // This one does nothing and won't fire an event
     43      document.getElementById("xhtml4").contentDocument.title = "Hello";
     44      is(document.getElementById("xhtml4").contentDocument.title, "", "Setting 'title' does nothing with no <head>");
     45    }
     46 
     47    function testDynamics() {
     48      var inProgress = {};
     49      var inProgressDoc = {};
     50      var inProgressWin = {};
     51      function testDynamic(id, expect, description, op, checkDOM) {
     52        inProgress[description] = true;
     53        inProgressDoc[description] = true;
     54        inProgressWin[description] = true;
     55        var frame = document.getElementById(id);
     56 
     57        function listener(ev) {
     58          inProgress[description] = false;
     59          is(frame.contentDocument.title, expect, "'title': " + description);
     60          is(frame.contentDocument, ev.target, "Unexpected target: " + description);
     61          if (typeof(checkDOM) != "undefined") {
     62            checkDOM(frame.contentDocument, "DOM: " + description);
     63          }
     64        }
     65 
     66        function listener2() {
     67          inProgressDoc[description] = false;
     68        }
     69        function listener3() {
     70          inProgressWin[description] = false;
     71        }
     72        frame.addEventListener("DOMTitleChanged", listener);
     73        frame.contentDocument.addEventListener("DOMTitleChanged", listener2);
     74        frame.contentWindow.addEventListener("DOMTitleChanged", listener3);
     75 
     76        op(frame.contentDocument);
     77      }
     78 
     79      var dynamicTests = [
     80        [ "html1", "Hello", "Setting HTML <title> text contents",
     81          function(doc){
     82            var t = doc.getElementById("t"); t.textContent = "Hello";
     83          } ],
     84        [ "html2", "Foo", "Removing HTML <title>",
     85          function(doc){
     86            var t = doc.getElementById("t"); t.remove();
     87          } ],
     88        [ "html3", "Hello", "Appending HTML <title> element to root element",
     89          function(doc){
     90            var t = doc.createElement("title"); t.textContent = "Hello"; doc.documentElement.appendChild(t);
     91          } ],
     92        [ "xhtml3", "Hello", "Setting 'title' clears existing <title> contents",
     93          function(doc){
     94            doc.title = "Hello";
     95          },
     96          function(doc, desc) {
     97            is(doc.documentElement.firstChild.data, "Hello", desc);
     98            is(doc.documentElement.firstChild.nextSibling, null, desc);
     99          } ],
    100        [ "xhtml5", "Hello", "Setting 'title' works with a <head>",
    101          function(doc){
    102            doc.title = "Hello";
    103          },
    104          function(doc, desc) {
    105            var head = doc.documentElement.firstChild;
    106            var title = head.firstChild;
    107            is(title.tagName.toLowerCase(), "title", desc);
    108            is(title.firstChild.data, "Hello", desc);
    109            is(title.firstChild.nextSibling, null, desc);
    110            is(title.nextSibling, null, desc);
    111          } ],
    112        [ "xhtml6", "Hello", "Setting 'title' appends to <head>",
    113          function(doc){
    114            doc.title = "Hello";
    115          },
    116          function(doc, desc) {
    117            var head = doc.documentElement.firstChild;
    118            is(head.firstChild.tagName.toLowerCase(), "style", desc);
    119            var title = head.firstChild.nextSibling;
    120            is(title.tagName.toLowerCase(), "title", desc);
    121            is(title.firstChild.data, "Hello", desc);
    122            is(title.firstChild.nextSibling, null, desc);
    123            is(title.nextSibling, null, desc);
    124          } ],
    125        [ "xul1", "Hello", "Setting XUL <window> title attribute",
    126          function(doc){
    127            doc.documentElement.setAttribute("title", "Hello");
    128          } ],
    129        [ "xul2", "Hello", "Setting 'title' in XUL",
    130          function(doc){
    131            doc.title = "Hello";
    132          },
    133          function(doc, desc) {
    134            is(doc.documentElement.getAttribute("title"), "Hello", desc);
    135            is(doc.documentElement.firstChild, null, desc);
    136          } ],
    137        [ "svg1", "Hello", "Setting SVG <title> text contents",
    138          function(doc){
    139            var t = doc.getElementById("t"); t.textContent = "Hello";
    140          } ],
    141        [ "svg2", "", "Removing SVG <title>",
    142          function(doc){
    143            var t = doc.getElementById("t"); t.remove();
    144          } ] ];
    145 
    146      var titleWindow = window;
    147 
    148      function runIndividualTest(i) {
    149        if (i == dynamicTests.length) {
    150          // Closing the window will nuke the global properties, since this
    151          // function is not really running on this window... or something
    152          // like that.  Thanks, executeSoon!
    153          var tester = SimpleTest;
    154          window.close();
    155          tester.finish();
    156        } else {
    157          var parameters = dynamicTests[i];
    158          var testElementId = parameters[0];
    159          var testExpectedValue = parameters[1];
    160          var testDescription = parameters[2];
    161          var testOp = parameters[3];
    162          var testCheckDOM = parameters[4];
    163 
    164          function checkTest() {
    165            ok(!inProgress[testDescription],
    166               testDescription + ": DOMTitleChange not fired");
    167            ok(inProgressDoc[testDescription],
    168               testDescription + ": DOMTitleChange fired on content document");
    169            ok(inProgressWin[testDescription],
    170               testDescription + ": DOMTitleChange fired on content window");
    171            // Run the next test in the context of the parent XUL window.
    172            titleWindow.setTimeout(runIndividualTest, 0, i+1);
    173          }
    174          function spinEventLoopOp(doc) {
    175            // Perform the test's operations.
    176            testOp(doc);
    177            // Spin the associated window's event loop to ensure we
    178            // drain any asynchronous changes and fire associated
    179            // events.
    180            doc.defaultView.setTimeout(checkTest, 0);
    181          }
    182 
    183          testDynamic(testElementId, testExpectedValue, testDescription,
    184                      spinEventLoopOp, testCheckDOM);
    185        }
    186      }
    187 
    188      window.setTimeout(runIndividualTest, 0, 0);
    189    }
    190 
    191    function runTests() {
    192      testStatics();
    193      testDynamics();
    194    }
    195    ]]>
    196  </script>
    197 </window>