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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/selection/collapse.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 testCollapse(range, point) {
4 selection.removeAllRanges();
5 var addedRange;
6 if (range) {
7 addedRange = range.cloneRange();
8 selection.addRange(addedRange);
9 }
10
11 if (point[0].nodeType == Node.DOCUMENT_TYPE_NODE) {
12 assert_throws("INVALID_NODE_TYPE_ERR", function() {
13 selection.collapse(point[0], point[1]);
14 }, "Must throw INVALID_NODE_TYPE_ERR when collapse()ing if the node is a DocumentType");
15 return;
16 }
17
18 if (point[1] < 0 || point[1] > getNodeLength(point[0])) {
19 assert_throws("INDEX_SIZE_ERR", function() {
20 selection.collapse(point[0], point[1]);
21 }, "Must throw INDEX_SIZE_ERR when collapse()ing if the offset is negati ve or greater than the node's length");
22 return;
23 }
24
25 selection.collapse(point[0], point[1]);
26
27 assert_equals(selection.rangeCount, 1,
28 "selection.rangeCount must equal 1 after collapse()");
29 assert_equals(selection.focusNode, point[0],
30 "focusNode must equal the node we collapse()d to");
31 assert_equals(selection.focusOffset, point[1],
32 "focusOffset must equal the offset we collapse()d to");
33 assert_equals(selection.focusNode, selection.anchorNode,
34 "focusNode and anchorNode must be equal after collapse()");
35 assert_equals(selection.focusOffset, selection.anchorOffset,
36 "focusOffset and anchorOffset must be equal after collapse()");
37 if (range) {
38 assert_equals(addedRange.startContainer, range.startContainer,
39 "collapse() must not change the startContainer of a preexisting Rang e");
40 assert_equals(addedRange.endContainer, range.endContainer,
41 "collapse() must not change the endContainer of a preexisting Range" );
42 assert_equals(addedRange.startOffset, range.startOffset,
43 "collapse() must not change the startOffset of a preexisting Range") ;
44 assert_equals(addedRange.endOffset, range.endOffset,
45 "collapse() must not change the endOffset of a preexisting Range");
46 }
47 }
48
49 // Also test a selection with no ranges
50 testRanges.unshift("[]");
51
52 // Don't want to eval() each point a bazillion times
53 var testPointsCached = [];
54 for (var i = 0; i < testPoints.length; i++) {
55 testPointsCached.push(eval(testPoints[i]));
56 }
57
58 // Run a subset of all of collapse tests.
59 // Huge number of tests in a single file causes problems. Each of
60 // collapse-NN.html runs a part of them.
61 //
62 // startIndex - Start index in testRanges array
63 // optionalEndIndex - End index in testRanges array + 1. If this argument is
64 // omitted, testRanges.length is applied.
65 function testCollapseSubSet(startIndex, optionalEndIndex) {
66 var endIndex = optionalEndIndex === undefined ? testRanges.length : optional EndIndex;
67 if (startIndex < 0 || startIndex >= testRanges.length)
68 throw "Sanity check: Specified index is invalid.";
69 if (endIndex < 0 || endIndex > testRanges.length)
70 throw "Sanity check: Specified index is invalid.";
71
72 var tests = [];
73 for (var i = startIndex; i < endIndex; i++) {
74 var endpoints = eval(testRanges[i]);
75 var range;
76 test(function() {
77 if (endpoints.length) {
78 range = ownerDocument(endpoints[0]).createRange();
79 range.setStart(endpoints[0], endpoints[1]);
80 range.setEnd(endpoints[2], endpoints[3]);
81 } else {
82 // Empty selection
83 range = null;
84 }
85 }, "Set up range " + i + " " + testRanges[i]);
86 for (var j = 0; j < testPoints.length; j++) {
87 tests.push(["Range " + i + " " + testRanges[i] + ", point " + j + " " + testPoints[j], range, testPointsCached[j]]);
88 }
89 }
90
91 generate_tests(testCollapse, tests);
92 }
93
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698