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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/selection/addRange.js

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

Powered by Google App Engine
This is Rietveld 408576698