summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_jsterm_editor_execute_selection.js
blob: 8e46247f4a8a13696ec9bf403c2d594e19e87d07 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

// Test that the user can execute only the code that is selected in the input, in editor
// mode.
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1576563

"use strict";

const TEST_URI =
  "data:text/html;charset=utf-8,<!DOCTYPE html>Web Console test for executing input selection";

add_task(async function () {
  await pushPref("devtools.webconsole.input.editor", true);
  const hud = await openNewTabAndConsole(TEST_URI);

  const expression = `x = "first assignment";x;
    x = "second assignment";x;`;

  info("Evaluate the whole expression");
  setInputValue(hud, expression);

  let onResultMessage = waitForMessageByType(
    hud,
    "second assignment",
    ".result"
  );
  synthesizeKeyboardEvaluation();
  await onResultMessage;
  ok(true, "The whole expression is evaluated when there's no selection");

  info("Select the first line and evaluate");
  hud.ui.jsterm.editor.setSelection(
    { line: 0, ch: 0 },
    { line: 0, ch: expression.split("\n")[0].length }
  );
  onResultMessage = waitForMessageByType(hud, "first assignment", ".result");
  synthesizeKeyboardEvaluation();
  await onResultMessage;
  ok(true, "Only the expression on the first line was evaluated");

  info("Check that it also works when clicking on the Run button");
  onResultMessage = waitForMessageByType(hud, "first assignment", ".result");
  hud.ui.outputNode
    .querySelector(".webconsole-editor-toolbar-executeButton")
    .click();
  await onResultMessage;
  ok(
    true,
    "Only the expression on the first line was evaluated when clicking the Run button"
  );

  info("Check that this is disabled in inline mode");
  await toggleLayout(hud);
  hud.ui.jsterm.editor.setSelection(
    { line: 0, ch: 0 },
    { line: 0, ch: expression.split("\n")[0].length }
  );
  onResultMessage = waitForMessageByType(hud, "second assignment", ".result");
  synthesizeKeyboardEvaluation();
  await onResultMessage;
  ok(true, "The whole expression was evaluated in inline mode");
});

function synthesizeKeyboardEvaluation() {
  EventUtils.synthesizeKey("KEY_Enter", {
    [Services.appinfo.OS === "Darwin" ? "metaKey" : "ctrlKey"]: true,
  });
}