browser_console_dead_objects.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 Dead Objects do not break the Web/Browser Consoles.
  5. // See bug 883649.
  6. // This test does:
  7. // - opens a new tab,
  8. // - opens the Browser Console,
  9. // - stores a reference to the content document of the tab on the chrome
  10. // window object,
  11. // - closes the tab,
  12. // - tries to use the object that was pointing to the now-defunct content
  13. // document. This is the dead object.
  14. "use strict";
  15. const TEST_URI = "data:text/html;charset=utf8,<p>dead objects!";
  16. function test() {
  17. let hud = null;
  18. registerCleanupFunction(() => {
  19. Services.prefs.clearUserPref("devtools.chrome.enabled");
  20. });
  21. Task.spawn(runner).then(finishTest);
  22. function* runner() {
  23. Services.prefs.setBoolPref("devtools.chrome.enabled", true);
  24. yield loadTab(TEST_URI);
  25. info("open the browser console");
  26. hud = yield HUDService.toggleBrowserConsole();
  27. ok(hud, "browser console opened");
  28. let jsterm = hud.jsterm;
  29. jsterm.clearOutput();
  30. // Add the reference to the content document.
  31. yield jsterm.execute("Cu = Components.utils;" +
  32. "Cu.import('resource://gre/modules/Services.jsm');" +
  33. "chromeWindow = Services.wm.getMostRecentWindow('" +
  34. "navigator:browser');" +
  35. "foobarzTezt = chromeWindow.content.document;" +
  36. "delete chromeWindow");
  37. gBrowser.removeCurrentTab();
  38. let msg = yield jsterm.execute("foobarzTezt");
  39. isnot(hud.outputNode.textContent.indexOf("[object DeadObject]"), -1,
  40. "dead object found");
  41. jsterm.setInputValue("foobarzTezt");
  42. for (let c of ".hello") {
  43. EventUtils.synthesizeKey(c, {}, hud.iframeWindow);
  44. }
  45. yield jsterm.execute();
  46. isnot(hud.outputNode.textContent.indexOf("can't access dead object"), -1,
  47. "'cannot access dead object' message found");
  48. // Click the second execute output.
  49. let clickable = msg.querySelector("a");
  50. ok(clickable, "clickable object found");
  51. isnot(clickable.textContent.indexOf("[object DeadObject]"), -1,
  52. "message text check");
  53. msg.scrollIntoView();
  54. executeSoon(() => {
  55. EventUtils.synthesizeMouseAtCenter(clickable, {}, hud.iframeWindow);
  56. });
  57. yield jsterm.once("variablesview-fetched");
  58. ok(true, "variables view fetched");
  59. msg = yield jsterm.execute("delete window.foobarzTezt; 2013-26");
  60. isnot(msg.textContent.indexOf("1987"), -1, "result message found");
  61. }
  62. }