Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: LayoutTests/fast/dom/Range/range-compareNode.html

Issue 1149373003: Remove Range.compareNode() as it is not in the spec (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: updated webexposed/global-interface-listing.html Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <html>
2 <head>
3 <title>Test for Range.compareNode()</title>
4 <script>
5 function test()
6 {
7 // This method returns one of the following constants:
8 // Node starts before the Range ( NODE_BEFORE = 0 )
9 // Node starts after the Range ( NODE_AFTER = 1 )
10 // Node starts before and ends after the Range ( NODE_BEFORE_AND_AFTER = 2 )
11 // Node starts after and ends before the Range, i.e. the Node is completely
12 // selected by the Range. ( NODE_INSIDE = 3 )
13
14 var range = document.createRange();
15
16 // test 1 - start before range, end before range
17 expectedResult = 0;
18 range.selectNode(document.getElementById("a2"));
19 result = range.compareNode(document.getElementById("b1"));
20 if (result == expectedResult)
21 document.getElementById("test1").innerHTML = "test 1 passed: start befor e range, end before range";
22
23 // test 2 - start before range, end on 1
24 expectedResult = 0;
25 range.setStart(document.getElementById("b2"), 1);
26 range.setEnd(document.getElementById("c2"), 1);
27 result = range.compareNode(document.getElementById("b2"));
28 if (result == expectedResult)
29 document.getElementById("test2").innerHTML = "test 2 passed: start befor e range, end on range start";
30
31 // test 3 - start before range, end in range
32 expectedResult = 0;
33 range.setStart(document.getElementById("b2"), 0);
34 range.setEnd(document.getElementById("c3"), 0);
35 result = range.compareNode(document.getElementById("a2"));
36 if (result == expectedResult)
37 document.getElementById("test3").innerHTML = "test 3 passed: start befor e range, end in range";
38
39 // test 4 - start on 0, end in range
40 expectedResult = 0;
41 range.setStart(document.getElementById("b2"), 0);
42 range.setEnd(document.getElementById("c2"),1);
43 result = range.compareNode(document.getElementById("b2"));
44 if (result == expectedResult)
45 document.getElementById("test4").innerHTML = "test 4 passed: start on ra nge start, end in range";
46
47 // test 5 - start in range, end in range
48 expectedResult = 3;
49 range.selectNode(document.getElementById("a2"));
50 result = range.compareNode(document.getElementById("b2"));
51 if (result == expectedResult)
52 document.getElementById("test5").innerHTML = "test 5 passed: start in ra nge, end in range";
53
54 // test 6 - start in range, end on 1
55 expectedResult = 1;
56 range.setStart(document.getElementById("b1"), 1);
57 range.setEnd(document.getElementById("c2"), 1);
58 result = range.compareNode( document.getElementById("c2"));
59 if (result == expectedResult)
60 document.getElementById("test6").innerHTML = "test 6 passed: start in ra nge, end on range end";
61
62 // test 7 - start in range, end after range end
63 expectedResult = 1;
64 range.setStart(document.getElementById("b1"), 1);
65 range.setEnd(document.getElementById("c2"), 0);
66 result = range.compareNode( document.getElementById("c2"));
67 if (result == expectedResult)
68 document.getElementById("test7").innerHTML = "test 7 passed: start in ra nge, end after range end";
69
70 // test 8 - start on 1, end after range
71 expectedResult = 1;
72 range.setStart(document.getElementById("b2"), 1);
73 range.setEnd(document.getElementById("c2"), 0);
74 result = range.compareNode( document.getElementById("c2"));
75 if (result == expectedResult)
76 document.getElementById("test8").innerHTML = "test 8 passed: start on ra nge end, end after range";
77
78 // test 9 - start on range start, end on range end
79 expectedResult = 3;
80 range.selectNode(document.getElementById("a2"));
81 result = range.compareNode(document.getElementById("a2"));
82 if (result == expectedResult)
83 document.getElementById("test9").innerHTML = "test 9 passed: start on ra nge start, end on range end";
84
85 // test 10 - start after range, end after range
86 expectedResult = 1;
87 range.selectNode(document.getElementById("b2"));
88 result = range.compareNode(document.getElementById("c3"));
89 if (result == expectedResult)
90 document.getElementById("test10").innerHTML = "test 10 passed: start aft er range, end after range";
91
92 // test 11 - start before range, end after range
93 expectedResult = 2;
94 range.selectNode(document.getElementById("b2"));
95 result = range.compareNode(document.getElementById("a2"));
96 if (result == expectedResult)
97 document.getElementById("test11").innerHTML = "test 11 passed: start bef ore range, end after range";
98
99 // test 12 - start before range, end 1
100 expectedResult = 2;
101 range.setEnd(document.getElementById("c2"), 1);
102 range.setStart(document.getElementById("c2"), 1);
103 result = range.compareNode(document.getElementById("c2"));
104 if (result == expectedResult)
105 document.getElementById("test12").innerHTML = "test 12 passed: start bef ore range, end at range end";
106
107 // test 13 - start at 0, end after range
108 expectedResult = 2;
109 range.setStart(document.getElementById("b2"), 0);
110 range.setEnd(document.getElementById("b2"), 1);
111 result = range.compareNode(document.getElementById("b2"));
112 if (result == expectedResult)
113 document.getElementById("test13").innerHTML = "test 13 passed: start at range start, end after range";
114
115 // test 14 - detached range, attached node
116 expectedResult = 1;
117 var detachedRange = document.createRange();
118 detachedRange.detach(); // no-op.
119 result = detachedRange.compareNode(document.getElementById("a1"));
120 if (result == expectedResult)
121 document.getElementById("test14").innerHTML = "test 14 passed: detached range, attached node";
122
123 // test 15 - attached range, detached node
124 // firefox does not throw an exception and returns 0 for this test
125 expectedResult = 0;
126 range.selectNode(document.getElementById("a1"));
127 var node = document.getElementById("b1");
128 node.parentNode.removeChild(node);
129 result = range.compareNode(node);
130 if (result == expectedResult)
131 document.getElementById("test15").innerHTML = "test 15 passed: attached range, detached node";
132
133 // test 16 - node has no parent
134 range.selectNode(document.getElementById("a2"));
135 try {
136 result = range.compareNode(document);
137 } catch (e) {
138 if(e.code == DOMException.NOT_FOUND_ERR) {
139 document.getElementById("test16").innerHTML = "test 16 passed: the n ode has no parent";
140 } else {
141 document.getElementById("test16").innerHTML = "<span style=\"color: red;\">test 16 failed error: " + e.message + "</span>";
142 }
143 }
144
145 // test 17 - range has no parent
146 try {
147 range.selectNode(document);
148 } catch (e) {
149 if(e.code == DOMException.INVALID_NODE_TYPE_ERR) {
150 document.getElementById("test17").innerHTML = "test 17 passed: the r ange has no parent";
151 } else {
152 document.getElementById("test17").innerHTML = "<span style=\"color: red;\">test 17 failed error: " + e.message + "\n Code: " + e.code +"</span>";
153 }
154 }
155
156 // test 18 - wrong documents
157 // firefox does not throw an exception here instead it returns 0
158 exptectedResult = 0;
159 var src1 = "<html>\n<head>\n<body>\n<div id=f1>f1</div>\n</body>\n</head>\n< html>";
160 window.frames['frame1'].document.open("text/html", "replace");
161 window.frames['frame1'].document.write(src1);
162 window.frames['frame1'].document.close();
163
164 var src2 = "<html>\n<head>\n<body>\n<div id=f2>f2</div>\n</body>\n</head>\n< html>";
165 window.frames['frame2'].document.open("text/html", "replace");
166 window.frames['frame2'].document.write(src2);
167 window.frames['frame2'].document.close();
168
169 var framerange = window.frames['frame1'].document.createRange();
170 var F1Div = window.frames['frame1'].document.getElementById("f1");
171 framerange.selectNode(F1Div);
172
173 result = framerange.compareNode(window.frames['frame2'].document.getElementB yId("f2"));
174 if (result == expectedResult)
175 document.getElementById("test18").innerHTML = "test 18 passed: wrong doc uments";
176
177
178 // test 19 - node deleted
179 range.selectNode(document.getElementById("a2"));
180 var node = null;
181 try {
182 result = range.compareNode(node);
183 } catch (e) {
184 if(e.name == "TypeError") {
185 document.getElementById("test19").innerHTML = "test 19 passed: delet ed node";
186 } else {
187 document.getElementById("test19").innerHTML = "<span style=\"color: red;\">test 19 failed error: " + e.message + "</span>";
188 }
189 }
190
191 if (window.testRunner)
192 testRunner.dumpAsText();
193 }
194
195 </script>
196 </head>
197 <body onload="test();">
198
199 <!-- visible area with test results -->
200 <div id=test1><span style="color: red;">test 1 failed</span></div>
201 <div id=test2><span style="color: red;">test 2 failed</span></div>
202 <div id=test3><span style="color: red;">test 3 failed</span></div>
203 <div id=test4><span style="color: red;">test 4 failed</span></div>
204 <div id=test5><span style="color: red;">test 5 failed</span></div>
205 <div id=test6><span style="color: red;">test 6 failed</span></div>
206 <div id=test7><span style="color: red;">test 7 failed</span></div>
207 <div id=test8><span style="color: red;">test 8 failed</span></div>
208 <div id=test9><span style="color: red;">test 9 failed</span></div>
209 <div id=test10><span style="color: red;">test 10 failed</span></div>
210 <div id=test11><span style="color: red;">test 11 failed</span></div>
211 <div id=test12><span style="color: red;">test 12 failed</span></div>
212 <div id=test13><span style="color: red;">test 13 failed</span></div>
213 <div id=test14><span style="color: red;">test 14 failed</span></div>
214 <div id=test15><span style="color: red;">test 15 failed</span></div>
215 <div id=test16><span style="color: red;">test 16 failed</span></div>
216 <div id=test17><span style="color: red;">test 17 failed</span></div>
217 <div id=test18><span style="color: red;">test 18 failed</span></div>
218 <div id=test19><span style="color: red;">test 19 failed</span></div>
219 <!-- hidden area to create the ranges being tested -->
220 <div style="visibility: hidden">
221 <div id=a1>a1
222 <div id=b1>b1</div>
223 <div id=c1>c1</div>
224 </div>
225
226 <div id=a2>a2
227 <div id=b2>b2</div>
228 <div id=c2>c2</div>
229 </div>
230 <div id=a3>a3
231 <div id=b3>b3</div>
232 <div id=c3>c3</div>
233 </div>
234
235 <iframe name="frame1" style="border: 1px solid black;"></iframe>
236 <iframe name="frame2" style="border: 1px solid black;"></iframe>
237 </div>
238
239 </body>
240 </html>
OLDNEW
« no previous file with comments | « LayoutTests/fast/dom/Range/invalid-arguments-expected.txt ('k') | LayoutTests/fast/dom/Range/range-compareNode-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698