4 testRunner
.dumpAsText();
10 document
.getElementById('logger').innerHTML
+= msg
+ '\n';
15 function runTest(test
, opt_expectedErrorName
)
21 errorName
= error
.name
;
24 var hasExpectedErrorName
= opt_expectedErrorName
;
25 if (hasExpectedErrorName
&& navigator
.userAgent
.indexOf('Firefox') != -1)
26 opt_expectedErrorName
= 'NS_ERROR_DOM_' + opt_expectedErrorName
;
28 if (!errorName
&& !opt_expectedErrorName
|| opt_expectedErrorName
== errorName
)
31 log(i
+ '. FAIL: expected ' + opt_expectedErrorName
+ ' got ' + (errorName
|| 'no error'));
35 function elementInCurrentDocument(html
)
37 var node
= document
.createElement('div');
38 node
.innerHTML
= html
|| 'lorem ipsum';
39 document
.body
.appendChild(node
);
43 function rangeInIframe()
45 var range
= iframeDoc
.createRange();
46 range
.setStart(iframeDoc
.body
, 0);
47 range
.setEnd(iframeDoc
.body
, 1);
51 function rangeInCurrentDocument()
53 var range
= document
.createRange();
54 range
.setStart(document
.body
, 0);
55 range
.setEnd(document
.body
, 1);
61 iframe
= document
.querySelector('iframe');
62 iframeDoc
= iframe
.contentDocument
;
65 iframeDoc
.body
.appendChild(document
.createElement('div'));
66 iframeDoc
.body
.appendChild(elementInCurrentDocument('appendChild'));
70 var dummy
= document
.createElement('span');
71 iframeDoc
.body
.appendChild(dummy
);
72 iframeDoc
.body
.replaceChild(document
.createElement('div'), dummy
);
74 var dummy
= document
.createElement('span');
75 iframeDoc
.body
.appendChild(dummy
);
76 iframeDoc
.body
.replaceChild(elementInCurrentDocument('replaceChild'), dummy
);
79 iframeDoc
.body
.insertBefore(document
.createElement('div'), iframeDoc
.body
.firstChild
);
80 iframeDoc
.body
.insertBefore(elementInCurrentDocument('insertBefore'), iframeDoc
.body
.firstChild
);
83 rangeInIframe().insertNode(document
.createElement('div'));
84 rangeInIframe().insertNode(elementInCurrentDocument('insertNode'));
87 rangeInIframe().surroundContents(document
.createElement('div'));
88 rangeInIframe().surroundContents(elementInCurrentDocument('surroundContents'));
92 iframeDoc
.body
.appendChild(document
.createElement('div'));
93 var element
= elementInCurrentDocument('insertBefore');
94 // Make sure we don't crash if the element is moved back to the original document during the insertBefore call.
95 var mutationHandler = function() {
96 document
.body
.removeEventListener('DOMSubtreeModified', mutationHandler
, true);
97 document
.body
.appendChild(element
);
98 // Access something on the element to see if it's in a valid state.
101 document
.body
.addEventListener('DOMSubtreeModified', mutationHandler
, true);
103 iframeDoc
.body
.insertBefore(element
);
107 // Clear the event handler to avoid affecting the following tests.
112 iframeDoc
.body
.appendChild(document
.createElement('div'));
113 var element
= elementInCurrentDocument('appendChild');
114 // Make sure we don't crash if the element is moved back to the original document during the insertBefore call.
115 var mutationHandler = function() {
116 document
.body
.removeEventListener('DOMSubtreeModified', mutationHandler
, true);
117 document
.body
.appendChild(element
);
118 // Access something on the element to see if it's in a valid state.
121 document
.body
.addEventListener('DOMSubtreeModified', mutationHandler
, true);
123 iframeDoc
.body
.appendChild(element
);
127 // Clear the event handler to avoid affecting the following tests.
132 iframeDoc
.body
.appendChild(document
.createElement('div'));
133 var element
= elementInCurrentDocument('replaceChild');
134 // Make sure we don't crash if the element is moved back to the original document during the insertBefore call.
135 var mutationHandler = function() {
136 document
.body
.removeEventListener('DOMSubtreeModified', mutationHandler
, true);
137 document
.body
.appendChild(element
);
138 // Access something on the element to see if it's in a valid state.
141 document
.body
.addEventListener('DOMSubtreeModified', mutationHandler
, true);
143 iframeDoc
.body
.replaceChild(element
, iframeDoc
.body
.firstChild
);
147 // Clear the event handler to avoid affecting the following tests.
152 var attribute
= document
.createAttribute('asdf');
153 iframeDoc
.body
.attributes
.setNamedItem(attribute
);
156 var attribute
= document
.createAttribute('asdf');
157 document
.body
.attributes
.setNamedItem(attribute
);
158 iframeDoc
.body
.attributes
.setNamedItem(attribute
);
159 }, 'InUseAttributeError');
162 var doctype
= document
.implementation
.createDocumentType(
164 '-//W3C//DTD XHTML 1.0 Strict//EN',
165 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'
167 iframeDoc
.implementation
.createDocument('', 'html', doctype
);
170 iframeDoc
.implementation
.createDocument('', 'html', document
.doctype
);
173 rangeInIframe().compareBoundaryPoints(Range
.END_TO_END
, rangeInCurrentDocument());
174 }, 'WrongDocumentError');
176 rangeInIframe().comparePoint(elementInCurrentDocument('comparePoint'), 0);
177 }, 'WrongDocumentError');
180 iframeDoc
.appendChild(document
.doctype
);
181 console
.log(document
.doctype
);
184 // When setting a boundary of the range in a different
185 // document, the call should succeed and the range should be collapsed.
187 rangeInIframe().setStart(elementInCurrentDocument('setStart'), 0);
190 rangeInIframe().setEnd(elementInCurrentDocument('setEnd'), 0);
193 rangeInIframe().setStartBefore(elementInCurrentDocument('setStartBefore'), 0);
196 rangeInIframe().setStartAfter(elementInCurrentDocument('setStartAfter'), 0);
199 rangeInIframe().setEndBefore(elementInCurrentDocument('setEndBefore'), 0);
202 rangeInIframe().setEndAfter(elementInCurrentDocument('setEndAfter'), 0);
205 rangeInIframe().isPointInRange(elementInCurrentDocument('isPointInRange'), 0);
210 <pre id='logger'
></pre>
211 <iframe onload='run()'
></iframe>