browser/devtools/tilt/test/browser_tilt_02_notifications.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/tilt/test/browser_tilt_02_notifications.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,133 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +"use strict";
     1.7 +
     1.8 +let tab0, tab1;
     1.9 +let testStep = -1;
    1.10 +let tabEvents = "";
    1.11 +
    1.12 +function test() {
    1.13 +  if (!isTiltEnabled()) {
    1.14 +    info("Skipping notifications test because Tilt isn't enabled.");
    1.15 +    return;
    1.16 +  }
    1.17 +  if (!isWebGLSupported()) {
    1.18 +    info("Skipping notifications test because WebGL isn't supported.");
    1.19 +    return;
    1.20 +  }
    1.21 +
    1.22 +  requestLongerTimeout(10);
    1.23 +  waitForExplicitFinish();
    1.24 +
    1.25 +  gBrowser.tabContainer.addEventListener("TabSelect", tabSelect, false);
    1.26 +  createNewTab();
    1.27 +}
    1.28 +
    1.29 +function createNewTab() {
    1.30 +  tab0 = gBrowser.selectedTab;
    1.31 +
    1.32 +  tab1 = createTab(function() {
    1.33 +    Services.obs.addObserver(finalize, DESTROYED, false);
    1.34 +    Services.obs.addObserver(tab_STARTUP, STARTUP, false);
    1.35 +    Services.obs.addObserver(tab_INITIALIZING, INITIALIZING, false);
    1.36 +    Services.obs.addObserver(tab_DESTROYING, DESTROYING, false);
    1.37 +    Services.obs.addObserver(tab_SHOWN, SHOWN, false);
    1.38 +    Services.obs.addObserver(tab_HIDDEN, HIDDEN, false);
    1.39 +
    1.40 +    info("Starting up the Tilt notifications test.");
    1.41 +    createTilt({
    1.42 +      onTiltOpen: function()
    1.43 +      {
    1.44 +        testStep = 0;
    1.45 +        tabSelect();
    1.46 +      }
    1.47 +    }, false, function suddenDeath()
    1.48 +    {
    1.49 +      info("Tilt could not be initialized properly.");
    1.50 +      cleanup();
    1.51 +    });
    1.52 +  });
    1.53 +}
    1.54 +
    1.55 +function tab_STARTUP(win) {
    1.56 +  info("Handling the STARTUP notification.");
    1.57 +  is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window");
    1.58 +  tabEvents += "STARTUP;";
    1.59 +}
    1.60 +
    1.61 +function tab_INITIALIZING(win) {
    1.62 +  info("Handling the INITIALIZING notification.");
    1.63 +  is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window");
    1.64 +  tabEvents += "INITIALIZING;";
    1.65 +}
    1.66 +
    1.67 +function tab_DESTROYING(win) {
    1.68 +  info("Handling the DESTROYING notification.");
    1.69 +  is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window");
    1.70 +  tabEvents += "DESTROYING;";
    1.71 +}
    1.72 +
    1.73 +function tab_SHOWN(win) {
    1.74 +  info("Handling the SHOWN notification.");
    1.75 +  is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window");
    1.76 +  tabEvents += "SHOWN;";
    1.77 +}
    1.78 +
    1.79 +function tab_HIDDEN(win) {
    1.80 +  info("Handling the HIDDEN notification.");
    1.81 +  is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window");
    1.82 +  tabEvents += "HIDDEN;";
    1.83 +}
    1.84 +
    1.85 +let testSteps = [
    1.86 +  function step0() {
    1.87 +    info("Selecting tab0.");
    1.88 +    gBrowser.selectedTab = tab0;
    1.89 +  },
    1.90 +  function step1() {
    1.91 +    info("Selecting tab1.");
    1.92 +    gBrowser.selectedTab = tab1;
    1.93 +  },
    1.94 +  function step2() {
    1.95 +    info("Killing it.");
    1.96 +    Tilt.destroy(Tilt.currentWindowId, true);
    1.97 +  }
    1.98 +];
    1.99 +
   1.100 +function finalize(win) {
   1.101 +  if (!tabEvents) {
   1.102 +    return;
   1.103 +  }
   1.104 +
   1.105 +  is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window");
   1.106 +
   1.107 +  is(tabEvents, "STARTUP;INITIALIZING;HIDDEN;SHOWN;DESTROYING;",
   1.108 +    "The notifications weren't fired in the correct order.");
   1.109 +
   1.110 +  cleanup();
   1.111 +}
   1.112 +
   1.113 +function cleanup() {
   1.114 +  info("Cleaning up the notifications test.");
   1.115 +
   1.116 +  tab0 = null;
   1.117 +  tab1 = null;
   1.118 +
   1.119 +  Services.obs.removeObserver(finalize, DESTROYED);
   1.120 +  Services.obs.removeObserver(tab_INITIALIZING, INITIALIZING);
   1.121 +  Services.obs.removeObserver(tab_DESTROYING, DESTROYING);
   1.122 +  Services.obs.removeObserver(tab_SHOWN, SHOWN);
   1.123 +  Services.obs.removeObserver(tab_HIDDEN, HIDDEN);
   1.124 +  Services.obs.removeObserver(tab_STARTUP, STARTUP);
   1.125 +
   1.126 +  gBrowser.tabContainer.removeEventListener("TabSelect", tabSelect);
   1.127 +  gBrowser.removeCurrentTab();
   1.128 +  finish();
   1.129 +}
   1.130 +
   1.131 +function tabSelect() {
   1.132 +  if (testStep !== -1) {
   1.133 +    executeSoon(testSteps[testStep]);
   1.134 +    testStep++;
   1.135 +  }
   1.136 +}

mercurial