gecko-dev/testing/web-platform/tests/selection/extend.js
James Graham f115b4f38d Bug 1345490 - Update web-platform-tests to revision 7c7db1b516b01394e19fad80094fbb81ab02ce75, a=testonly
MozReview-Commit-ID: 4wsHtf9312c


--HG--
rename : testing/web-platform/tests/html/browsers/windows/support-window-name-echo.html => testing/web-platform/tests/html/browsers/windows/resources/echo-window-name.html
rename : testing/web-platform/tests/html/browsers/windows/support-nested-browsing-contexts.html => testing/web-platform/tests/html/browsers/windows/resources/nested-post-to-opener.html
rename : testing/web-platform/tests/html/browsers/windows/support-named-null-opener.html => testing/web-platform/tests/html/browsers/windows/resources/noreferrer-window-name.html
rename : testing/web-platform/tests/html/browsers/windows/support-post-to-opener.html => testing/web-platform/tests/html/browsers/windows/resources/post-to-opener.html
rename : testing/web-platform/tests/html/browsers/windows/support-close.html => testing/web-platform/tests/html/browsers/windows/resources/window-close-button.html
rename : testing/web-platform/tests/html/browsers/windows/support-opener-null.html => testing/web-platform/tests/html/browsers/windows/resources/window-opener.html
rename : testing/web-platform/tests/mediacapture-streams/MediaStreamTrack-end.https.html => testing/web-platform/tests/mediacapture-streams/MediaStreamTrack-end-manual.https.html
rename : testing/web-platform/tests/notifications/shownotification-resolve-manual.html => testing/web-platform/tests/notifications/shownotification-resolve-manual.https.html
rename : testing/web-platform/tests/service-workers/service-worker/fetch-event-within-sw-manual.html => testing/web-platform/tests/service-workers/service-worker/fetch-event-within-sw-manual.https.html
rename : testing/web-platform/tests/service-workers/service-worker/fetch-event-within-sw.html => testing/web-platform/tests/service-workers/service-worker/fetch-event-within-sw.https.html
rename : testing/web-platform/tests/webvtt/webvtt-file-format-parsing/webvtt-cue-text-parsing-rules/buildtests.py => testing/web-platform/tests/webvtt/parsing/cue-text-parsing/buildtests.py
rename : testing/web-platform/tests/webvtt/webvtt-file-format-parsing/webvtt-cue-text-parsing-rules/common.js => testing/web-platform/tests/webvtt/parsing/cue-text-parsing/common.js
rename : testing/web-platform/tests/webvtt/webvtt-file-format-parsing/webvtt-cue-text-parsing-rules/dat/entities.dat => testing/web-platform/tests/webvtt/parsing/cue-text-parsing/dat/entities.dat
rename : testing/web-platform/tests/webvtt/webvtt-file-format-parsing/webvtt-cue-text-parsing-rules/dat/tags.dat => testing/web-platform/tests/webvtt/parsing/cue-text-parsing/dat/tags.dat
rename : testing/web-platform/tests/webvtt/webvtt-file-format-parsing/webvtt-cue-text-parsing-rules/dat/timestamps.dat => testing/web-platform/tests/webvtt/parsing/cue-text-parsing/dat/timestamps.dat
rename : testing/web-platform/tests/webvtt/webvtt-file-format-parsing/webvtt-cue-text-parsing-rules/dat/tree-building.dat => testing/web-platform/tests/webvtt/parsing/cue-text-parsing/dat/tree-building.dat
rename : testing/web-platform/tests/webvtt/webvtt-file-format-parsing/webvtt-cue-text-parsing-rules/tests/entities.html => testing/web-platform/tests/webvtt/parsing/cue-text-parsing/tests/entities.html
rename : testing/web-platform/tests/webvtt/webvtt-file-format-parsing/webvtt-cue-text-parsing-rules/tests/tags.html => testing/web-platform/tests/webvtt/parsing/cue-text-parsing/tests/tags.html
rename : testing/web-platform/tests/webvtt/webvtt-file-format-parsing/webvtt-cue-text-parsing-rules/tests/timestamps.html => testing/web-platform/tests/webvtt/parsing/cue-text-parsing/tests/timestamps.html
rename : testing/web-platform/tests/webvtt/webvtt-file-format-parsing/webvtt-cue-text-parsing-rules/tests/tree-building.html => testing/web-platform/tests/webvtt/parsing/cue-text-parsing/tests/tree-building.html
rename : testing/web-platform/tests/webvtt/webvtt-file-format-parsing/webvtt-file-parsing/support/signature-formfeed.vtt => testing/web-platform/tests/webvtt/parsing/file-parsing/support/signature-formfeed.vtt
rename : testing/web-platform/tests/webvtt/webvtt-file-format-parsing/webvtt-file-parsing/support/signature-lowercase.vtt => testing/web-platform/tests/webvtt/parsing/file-parsing/support/signature-lowercase.vtt
rename : testing/web-platform/tests/webvtt/webvtt-file-format-parsing/webvtt-file-parsing/support/signature-null.vtt => testing/web-platform/tests/webvtt/parsing/file-parsing/support/signature-null.vtt
rename : testing/web-platform/tests/webvtt/webvtt-file-format-parsing/webvtt-file-parsing/support/signature-too-short.vtt => testing/web-platform/tests/webvtt/parsing/file-parsing/support/signature-partial.vtt
rename : testing/web-platform/tests/webvtt/webvtt-file-format-parsing/webvtt-file-parsing/support/signature-two-boms.vtt => testing/web-platform/tests/webvtt/parsing/file-parsing/support/signature-two-boms.vtt
rename : testing/web-platform/tests/webvtt/webvtt-file-format-parsing/webvtt-file-parsing/support/signature-websrt.vtt => testing/web-platform/tests/webvtt/parsing/file-parsing/support/signature-websrt.vtt
rename : testing/web-platform/tests/webvtt/webvtt-file-format-parsing/webvtt-file-parsing/support/signature-bom.vtt => testing/web-platform/tests/webvtt/parsing/file-parsing/tests/support/signature-bom.vtt
rename : testing/web-platform/tests/webvtt/webvtt-file-format-parsing/webvtt-file-parsing/support/signature-no-newline.vtt => testing/web-platform/tests/webvtt/parsing/file-parsing/tests/support/signature-no-newline.vtt
rename : testing/web-platform/tests/webvtt/webvtt-file-format-parsing/webvtt-file-parsing/support/signature-space-no-newline.vtt => testing/web-platform/tests/webvtt/parsing/file-parsing/tests/support/signature-space-no-newline.vtt
rename : testing/web-platform/tests/webvtt/webvtt-file-format-parsing/webvtt-file-parsing/support/signature-space.vtt => testing/web-platform/tests/webvtt/parsing/file-parsing/tests/support/signature-space.vtt
rename : testing/web-platform/tests/webvtt/webvtt-file-format-parsing/webvtt-file-parsing/support/signature-tab-no-newline.vtt => testing/web-platform/tests/webvtt/parsing/file-parsing/tests/support/signature-tab-no-newline.vtt
rename : testing/web-platform/tests/webvtt/webvtt-file-format-parsing/webvtt-file-parsing/support/signature-tab.vtt => testing/web-platform/tests/webvtt/parsing/file-parsing/tests/support/signature-tab.vtt
2017-03-17 14:34:25 +00:00

