summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/infrastructure/testdriver/actions/textEditCommands.html
blob: 0bc533ecb035288d3094832b5641a538cd97c983 (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
<!DOCTYPE html>
<meta charset="utf-8">
<title>TestDriver actions: text edit commands</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>

<style>
div { padding:0px; margin: 0px; }
</style>
<body>
  <div>
    <input type="text" id="text1" value="Hello World" />
    <input type="text" id="text2">
  </div>
</body>
<script>
async_test(t => {
  let text1 = document.getElementById("text1");
  let text2 = document.getElementById("text2");
  text1.addEventListener("click", function() {
    let text1 = document.getElementById("text1");
    text1.value="new text";
  });

  const ctrl_key = "\uE009";
  const cmd_key = "\uE03D";
  let edit_command_key = ctrl_key;
  if(navigator.platform.includes('Mac'))
    edit_command_key = cmd_key;

  let actions = new test_driver.Actions()
      .pointerMove(0, 0, {origin: text1})
      .pointerDown()
      .pointerUp()
      .addTick()
      .keyDown(edit_command_key)
      .keyDown("a")
      .keyUp("a")
      .keyDown("x")
      .keyUp("x")
      .keyUp(edit_command_key)
      .addTick()
      .pointerMove(0, 0, {origin: text2})
      .pointerDown()
      .pointerUp()
      .keyDown(edit_command_key)
      .keyDown("v")
      .keyUp("v")
      .keyUp(edit_command_key);

  actions.send()
    .then(t.step_func_done(() => {
      assert_equals(text1.value, "");
      assert_equals(text2.value, "new text");
    }))
    .catch(e => t.step_func(() => assert_unreached("Actions sequence failed " + e)));
});
</script>