browser/devtools/tilt/test/browser_tilt_02_notifications-seq.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 tabEvents = "";
     7 function test() {
     8   if (!isTiltEnabled()) {
     9     info("Skipping notifications test because Tilt isn't enabled.");
    10     return;
    11   }
    12   if (!isWebGLSupported()) {
    13     info("Skipping notifications test because WebGL isn't supported.");
    14     return;
    15   }
    17   requestLongerTimeout(10);
    18   waitForExplicitFinish();
    20   createTab(function() {
    21     Services.obs.addObserver(finalize, DESTROYED, false);
    22     Services.obs.addObserver(obs_STARTUP, STARTUP, false);
    23     Services.obs.addObserver(obs_INITIALIZING, INITIALIZING, false);
    24     Services.obs.addObserver(obs_INITIALIZED, INITIALIZED, false);
    25     Services.obs.addObserver(obs_DESTROYING, DESTROYING, false);
    26     Services.obs.addObserver(obs_BEFORE_DESTROYED, BEFORE_DESTROYED, false);
    27     Services.obs.addObserver(obs_DESTROYED, DESTROYED, false);
    29     info("Starting up the Tilt notifications test.");
    30     createTilt({}, false, function suddenDeath()
    31     {
    32       info("Tilt could not be initialized properly.");
    33       cleanup();
    34     });
    35   });
    36 }
    38 function obs_STARTUP(win) {
    39   info("Handling the STARTUP notification.");
    40   is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window");
    41   tabEvents += "STARTUP;";
    42 }
    44 function obs_INITIALIZING(win) {
    45   info("Handling the INITIALIZING notification.");
    46   is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window");
    47   tabEvents += "INITIALIZING;";
    48 }
    50 function obs_INITIALIZED(win) {
    51   info("Handling the INITIALIZED notification.");
    52   is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window");
    53   tabEvents += "INITIALIZED;";
    55   Tilt.destroy(Tilt.currentWindowId, true);
    56 }
    58 function obs_DESTROYING(win) {
    59   info("Handling the DESTROYING( notification.");
    60   is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window");
    61   tabEvents += "DESTROYING;";
    62 }
    64 function obs_BEFORE_DESTROYED(win) {
    65   info("Handling the BEFORE_DESTROYED notification.");
    66   is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window");
    67   tabEvents += "BEFORE_DESTROYED;";
    68 }
    70 function obs_DESTROYED(win) {
    71   info("Handling the DESTROYED notification.");
    72   is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window");
    73   tabEvents += "DESTROYED;";
    74 }
    76 function finalize(win) {
    77   if (!tabEvents) {
    78     return;
    79   }
    81   is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window");
    82   is(tabEvents, "STARTUP;INITIALIZING;INITIALIZED;DESTROYING;BEFORE_DESTROYED;DESTROYED;",
    83     "The notifications weren't fired in the correct order.");
    85   cleanup();
    86 }
    88 function cleanup() {
    89   info("Cleaning up the notifications test.");
    91   Services.obs.removeObserver(finalize, DESTROYED);
    92   Services.obs.removeObserver(obs_INITIALIZING, INITIALIZING);
    93   Services.obs.removeObserver(obs_INITIALIZED, INITIALIZED);
    94   Services.obs.removeObserver(obs_DESTROYING, DESTROYING);
    95   Services.obs.removeObserver(obs_BEFORE_DESTROYED, BEFORE_DESTROYED);
    96   Services.obs.removeObserver(obs_DESTROYED, DESTROYED);
    97   Services.obs.removeObserver(obs_STARTUP, STARTUP);
    99   gBrowser.removeCurrentTab();
   100   finish();
   101 }

mercurial