Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / Range / resources / intersectsNode.js
blob10122b0cbf31657dd7a0a71c55b8e4b3ac53a5a0
1 description(
2 "This test checks the behavior of the intersectsNode() method on the Range object.<br>" +
3 "It covers all configurations of the node/Range relationship and some exception conditions."
4 );
6 var range = document.createRange();
7 var intersects = 0;
9 debug("1.1 Node starts before the range and ends before the range");
10 range.selectNode(document.getElementById("a2"));
11 intersects = range.intersectsNode(document.getElementById("b1"));
12 shouldBeFalse("intersects");
13 debug("");
15 debug("1.2 Node starts before the range, and range ends on a 1");
16 range.setStart(document.getElementById("b2"), 1);
17 range.setEnd(document.getElementById("c2"), 1);
18 intersects = range.intersectsNode(document.getElementById("b2"));
19 shouldBeTrue("intersects");
20 debug("");
22 debug("1.3 Node starts before the range and ends within the range");
23 range.setStart(document.getElementById("b2"), 0);
24 range.setEnd(document.getElementById("c3"), 0);
25 intersects = range.intersectsNode(document.getElementById("a2"));
26 shouldBeTrue("intersects");
27 debug("");
29 debug("1.4 Range starts on 0, and node starts before range and ends in range");
30 range.setStart(document.getElementById("b2"), 0);
31 range.setEnd(document.getElementById("c2"), 1);
32 intersects = range.intersectsNode(document.getElementById("b2"));
33 shouldBeTrue("intersects");
34 debug("");
36 debug("1.5 Node starts and ends in range");
37 range.selectNode(document.getElementById("a2"));
38 intersects = range.intersectsNode(document.getElementById("b2"));
39 shouldBeTrue("intersects");
40 debug("");
42 debug("1.6 Node starts in the range, and the range ends on 1");
43 range.setStart(document.getElementById("b1"), 1);
44 range.setEnd(document.getElementById("c2"), 1);
45 intersects = range.intersectsNode( document.getElementById("c2"));
46 shouldBeTrue("intersects");
47 debug("");
49 debug("1.7 Node starts in the range, and ends after the range");
50 range.setStart(document.getElementById("b1"), 1);
51 range.setEnd(document.getElementById("c2"), 0);
52 intersects = range.intersectsNode( document.getElementById("c2"));
53 shouldBeTrue("intersects");
54 debug("");
56 debug("1.8 Range start on 1, node starts in range and ends after");
57 range.setStart(document.getElementById("b2"), 1);
58 range.setEnd(document.getElementById("c2"), 0);
59 intersects = range.intersectsNode( document.getElementById("c2"));
60 shouldBeTrue("intersects");
61 debug("");
63 debug("1.9 Node starts on range start and ends on range end");
64 range.selectNode(document.getElementById("a2"));
65 intersects = range.intersectsNode(document.getElementById("a2"));
66 shouldBeTrue("intersects");
67 debug("");
69 debug("1.10 Node starts after range end and ends after range end");
70 range.selectNode(document.getElementById("b2"));
71 intersects = range.intersectsNode(document.getElementById("c3"));
72 shouldBeFalse("intersects");
73 debug("");
75 debug("1.11 Node starts before range start and ends after range end");
76 range.selectNode(document.getElementById("b2"));
77 intersects = range.intersectsNode(document.getElementById("a2"));
78 shouldBeTrue("intersects");
79 debug("");
81 debug("1.12 Node starts before range start and range begins and ends on 1");
82 range.setEnd(document.getElementById("c2"), 1);
83 range.setStart(document.getElementById("c2"), 1);
84 intersects = range.intersectsNode(document.getElementById("c2"));
85 shouldBeTrue("intersects");
86 debug("");
88 debug("1.13 Range starts at 0 and ends at 1");
89 range.setStart(document.getElementById("b2"), 0);
90 range.setEnd(document.getElementById("b2"), 1);
91 intersects = range.intersectsNode(document.getElementById("b2"));
92 shouldBeTrue("intersects");
93 debug("");
95 debug("2.1 Detached Range, attached node");
96 var detachedRange = document.createRange();
97 detachedRange.detach(); // No-op.
98 shouldBeFalse("detachedRange.intersectsNode(document.getElementById('a1'))");
99 debug("");
101 debug("2.2 attached range, detached node");
102 // firefox does not throw an exception but returns 0
103 range.selectNode(document.getElementById("a1"));
104 var node = document.getElementById("b1");
105 node.parentNode.removeChild(node);
106 intersects = range.intersectsNode(node);
107 shouldBeFalse("intersects");
108 debug("");
110 debug("2.3 Node has no parent");
111 range.selectNode(document.getElementById("a2"));
112 shouldThrow("range.intersectsNode(document)");
113 debug("");
115 debug("2.4 Range has no parent");
116 shouldThrow("range.selectNode(document)", '"InvalidNodeTypeError: Failed to execute \'selectNode\' on \'Range\': the given Node has no parent."');
117 debug("");
119 debug("2.5 Wrong documents");
120 // firefox does not throw an exception here instead it returns 0
121 var src1 = "<html>\n<head>\n<body>\n<div id=f1>f1</div>\n</body>\n</head>\n<html>";
122 window.frames['frame1'].document.open("text/html", "replace");
123 window.frames['frame1'].document.write(src1);
124 window.frames['frame1'].document.close();
126 var src2 = "<html>\n<head>\n<body>\n<div id=f2>f2</div>\n</body>\n</head>\n<html>";
127 window.frames['frame2'].document.open("text/html", "replace");
128 window.frames['frame2'].document.write(src2);
129 window.frames['frame2'].document.close();
131 var framerange = window.frames['frame1'].document.createRange();
132 var F1Div = window.frames['frame1'].document.getElementById("f1");
133 framerange.selectNode(F1Div);
135 intersects =framerange.intersectsNode(window.frames['frame2'].document.getElementById("f2"));
136 shouldBeFalse("intersects");
137 debug("");
139 debug("2.6 Node deleted");
140 range.selectNode(document.getElementById("a2"));
141 var node = null;
142 shouldThrow("range.intersectsNode(node)");
143 debug("");
145 if (window.testRunner)
146 testRunner.dumpAsText();