1 <iframe src=
"empty.html" id=
"selectors" width=
0 height=
0 frameborder=
0></iframe>
2 <p>The test below should report no failures, and should say PASS at the end.
</p>
4 if (window
.testRunner
) {
5 testRunner
.dumpAsText();
10 function getTestDocument() {
11 var iframe
= document
.getElementById("selectors");
12 var doc
= iframe
.contentDocument
;
13 for (var i
= doc
.documentElement
.childNodes
.length
-1; i
>= 0; i
-= 1)
14 doc
.documentElement
.removeChild(doc
.documentElement
.childNodes
[i
]);
15 doc
.documentElement
.appendChild(doc
.createElement('head'));
16 doc
.documentElement
.firstChild
.appendChild(doc
.createElement('title'));
17 doc
.documentElement
.appendChild(doc
.createElement('body'));
23 function fail(message
) {
24 document
.write(message
.replace("&", "&").replace("<", "<") + "<br>");
28 function assert(condition
, message
) {
33 function assertEquals(expression
, value
, message
) {
34 if (expression
!= value
) {
35 expression
= (""+expression
).replace(/[\r\n]+/g, "\\n");
36 value
= (""+value
).replace(/\r?\n/g, "\\n");
37 fail("expected '" + value
+ "' but got '" + expression
+ "' - " + message
);
41 // test 11: Ranges and Comments
43 var doc
= getTestDocument();
44 var c1
= doc
.createComment("11111");
46 var r
= doc
.createRange();
48 msg
= 'wrong exception raised';
50 r
.surroundContents(doc
.createElement('a'));
51 msg
= 'no exception raised';
54 msg
+= '; code = ' + e
.code
;
55 if (e
.code
== 3) // HIERARCHY_REQUEST_ERR
58 assert(msg
== '', "when inserting <a> into Document with another child: " + msg
);
59 var c2
= doc
.createComment("22222");
60 doc
.body
.appendChild(c2
);
61 var c3
= doc
.createComment("33333");
62 doc
.body
.appendChild(c3
);
65 var msg
= 'wrong exception raised';
67 r
.surroundContents(doc
.createElement('a'));
68 msg
= 'no exception raised';
70 // COMMENTED OUT FOR 2011 UPDATE - DOM Core changes the exception from RangeException.BAD_BOUNDARYPOINTS_ERR (1) to DOMException.INVALID_STATE_ERR (11)
72 // msg += '; code = ' + e.code;
76 assert(msg
== '', "when trying to surround two halves of comment: " + msg
);
77 assertEquals(r
.toString(), "", "comments returned text");
80 document
.write("PASS<br>");