summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg_search-basic-03.js
blob: 0020776d6be95f10fce00bd71917825d8fdd06a8 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Tests that searches which cause a popup to be shown properly handle the
 * ESCAPE key.
 */

const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";

var gTab, gPanel, gDebugger;
var gSources, gSearchBox;

function test() {
  let options = {
    source: EXAMPLE_URL + "code_script-switching-01.js",
    line: 1,
  };
  initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
    gTab = aTab;
    gPanel = aPanel;
    gDebugger = gPanel.panelWin;
    gSources = gDebugger.DebuggerView.Sources;
    gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;

    // Calling `firstCall` is going to break into the other script
    waitForSourceAndCaretAndScopes(gPanel, "-02.js", 6)
      .then(performFileSearch)
      .then(escapeAndHide)
      .then(escapeAndClear)
      .then(() => verifySourceAndCaret("-01.js", 1, 1))
      .then(performFunctionSearch)
      .then(escapeAndHide)
      .then(escapeAndClear)
      .then(() => verifySourceAndCaret("-01.js", 4, 10))
      .then(performGlobalSearch)
      .then(escapeAndClear)
      .then(() => verifySourceAndCaret("-01.js", 4, 10))
      .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
      .then(null, aError => {
        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
      });

    callInTab(gTab, "firstCall");
  });
}

function performFileSearch() {
  let finished = promise.all([
    ensureSourceIs(gPanel, "-02.js"),
    ensureCaretAt(gPanel, 6),
    once(gDebugger, "popupshown"),
    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
    waitForSourceShown(gPanel, "-01.js")
  ]);

  setText(gSearchBox, ".");

  return finished.then(() => promise.all([
    ensureSourceIs(gPanel, "-01.js"),
    ensureCaretAt(gPanel, 1)
  ]));
}

function performFunctionSearch() {
  let finished = promise.all([
    ensureSourceIs(gPanel, "-01.js"),
    ensureCaretAt(gPanel, 1),
    once(gDebugger, "popupshown"),
    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FUNCTION_SEARCH_MATCH_FOUND)
  ]);

  setText(gSearchBox, "@");

  return finished.then(() => promise.all([
    ensureSourceIs(gPanel, "-01.js"),
    ensureCaretAt(gPanel, 4, 10)
  ]));
}

function performGlobalSearch() {
  let finished = promise.all([
    ensureSourceIs(gPanel, "-01.js"),
    ensureCaretAt(gPanel, 4, 10),
    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND)
  ]);

  setText(gSearchBox, "!first");

  return finished.then(() => promise.all([
    ensureSourceIs(gPanel, "-01.js"),
    ensureCaretAt(gPanel, 4, 10)
  ]));
}

function escapeAndHide() {
  let finished = once(gDebugger, "popuphidden", true);
  EventUtils.sendKey("ESCAPE", gDebugger);
  return finished;
}

function escapeAndClear() {
  EventUtils.sendKey("ESCAPE", gDebugger);
  is(gSearchBox.getAttribute("value"), "",
    "The searchbox has properly emptied after pressing escape.");
}

function verifySourceAndCaret(aUrl, aLine, aColumn) {
  ok(gSources.selectedItem.attachment.label.includes(aUrl),
    "The selected item's label appears to be correct.");
  ok(gSources.selectedItem.attachment.source.url.includes(aUrl),
    "The selected item's value appears to be correct.");
  ok(isCaretPos(gPanel, aLine, aColumn),
    "The current caret position appears to be correct.");
}

registerCleanupFunction(function () {
  gTab = null;
  gPanel = null;
  gDebugger = null;
  gSources = null;
  gSearchBox = null;
});