summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/editing/other/legacy-edit-command.html
blob: 81ff89d81bd9037e2ffb5d2929951ad862e19bed (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
<!doctype html>
<html>
<meta charset=utf-8>
<meta name="variant" content="?command=increaseFontSize">
<meta name="variant" content="?command=decreaseFontSize">
<meta name="variant" content="?command=getHTML">
<meta name="variant" content="?command=insertBrOrReturn&param=true">
<meta name="variant" content="?command=insertBrOrReturn&param=false">
<meta name="variant" content="?command=heading&param=h1">
<meta name="variant" content="?command=heading&param=h2">
<meta name="variant" content="?command=heading&param=h3">
<meta name="variant" content="?command=heading&param=h4">
<meta name="variant" content="?command=heading&param=h5">
<meta name="variant" content="?command=heading&param=h6">
<meta name="variant" content="?command=contentReadOnly&param=true">
<meta name="variant" content="?command=contentReadOnly&param=false">
<meta name="variant" content="?command=readonly&param=true">
<meta name="variant" content="?command=readonly&param=false">
<title>Test legacy commands won't work</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
</head>
<body contenteditable></body>
<script>
"use strict";

const testParams = new URLSearchParams(location.search.substring(1));
const command = testParams.get("command");
const param = testParams.has("param") ? testParams.get("param") : undefined;

const editor = document.body;

promise_test(async () => {
  await new Promise(resolve => addEventListener("load", resolve, {once: true}));
}, "Wait for load...");

promise_test(async () => {
  function reset() {
    editor.innerHTML = "<p>abc</p>";
    editor.focus();
    getSelection().setBaseAndExtent(
      editor.querySelector("p").firstChild,
      1,
      editor.querySelector("p").firstChild,
      2
    );
  }
  test(() => {
    reset();
    let inputEvents = [];
    function onInput(event) {
      inputEvents.push(event);
    }
    editor.addEventListener("input", onInput);
    try {
      assert_equals(
        document.execCommand(command, false, param),
        false,
        "result should be false"
      );
      assert_equals(
        editor.outerHTML,
        "<body contenteditable=\"\"><p>abc</p></body>",
        "editable content shouldn't be modified"
      );
      assert_equals(
        inputEvents.length,
        0,
        "no input events should be fired"
      );
    } finally {
      editor.removeEventListener("input", onInput);
    }
  }, `execCommand("${command}", false, ${param === undefined ? "undefined" : `"${param}"`})`);
  test(() => {
    reset();
    assert_equals(
      document.queryCommandState(command),
      false,
      "result should be false"
    );
  }, `queryCommandState("${command}")`);
  test(() => {
    reset();
    assert_equals(
      document.queryCommandEnabled(command),
      false,
      "result should be false"
    );
  }, `queryCommandEnabled("${command}")`);
  test(() => {
    reset();
    assert_equals(
      document.queryCommandIndeterm(command),
      false,
      "result should be false"
    );
  }, `queryCommandIndeterm("${command}")`);
  test(() => {
    reset();
    assert_equals(
      document.queryCommandValue(command),
      "",
      "result should be empty string"
    );
  }, `queryCommandValue("${command}")`);
  test(() => {
    reset();
    assert_equals(
      document.queryCommandSupported(command),
      false,
      "result should be false"
    );
  }, `queryCommandSupported("${command}")`);
}, `command: "${command}", param: "${param}"`);
</script>
</html>