Debian Codegraph @

testing/web-platform/mozilla/tests/focus/Selection_addRange_in_iframe.html

raw
1 <!doctype html>
2 <meta charset=utf-8>
3 <title>focus move and auto scroll tests caused by a call of Selection.addRange() into a contenteditable element in iframe</title>
4 <script src="/resources/testharness.js"></script>
5 <script src="/resources/testharnessreport.js"></script>
6 <body>
7 <div style="height: 3000px;">Spacer to check whether or not page was scrolled down to focused editor</div>
8 <iframe srcdoc="<div style='height: 1000px;'></div><div id='editor' contenteditable>editor</div>" style="height: 500px;"></iframe>
9 <script>
10 "use strict";
11 setup({explicit_done:true});
12
13 window.onload = ()=>{
14 test(function() {
15 var subDocument = document.querySelector("iframe").contentDocument;
16 var editorInFrame = subDocument.getElementById("editor");
17 var range = subDocument.createRange();
18 range.setStart(editorInFrame, 0);
19 var selection = subDocument.getSelection();
20 selection.removeAllRanges();
21 document.documentElement.scrollTop = 0;
22 subDocument.documentElement.scrollTop = 0;
23 selection.addRange(range);
24 assert_equals(document.activeElement, document.body);
25 assert_equals(document.documentElement.scrollTop, 0);
26 assert_equals(subDocument.activeElement, editorInFrame);
27 assert_equals(subDocument.documentElement.scrollTop, 0);
28 }, "Moving selection into inactive contenteditable element in non-focused document shouldn't cause scrolling");
29
30 test(function() {
31 var iframe = document.querySelector("iframe");
32 var subDocument = iframe.contentDocument;
33 var selection = subDocument.getSelection();
34
35 // Reset selection in <iframe>
36 var editorInFrame = subDocument.getElementById("editor");
37 editorInFrame.blur();
38 selection.removeAllRanges();
39 var range = document.createRange();
40 range.setStart(subDocument.body, 0);
41 selection.addRange(range);
42 subDocument.documentElement.scrollTop = 0;
43
44 // Move focus to the <iframe>
45 iframe.contentWindow.focus();
46 document.documentElement.scrollTop = 0;
47 assert_equals(document.activeElement, iframe);
48 assert_equals(subDocument.activeElement, subDocument.body);
49 assert_equals(subDocument.documentElement.scrollTop, 0);
50
51 range = subDocument.createRange();
52 range.setStart(editorInFrame, 0);
53 selection.removeAllRanges();
54 selection.addRange(range);
55 assert_equals(document.activeElement, iframe);
56 assert_equals(document.documentElement.scrollTop, 0);
57 assert_equals(subDocument.activeElement, editorInFrame);
58 assert_equals(subDocument.documentElement.scrollTop, 0);
59 }, "Moving selection into inactive contenteditable element in focused document shouldn't cause scrolling");
60
61 done();
62 };
63 </script>