summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg_variables-view-map-set.js
blob: 0c301c683ca7680f9b4bce55b95cd94d61d7d76c (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
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Test that Map and Set and their Weak friends are displayed in variables view.
 */

"use strict";

const TAB_URL = EXAMPLE_URL + "doc_map-set.html";

var test = Task.async(function* () {
  let options = {
    source: TAB_URL,
    line: 1
  };
  const [tab,, panel] = yield initDebugger(TAB_URL, options);

  const scopes = waitForCaretAndScopes(panel, 37);
  callInTab(tab, "startTest");
  yield scopes;

  const variables = panel.panelWin.DebuggerView.Variables;
  ok(variables, "Should get the variables view.");

  const scope = variables.getScopeAtIndex(0);
  ok(scope, "Should get the current function's scope.");

  /* Test the maps */
  for (let varName of ["map", "weakMap"]) {
    const mapVar = scope.get(varName);
    ok(mapVar, `Retrieved the '${varName}' variable from the scope`);

    info(`Expanding '${varName}' variable`);
    yield mapVar.expand();

    const entries = mapVar.get("<entries>");
    ok(entries, `Retrieved the '${varName}' entries`);

    info(`Expanding '${varName}' entries`);
    yield entries.expand();

    // Check the entries. WeakMap returns its entries in a nondeterministic
    // order, so we make our job easier by not testing the exact values.
    let i = 0;
    for (let [ name, entry ] of entries) {
      is(name, i, `The '${varName}' entry's property name is correct`);
      ok(entry.displayValue.startsWith("Object \u2192 "),
        `The '${varName}' entry's property value is correct`);
      yield entry.expand();

      let key = entry.get("key");
      ok(key, `The '${varName}' entry has the 'key' property`);
      yield key.expand();

      let keyProperty = key.get("a");
      ok(keyProperty,
        `The '${varName}' entry's 'key' has the correct property`);

      let value = entry.get("value");
      ok(value, `The '${varName}' entry has the 'value' property`);

      i++;
    }

    is(i, 2, `The '${varName}' entry count is correct`);

    // Check the extra property on the object
    let extraProp = mapVar.get("extraProp");
    ok(extraProp, `Retrieved the '${varName}' extraProp`);
    is(extraProp.displayValue, "true",
      `The '${varName}' extraProp's value is correct`);
  }

  /* Test the sets */
  for (let varName of ["set", "weakSet"]) {
    const setVar = scope.get(varName);
    ok(setVar, `Retrieved the '${varName}' variable from the scope`);

    info(`Expanding '${varName}' variable`);
    yield setVar.expand();

    const entries = setVar.get("<entries>");
    ok(entries, `Retrieved the '${varName}' entries`);

    info(`Expanding '${varName}' entries`);
    yield entries.expand();

    // Check the entries. WeakSet returns its entries in a nondeterministic
    // order, so we make our job easier by not testing the exact values.
    let i = 0;
    for (let [ name, entry ] of entries) {
      is(name, i, `The '${varName}' entry's property name is correct`);
      is(entry.displayValue, "Object",
        `The '${varName}' entry's property value is correct`);
      yield entry.expand();

      let entryProperty = entry.get("a");
      ok(entryProperty,
        `The '${varName}' entry's value has the correct property`);

      i++;
    }

    is(i, 2, `The '${varName}' entry count is correct`);

    // Check the extra property on the object
    let extraProp = setVar.get("extraProp");
    ok(extraProp, `Retrieved the '${varName}' extraProp`);
    is(extraProp.displayValue, "true",
      `The '${varName}' extraProp's value is correct`);
  }

  resumeDebuggerThenCloseAndFinish(panel);
});