summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/selection/contenteditable/collapse.html
blob: 6081d05516729dbef483f6bf2b966b117416fa8d (plain)
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
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Selection across multiple contenteditable</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<button id="button"></button>
<div contenteditable id="host1"></div>
<div contenteditable id="host2"></div>
<div contenteditable id="host3">
  <div contenteditable="false">
    <div contenteditable id="host4"></div>
  </div>
</div>
<script>
function clearFocus() {
  // Move focus from editable host to a button to remove selection limiter
  button.focus();
}
test(() => {
  clearFocus();
  getSelection().collapse(host1);
  assert_equals(document.activeElement, host1);
  getSelection().collapse(host2);
  assert_equals(document.activeElement, host2);
}, "Selection.collapse() must succeed across siblings");

test(() => {
  clearFocus();
  getSelection().collapse(host4);
  assert_equals(document.activeElement, host4);
  getSelection().collapse(host3);
  assert_equals(document.activeElement, host3);
}, "Selection.collapse() must succeed for the ancestor");


test(() => {
  clearFocus();
  getSelection().collapse(host3);
  assert_equals(document.activeElement, host3);
  getSelection().collapse(host4);
  assert_equals(document.activeElement, host4);
}, "Selection.collapse() must succeed for the descendant");
</script>