browser/devtools/debugger/test/browser_dbg_clean-exit-window.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/debugger/test/browser_dbg_clean-exit-window.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,87 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Test that closing a window with the debugger in a paused state exits cleanly.
     1.9 + */
    1.10 +
    1.11 +let gDebuggee, gPanel, gDebugger, gWindow;
    1.12 +
    1.13 +const TAB_URL = EXAMPLE_URL + "doc_inline-debugger-statement.html";
    1.14 +
    1.15 +function test() {
    1.16 +  addWindow(TAB_URL)
    1.17 +    .then(win => initDebugger(TAB_URL, win))
    1.18 +    .then(([aTab, aDebuggee, aPanel, aWindow]) => {
    1.19 +      gDebuggee = aDebuggee;
    1.20 +      gPanel = aPanel;
    1.21 +      gDebugger = gPanel.panelWin;
    1.22 +      gWindow = aWindow;
    1.23 +
    1.24 +      return testCleanExit();
    1.25 +    })
    1.26 +    .then(null, aError => {
    1.27 +      ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    1.28 +    });
    1.29 +}
    1.30 +
    1.31 +function testCleanExit() {
    1.32 +  let deferred = promise.defer();
    1.33 +
    1.34 +  ok(!!gWindow, "Second window created.");
    1.35 +
    1.36 +  gWindow.focus();
    1.37 +
    1.38 +  is(Services.wm.getMostRecentWindow("navigator:browser"), gWindow,
    1.39 +    "The second window is on top.");
    1.40 +
    1.41 +  let isActive = promise.defer();
    1.42 +  let isLoaded = promise.defer();
    1.43 +
    1.44 +  promise.all([isActive.promise, isLoaded.promise]).then(() => {
    1.45 +    gWindow.BrowserChromeTest.runWhenReady(() => {
    1.46 +      waitForSourceAndCaretAndScopes(gPanel, ".html", 16).then(() => {
    1.47 +        is(gDebugger.gThreadClient.paused, true,
    1.48 +          "Should be paused after the debugger statement.");
    1.49 +        gWindow.close();
    1.50 +        deferred.resolve();
    1.51 +        finish();
    1.52 +      });
    1.53 +
    1.54 +      gDebuggee.runDebuggerStatement();
    1.55 +    });
    1.56 +  });
    1.57 +
    1.58 +  let focusManager = Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager);
    1.59 +  if (focusManager.activeWindow != gWindow) {
    1.60 +    gWindow.addEventListener("activate", function onActivate(aEvent) {
    1.61 +      if (aEvent.target != gWindow) {
    1.62 +        return;
    1.63 +      }
    1.64 +      gWindow.removeEventListener("activate", onActivate, true);
    1.65 +      isActive.resolve();
    1.66 +    }, true);
    1.67 +  } else {
    1.68 +    isActive.resolve();
    1.69 +  }
    1.70 +
    1.71 +  if (gWindow.content.location.href != TAB_URL) {
    1.72 +    gWindow.document.addEventListener("load", function onLoad(aEvent) {
    1.73 +      if (aEvent.target.documentURI != TAB_URL) {
    1.74 +        return;
    1.75 +      }
    1.76 +      gWindow.document.removeEventListener("load", onLoad, true);
    1.77 +      isLoaded.resolve();
    1.78 +    }, true);
    1.79 +  } else {
    1.80 +    isLoaded.resolve();
    1.81 +  }
    1.82 +  return deferred.promise;
    1.83 +}
    1.84 +
    1.85 +registerCleanupFunction(function() {
    1.86 +  gWindow = null;
    1.87 +  gDebuggee = null;
    1.88 +  gPanel = null;
    1.89 +  gDebugger = null;
    1.90 +});

mercurial