161 lines
7.1 KiB
JavaScript

"use strict";
// Also test a selection with no ranges
testRanges.unshift("[]");
// Run a subset of all of extend tests.
// Huge number of tests in a single file causes problems. Each of
// extend-NN.html runs a part of them.
//
// startIndex - Start index in testRanges array
// optionalEndIndex - End index in testRanges array + 1. If this argument is
// omitted, testRanges.length is applied.
function testExtendSubSet(startIndex, optionalEndIndex) {
var endIndex = optionalEndIndex === undefined ? testRanges.length : optionalEndIndex;
if (startIndex < 0 || startIndex >= testRanges.length)
throw "Sanity check: Specified index is invalid.";
if (endIndex < 0 || endIndex > testRanges.length)
throw "Sanity check: Specified index is invalid.";
// We test Selections that go both forwards and backwards here. In the
// latter case we need to use extend() to force it to go backwards, which is
// fair enough, since that's what we're testing. We test collapsed
// selections only once.
for (var i = startIndex; i < endIndex; i++) {
var endpoints = eval(testRanges[i]);
// We can't test extend() with unselectable endpoints.
if (!isSelectableNode(endpoints[0]) || !isSelectableNode(endpoints[2]))
continue;
for (var j = 0; j < testPoints.length; j++) {
if (endpoints[0] == endpoints[2]
&& endpoints[1] == endpoints[3]) {
// Test collapsed selections only once
test(function() {
setSelectionForwards(endpoints);
testExtend(endpoints, eval(testPoints[j]));
}, "extend() with range " + i + " " + testRanges[i]
+ " and point " + j + " " + testPoints[j]);
} else {
test(function() {
setSelectionForwards(endpoints);
testExtend(endpoints, eval(testPoints[j]));
}, "extend() forwards with range " + i + " " + testRanges[i]
+ " and point " + j + " " + testPoints[j]);
test(function() {
setSelectionBackwards(endpoints);
testExtend(endpoints, eval(testPoints[j]));
}, "extend() backwards with range " + i + " " + testRanges[i]
+ " and point " + j + " " + testPoints[j]);
}
}
}
}
function testExtend(endpoints, target) {
assert_equals(getSelection().rangeCount, endpoints.length/4,
"Sanity check: rangeCount must be correct");
var node = target[0];
var offset = target[1];
// "If node's root is not the document associated with the context object,
// abort these steps."
if (!document.contains(node)) {
assertSelectionNoChange(function() {
selection.extend(node, offset);
});
return;
}
// "If the context object's range is null, throw an InvalidStateError
// exception and abort these steps."
if (getSelection().rangeCount == 0) {
assert_throws("INVALID_STATE_ERR", function() {
selection.extend(node, offset);
}, "extend() when rangeCount is 0 must throw InvalidStateError");
return;
}
assert_equals(getSelection().getRangeAt(0).startContainer, endpoints[0],
"Sanity check: startContainer must be correct");
assert_equals(getSelection().getRangeAt(0).startOffset, endpoints[1],
"Sanity check: startOffset must be correct");
assert_equals(getSelection().getRangeAt(0).endContainer, endpoints[2],
"Sanity check: endContainer must be correct");
assert_equals(getSelection().getRangeAt(0).endOffset, endpoints[3],
"Sanity check: endOffset must be correct");
// "Let anchor and focus be the context object's anchor and focus, and let
// new focus be the boundary point (node, offset)."
var anchorNode = getSelection().anchorNode;
var anchorOffset = getSelection().anchorOffset;
var focusNode = getSelection().focusNode;
var focusOffset = getSelection().focusOffset;
// "Let new range be a new range."
//
// We'll always be setting either new range's start or its end to new
// focus, so we'll always throw at some point. Test that now.
//
// From DOM4's "set the start or end of a range": "If node is a doctype,
// throw an "InvalidNodeTypeError" exception and terminate these steps."
if (node.nodeType == Node.DOCUMENT_TYPE_NODE) {
assert_throws("INVALID_NODE_TYPE_ERR", function() {
selection.extend(node, offset);
}, "extend() to a doctype must throw InvalidNodeTypeError");
return;
}
// From DOM4's "set the start or end of a range": "If offset is greater
// than node's length, throw an "IndexSizeError" exception and terminate
// these steps."
//
// FIXME: We should be casting offset to an unsigned int per WebIDL. Until
// we do, we need the offset < 0 check too.
if (offset < 0 || offset > getNodeLength(node)) {
assert_throws("INDEX_SIZE_ERR", function() {
selection.extend(node, offset);
}, "extend() to an offset that's greater than node length (" + getNodeLength(node) + ") must throw IndexSizeError");
return;
}
// Now back to the editing spec.
var originalRange = getSelection().getRangeAt(0);
// "If node's root is not the same as the context object's range's root,
// set new range's start and end to (node, offset)."
//
// "Otherwise, if anchor is before or equal to new focus, set new range's
// start to anchor, then set its end to new focus."
//
// "Otherwise, set new range's start to new focus, then set its end to
// anchor."
//
// "Set the context object's range to new range."
//
// "If new focus is before anchor, set the context object's direction to
// backwards. Otherwise, set it to forwards."
//
// The upshot of all these is summed up by just testing the anchor and
// offset.
getSelection().extend(node, offset);
if (furthestAncestor(anchorNode) == furthestAncestor(node)) {
assert_equals(getSelection().anchorNode, anchorNode,
"anchorNode must not change if the node passed to extend() has the same root as the original range");
assert_equals(getSelection().anchorOffset, anchorOffset,
"anchorOffset must not change if the node passed to extend() has the same root as the original range");
} else {
assert_equals(getSelection().anchorNode, node,
"anchorNode must be the node passed to extend() if it has a different root from the original range");
assert_equals(getSelection().anchorOffset, offset,
"anchorOffset must be the offset passed to extend() if the node has a different root from the original range");
}
assert_equals(getSelection().focusNode, node,
"focusNode must be the node passed to extend()");
assert_equals(getSelection().focusOffset, offset,
"focusOffset must be the offset passed to extend()");
assert_not_equals(getSelection().getRangeAt(0), originalRange,
"extend() must replace any existing range with a new one, not mutate the existing one");
}