summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg_variables-view-frame-parameters-03.js
blob: 6151535318266f72fa00990539acf8194fbe195e (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
/* -*- 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 the variables view displays the right variables and
 * properties in the global scope when debugger is paused.
 */

const TAB_URL = EXAMPLE_URL + "doc_frame-parameters.html";

var gTab, gPanel, gDebugger;
var gVariables;

function test() {
  // Debug test slaves are a bit slow at this test.
  requestLongerTimeout(2);

  let options = {
    source: TAB_URL,
    line: 1
  };
  initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
    gTab = aTab;
    gPanel = aPanel;
    gDebugger = gPanel.panelWin;
    gVariables = gDebugger.DebuggerView.Variables;

    waitForCaretAndScopes(gPanel, 24)
      .then(expandGlobalScope)
      .then(testGlobalScope)
      .then(expandWindowVariable)
      .then(testWindowVariable)
      .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
      .then(null, aError => {
        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
      });

    generateMouseClickInTab(gTab, "content.document.querySelector('button')");
  });
}

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

  let globalScope = gVariables.getScopeAtIndex(2);
  is(globalScope.expanded, false,
    "The global scope should not be expanded by default.");

  gDebugger.once(gDebugger.EVENTS.FETCHED_VARIABLES, deferred.resolve);

  EventUtils.sendMouseEvent({ type: "mousedown" },
    globalScope.target.querySelector(".name"),
    gDebugger);

  return deferred.promise;
}

function testGlobalScope() {
  let globalScope = gVariables.getScopeAtIndex(2);
  is(globalScope.expanded, true,
    "The global scope should now be expanded.");

  is(globalScope.get("InstallTrigger").target.querySelector(".name").getAttribute("value"), "InstallTrigger",
    "Should have the right property name for 'InstallTrigger'.");
  is(globalScope.get("InstallTrigger").target.querySelector(".value").getAttribute("value"), "InstallTriggerImpl",
    "Should have the right property value for 'InstallTrigger'.");

  is(globalScope.get("SpecialPowers").target.querySelector(".name").getAttribute("value"), "SpecialPowers",
    "Should have the right property name for 'SpecialPowers'.");
  is(globalScope.get("SpecialPowers").target.querySelector(".value").getAttribute("value"), "Object",
    "Should have the right property value for 'SpecialPowers'.");

  is(globalScope.get("window").target.querySelector(".name").getAttribute("value"), "window",
    "Should have the right property name for 'window'.");
  is(globalScope.get("window").target.querySelector(".value").getAttribute("value"),
    "Window \u2192 doc_frame-parameters.html",
    "Should have the right property value for 'window'.");

  is(globalScope.get("document").target.querySelector(".name").getAttribute("value"), "document",
    "Should have the right property name for 'document'.");
  is(globalScope.get("document").target.querySelector(".value").getAttribute("value"),
    "HTMLDocument \u2192 doc_frame-parameters.html",
    "Should have the right property value for 'document'.");

  is(globalScope.get("undefined").target.querySelector(".name").getAttribute("value"), "undefined",
    "Should have the right property name for 'undefined'.");
  is(globalScope.get("undefined").target.querySelector(".value").getAttribute("value"), "undefined",
    "Should have the right property value for 'undefined'.");

  is(globalScope.get("undefined").target.querySelector(".enum").childNodes.length, 0,
    "Should have no child enumerable properties for 'undefined'.");
  is(globalScope.get("undefined").target.querySelector(".nonenum").childNodes.length, 0,
    "Should have no child non-enumerable properties for 'undefined'.");
}

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

  let windowVar = gVariables.getScopeAtIndex(2).get("window");
  is(windowVar.expanded, false,
    "The window variable should not be expanded by default.");

  gDebugger.once(gDebugger.EVENTS.FETCHED_PROPERTIES, deferred.resolve);

  EventUtils.sendMouseEvent({ type: "mousedown" },
    windowVar.target.querySelector(".name"),
    gDebugger);

  return deferred.promise;
}

function testWindowVariable() {
  let windowVar = gVariables.getScopeAtIndex(2).get("window");
  is(windowVar.expanded, true,
    "The window variable should now be expanded.");

  is(windowVar.get("InstallTrigger").target.querySelector(".name").getAttribute("value"), "InstallTrigger",
    "Should have the right property name for 'InstallTrigger'.");
  is(windowVar.get("InstallTrigger").target.querySelector(".value").getAttribute("value"), "InstallTriggerImpl",
    "Should have the right property value for 'InstallTrigger'.");

  is(windowVar.get("SpecialPowers").target.querySelector(".name").getAttribute("value"), "SpecialPowers",
    "Should have the right property name for 'SpecialPowers'.");
  is(windowVar.get("SpecialPowers").target.querySelector(".value").getAttribute("value"), "Object",
    "Should have the right property value for 'SpecialPowers'.");

  is(windowVar.get("window").target.querySelector(".name").getAttribute("value"), "window",
    "Should have the right property name for 'window'.");
  is(windowVar.get("window").target.querySelector(".value").getAttribute("value"),
    "Window \u2192 doc_frame-parameters.html",
    "Should have the right property value for 'window'.");

  is(windowVar.get("document").target.querySelector(".name").getAttribute("value"), "document",
    "Should have the right property name for 'document'.");
  is(windowVar.get("document").target.querySelector(".value").getAttribute("value"),
    "HTMLDocument \u2192 doc_frame-parameters.html",
    "Should have the right property value for 'document'.");

  is(windowVar.get("undefined").target.querySelector(".name").getAttribute("value"), "undefined",
    "Should have the right property name for 'undefined'.");
  is(windowVar.get("undefined").target.querySelector(".value").getAttribute("value"), "undefined",
    "Should have the right property value for 'undefined'.");

  is(windowVar.get("undefined").target.querySelector(".enum").childNodes.length, 0,
    "Should have no child enumerable properties for 'undefined'.");
  is(windowVar.get("undefined").target.querySelector(".nonenum").childNodes.length, 0,
    "Should have no child non-enumerable properties for 'undefined'.");
}

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