mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-13 20:14:57 -10:00
Automatic update from web-platform-tests
Replace some assert_throws("Something", stuff) calls with assert_throws_dom. (#21377)
This diff was generated by running:
find . -type f -print0 | xargs -0 perl -pi -e 'BEGIN { $/ = undef; } s/assert_throws\(([ \n]*"[A-Za-z_]*") *(, *.)/assert_throws_dom(\1\2/gs'
followed by a fix to
xhr/resources/send-after-setting-document-domain-window-helper.js to make
xhr/send-after-setting-document-domain.htm pass.
This does affect indentation poorly in cases when the first arg was on the same
line as the assert_throws, there was a newline after the ',' after the first
arg, and the following args were lined up with the first arg. Fixing that,
especially when there are multiple lines after the first arg, is not trivial
with a regexp.
Co-authored-by: Boris Zbarsky <[email protected]>
--
wpt-commits: 3696f2233a37437896505b7187968aa605be9255
wpt-pr: 21377
115 lines
5.4 KiB
HTML
115 lines
5.4 KiB
HTML
<!doctype html>
|
|
<title>Selection.collapseTo(Start|End)() tests</title>
|
|
<div id=log></div>
|
|
<script src=/resources/testharness.js></script>
|
|
<script src=/resources/testharnessreport.js></script>
|
|
<script src=common.js></script>
|
|
<script>
|
|
"use strict";
|
|
|
|
test(function() {
|
|
selection.removeAllRanges();
|
|
assert_throws_dom("INVALID_STATE_ERR", function() {
|
|
selection.collapseToStart();
|
|
});
|
|
}, "Must throw InvalidStateErr if the selection's range is null");
|
|
|
|
for (var i = 0; i < testRanges.length; i++) {
|
|
var endpoints = eval(testRanges[i]);
|
|
if (!isSelectableNode(endpoints[0]) || !isSelectableNode(endpoints[2]))
|
|
continue;
|
|
test(function() {
|
|
selection.removeAllRanges();
|
|
|
|
var addedRange = ownerDocument(endpoints[0]).createRange();
|
|
addedRange.setStart(endpoints[0], endpoints[1]);
|
|
addedRange.setEnd(endpoints[2], endpoints[3]);
|
|
selection.addRange(addedRange);
|
|
|
|
// We don't penalize browsers here for mishandling addRange() and
|
|
// adding a different range than we specified. They fail addRange()
|
|
// tests for that, and don't have to fail collapseToStart/End() tests
|
|
// too. They do fail if they throw unexpectedly, though. I also fail
|
|
// them if there's no range at all, because otherwise they could pass
|
|
// all tests if addRange() always does nothing and collapseToStart()
|
|
// always throws.
|
|
assert_equals(selection.rangeCount, 1,
|
|
"Sanity check: rangeCount must equal 1 after addRange()");
|
|
|
|
var expectedEndpoint = [
|
|
selection.getRangeAt(0).startContainer,
|
|
selection.getRangeAt(0).startOffset
|
|
];
|
|
|
|
selection.collapseToStart();
|
|
|
|
assert_equals(selection.rangeCount, 1,
|
|
"selection.rangeCount must equal 1");
|
|
assert_equals(selection.focusNode, expectedEndpoint[0],
|
|
"focusNode must equal the original start node");
|
|
assert_equals(selection.focusOffset, expectedEndpoint[1],
|
|
"focusOffset must equal the original start offset");
|
|
assert_equals(selection.anchorNode, expectedEndpoint[0],
|
|
"anchorNode must equal the original start node");
|
|
assert_equals(selection.anchorOffset, expectedEndpoint[1],
|
|
"anchorOffset must equal the original start offset");
|
|
assert_equals(addedRange.startContainer, endpoints[0],
|
|
"collapseToStart() must not change the startContainer of the selection's original range");
|
|
assert_equals(addedRange.startOffset, endpoints[1],
|
|
"collapseToStart() must not change the startOffset of the selection's original range");
|
|
assert_equals(addedRange.endContainer, endpoints[2],
|
|
"collapseToStart() must not change the endContainer of the selection's original range");
|
|
assert_equals(addedRange.endOffset, endpoints[3],
|
|
"collapseToStart() must not change the endOffset of the selection's original range");
|
|
}, "Range " + i + " " + testRanges[i] + " collapseToStart()");
|
|
|
|
// Copy-paste of above
|
|
test(function() {
|
|
selection.removeAllRanges();
|
|
|
|
var addedRange = ownerDocument(endpoints[0]).createRange();
|
|
addedRange.setStart(endpoints[0], endpoints[1]);
|
|
addedRange.setEnd(endpoints[2], endpoints[3]);
|
|
selection.addRange(addedRange);
|
|
|
|
// We don't penalize browsers here for mishandling addRange() and
|
|
// adding a different range than we specified. They fail addRange()
|
|
// tests for that, and don't have to fail collapseToStart/End() tests
|
|
// too. They do fail if they throw unexpectedly, though. I also fail
|
|
// them if there's no range at all, because otherwise they could pass
|
|
// all tests if addRange() always does nothing and collapseToStart()
|
|
// always throws.
|
|
assert_equals(selection.rangeCount, 1,
|
|
"Sanity check: rangeCount must equal 1 after addRange()");
|
|
|
|
var expectedEndpoint = [
|
|
selection.getRangeAt(0).endContainer,
|
|
selection.getRangeAt(0).endOffset
|
|
];
|
|
|
|
selection.collapseToEnd();
|
|
|
|
assert_equals(selection.rangeCount, 1,
|
|
"selection.rangeCount must equal 1");
|
|
assert_equals(selection.focusNode, expectedEndpoint[0],
|
|
"focusNode must equal the original end node");
|
|
assert_equals(selection.focusOffset, expectedEndpoint[1],
|
|
"focusOffset must equal the original end offset");
|
|
assert_equals(selection.anchorNode, expectedEndpoint[0],
|
|
"anchorNode must equal the original end node");
|
|
assert_equals(selection.anchorOffset, expectedEndpoint[1],
|
|
"anchorOffset must equal the original end offset");
|
|
assert_equals(addedRange.startContainer, endpoints[0],
|
|
"collapseToEnd() must not change the startContainer of the selection's original range");
|
|
assert_equals(addedRange.startOffset, endpoints[1],
|
|
"collapseToEnd() must not change the startOffset of the selection's original range");
|
|
assert_equals(addedRange.endContainer, endpoints[2],
|
|
"collapseToEnd() must not change the endContainer of the selection's original range");
|
|
assert_equals(addedRange.endOffset, endpoints[3],
|
|
"collapseToEnd() must not change the endOffset of the selection's original range");
|
|
}, "Range " + i + " " + testRanges[i] + " collapseToEnd()");
|
|
}
|
|
|
|
testDiv.style.display = "none";
|
|
</script>
|