browser/devtools/tilt/test/browser_tilt_02_notifications.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     3 "use strict";
     5 let tab0, tab1;
     6 let testStep = -1;
     7 let tabEvents = "";
     9 function test() {
    10   if (!isTiltEnabled()) {
    11     info("Skipping notifications test because Tilt isn't enabled.");
    12     return;
    13   }
    14   if (!isWebGLSupported()) {
    15     info("Skipping notifications test because WebGL isn't supported.");
    16     return;
    17   }
    19   requestLongerTimeout(10);
    20   waitForExplicitFinish();
    22   gBrowser.tabContainer.addEventListener("TabSelect", tabSelect, false);
    23   createNewTab();
    24 }
    26 function createNewTab() {
    27   tab0 = gBrowser.selectedTab;
    29   tab1 = createTab(function() {
    30     Services.obs.addObserver(finalize, DESTROYED, false);
    31     Services.obs.addObserver(tab_STARTUP, STARTUP, false);
    32     Services.obs.addObserver(tab_INITIALIZING, INITIALIZING, false);
    33     Services.obs.addObserver(tab_DESTROYING, DESTROYING, false);
    34     Services.obs.addObserver(tab_SHOWN, SHOWN, false);
    35     Services.obs.addObserver(tab_HIDDEN, HIDDEN, false);
    37     info("Starting up the Tilt notifications test.");
    38     createTilt({
    39       onTiltOpen: function()
    40       {
    41         testStep = 0;
    42         tabSelect();
    43       }
    44     }, false, function suddenDeath()
    45     {
    46       info("Tilt could not be initialized properly.");
    47       cleanup();
    48     });
    49   });
    50 }
    52 function tab_STARTUP(win) {
    53   info("Handling the STARTUP notification.");
    54   is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window");
    55   tabEvents += "STARTUP;";
    56 }
    58 function tab_INITIALIZING(win) {
    59   info("Handling the INITIALIZING notification.");
    60   is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window");
    61   tabEvents += "INITIALIZING;";
    62 }
    64 function tab_DESTROYING(win) {
    65   info("Handling the DESTROYING notification.");
    66   is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window");
    67   tabEvents += "DESTROYING;";
    68 }
    70 function tab_SHOWN(win) {
    71   info("Handling the SHOWN notification.");
    72   is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window");
    73   tabEvents += "SHOWN;";
    74 }
    76 function tab_HIDDEN(win) {
    77   info("Handling the HIDDEN notification.");
    78   is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window");
    79   tabEvents += "HIDDEN;";
    80 }
    82 let testSteps = [
    83   function step0() {
    84     info("Selecting tab0.");
    85     gBrowser.selectedTab = tab0;
    86   },
    87   function step1() {
    88     info("Selecting tab1.");
    89     gBrowser.selectedTab = tab1;
    90   },
    91   function step2() {
    92     info("Killing it.");
    93     Tilt.destroy(Tilt.currentWindowId, true);
    94   }
    95 ];
    97 function finalize(win) {
    98   if (!tabEvents) {
    99     return;
   100   }
   102   is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window");
   104   is(tabEvents, "STARTUP;INITIALIZING;HIDDEN;SHOWN;DESTROYING;",
   105     "The notifications weren't fired in the correct order.");
   107   cleanup();
   108 }
   110 function cleanup() {
   111   info("Cleaning up the notifications test.");
   113   tab0 = null;
   114   tab1 = null;
   116   Services.obs.removeObserver(finalize, DESTROYED);
   117   Services.obs.removeObserver(tab_INITIALIZING, INITIALIZING);
   118   Services.obs.removeObserver(tab_DESTROYING, DESTROYING);
   119   Services.obs.removeObserver(tab_SHOWN, SHOWN);
   120   Services.obs.removeObserver(tab_HIDDEN, HIDDEN);
   121   Services.obs.removeObserver(tab_STARTUP, STARTUP);
   123   gBrowser.tabContainer.removeEventListener("TabSelect", tabSelect);
   124   gBrowser.removeCurrentTab();
   125   finish();
   126 }
   128 function tabSelect() {
   129   if (testStep !== -1) {
   130     executeSoon(testSteps[testStep]);
   131     testStep++;
   132   }
   133 }

mercurial