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

Side by Side Diff: third_party/WebKit/LayoutTests/fast/dom/Range/mutation.html

Issue 2667393002: Stop using script-tests in fast/dom/. (Closed)
Patch Set: . Created 3 years, 10 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
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html> 2 <html>
3 <head> 3 <head>
4 <script src="../../../resources/js-test.js"></script> 4 <script src="../../../resources/js-test.js"></script>
5 </head> 5 </head>
6 <body> 6 <body>
7 <script src="script-tests/mutation.js"></script> 7 <script>
8 description(
9 "This test checks mutation of the DOM and how it affects Ranges."
10 );
11
12 var a;
13 var b;
14 var c;
15 var d;
16 var e;
17 var paragraph;
18 var section;
19 var text;
20 var text1;
21 var text2;
22 var text3;
23
24 function name(node)
25 {
26 if (node == a)
27 return "a";
28 if (node == b)
29 return "b";
30 if (node == c)
31 return "c";
32 if (node == d)
33 return "d";
34 if (node == e)
35 return "e";
36 if (node == paragraph)
37 return "paragraph";
38 if (node == section)
39 return "section";
40 if (node == text)
41 return "text";
42 if (node == text1)
43 return "text1";
44 if (node == text2)
45 return "text2";
46 if (node == text3)
47 return "text3";
48 return "???";
49 }
50
51 function description(range)
52 {
53 return name(range.startContainer) + "," + range.startOffset + " -> " + name( range.endContainer) + "," + range.endOffset + ": " + range.toString();
54 }
55
56 function makeRange(sc, so, ec, eo)
57 {
58 var newRange = document.createRange();
59 newRange.setStart(sc, so);
60 newRange.setEnd(ec, eo);
61 return newRange;
62 }
63
64 function setUp1()
65 {
66 paragraph = document.createElement("p");
67 text = document.createTextNode("Abcd efgh XY blah ijkl");
68 paragraph.appendChild(text);
69 range = makeRange(text, 11, text, 19);
70 }
71
72 function createTestElement(name)
73 {
74 var element = document.createElement("em");
75 var text = document.createTextNode(name);
76 element.appendChild(text);
77 return element;
78 }
79
80 function setUp2()
81 {
82 paragraph = document.createElement("p");
83 a = createTestElement("a");
84 b = createTestElement("b");
85 c = createTestElement("c");
86 d = createTestElement("d");
87 e = createTestElement("e");
88
89 paragraph.appendChild(a);
90 paragraph.appendChild(b);
91 paragraph.appendChild(c);
92 paragraph.appendChild(d);
93 range = makeRange(paragraph, 1, paragraph, 3);
94 }
95
96 function setUp3()
97 {
98 paragraph = document.createElement("p");
99 a = document.createTextNode("ax");
100 b = document.createTextNode("by");
101
102 paragraph.appendChild(a);
103 paragraph.appendChild(b);
104
105 range = makeRange(a, 1, b, 1);
106 }
107
108 function setUp4()
109 {
110 paragraph = document.createElement("p");
111 a = document.createTextNode("abcd");
112
113 paragraph.appendChild(a);
114
115 range = makeRange(a, 1, a, 3);
116 }
117
118 function setUp5()
119 {
120 section = document.createElement("div");
121 paragraph = document.createElement("p");
122 a = document.createTextNode("abcde");
123
124 section.appendChild(paragraph);
125 paragraph.appendChild(a);
126
127 range = makeRange(a, 2, section, 1);
128 }
129
130 // First, tests from the DOM Level 2 specification.
131
132 // DOM Level 2 Traversal Range, 2.12.1. Insertions, example 1.
133 setUp1();
134 text.insertData(10, "inserted text");
135 shouldBe('description(range)', '"text,24 -> text,32: Y blah i"');
136
137 // DOM Level 2 Traversal Range, 2.12.1. Insertions, example 2.
138 // Firefox does not match the DOM Level 2 specification on this one.
139 setUp1();
140 text.insertData(11, "inserted text");
141 shouldBe('description(range)', '"text,11 -> text,32: inserted textY blah i"');
142
143 // DOM Level 2 Traversal Range, 2.12.1. Insertions, example 3.
144 setUp1();
145 text.insertData(12, "inserted text");
146 shouldBe('description(range)', '"text,11 -> text,32: Yinserted text blah i"');
147
148 // DOM Level 2 Traversal Range, 2.12.1. Insertions, example 4.
149 setUp1();
150 text.insertData(17, "inserted text");
151 shouldBe('description(range)', '"text,11 -> text,32: Y blahinserted text i"');
152
153 // Similar test at the range end.
154 setUp1();
155 text.insertData(18, "inserted text");
156 shouldBe('description(range)', '"text,11 -> text,32: Y blah inserted texti"');
157
158 // Similar test at the range end.
159 setUp1();
160 text.insertData(19, "inserted text");
161 shouldBe('description(range)', '"text,11 -> text,19: Y blah i"');
162
163 // DOM Level 2 Traversal Range, 2.12.2. Deletions, example 1.
164 paragraph = document.createElement("p");
165 text = document.createTextNode("Abcd efgh The Range ijkl");
166 paragraph.appendChild(text);
167 range = makeRange(text, 11, text, 21);
168 text.deleteData(5, 8);
169 shouldBe('description(range)', '"text,5 -> text,13: Range i"');
170
171 // DOM Level 2 Traversal Range, 2.12.2. Deletions, example 2.
172 paragraph = document.createElement("p");
173 text = document.createTextNode("Abcd efgh The Range ijkl");
174 paragraph.appendChild(text);
175 range = makeRange(text, 11, text, 21);
176 text.deleteData(5, 17);
177 shouldBe('description(range)', '"text,5 -> text,5: "');
178
179 // DOM Level 2 Traversal Range, 2.12.2. Deletions, example 3.
180 // Firefox does not match the DOM Level 2 specification on this one.
181 // Or maybe I wrote the test wrong?
182 paragraph = document.createElement("p");
183 text1 = document.createTextNode("ABCD efgh The ");
184 paragraph.appendChild(text1);
185 em = document.createElement("em");
186 paragraph.appendChild(em);
187 text2 = document.createTextNode("Range");
188 em.appendChild(text2);
189 text3 = document.createTextNode(" ijkl");
190 paragraph.appendChild(text3);
191 range = makeRange(text1, 11, text2, 5);
192 makeRange(text1, 5, text2, 1).deleteContents();
193 shouldBe('description(range)', '"text1,5 -> text2,4: ange"');
194
195 // DOM Level 2 Traversal Range, 2.12.2. Deletions, example 4.
196 paragraph = document.createElement("p");
197 text = document.createTextNode("Abcd efgh The Range ijkl");
198 paragraph.appendChild(text);
199 range = makeRange(text, 11, text, 21);
200 text.deleteData(5, 6);
201 shouldBe('description(range)', '"text,5 -> text,15: he Range i"');
202
203 // DOM Level 2 Traversal Range, 2.12.2. Deletions, example 5.
204 paragraph = document.createElement("p");
205 text1 = document.createTextNode("Abcd ");
206 paragraph.appendChild(text1);
207 em = document.createElement("em");
208 paragraph.appendChild(em);
209 text2 = document.createTextNode("efgh The Range ij");
210 em.appendChild(text2);
211 text3 = document.createTextNode("kl");
212 paragraph.appendChild(text3);
213 range = makeRange(text2, 6, text2, 16);
214 makeRange(paragraph, 1, paragraph, 2).deleteContents();
215 shouldBe('paragraph.childNodes.length', '2');
216 shouldBe('text1.length', '5');
217 shouldBe('description(range)', '"paragraph,1 -> paragraph,1: "');
218 paragraph.normalize();
219 shouldBe('paragraph.childNodes.length', '1');
220 shouldBe('text1.length', '7');
221 shouldBe('description(range)', '"text1,5 -> text1,5: "');
222
223 // Inserting a node in the start container, before the range start offset.
224 setUp2();
225 paragraph.insertBefore(e, a);
226 shouldBe('description(range)', '"paragraph,2 -> paragraph,4: bc"');
227
228 // Inserting a node in the start container, at the range start offset.
229 setUp2();
230 paragraph.insertBefore(e, b);
231 shouldBe('description(range)', '"paragraph,1 -> paragraph,4: ebc"');
232
233 // Inserting a node in the start container, between start and end.
234 setUp2();
235 paragraph.insertBefore(e, c);
236 shouldBe('description(range)', '"paragraph,1 -> paragraph,4: bec"');
237
238 // Inserting a node in the end container, at the range end offset.
239 setUp2();
240 paragraph.insertBefore(e, d);
241 shouldBe('description(range)', '"paragraph,1 -> paragraph,3: bc"');
242
243 // Inserting a node in the end container, after the range end offset.
244 setUp2();
245 paragraph.appendChild(e);
246 shouldBe('description(range)', '"paragraph,1 -> paragraph,3: bc"');
247
248 // Removing the start container of a range.
249 setUp2();
250 range = makeRange(b, 0, d, 1);
251 paragraph.removeChild(b);
252 shouldBe('description(range)', '"paragraph,1 -> d,1: cd"');
253 setUp2();
254 range = makeRange(b, 1, d, 0);
255 paragraph.removeChild(b);
256 shouldBe('description(range)', '"paragraph,1 -> d,0: c"');
257
258 // Removing the end container of a range.
259 setUp2();
260 range = makeRange(b, 0, d, 1);
261 paragraph.removeChild(d);
262 shouldBe('description(range)', '"b,0 -> paragraph,3: bc"');
263 setUp2();
264 range = makeRange(b, 1, d, 0);
265 paragraph.removeChild(d);
266 shouldBe('description(range)', '"b,1 -> paragraph,3: c"');
267
268 // Calling normalize with a range that has an endpoint in a text node that gets merged into another.
269 // Firefox does not do what the DOM Level 2 specification seems to call for on t his one.
270 setUp3();
271 paragraph.normalize();
272 shouldBe('description(range)', '"a,1 -> a,3: xb"');
273
274 // Calling splitText when a range has an endpoint on in the piece that gets made into a new text node.
275 // Firefox does not do what the DOM Level 2 specification seems to call for on t his one.
276 setUp4();
277 b = a.splitText(1);
278 shouldBe('description(range)', '"a,1 -> b,2: bc"');
279 setUp4();
280 b = a.splitText(2);
281 shouldBe('description(range)', '"a,1 -> b,1: bc"');
282 setUp4();
283 b = a.splitText(3);
284 shouldBe('description(range)', '"a,1 -> a,3: bc"');
285
286 // Range test in Acid3.
287 setUp5();
288 shouldBe('description(range)', '"a,2 -> section,1: cde"');
289 section.removeChild(paragraph);
290 shouldBe('description(range)', '"section,0 -> section,0: "');
291
292 // Children in a range being removed, but by DOM mutation (not CharacterData mut ation).
293 // Test CharacterData.replaceData cases?
294 // Test Element.innerHTML cases (setting it)?
295 // Test Element.innerText cases (setting it)?
296 // Test Element.outerHTML cases (setting it)?
297 // Test Element.outerText cases (setting it)?
298 // Test Node.replaceChild cases?
299 // Test cases where Node.insertBefore/appendChild has a side effect of deleting the node from a range.
300 // Test Range.deleteContents cases?
301 // Test Range.extractContents cases?
302 // Test Range.surroundContents cases?
303 // Test Text.replaceWholeText cases?
304 </script>
8 </body> 305 </body>
9 </html> 306 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698