summaryrefslogtreecommitdiffstats
path: root/devtools/client/shared/sourceeditor/test/browser_editor_alt_b_f.js
blob: cacefd8dac49414edd8ab0ebc0719248f67f27ac (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Ensure Alt-B and Alt-F keyboard shortcuts work as expected in the source editor.
// See Bug 1481443.

add_task(async function () {
  const { ed, win } = await setup();
  const editorDoc = ed.container.contentDocument;
  await promiseWaitForFocus();
  const isMacOS = Services.appinfo.OS === "Darwin";

  ed.focus();

  const initialText = "a b c d e";
  ed.setText(initialText);

  ed.setCursor({ line: 1, ch: initialText.length });

  EventUtils.synthesizeKey("b", { altKey: true }, editorDoc.defaultView);

  // A character is added only on OSX.
  let expectedText = isMacOS ? initialText + "b" : initialText;
  is(
    ed.getCursor().ch,
    expectedText.length,
    "Cursor is at expected position after Alt-B"
  );
  is(ed.getText(), expectedText, "Editor has expected content after Alt-B");

  EventUtils.synthesizeKey("f", { altKey: true }, editorDoc.defaultView);

  // A character is added only on OSX.
  expectedText = isMacOS ? expectedText + "f" : initialText;
  is(
    ed.getCursor().ch,
    expectedText.length,
    "Cursor is at expected position after Alt-F"
  );
  is(ed.getText(), expectedText, "Editor has expected content after Alt-F");

  ed.destroy();
  win.close();
});