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

Side by Side Diff: third_party/WebKit/LayoutTests/imported/wpt/selection/addRange.html

Issue 2630243004: Manually import wpt/editing and wpt/selection/ (Closed)
Patch Set: Add expectation Created 3 years, 11 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 <!doctype html>
2 <title>Selection.addRange() tests</title>
3 <div id=log></div>
4 <meta name="timeout" content="long">
5 <script src=/resources/testharness.js></script>
6 <script src=/resources/testharnessreport.js></script>
7 <script src=common.js></script>
8 <script>
9 "use strict";
10
11 function testAddRange(exception, range, endpoints, qualifier, testName) {
12 test(function() {
13 assert_equals(exception, null, "Test setup must not throw exceptions");
14
15 selection.addRange(range);
16
17 assert_equals(range.startContainer, endpoints[0],
18 "addRange() must not modify the startContainer of the Range it's giv en");
19 assert_equals(range.startOffset, endpoints[1],
20 "addRange() must not modify the startOffset of the Range it's given" );
21 assert_equals(range.endContainer, endpoints[2],
22 "addRange() must not modify the endContainer of the Range it's given ");
23 assert_equals(range.endOffset, endpoints[3],
24 "addRange() must not modify the endOffset of the Range it's given");
25 }, testName + ": " + qualifier + " addRange() must not throw exceptions or m odify the range it's given");
26
27 test(function() {
28 assert_equals(exception, null, "Test setup must not throw exceptions");
29
30 assert_equals(selection.rangeCount, 1, "rangeCount must be 1");
31 }, testName + ": " + qualifier + " addRange() must result in rangeCount bein g 1");
32
33 // From here on out we check selection.getRangeAt(selection.rangeCount - 1)
34 // so as not to double-fail Gecko.
35
36 test(function() {
37 assert_equals(exception, null, "Test setup must not throw exceptions");
38 assert_not_equals(selection.rangeCount, 0, "Cannot proceed with tests if rangeCount is 0");
39
40 var newRange = selection.getRangeAt(selection.rangeCount - 1);
41
42 assert_not_equals(newRange, null,
43 "getRangeAt(rangeCount - 1) must not return null");
44 assert_equals(typeof newRange, "object",
45 "getRangeAt(rangeCount - 1) must return an object");
46
47 assert_equals(newRange.startContainer, range.startContainer,
48 "startContainer of the Selection's last Range must match the added R ange");
49 assert_equals(newRange.startOffset, range.startOffset,
50 "startOffset of the Selection's last Range must match the added Rang e");
51 assert_equals(newRange.endContainer, range.endContainer,
52 "endContainer of the Selection's last Range must match the added Ran ge");
53 assert_equals(newRange.endOffset, range.endOffset,
54 "endOffset of the Selection's last Range must match the added Range" );
55 }, testName + ": " + qualifier + " addRange() must result in the selection's last range having the specified endpoints");
56
57 test(function() {
58 assert_equals(exception, null, "Test setup must not throw exceptions");
59 assert_not_equals(selection.rangeCount, 0, "Cannot proceed with tests if rangeCount is 0");
60
61 assert_equals(selection.getRangeAt(selection.rangeCount - 1), range,
62 "getRangeAt(rangeCount - 1) must return the same object we added");
63 }, testName + ": " + qualifier + " addRange() must result in the selection's last range being the same object we added");
64
65 // Let's not test many different modifications -- one should be enough.
66 test(function() {
67 assert_equals(exception, null, "Test setup must not throw exceptions");
68 assert_not_equals(selection.rangeCount, 0, "Cannot proceed with tests if rangeCount is 0");
69
70 if (range.startContainer == paras[0].firstChild
71 && range.startOffset == 0
72 && range.endContainer == paras[0].firstChild
73 && range.endOffset == 2) {
74 // Just in case . . .
75 range.setStart(paras[0].firstChild, 1);
76 } else {
77 range.setStart(paras[0].firstChild, 0);
78 range.setEnd(paras[0].firstChild, 2);
79 }
80
81 var newRange = selection.getRangeAt(selection.rangeCount - 1);
82
83 assert_equals(newRange.startContainer, range.startContainer,
84 "After mutating the " + qualifier + " added Range, startContainer of the Selection's last Range must match the added Range");
85 assert_equals(newRange.startOffset, range.startOffset,
86 "After mutating the " + qualifier + " added Range, startOffset of th e Selection's last Range must match the added Range");
87 assert_equals(newRange.endContainer, range.endContainer,
88 "After mutating the " + qualifier + " added Range, endContainer of t he Selection's last Range must match the added Range");
89 assert_equals(newRange.endOffset, range.endOffset,
90 "After mutating the " + qualifier + " added Range, endOffset of the Selection's last Range must match the added Range");
91 }, testName + ": modifying the " + qualifier + " added range must modify the Selection's last Range");
92
93 // Now test the other way too.
94 test(function() {
95 assert_equals(exception, null, "Test setup must not throw exceptions");
96 assert_not_equals(selection.rangeCount, 0, "Cannot proceed with tests if rangeCount is 0");
97
98 var newRange = selection.getRangeAt(selection.rangeCount - 1);
99
100 if (newRange.startContainer == paras[0].firstChild
101 && newRange.startOffset == 4
102 && newRange.endContainer == paras[0].firstChild
103 && newRange.endOffset == 6) {
104 newRange.setStart(paras[0].firstChild, 5);
105 } else {
106 newRange.setStart(paras[0].firstChild, 4);
107 newRange.setStart(paras[0].firstChild, 6);
108 }
109
110 assert_equals(newRange.startContainer, range.startContainer,
111 "After " + qualifier + " addRange(), after mutating the Selection's last Range, startContainer of the Selection's last Range must match the added Ra nge");
112 assert_equals(newRange.startOffset, range.startOffset,
113 "After " + qualifier + " addRange(), after mutating the Selection's last Range, startOffset of the Selection's last Range must match the added Range ");
114 assert_equals(newRange.endContainer, range.endContainer,
115 "After " + qualifier + " addRange(), after mutating the Selection's last Range, endContainer of the Selection's last Range must match the added Rang e");
116 assert_equals(newRange.endOffset, range.endOffset,
117 "After " + qualifier + " addRange(), after mutating the Selection's last Range, endOffset of the Selection's last Range must match the added Range") ;
118 }, testName + ": modifying the Selection's last Range must modify the " + qu alifier + " added Range");
119 }
120
121 // Do only n evals, not n^2
122 var testRangesEvaled = testRanges.map(eval);
123
124 for (var i = 0; i < testRanges.length; i++) {
125 for (var j = 0; j < testRanges.length; j++) {
126 var testName = "Range " + i + " " + testRanges[i]
127 + " followed by Range " + j + " " + testRanges[j];
128
129 var exception = null;
130 try {
131 selection.removeAllRanges();
132
133 var endpoints1 = testRangesEvaled[i];
134 var range1 = ownerDocument(endpoints1[0]).createRange();
135 range1.setStart(endpoints1[0], endpoints1[1]);
136 range1.setEnd(endpoints1[2], endpoints1[3]);
137
138 if (range1.startContainer !== endpoints1[0]) {
139 throw "Sanity check: the first Range we created must have the de sired startContainer";
140 }
141 if (range1.startOffset !== endpoints1[1]) {
142 throw "Sanity check: the first Range we created must have the de sired startOffset";
143 }
144 if (range1.endContainer !== endpoints1[2]) {
145 throw "Sanity check: the first Range we created must have the de sired endContainer";
146 }
147 if (range1.endOffset !== endpoints1[3]) {
148 throw "Sanity check: the first Range we created must have the de sired endOffset";
149 }
150
151 var endpoints2 = testRangesEvaled[j];
152 var range2 = ownerDocument(endpoints2[0]).createRange();
153 range2.setStart(endpoints2[0], endpoints2[1]);
154 range2.setEnd(endpoints2[2], endpoints2[3]);
155
156 if (range2.startContainer !== endpoints2[0]) {
157 throw "Sanity check: the second Range we created must have the d esired startContainer";
158 }
159 if (range2.startOffset !== endpoints2[1]) {
160 throw "Sanity check: the second Range we created must have the d esired startOffset";
161 }
162 if (range2.endContainer !== endpoints2[2]) {
163 throw "Sanity check: the second Range we created must have the d esired endContainer";
164 }
165 if (range2.endOffset !== endpoints2[3]) {
166 throw "Sanity check: the second Range we created must have the d esired endOffset";
167 }
168 } catch (e) {
169 exception = e;
170 }
171
172 testAddRange(exception, range1, endpoints1, "first", testName);
173 testAddRange(exception, range2, endpoints2, "second", testName);
174 }
175 }
176
177 testDiv.style.display = "none";
178 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698