summaryrefslogtreecommitdiff
path: root/browser/devtools/tilt/test/browser_tilt_05_destruction-esc.js
blob: 7e0fd57722be9575b6b9cc6c68c24dd0043dfba4 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

let tiltOpened = false;

function test() {
  if (!isTiltEnabled()) {
    aborting();
    info("Skipping destruction test because Tilt isn't enabled.");
    return;
  }
  if (!isWebGLSupported()) {
    aborting();
    info("Skipping destruction test because WebGL isn't supported.");
    return;
  }

  waitForExplicitFinish();

  createTab(function() {
    createTilt({
      onTiltOpen: function()
      {
        tiltOpened = true;

        Services.obs.addObserver(finalize, DESTROYED, false);
        EventUtils.sendKey("ESCAPE");
      }
    }, false, function suddenDeath()
    {
      ok(false, "Tilt could not be initialized properly.");
      cleanup();
    });
  });
}

function finalize() {
  let id = TiltUtils.getWindowId(gBrowser.selectedBrowser.contentWindow);

  is(Tilt.visualizers[id], null,
    "The current instance of the visualizer wasn't destroyed properly.");

  cleanup();
}

function cleanup() {
  if (tiltOpened) { Services.obs.removeObserver(finalize, DESTROYED); }
  gBrowser.removeCurrentTab();
  finish();
}