summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg_scripts-switching-02.js
blob: 075beaf27b30097823dbd4a8fbb13839ec7506ab (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
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Make sure that switching the displayed source in the UI works as advertised.
 */

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

var gLabel1 = "code_script-switching-01.js";
var gLabel2 = "code_script-switching-02.js";
var gParams = "?foo=bar,baz|lol";

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

    function testSourcesDisplay() {
      let deferred = promise.defer();

      is(gSources.itemCount, 2,
         "Found the expected number of sources. (1)");

      ok(getSourceActor(gSources, EXAMPLE_URL + gLabel1),
         "First source url is incorrect. (1)");
      ok(getSourceActor(gSources, EXAMPLE_URL + gLabel2 + gParams),
         "Second source url is incorrect. (1)");

      ok(gSources.getItemForAttachment(e => e.label == gLabel1),
         "First source label is incorrect. (1)");
      ok(gSources.getItemForAttachment(e => e.label == gLabel2),
         "Second source label is incorrect. (1)");

      ok(gSources.selectedItem,
         "There should be a selected item in the sources pane. (1)");
      is(getSelectedSourceURL(gSources), EXAMPLE_URL + gLabel2 + gParams,
         "The selected value is the sources pane is incorrect. (1)");

      is(gEditor.getText().search(/firstCall/), -1,
         "The first source is not displayed. (1)");
      is(gEditor.getText().search(/debugger/), 166,
         "The second source is displayed. (1)");

      ok(isCaretPos(gPanel, 6),
         "Editor caret location is correct. (1)");
      is(gEditor.getDebugLocation(), 5,
         "Editor debugger location is correct. (1)");
      ok(gEditor.hasLineClass(5, "debug-line"),
         "The debugged line is highlighted appropriately. (1)");

      waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
      gSources.selectedItem = e => e.attachment.label == gLabel1;

      return deferred.promise;
    }

    function testSwitchPaused1() {
      let deferred = promise.defer();

      ok(gSources.selectedItem,
         "There should be a selected item in the sources pane. (2)");
      is(getSelectedSourceURL(gSources), EXAMPLE_URL + gLabel1,
         "The selected value is the sources pane is incorrect. (2)");

      is(gEditor.getText().search(/firstCall/), 118,
         "The first source is displayed. (2)");
      is(gEditor.getText().search(/debugger/), -1,
         "The second source is not displayed. (2)");

      // The editor's debug location takes a tick to update.
      ok(isCaretPos(gPanel, 1),
         "Editor caret location is correct. (2)");

      is(gEditor.getDebugLocation(), null,
         "Editor debugger location is correct. (2)");
      ok(!gEditor.hasLineClass(5, "debug-line"),
         "The debugged line highlight was removed. (2)");

      waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
      gSources.selectedItem = e => e.attachment.label == gLabel2;

      return deferred.promise;
    }

    function testSwitchPaused2() {
      let deferred = promise.defer();

      ok(gSources.selectedItem,
         "There should be a selected item in the sources pane. (3)");
      is(getSelectedSourceURL(gSources), EXAMPLE_URL + gLabel2 + gParams,
         "The selected value is the sources pane is incorrect. (3)");

      is(gEditor.getText().search(/firstCall/), -1,
         "The first source is not displayed. (3)");
      is(gEditor.getText().search(/debugger/), 166,
         "The second source is displayed. (3)");

      // The editor's debug location takes a tick to update.
      ok(isCaretPos(gPanel, 6),
         "Editor caret location is correct. (3)");
      is(gEditor.getDebugLocation(), 5,
         "Editor debugger location is correct. (3)");
      ok(gEditor.hasLineClass(5, "debug-line"),
         "The debugged line is highlighted appropriately. (3)");

      // Step out three times.
      waitForThreadEvents(gPanel, "paused").then(() => {
        waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
        gDebugger.gThreadClient.stepOut();
      });
      gDebugger.gThreadClient.stepOut();

      return deferred.promise;
    }

    function testSwitchRunning() {
      let deferred = promise.defer();

      ok(gSources.selectedItem,
         "There should be a selected item in the sources pane. (4)");
      is(getSelectedSourceURL(gSources), EXAMPLE_URL + gLabel1,
         "The selected value is the sources pane is incorrect. (4)");

      is(gEditor.getText().search(/firstCall/), 118,
         "The first source is displayed. (4)");
      is(gEditor.getText().search(/debugger/), -1,
         "The second source is not displayed. (4)");

      // The editor's debug location takes a tick to update.
      ok(isCaretPos(gPanel, 6),
         "Editor caret location is correct. (4)");
      is(gEditor.getDebugLocation(), 5,
         "Editor debugger location is correct. (4)");
      ok(gEditor.hasLineClass(5, "debug-line"),
         "The debugged line is highlighted appropriately. (4)");

      deferred.resolve();

      return deferred.promise;
    }

    Task.spawn(function* () {
      yield waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1);
      yield testSourcesDisplay();
      yield testSwitchPaused1();
      yield testSwitchPaused2();
      yield testSwitchRunning();
      resumeDebuggerThenCloseAndFinish(gPanel);
    });

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