content/base/test/chrome/title_window.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial