Files
firefox/testing/web-platform/mozilla/tests/focus/Selection_extend.html
T
Masayuki Nakano c0a99daa97 Bug 1367460 Shouldn't make focused editing host blurred when moving selection with Selection API r=smaug
Chromium doesn't make focused editing host blurred when a Selection API method call moves selection to a non-editable node.  Let's follow same behavior for compatibility with both Chromium and Gecko 54.

MozReview-Commit-ID: HXmYX18HVA5
2017-05-30 18:07:22 +09:00

169 lines
9.6 KiB
HTML

<!doctype html>
<meta charset=utf-8>
<title>focus move tests caused by a call of Selection.extend()</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<p id="staticBefore">static text</p>
<div id="editor" contenteditable><p>content of editor</p></div>
<div id="outerEditor" contenteditable
><p>content of outer editor</p><div id="staticInEditor" contenteditable="false"
><p>static content of outer editor</p><div id="innerEditor" contenteditable
><p>content of inner editor</p></div></div></div>
<p id="staticAfter">static text</p>
<p><a id="anchor" href="about:blank">anchor</a></p>
<script>
"use strict";
var staticBefore = {
element: document.getElementById("staticBefore"),
textNode: document.getElementById("staticBefore").firstChild,
textLength: document.getElementById("staticBefore").firstChild.length
};
var editor = {
element: document.getElementById("editor"),
textNode: document.getElementById("editor").firstChild.firstChild,
textLength: document.getElementById("editor").firstChild.firstChild.length
};
var outerEditor = {
element: document.getElementById("outerEditor"),
textNode: document.getElementById("outerEditor").firstChild.firstChild,
textLength: document.getElementById("outerEditor").firstChild.firstChild.length
};
var staticInEditor = {
element: document.getElementById("staticInEditor"),
textNode: document.getElementById("staticInEditor").firstChild,
textLength: document.getElementById("staticInEditor").firstChild.length
};
var innerEditor = {
element: document.getElementById("innerEditor"),
textNode: document.getElementById("innerEditor").firstChild.firstChild,
textLength: document.getElementById("innerEditor").firstChild.firstChild.length
};
var staticAfter = {
element: document.getElementById("staticAfter"),
textNode: document.getElementById("staticAfter").firstChild,
textLength: document.getElementById("staticAfter").firstChild.length
};
var anchor = {
element: document.getElementById("anchor"),
textNode: document.getElementById("anchor").firstChild,
textLength: document.getElementById("anchor").firstChild.length
};
function resetFocusAndSelectionRange(aFocus)
{
document.getSelection().removeAllRanges();
if (document.activeElement) {
document.activeElement.blur();
}
if (aFocus) {
aFocus.element.focus();
document.getSelection().collapse(aFocus.textNode, 0);
} else {
document.getSelection().collapse(staticBefore.textNode, 0);
}
}
test(function() {
resetFocusAndSelectionRange();
document.getSelection().extend(editor.textNode, 0);
assert_equals(document.activeElement, document.body);
}, "Active element should be the <body> after Selection.extend() from selection at start of the first text node of 'staticBefore' to start of the first text node of 'editor'");
test(function() {
resetFocusAndSelectionRange();
document.getSelection().extend(outerEditor.textNode, 0);
assert_equals(document.activeElement, document.body);
}, "Active element should be the <body> after Selection.extend() from selection at start of the first text node of 'staticBefore' to start of the first text node of 'outerEditor'");
test(function() {
resetFocusAndSelectionRange();
document.getSelection().extend(staticInEditor.textNode, 0);
assert_equals(document.activeElement, document.body);
}, "Active element should be the <body> after Selection.extend() from selection at start of the first text node of 'staticBefore' to start of the first text node of 'staticInEditor'");
test(function() {
resetFocusAndSelectionRange();
document.getSelection().extend(innerEditor.textNode, 0);
assert_equals(document.activeElement, document.body);
}, "Active element should be the <body> after Selection.extend() from selection at start of the first text node of 'staticBefore' to start of the first text node of 'innerEditor'");
test(function() {
resetFocusAndSelectionRange();
document.getSelection().extend(staticAfter.textNode, 0);
assert_equals(document.activeElement, document.body);
}, "Active element should be the <body> after Selection.extend() from selection at start of the first text node of 'staticBefore' to start of the first text node of 'staticAfter'");
test(function() {
resetFocusAndSelectionRange();
document.getSelection().extend(anchor.textNode, 0);
assert_equals(document.activeElement, document.body);
}, "Active element should be the <body> after Selection.extend() from selection at start of the first text node of 'staticBefore' to start of the first text node of 'anchor'");
test(function() {
resetFocusAndSelectionRange(editor);
document.getSelection().extend(editor.textNode, editor.textLength);
assert_equals(document.activeElement, editor.element);
}, "Active element should be 'editor' after Selection.extend() from selection at start of the first text node of 'editor' to end of the first text node of 'editor'");
test(function() {
resetFocusAndSelectionRange(editor);
document.getSelection().extend(outerEditor.textNode, 0);
assert_equals(document.activeElement, editor.element);
}, "Active element should be 'editor' after Selection.extend() from selection at start of the first text node of 'editor' to start of the first text node of 'outerEditor'");
test(function() {
resetFocusAndSelectionRange(editor);
document.getSelection().extend(innerEditor.textNode, 0);
assert_equals(document.activeElement, editor.element);
}, "Active element should be 'editor' after Selection.extend() from selection at start of the first text node of 'editor' to start of the first text node of 'innerEditor'");
test(function() {
resetFocusAndSelectionRange(outerEditor);
document.getSelection().extend(outerEditor.textNode, outerEditor.textLength);
assert_equals(document.activeElement, outerEditor.element);
}, "Active element should be 'outerEditor' after Selection.extend() from selection at start of the first text node of 'outerEditor' to end of the first text node of 'outerEditor'");
test(function() {
resetFocusAndSelectionRange(outerEditor);
document.getSelection().extend(staticInEditor.textNode, 0);
assert_equals(document.activeElement, outerEditor.element);
}, "Active element should be 'outerEditor' after Selection.extend() from selection at start of the first text node of 'outerEditor' to start of the first text node of 'staticInEditor'");
test(function() {
resetFocusAndSelectionRange(outerEditor);
document.getSelection().extend(innerEditor.textNode, 0);
assert_equals(document.activeElement, outerEditor.element);
}, "Active element should be 'outerEditor' after Selection.extend() from selection at start of the first text node of 'outerEditor' to start of the first text node of 'innerEditor'");
test(function() {
resetFocusAndSelectionRange(outerEditor);
document.getSelection().extend(editor.textNode, 0);
assert_equals(document.activeElement, outerEditor.element);
}, "Active element should be 'outerEditor' after Selection.extend() from selection at start of the first text node of 'outerEditor' to start of the first text node of 'editor'");
test(function() {
resetFocusAndSelectionRange(innerEditor);
document.getSelection().extend(innerEditor.textNode, innerEditor.textLength);
assert_equals(document.activeElement, innerEditor.element);
}, "Active element should be 'innerEditor' after Selection.extend() from selection at start of the first text node of 'innerEditor' to end of the first text node of 'innerEditor'");
test(function() {
resetFocusAndSelectionRange(innerEditor);
document.getSelection().extend(outerEditor.textNode, 0);
assert_equals(document.activeElement, outerEditor.element);
}, "Active element should be 'outerEditor' after Selection.extend() from selection at start of the first text node of 'innerEditor' to start of the first text node of 'outerEditor'");
test(function() {
resetFocusAndSelectionRange(innerEditor);
document.getSelection().extend(staticInEditor.textNode, 0);
assert_equals(document.activeElement, outerEditor.element);
}, "Active element should be 'outerEditor' after Selection.extend() from selection at start of the first text node of 'innerEditor' to start of the first text node of 'staticInEditor'");
test(function() {
resetFocusAndSelectionRange(innerEditor);
document.getSelection().extend(anchor.textNode, 0);
assert_equals(document.activeElement, innerEditor.element);
}, "Active element should be 'innerEditor' after Selection.extend() from selection at start of the first text node of 'innerEditor' to start of the first text node of 'anchor'");
test(function() {
resetFocusAndSelectionRange(anchor);
document.getSelection().extend(anchor.textNode, anchor.textLength);
assert_equals(document.activeElement, anchor.element);
}, "Active element should be 'anchor' after Selection.extend() from selection at start of the first text node of 'anchor' to end of the first text node of 'anchor' and 'anchor' has focus before the call");
test(function() {
resetFocusAndSelectionRange(anchor);
anchor.element.blur();
document.getSelection().extend(anchor.textNode, anchor.textLength);
assert_equals(document.activeElement, document.body);
}, "Active element should be the <body> after Selection.extend() from selection at start of the first text node of 'anchor' to end of the first text node of 'anchor' and 'anchor' doesn't have focus before the call");
</script>