summaryrefslogtreecommitdiffstats
path: root/accessible/tests/browser/text/browser_editabletext.js
blob: 0310122debf1100176159c837e2e6ac0f332fb10 (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

async function testEditable(browser, acc, aBefore = "", aAfter = "") {
  async function resetInput() {
    if (acc.childCount <= 1) {
      return;
    }

    let emptyInputEvent = waitForEvent(EVENT_TEXT_VALUE_CHANGE, "input");
    await invokeContentTask(browser, [], async () => {
      content.document.getElementById("input").innerHTML = "";
    });

    await emptyInputEvent;
  }

  // ////////////////////////////////////////////////////////////////////////
  // insertText
  await testInsertText(acc, "hello", 0, aBefore.length);
  await isFinalValueCorrect(browser, acc, [aBefore, "hello", aAfter]);
  await testInsertText(acc, "ma ", 0, aBefore.length);
  await isFinalValueCorrect(browser, acc, [aBefore, "ma hello", aAfter]);
  await testInsertText(acc, "ma", 2, aBefore.length);
  await isFinalValueCorrect(browser, acc, [aBefore, "mama hello", aAfter]);
  await testInsertText(acc, " hello", 10, aBefore.length);
  await isFinalValueCorrect(browser, acc, [
    aBefore,
    "mama hello hello",
    aAfter,
  ]);

  // ////////////////////////////////////////////////////////////////////////
  // deleteText
  await testDeleteText(acc, 0, 5, aBefore.length);
  await isFinalValueCorrect(browser, acc, [aBefore, "hello hello", aAfter]);
  await testDeleteText(acc, 5, 6, aBefore.length);
  await isFinalValueCorrect(browser, acc, [aBefore, "hellohello", aAfter]);
  await testDeleteText(acc, 5, 10, aBefore.length);
  await isFinalValueCorrect(browser, acc, [aBefore, "hello", aAfter]);
  await testDeleteText(acc, 0, 5, aBefore.length);
  await isFinalValueCorrect(browser, acc, [aBefore, "", aAfter]);

  // XXX: clipboard operation tests don't work well with editable documents.
  if (acc.role == ROLE_DOCUMENT) {
    return;
  }

  await resetInput();

  // copyText and pasteText
  await testInsertText(acc, "hello", 0, aBefore.length);
  await isFinalValueCorrect(browser, acc, [aBefore, "hello", aAfter]);

  await testCopyText(acc, 0, 1, aBefore.length, browser, "h");
  await testPasteText(acc, 1, aBefore.length);
  await isFinalValueCorrect(browser, acc, [aBefore, "hhello", aAfter]);

  await testCopyText(acc, 5, 6, aBefore.length, browser, "o");
  await testPasteText(acc, 6, aBefore.length);
  await isFinalValueCorrect(browser, acc, [aBefore, "hhelloo", aAfter]);

  await testCopyText(acc, 2, 3, aBefore.length, browser, "e");
  await testPasteText(acc, 1, aBefore.length);
  await isFinalValueCorrect(browser, acc, [aBefore, "hehelloo", aAfter]);

  // cut & paste
  await testCutText(acc, 0, 1, aBefore.length);
  await isFinalValueCorrect(browser, acc, [aBefore, "ehelloo", aAfter]);
  await testPasteText(acc, 2, aBefore.length);
  await isFinalValueCorrect(browser, acc, [aBefore, "ehhelloo", aAfter]);

  await testCutText(acc, 3, 4, aBefore.length);
  await isFinalValueCorrect(browser, acc, [aBefore, "ehhlloo", aAfter]);
  await testPasteText(acc, 6, aBefore.length);
  await isFinalValueCorrect(browser, acc, [aBefore, "ehhlloeo", aAfter]);

  await testCutText(acc, 0, 8, aBefore.length);
  await isFinalValueCorrect(browser, acc, [aBefore, "", aAfter]);

  await resetInput();

  // ////////////////////////////////////////////////////////////////////////
  // setTextContents
  await testSetTextContents(acc, "hello", aBefore.length, [
    EVENT_TEXT_INSERTED,
  ]);
  await isFinalValueCorrect(browser, acc, [aBefore, "hello", aAfter]);
  await testSetTextContents(acc, "katze", aBefore.length, [
    EVENT_TEXT_REMOVED,
    EVENT_TEXT_INSERTED,
  ]);
  await isFinalValueCorrect(browser, acc, [aBefore, "katze", aAfter]);
}

addAccessibleTask(
  `<input id="input"/>`,
  async function (browser, docAcc) {
    await testEditable(browser, findAccessibleChildByID(docAcc, "input"));
  },
  { chrome: true, topLevel: true }
);

addAccessibleTask(
  `<style>
  #input::after {
    content: "pseudo element";
  }
</style>
<div id="input" contenteditable="true" role="textbox"></div>`,
  async function (browser, docAcc) {
    await testEditable(
      browser,
      findAccessibleChildByID(docAcc, "input"),
      "",
      "pseudo element"
    );
  },
  { chrome: true, topLevel: false /* bug 1834129 */ }
);

addAccessibleTask(
  `<style>
  #input::before {
    content: "pseudo element";
  }
</style>
<div id="input" contenteditable="true" role="textbox"></div>`,
  async function (browser, docAcc) {
    await testEditable(
      browser,
      findAccessibleChildByID(docAcc, "input"),
      "pseudo element"
    );
  },
  { chrome: true, topLevel: false /* bug 1834129 */ }
);

addAccessibleTask(
  `<style>
  #input::before {
    content: "before";
  }
  #input::after {
    content: "after";
  }
</style>
<div id="input" contenteditable="true" role="textbox"></div>`,
  async function (browser, docAcc) {
    await testEditable(
      browser,
      findAccessibleChildByID(docAcc, "input"),
      "before",
      "after"
    );
  },
  { chrome: true, topLevel: false /* bug 1834129 */ }
);

addAccessibleTask(
  ``,
  async function (browser, docAcc) {
    await testEditable(browser, docAcc);
  },
  {
    chrome: true,
    topLevel: true,
    contentDocBodyAttrs: { contentEditable: "true" },
  }
);