summaryrefslogtreecommitdiff
path: root/browser/devtools/debugger/test/browser_dbg_location-changes-blank.js
blob: 478a7677be1bb3a8274666f71708971a95beaa5e (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
/* vim:set ts=2 sw=2 sts=2 et: */
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Make sure that changing the tab location URL to a page with no scripts works.
 */

var gPane = null;
var gTab = null;
var gDebuggee = null;
var gDebugger = null;

function test()
{
  let scriptShown = false;
  let framesAdded = false;

  debug_tab_pane(STACK_URL, function(aTab, aDebuggee, aPane) {
    gTab = aTab;
    gDebuggee = aDebuggee;
    gPane = aPane;
    gDebugger = gPane.panelWin;

    gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
      let url = aEvent.detail.url;
      if (url.indexOf("browser_dbg_stack") != -1) {
        scriptShown = true;
        gDebugger.removeEventListener(aEvent.type, _onEvent);
        runTest();
      }
    });

    gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
      framesAdded = true;
      runTest();
    });

    gDebuggee.simpleCall();
  });

  function runTest()
  {
    if (scriptShown && framesAdded) {
      Services.tm.currentThread.dispatch({ run: testSimpleCall }, 0);
    }
  }
}

function testSimpleCall() {
  var frames = gDebugger.DebuggerView.StackFrames.widget._list,
      childNodes = frames.childNodes;

  is(gDebugger.DebuggerController.activeThread.state, "paused",
    "Should only be getting stack frames while paused.");

  is(frames.querySelectorAll(".dbg-stackframe").length, 1,
    "Should have only one frame.");

  is(childNodes.length, frames.querySelectorAll(".dbg-stackframe").length,
    "All children should be frames.");

  isnot(gDebugger.DebuggerView.Sources.selectedValue, null,
    "There should be a selected script.");
  isnot(gDebugger.editor.getText().length, 0,
    "The source editor should have some text displayed.");
  isnot(gDebugger.editor.getText(), gDebugger.L10N.getStr("loadingText"),
    "The source editor text should not be 'Loading...'");

  testLocationChange();
}

function testLocationChange()
{
  gDebugger.DebuggerController.activeThread.resume(function() {
    gDebugger.DebuggerController._target.once("navigate", function onTabNavigated(aEvent, aPacket) {
      ok(true, "tabNavigated event was fired.");
      info("Still attached to the tab.");

      gDebugger.addEventListener("Debugger:AfterSourcesAdded", function _onEvent(aEvent) {
        gDebugger.removeEventListener(aEvent.type, _onEvent);

        is(gDebugger.DebuggerView.Sources.selectedValue, "",
          "There should be no selected script.");
        is(gDebugger.editor.getText().length, 0,
          "The source editor not have any text displayed.");

        let menulist = gDebugger.DebuggerView.Sources.widget;
        let noScripts = gDebugger.L10N.getStr("noSourcesText");
        is(menulist.getAttribute("label"), noScripts,
          "The menulist should display a notice that there are no scripts availalble.");
        is(menulist.getAttribute("tooltiptext"), "",
          "The menulist shouldn't have any tooltip text attributed when there are no scripts available.");

        closeDebuggerAndFinish();
      });
    });
    content.location = "about:blank";
  });
}

registerCleanupFunction(function() {
  removeTab(gTab);
  gPane = null;
  gTab = null;
  gDebuggee = null;
  gDebugger = null;
});