Bug 1377752 - Part 1: Add automated test for checking scroll position and focused document when setting selection into a contenteditable element in an iframe element. r=smaug, a=jcristau
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 05 Jul 2017 22:21:43 +0900
changeset 414241 8fd07c6b8c0e41f7ce1cfc650039b9702029d7a1
parent 414240 610e42d0872d39989b98abb3a5918ac5a39be495
child 414242 e39f3951ae1cd63cac90615f3b4ed2667d3a3eea
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, jcristau
bugs1377752
milestone55.0
Bug 1377752 - Part 1: Add automated test for checking scroll position and focused document when setting selection into a contenteditable element in an iframe element. r=smaug, a=jcristau 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
testing/web-platform/mozilla/meta/MANIFEST.json
testing/web-platform/mozilla/tests/focus/Selection_addRange_in_iframe.html
--- 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>