summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/selection/contenteditable/cefalse-on-boundaries.html
blob: 945058dfc3895a309d7840257d4521e97b8313a5 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Selection of contenteditable=false at the beginning and end of contenteditable element</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div contenteditable id="host">
  <div contenteditable="false" id="beginning">&nbsp;</div>
  <p id="paragraph">Lorem ipsum dolor sit amet.</p>
  <div contenteditable="false" id="end">&nbsp;</div>
</div>
<script>
test( () => {
  const range = document.createRange();

  range.setStartBefore( beginning );
  range.setEndAfter( paragraph );
  getSelection().removeAllRanges();
  getSelection().addRange( range );

  const selectedRange = getSelection().getRangeAt( 0 );

  assert_equals( selectedRange.startContainer, host );
  assert_equals( selectedRange.startOffset, 1 );
  assert_equals( selectedRange.endContainer, host );
  assert_equals( selectedRange.endOffset, 4 );
}, 'Selection can start on cE=false element at the beginning of the cE=true element' );

test( () => {
  const range = document.createRange();

  range.setStartBefore( paragraph );
  range.setEndAfter( end );
  getSelection().removeAllRanges();
  getSelection().addRange( range );

  const selectedRange = getSelection().getRangeAt( 0 );

  assert_equals( selectedRange.startContainer, host );
  assert_equals( selectedRange.startOffset, 3 );
  assert_equals( selectedRange.endContainer, host );
  assert_equals( selectedRange.endOffset, 6 );
}, 'Selection can end on cE=false element at the end of the cE=true element' );

test( () => {
  const range = document.createRange();

  range.setStartBefore( beginning );
  range.setEndAfter( end );
  getSelection().removeAllRanges();
  getSelection().addRange( range );

  const selectedRange = getSelection().getRangeAt( 0 );

  assert_equals( selectedRange.startContainer, host );
  assert_equals( selectedRange.startOffset, 1 );
  assert_equals( selectedRange.endContainer, host );
  assert_equals( selectedRange.endOffset, 6 );
}, 'Selection can start and end on cE=false elements at the boundaries of cE=true element' );

test( () => {
  const range = document.createRange();

  range.selectNodeContents( host );

  const selectedRange = getSelection().getRangeAt( 0 );

  assert_equals( selectedRange.startContainer, host );
  assert_equals( selectedRange.startOffset, 1 );
  assert_equals( selectedRange.endContainer, host );
  assert_equals( selectedRange.endOffset, 6 );
}, 'Range#selectNodeContents() correctly select contents of cE=true element with cE=false elements on boundaries' );
</script>