Bug 1377752 - part1: Add automated test for checking scroll position and focused document when setting selection into a contenteditable element in an iframe element r?smaug
When an iframe doesn't have focus, moving selection into a contenteditable element in it shouldn't cause moving focus to the document, moving focus to the editable element nor scrolling to the editor but the editor should become active element.
When an iframe has focus, moving selection into a contenteditable element in it should cause moving focus to the editor and scroll it into the view.
MozReview-Commit-ID: 1ZDPj6UotLn
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -178656,17 +178656,17 @@
"ac9d401368b75e00adbdf80ee42dd8dce1e48e13",
"testharness"
],
"html/browsers/the-window-object/window-indexed-properties.html": [
"22d5cb06bfc4724d27f565b8ffa2280bf2e8538b",
"testharness"
],
"html/browsers/the-window-object/window-named-properties.html": [
- "03bab12397e43003c6a4d768d2faa580501400bf",
+ "21bb2b7a30381decf8b55152ba33cd723b67b8d5",
"testharness"
],
"html/browsers/the-window-object/window-open-noopener.html": [
"2e20bfcd1dfe9bee00a9747b87cdaf42004d6415",
"testharness"
],
"html/browsers/the-window-object/window-properties.html": [
"ee0ade0a8de422597c362d15cf4a9dd446e4af00",
--- a/testing/web-platform/mozilla/meta/MANIFEST.json
+++ b/testing/web-platform/mozilla/meta/MANIFEST.json
@@ -387,16 +387,22 @@
]
],
"focus/Selection_addRange.html": [
[
"/_mozilla/focus/Selection_addRange.html",
{}
]
],
+ "focus/Selection_addRange_in_iframe.html": [
+ [
+ "/_mozilla/focus/Selection_addRange_in_iframe.html",
+ {}
+ ]
+ ],
"focus/Selection_addRange_into_iframe.html": [
[
"/_mozilla/focus/Selection_addRange_into_iframe.html",
{}
]
],
"focus/Selection_collapse.html": [
[
@@ -864,16 +870,20 @@
"focus/Range_setStart.html": [
"ab6633c08a3a501d3766d9ee38da69e26dc8a9e4",
"testharness"
],
"focus/Selection_addRange.html": [
"e733930483c74e73210c5a127db1d04f82c966cf",
"testharness"
],
+ "focus/Selection_addRange_in_iframe.html": [
+ "7ce21d66cd147f2c0313168f8e4d97628270b67b",
+ "testharness"
+ ],
"focus/Selection_addRange_into_iframe.html": [
"65143dd5377acc88b180460a46dd4bbb79cbf68e",
"testharness"
],
"focus/Selection_addRange_into_iframe_iframe.html": [
"8e8eb8ee04e7a0879828de2c5fb2501c088504a4",
"support"
],
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/focus/Selection_addRange_in_iframe.html
@@ -0,0 +1,57 @@
+<!doctype html>
+<meta charset=utf-8>
+<title>focus move and auto scroll tests caused by a call of Selection.addRange() into a contenteditable element in iframe</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<body>
+<iframe srcdoc="<div style='height: 1000px;'></div><div id='editor' contenteditable>editor</div>" style="height: 500px;"></iframe>
+<script>
+"use strict";
+setup({explicit_done:true});
+
+window.onload = ()=>{
+ test(function() {
+ var subDocument = document.querySelector("iframe").contentDocument;
+ var editorInFrame = subDocument.getElementById("editor");
+ var range = subDocument.createRange();
+ range.setStart(editorInFrame, 0);
+ var selection = subDocument.getSelection();
+ selection.removeAllRanges();
+ selection.addRange(range);
+ assert_equals(document.activeElement, document.body);
+ assert_equals(subDocument.documentElement.scrollTop, 0);
+ assert_equals(subDocument.activeElement, editorInFrame);
+ }, "Moving selection into inactive contenteditable element in non-focused document shouldn't cause scrolling");
+
+ test(function() {
+ var iframe = document.querySelector("iframe");
+ var subDocument = iframe.contentDocument;
+ var selection = subDocument.getSelection();
+
+ // Reset selection in <iframe>
+ var editorInFrame = subDocument.getElementById("editor");
+ editorInFrame.blur();
+ selection.removeAllRanges();
+ var range = document.createRange();
+ range.setStart(subDocument.body, 0);
+ selection.addRange(range);
+ subDocument.documentElement.scrollTop = 0;
+
+ // Move focus to the <iframe>
+ iframe.contentWindow.focus();
+ assert_equals(document.activeElement, iframe);
+ assert_equals(subDocument.activeElement, subDocument.body);
+ assert_equals(subDocument.documentElement.scrollTop, 0);
+
+ range = subDocument.createRange();
+ range.setStart(editorInFrame, 0);
+ selection.removeAllRanges();
+ selection.addRange(range);
+ assert_equals(document.activeElement, iframe);
+ assert_not_equals(subDocument.documentElement.scrollTop, 0);
+ assert_equals(subDocument.activeElement, editorInFrame);
+ }, "Moving selection into inactive contenteditable element in focused document should cause scrolling");
+
+ done();
+};
+</script>