5 <title>Test for titles
</title>
6 <script type=
"text/javascript" src=
"/MochiKit/MochiKit.js"></script>
7 <script type=
"text/javascript" src=
"/tests/SimpleTest/SimpleTest.js"></script>
8 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css" />
9 <style type=
"text/css">
13 <body onload=
"runTests()">
16 <div style=
"display:none;">
17 <iframe id=
"html1" src=
"data:text/html,<html><head><title id='t'>Test</title></head></html>"></iframe>
18 <iframe id=
"html2" src=
"data:text/html,<html><head><title id='t'>Test</title><title>Foo</title></head></html>"></iframe>
19 <iframe id=
"html3" src=
"data:text/html,<html></html>"></iframe>
20 <iframe id=
"xhtml1" src=
"data:text/xml,<html xmlns='http://www.w3.org/1999/xhtml'><body><title id='t'>Test</title></body></html>"></iframe>
21 <iframe id=
"xhtml2" src=
"data:text/xml,<title xmlns='http://www.w3.org/1999/xhtml'>Test</title>"></iframe>
22 <iframe id=
"xhtml3" src=
"data:text/xml,<title xmlns='http://www.w3.org/1999/xhtml'>Te<div>bogus</div>st</title>"></iframe>
23 <iframe id=
"xhtml4" src=
"data:text/xml,<html xmlns='http://www.w3.org/1999/xhtml'/>"></iframe>
24 <iframe id=
"xhtml5" src=
"data:text/xml,<html xmlns='http://www.w3.org/1999/xhtml'><head/></html>"></iframe>
25 <iframe id=
"xhtml6" src=
"data:text/xml,<html xmlns='http://www.w3.org/1999/xhtml'><head><style/></head></html>"></iframe>
26 <iframe id=
"xul1" src=
"data:application/vnd.mozilla.xul+xml,<window xmlns='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul' title='Test'/>"></iframe>
27 <iframe id=
"xul2" src=
"data:application/vnd.mozilla.xul+xml,<window xmlns='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul' title='Test'/>"></iframe>
28 <iframe id=
"svg1" src=
"data:text/xml,<svg xmlns='http://www.w3.org/2000/svg'><title id='t'>Test</title></svg>"></iframe>
29 <iframe id=
"svg2" src=
"data:text/xml,<svg xmlns='http://www.w3.org/2000/svg'><title id='t'>Test</title></svg>"></iframe>
34 SimpleTest
.waitForExplicitFinish();
36 function testStatics() {
37 function testStatic(id
, expect
, description
) {
38 is(document
.getElementById(id
).contentDocument
.title
, expect
, description
);
41 testStatic("html1", "Test", "HTML <title>");
42 testStatic("html2", "Test", "choose the first HTML <title>");
43 testStatic("html3", "", "No title");
44 testStatic("xhtml1", "Test", "XHTML <title> in body");
45 testStatic("xhtml2", "Test", "XHTML <title> as root element");
46 testStatic("xhtml3", "Test", "XHTML <title> containing an element");
47 testStatic("xul1", "Test", "XUL <window> title attribute");
48 testStatic("svg1", "Test", "SVG <title>");
51 function testDynamics() {
53 function testDynamic(id
, expect
, description
, op
, checkDOM
) {
54 inProgress
[description
] = true;
55 var frame
= document
.getElementById(id
);
59 inProgress
[description
] = false;
60 is(frame
.contentDocument
.title
, expect
, "'title': " + description
);
61 if (typeof(checkDOM
) != undefined) {
62 checkDOM(frame
.contentDocument
, "DOM: " + description
);
65 frame
.contentDocument
.addEventListener("DOMTitleChanged", listener
, false);
67 op(frame
.contentDocument
);
70 testDynamic("html1", "Hello", "Setting HTML <title> text contents", function(doc
){
71 var t
= doc
.getElementById("t"); t
.textContent
= "Hello";
73 testDynamic("html2", "Foo", "Removing HTML <title>", function(doc
){
74 var t
= doc
.getElementById("t"); t
.parentNode
.removeChild(t
);
76 testDynamic("html3", "Hello", "Appending HTML <title> element to root element", function(doc
){
77 var t
= doc
.createElement("title"); t
.textContent
= "Hello"; doc
.documentElement
.appendChild(t
);
80 testDynamic("xhtml3", "Hello", "Setting 'title' clears existing <title> contents", function(doc
){
82 }, function(doc
, desc
) {
83 is(doc
.documentElement
.firstChild
.data
, "Hello", desc
);
84 is(doc
.documentElement
.firstChild
.nextSibling
, null, desc
);
86 // This one does nothing and won't fire an event
87 document
.getElementById("xhtml4").contentDocument
.title
= "Hello";
88 is(document
.getElementById("xhtml4").contentDocument
.title
, "", "Setting 'title' does nothing with no <head>");
89 testDynamic("xhtml5", "Hello", "Setting 'title' works with a <head>", function(doc
){
91 }, function(doc
, desc
) {
92 var head
= doc
.documentElement
.firstChild
;
93 var title
= head
.firstChild
;
94 is(title
.tagName
.toLowerCase(), "title", desc
);
95 is(title
.firstChild
.data
, "Hello", desc
);
96 is(title
.firstChild
.nextSibling
, null, desc
);
97 is(title
.nextSibling
, null, desc
);
99 testDynamic("xhtml6", "Hello", "Setting 'title' appends to <head>", function(doc
){
101 }, function(doc
, desc
) {
102 var head
= doc
.documentElement
.firstChild
;
103 is(head
.firstChild
.tagName
.toLowerCase(), "style", desc
);
104 var title
= head
.firstChild
.nextSibling
;
105 is(title
.tagName
.toLowerCase(), "title", desc
);
106 is(title
.firstChild
.data
, "Hello", desc
);
107 is(title
.firstChild
.nextSibling
, null, desc
);
108 is(title
.nextSibling
, null, desc
);
111 testDynamic("xul1", "Hello", "Setting XUL <window> title attribute", function(doc
){
112 doc
.documentElement
.setAttribute("title", "Hello");
114 testDynamic("xul2", "Hello", "Setting 'title' in XUL", function(doc
){
116 }, function(doc
, desc
) {
117 is(doc
.documentElement
.getAttribute("title"), "Hello", desc
);
118 is(doc
.documentElement
.firstChild
, null, desc
);
121 testDynamic("svg1", "Hello", "Setting SVG <title> text contents", function(doc
){
122 var t
= doc
.getElementById("t"); t
.textContent
= "Hello";
124 testDynamic("svg2", "", "Removing SVG <title>", function(doc
){
125 var t
= doc
.getElementById("t"); t
.parentNode
.removeChild(t
);
129 for (description
in inProgress
) {
130 ok(!inProgress
[description
], description
+ ": DOMTitleChange not fired");
134 setTimeout(end
, 500);
137 function runTests() {