1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
<!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>
<div style="height: 3000px;">Spacer to check whether or not page was scrolled down to focused editor</div>
<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();
document.documentElement.scrollTop = 0;
subDocument.documentElement.scrollTop = 0;
selection.addRange(range);
assert_equals(document.activeElement, document.body);
assert_equals(document.documentElement.scrollTop, 0);
assert_equals(subDocument.activeElement, editorInFrame);
assert_equals(subDocument.documentElement.scrollTop, 0);
}, "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();
document.documentElement.scrollTop = 0;
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_equals(document.documentElement.scrollTop, 0);
assert_equals(subDocument.activeElement, editorInFrame);
assert_equals(subDocument.documentElement.scrollTop, 0);
}, "Moving selection into inactive contenteditable element in focused document shouldn't cause scrolling");
done();
};
</script>
|