browser_dbg_variables-view-map-set.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* Any copyright is dedicated to the Public Domain.
  3. * http://creativecommons.org/publicdomain/zero/1.0/ */
  4. /**
  5. * Test that Map and Set and their Weak friends are displayed in variables view.
  6. */
  7. "use strict";
  8. const TAB_URL = EXAMPLE_URL + "doc_map-set.html";
  9. var test = Task.async(function* () {
  10. let options = {
  11. source: TAB_URL,
  12. line: 1
  13. };
  14. const [tab,, panel] = yield initDebugger(TAB_URL, options);
  15. const scopes = waitForCaretAndScopes(panel, 37);
  16. callInTab(tab, "startTest");
  17. yield scopes;
  18. const variables = panel.panelWin.DebuggerView.Variables;
  19. ok(variables, "Should get the variables view.");
  20. const scope = variables.getScopeAtIndex(0);
  21. ok(scope, "Should get the current function's scope.");
  22. /* Test the maps */
  23. for (let varName of ["map", "weakMap"]) {
  24. const mapVar = scope.get(varName);
  25. ok(mapVar, `Retrieved the '${varName}' variable from the scope`);
  26. info(`Expanding '${varName}' variable`);
  27. yield mapVar.expand();
  28. const entries = mapVar.get("<entries>");
  29. ok(entries, `Retrieved the '${varName}' entries`);
  30. info(`Expanding '${varName}' entries`);
  31. yield entries.expand();
  32. // Check the entries. WeakMap returns its entries in a nondeterministic
  33. // order, so we make our job easier by not testing the exact values.
  34. let i = 0;
  35. for (let [ name, entry ] of entries) {
  36. is(name, i, `The '${varName}' entry's property name is correct`);
  37. ok(entry.displayValue.startsWith("Object \u2192 "),
  38. `The '${varName}' entry's property value is correct`);
  39. yield entry.expand();
  40. let key = entry.get("key");
  41. ok(key, `The '${varName}' entry has the 'key' property`);
  42. yield key.expand();
  43. let keyProperty = key.get("a");
  44. ok(keyProperty,
  45. `The '${varName}' entry's 'key' has the correct property`);
  46. let value = entry.get("value");
  47. ok(value, `The '${varName}' entry has the 'value' property`);
  48. i++;
  49. }
  50. is(i, 2, `The '${varName}' entry count is correct`);
  51. // Check the extra property on the object
  52. let extraProp = mapVar.get("extraProp");
  53. ok(extraProp, `Retrieved the '${varName}' extraProp`);
  54. is(extraProp.displayValue, "true",
  55. `The '${varName}' extraProp's value is correct`);
  56. }
  57. /* Test the sets */
  58. for (let varName of ["set", "weakSet"]) {
  59. const setVar = scope.get(varName);
  60. ok(setVar, `Retrieved the '${varName}' variable from the scope`);
  61. info(`Expanding '${varName}' variable`);
  62. yield setVar.expand();
  63. const entries = setVar.get("<entries>");
  64. ok(entries, `Retrieved the '${varName}' entries`);
  65. info(`Expanding '${varName}' entries`);
  66. yield entries.expand();
  67. // Check the entries. WeakSet returns its entries in a nondeterministic
  68. // order, so we make our job easier by not testing the exact values.
  69. let i = 0;
  70. for (let [ name, entry ] of entries) {
  71. is(name, i, `The '${varName}' entry's property name is correct`);
  72. is(entry.displayValue, "Object",
  73. `The '${varName}' entry's property value is correct`);
  74. yield entry.expand();
  75. let entryProperty = entry.get("a");
  76. ok(entryProperty,
  77. `The '${varName}' entry's value has the correct property`);
  78. i++;
  79. }
  80. is(i, 2, `The '${varName}' entry count is correct`);
  81. // Check the extra property on the object
  82. let extraProp = setVar.get("extraProp");
  83. ok(extraProp, `Retrieved the '${varName}' extraProp`);
  84. is(extraProp.displayValue, "true",
  85. `The '${varName}' extraProp's value is correct`);
  86. }
  87. resumeDebuggerThenCloseAndFinish(panel);
  88. });