summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg_clean-exit-window.js
blob: 63ce96a3c7c87960af5e5f309992b73f3261c2f5 (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
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Test that closing a window with the debugger in a paused state exits cleanly.
 */

var gDebuggee, gPanel, gDebugger, gWindow;

const TAB_URL = EXAMPLE_URL + "doc_inline-debugger-statement.html";

function test() {
  addWindow(TAB_URL)
    .then(win => initDebugger(TAB_URL, { window: win }))
    .then(([aTab, aDebuggee, aPanel, aWindow]) => {
      gDebuggee = aDebuggee;
      gPanel = aPanel;
      gDebugger = gPanel.panelWin;
      gWindow = aWindow;

      return testCleanExit();
    })
    .then(null, aError => {
      ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    });
}

function testCleanExit() {
  let deferred = promise.defer();

  ok(!!gWindow, "Second window created.");

  gWindow.focus();

  is(Services.wm.getMostRecentWindow("navigator:browser"), gWindow,
    "The second window is on top.");

  let isActive = promise.defer();
  let isLoaded = promise.defer();

  promise.all([isActive.promise, isLoaded.promise]).then(() => {
    waitForSourceAndCaretAndScopes(gPanel, ".html", 16).then(() => {
      is(gDebugger.gThreadClient.paused, true,
        "Should be paused after the debugger statement.");
      gWindow.close();
      deferred.resolve();
      finish();
    });

    gDebuggee.runDebuggerStatement();
  });

  if (Services.focus.activeWindow != gWindow) {
    gWindow.addEventListener("activate", function onActivate(aEvent) {
      if (aEvent.target != gWindow) {
        return;
      }
      gWindow.removeEventListener("activate", onActivate, true);
      isActive.resolve();
    }, true);
  } else {
    isActive.resolve();
  }

  if (gWindow.content.location.href != TAB_URL) {
    gWindow.document.addEventListener("load", function onLoad(aEvent) {
      if (aEvent.target.documentURI != TAB_URL) {
        return;
      }
      gWindow.document.removeEventListener("load", onLoad, true);
      isLoaded.resolve();
    }, true);
  } else {
    isLoaded.resolve();
  }
  return deferred.promise;
}

registerCleanupFunction(function () {
  gWindow = null;
  gDebuggee = null;
  gPanel = null;
  gDebugger = null;
});