Debian Codegraph @

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

raw
1 <!doctype html>
2 <meta charset=utf-8>
3 <title>focus move tests caused by a call of Selection.addRange() into iframe</title>
4 <script src="/resources/testharness.js"></script>
5 <script src="/resources/testharnessreport.js"></script>
6 <body onload="doTest()">
7 <div style="height: 3000px;">Spacer to check whether or not page was scrolled down to focused editor</div>
8 <p>Here is an iframe:</p>
9 <iframe src="Selection_addRange_into_iframe_iframe.html"></iframe>
10 <script>
11 "use strict";
12
13 setup({explicit_done:true});
14
15 function doTest() {
16 var selection = document.getSelection();
17 var childDocument = document.getElementsByTagName("iframe")[0].contentDocument;
18 var childSelection = childDocument.getSelection();
19 test(function() {
20 selection.collapse(document.body.firstChild, 0);
21 childSelection.collapse(childDocument.body.firstChild, 0);
22
23 document.documentElement.scrollTop = 0;
24 childDocument.documentElement.scrollTop = 0;
25 childSelection.removeAllRanges();
26 var range = childDocument.createRange();
27 range.selectNodeContents(childDocument.getElementById("editor1"));
28 childSelection.addRange(range);
29 assert_equals(document.activeElement, document.body);
30 assert_equals(childDocument.activeElement, childDocument.getElementById("editor1"));
31 assert_equals(document.documentElement.scrollTop, 0);
32 assert_equals(childDocument.documentElement.scrollTop, 0);
33 }, "Active element should be 'editor1' in the <iframe> after Selection.addRange() but parent's active document should be the <body>");
34 test(function() {
35 selection.collapse(document.body.firstChild, 0);
36 childSelection.collapse(childDocument.getElementById("editor1").firstChild, 0);
37
38 document.documentElement.scrollTop = 0;
39 childDocument.documentElement.scrollTop = 0;
40 childSelection.removeAllRanges();
41 var range = childDocument.createRange();
42 range.selectNodeContents(childDocument.getElementById("editor2"));
43 childSelection.addRange(range);
44 assert_equals(document.activeElement, document.body);
45 assert_equals(childDocument.activeElement, childDocument.getElementById("editor2"));
46 assert_equals(document.documentElement.scrollTop, 0);
47 assert_equals(childDocument.documentElement.scrollTop, 0);
48 }, "Active element should be 'editor2' in the <iframe> after Selection.addRange() but parent's active document should be the <body>");
49 test(function() {
50 selection.collapse(document.body.firstChild, 0);
51 childSelection.collapse(childDocument.getElementById("editor2").firstChild, 0);
52
53 document.documentElement.scrollTop = 0;
54 childDocument.documentElement.scrollTop = 0;
55 childSelection.removeAllRanges();
56 var range = childDocument.createRange();
57 range.selectNodeContents(childDocument.getElementById("non-editor"));
58 childSelection.addRange(range);
59 assert_equals(document.activeElement, document.body);
60 assert_equals(childDocument.activeElement, childDocument.getElementById("editor2"));
61 assert_equals(document.documentElement.scrollTop, 0);
62 assert_equals(childDocument.documentElement.scrollTop, 0);
63 }, "Active element should be 'editor2' in the <iframe> after Selection.addRange() to non-editable <div> and parent's active document should be the <body>");
64
65 done();
66 }
67 </script>