browser_webconsole_closure_inspection.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. // Check that inspecting a closure in the variables view sidebar works when
  5. // execution is paused.
  6. "use strict";
  7. const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
  8. "test/test-closures.html";
  9. var gWebConsole, gJSTerm, gVariablesView;
  10. // Force the old debugger UI since it's directly used (see Bug 1301705)
  11. Services.prefs.setBoolPref("devtools.debugger.new-debugger-frontend", false);
  12. registerCleanupFunction(function* () {
  13. Services.prefs.clearUserPref("devtools.debugger.new-debugger-frontend");
  14. });
  15. function test() {
  16. registerCleanupFunction(() => {
  17. gWebConsole = gJSTerm = gVariablesView = null;
  18. });
  19. function fetchScopes(hud, toolbox, panelWin, deferred) {
  20. panelWin.once(panelWin.EVENTS.FETCHED_SCOPES, () => {
  21. ok(true, "Scopes were fetched");
  22. toolbox.selectTool("webconsole").then(() => consoleOpened(hud));
  23. deferred.resolve();
  24. });
  25. }
  26. loadTab(TEST_URI).then(() => {
  27. openConsole().then((hud) => {
  28. openDebugger().then(({ toolbox, panelWin }) => {
  29. let deferred = promise.defer();
  30. fetchScopes(hud, toolbox, panelWin, deferred);
  31. ContentTask.spawn(gBrowser.selectedBrowser, {}, function* () {
  32. let button = content.document.querySelector("button");
  33. ok(button, "button element found");
  34. button.click();
  35. });
  36. return deferred.promise;
  37. });
  38. });
  39. });
  40. }
  41. function consoleOpened(hud) {
  42. gWebConsole = hud;
  43. gJSTerm = hud.jsterm;
  44. gJSTerm.execute("window.george.getName");
  45. waitForMessages({
  46. webconsole: gWebConsole,
  47. messages: [{
  48. text: "getName()",
  49. category: CATEGORY_OUTPUT,
  50. objects: true,
  51. }],
  52. }).then(onExecuteGetName);
  53. }
  54. function onExecuteGetName(results) {
  55. let clickable = results[0].clickableElements[0];
  56. ok(clickable, "clickable object found");
  57. gJSTerm.once("variablesview-fetched", onGetNameFetch);
  58. let contextMenu =
  59. gWebConsole.iframeWindow.document.getElementById("output-contextmenu");
  60. waitForContextMenu(contextMenu, clickable, () => {
  61. let openInVarView = contextMenu.querySelector("#menu_openInVarView");
  62. ok(openInVarView.disabled === false,
  63. "the \"Open In Variables View\" context menu item should be clickable");
  64. // EventUtils.synthesizeMouseAtCenter seems to fail here in Mac OSX
  65. openInVarView.click();
  66. });
  67. }
  68. function onGetNameFetch(evt, view) {
  69. gVariablesView = view._variablesView;
  70. ok(gVariablesView, "variables view object");
  71. findVariableViewProperties(view, [
  72. { name: /_pfactory/, value: "" },
  73. ], { webconsole: gWebConsole }).then(onExpandClosure);
  74. }
  75. function onExpandClosure(results) {
  76. let prop = results[0].matchedProp;
  77. ok(prop, "matched the name property in the variables view");
  78. gVariablesView.window.focus();
  79. gJSTerm.once("sidebar-closed", finishTest);
  80. EventUtils.synthesizeKey("VK_ESCAPE", {}, gVariablesView.window);
  81. }