summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/editing/other/empty-elements-insertion.html
blob: c654521354529a46de29aae7cf7e82a3154f5a50 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Placing selection and typing inside empty elements</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="../include/editor-test-utils.js"></script>
<style>
  #border {
    display: inline-block;
    border: 2px red solid;
  }

  #padding {
    display: inline-block;
    padding: 1em;
  }

  #unstyled-before::before,
  #unstyled-after::after,
  #unstyled-both::before,
  #unstyled-both::after {
    content: '';
    display: inline-block;
    border: 2px red solid;
  }
</style>
<div contenteditable></div>

<script>
  const utils = new EditorTestUtils( document.querySelector( 'div[contenteditable]' ) );

  promise_test( async () => {
    utils.setupEditingHost( `<p><strong id="border"></strong></p>` );

    const target = document.querySelector( '#border' );
    const actions = new test_driver.Actions();
    await actions
      .pointerMove( 0, 0, { origin: target } )
      .pointerDown( { button: actions.ButtonType.LEFT } )
      .pointerUp( { button: actions.ButtonType.LEFT } )
      .send();
    document.execCommand( 'insertText', false, 'a' );
    assert_greater_than( target.innerHTML.length, 0, 'The text should be inserted into the styled <strong> element' );
  }, 'Insert text into the inline element styled with border' );

  promise_test( async () => {
    utils.setupEditingHost( `<p><strong id="padding"></strong></p>` );

    const target = document.querySelector( '#padding' );
    const actions = new test_driver.Actions();
    await actions
      .pointerMove( 0, 0, { origin: target } )
      .pointerDown( { button: actions.ButtonType.LEFT } )
      .pointerUp( { button: actions.ButtonType.LEFT } )
      .send();
    document.execCommand( 'insertText', false, 'a' );
    assert_greater_than( target.innerHTML.length, 0, 'The text should be inserted into the styled <strong> element' );
  }, 'Insert text into the inline element styled with padding' );

  promise_test( async () => {
    utils.setupEditingHost( `<p><strong id="unstyled"></strong></p>` );

    const target = document.querySelector( '#unstyled' );
    const actions = new test_driver.Actions();
    await actions
      .pointerMove( 0, 0, { origin: target } )
      .pointerDown( { button: actions.ButtonType.LEFT } )
      .pointerUp( { button: actions.ButtonType.LEFT } )
      .send();
    document.execCommand( 'insertText', false, 'a' );
    assert_greater_than( target.innerHTML.length, 0, 'The text should be inserted into the unstyled <strong> element' );
  }, 'Insert text into the unstyled inline element' );

  promise_test( async () => {
    utils.setupEditingHost( `<p><strong id="unstyled-before"></strong></p>` );

    const target = document.querySelector( '#unstyled-before' );
    const actions = new test_driver.Actions();
    await actions
      .pointerMove( 0, 0, { origin: target } )
      .pointerDown( { button: actions.ButtonType.LEFT } )
      .pointerUp( { button: actions.ButtonType.LEFT } )
      .send();
    document.execCommand( 'insertText', false, 'a' );
    assert_greater_than( target.innerHTML.length, 0, 'The text should be inserted into the <strong> element' );
  }, 'Insert text into the unstyled inline element with the styled ::before pseudoelement' );

  promise_test( async () => {
    utils.setupEditingHost( `<p><strong id="unstyled-after"></strong></p>` );

    const target = document.querySelector( '#unstyled-after' );
    const actions = new test_driver.Actions();
    await actions
      .pointerMove( 0, 0, { origin: target } )
      .pointerDown( { button: actions.ButtonType.LEFT } )
      .pointerUp( { button: actions.ButtonType.LEFT } )
      .send();
    document.execCommand( 'insertText', false, 'a' );
    assert_greater_than( target.innerHTML.length, 0, 'The text should be inserted into the <strong> element' );
  }, 'Insert text into the unstyled inline element with the styled ::after pseudoelement' );

  promise_test( async () => {
    utils.setupEditingHost( `<p><strong id="unstyled-both"></strong></p>` );

    const target = document.querySelector( '#unstyled-both' );
    const actions = new test_driver.Actions();
    await actions
      .pointerMove( 0, 0, { origin: target } )
      .pointerDown( { button: actions.ButtonType.LEFT } )
      .pointerUp( { button: actions.ButtonType.LEFT } )
      .send();
    document.execCommand( 'insertText', false, 'a' );
    assert_greater_than( target.innerHTML.length, 0, 'The text should be inserted into the <strong> element' );
  }, 'Insert text into the unstyled inline element with the styled ::before and ::after pseudoelements' );
</script>