summaryrefslogtreecommitdiffstats
path: root/devtools/client/scratchpad/test/browser_scratchpad_inspect_primitives.js
blob: 914f0a6d8919fee0e72986fb3151d9aa2137c341 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// Test that inspecting primitive values uses the object inspector, not an
// inline comment.

var {Task} = require("devtools/shared/task");

function test() {
  const options = {
    tabContent: "test inspecting primitive values"
  };
  openTabAndScratchpad(options)
    .then(Task.async(runTests))
    .then(finish, console.error);
}

function* runTests([win, sp]) {
  // Inspect a number.
  yield checkResults(sp, 7);

  // Inspect a string.
  yield checkResults(sp, "foobar", true);

  // Inspect a boolean.
  yield checkResults(sp, true);
}

// Helper function that does the actual testing.
var checkResults = Task.async(function* (sp, value, isString = false) {
  let sourceValue = value;
  if (isString) {
    sourceValue = '"' + value + '"';
  }
  let source = "var foobar = " + sourceValue + "; foobar";
  sp.setText(source);
  yield sp.inspect();

  let sidebar = sp.sidebar;
  ok(sidebar.visible, "sidebar is open");

  let found = false;

  outer: for (let scope of sidebar.variablesView) {
    for (let [, obj] of scope) {
      for (let [, prop] of obj) {
        if (prop.name == "value" && prop.value == value) {
          found = true;
          break outer;
        }
      }
    }
  }

  ok(found, "found the value of " + value);

  let tabbox = sidebar._sidebar._tabbox;
  ok(!tabbox.hasAttribute("hidden"), "Scratchpad sidebar visible");
  sidebar.hide();
  ok(tabbox.hasAttribute("hidden"), "Scratchpad sidebar hidden");
});