2 "Test modification of contents of a range"
7 // TEST 1: Initial values
8 debug('<span>Start test 1</span>');
9 var r = document.createRange();
10 shouldBe("r.startOffset", "0");
11 shouldBe("r.endOffset", "0");
12 shouldBe("r.startContainer", "document");
13 shouldBe("r.endContainer", "document");
14 shouldBeTrue("r.collapsed");
15 shouldBe("r.commonAncestorContainer", "document");
17 // TEST 2: Insert a comment into the document
18 debug('<span>Start test 2</span>');
19 r.insertNode(document.createComment("test comment"));
20 shouldBe("r.startOffset", "0");
21 shouldBe("r.endOffset", "1");
22 shouldBe("r.startContainer", "document");
23 shouldBe("r.endContainer", "document");
24 shouldBeFalse("r.collapsed");
25 shouldBe("r.commonAncestorContainer", "document");
27 // TEST 3: Remove the comment again
28 debug('<span>Start test 3</span>');
30 shouldBe("r.startOffset", "0");
31 shouldBe("r.endOffset", "0");
32 shouldBe("r.startContainer", "document");
33 shouldBe("r.endContainer", "document");
34 shouldBeTrue("r.collapsed");
35 shouldBe("r.commonAncestorContainer", "document");
37 // TEST 4: Insert a document fragment
38 debug('<span>Start test 4</span>');
39 var f = document.createDocumentFragment();
40 var c = document.getElementById("description");
42 f.appendChild(document.createTextNode("test text node"));
43 f.appendChild(document.createComment("another text comment"));
44 f.appendChild(document.createTextNode("another test text node"));
46 shouldBe("r.startOffset", "0");
47 shouldBe("r.endOffset", "3");
48 shouldBe("r.startContainer", "c");
49 shouldBe("r.endContainer", "c");
50 shouldBeFalse("r.collapsed");
51 shouldBe("r.commonAncestorContainer", "c");
53 // TEST 5: Remove the fragment again
54 debug('<span>Start test 5</span>');
56 shouldBe("r.startOffset", "0");
57 shouldBe("r.endOffset", "0");
58 shouldBe("r.startContainer", "c");
59 shouldBe("r.endContainer", "c");
60 shouldBeTrue("r.collapsed");
61 shouldBe("r.commonAncestorContainer", "c");
63 // TEST 6: Insert an empty document fragment
64 debug('<span>Start test 6</span>');
65 f = document.createDocumentFragment();
67 shouldBe("r.startOffset", "0");
68 shouldBe("r.endOffset", "0");
69 shouldBe("r.startContainer", "c");
70 shouldBe("r.endContainer", "c");
71 shouldBeTrue("r.collapsed");
72 shouldBe("r.commonAncestorContainer", "c");
74 // TEST 7: Insert a div
75 debug('<span>Start test 7</span>');
76 var d = document.createElement("div");
77 d.appendChild(document.createTextNode("test text node"));
78 d.appendChild(document.createComment("another text comment"));
79 d.appendChild(document.createTextNode("another test text node"));
81 shouldBe("r.startOffset", "0");
82 shouldBe("r.endOffset", "1");
83 shouldBe("r.startContainer", "c");
84 shouldBe("r.endContainer", "c");
85 shouldBeFalse("r.collapsed");
86 shouldBe("r.commonAncestorContainer", "c");
88 // TEST 8: Remove the div
89 debug('<span>Start test 8</span>');
91 shouldBe("r.startOffset", "0");
92 shouldBe("r.endOffset", "0");
93 shouldBe("r.startContainer", "c");
94 shouldBe("r.endContainer", "c");
95 shouldBeTrue("r.collapsed");
96 shouldBe("r.commonAncestorContainer", "c");