browser/devtools/tilt/test/browser_tilt_02_notifications-tabs.js

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     3 "use strict";
     5 let tab0, tab1, tab2;
     6 let testStep = -1;
     8 let expected = [];
     9 function expect(notification, win) {
    10   expected.push({ notification: notification, window: win });
    11 }
    13 function notification(win, topic) {
    14   if (expected.length == 0) {
    15     is(topic, null, "Shouldn't see a notification");
    16     return;
    17   }
    19   let { notification, window } = expected.shift();
    20   is(topic, notification, "Saw the expected notification");
    21   is(win, window, "Saw the expected window");
    22 }
    24 function after(notification, callback) {
    25   function observer() {
    26     Services.obs.removeObserver(observer, notification);
    27     executeSoon(callback);
    28   }
    29   Services.obs.addObserver(observer, notification, false);
    30 }
    32 function test() {
    33   if (!isTiltEnabled()) {
    34     info("Skipping tab switch test because Tilt isn't enabled.");
    35     return;
    36   }
    37   if (!isWebGLSupported()) {
    38     info("Skipping tab switch test because WebGL isn't supported.");
    39     return;
    40   }
    42   Services.obs.addObserver(notification, STARTUP, false);
    43   Services.obs.addObserver(notification, INITIALIZING, false);
    44   Services.obs.addObserver(notification, INITIALIZED, false);
    45   Services.obs.addObserver(notification, DESTROYING, false);
    46   Services.obs.addObserver(notification, BEFORE_DESTROYED, false);
    47   Services.obs.addObserver(notification, DESTROYED, false);
    48   Services.obs.addObserver(notification, SHOWN, false);
    49   Services.obs.addObserver(notification, HIDDEN, false);
    51   waitForExplicitFinish();
    53   tab0 = gBrowser.selectedTab;
    54   nextStep();
    55 }
    57 function createTab2() {
    58 }
    60 let testSteps = [
    61   function step0() {
    62     tab1 = createTab(function() {
    63       expect(STARTUP, tab1.linkedBrowser.contentWindow);
    64       expect(INITIALIZING, tab1.linkedBrowser.contentWindow);
    65       expect(INITIALIZED, tab1.linkedBrowser.contentWindow);
    66       after(INITIALIZED, nextStep);
    68       createTilt({}, false, function suddenDeath()
    69       {
    70         info("Tilt could not be initialized properly.");
    71         cleanup();
    72       });
    73     });
    74   },
    75   function step1() {
    76     expect(HIDDEN, tab1.linkedBrowser.contentWindow);
    78     tab2 = createTab(function() {
    79       expect(STARTUP, tab2.linkedBrowser.contentWindow);
    80       expect(INITIALIZING, tab2.linkedBrowser.contentWindow);
    81       expect(INITIALIZED, tab2.linkedBrowser.contentWindow);
    82       after(INITIALIZED, nextStep);
    84       createTilt({}, false, function suddenDeath()
    85       {
    86         info("Tilt could not be initialized properly.");
    87         cleanup();
    88       });
    89     });
    90   },
    91   function step2() {
    92     expect(HIDDEN, tab2.linkedBrowser.contentWindow);
    93     after(HIDDEN, nextStep);
    95     gBrowser.selectedTab = tab0;
    96   },
    97   function step3() {
    98     expect(SHOWN, tab2.linkedBrowser.contentWindow);
    99     after(SHOWN, nextStep);
   101     gBrowser.selectedTab = tab2;
   102   },
   103   function step4() {
   104     expect(HIDDEN, tab2.linkedBrowser.contentWindow);
   105     expect(SHOWN, tab1.linkedBrowser.contentWindow);
   106     after(SHOWN, nextStep);
   108     gBrowser.selectedTab = tab1;
   109   },
   110   function step5() {
   111     expect(HIDDEN, tab1.linkedBrowser.contentWindow);
   112     expect(SHOWN, tab2.linkedBrowser.contentWindow);
   113     after(SHOWN, nextStep);
   115     gBrowser.selectedTab = tab2;
   116   },
   117   function step6() {
   118     expect(DESTROYING, tab2.linkedBrowser.contentWindow);
   119     expect(BEFORE_DESTROYED, tab2.linkedBrowser.contentWindow);
   120     expect(DESTROYED, tab2.linkedBrowser.contentWindow);
   121     after(DESTROYED, nextStep);
   123     Tilt.destroy(Tilt.currentWindowId, true);
   124   },
   125   function step7() {
   126     expect(SHOWN, tab1.linkedBrowser.contentWindow);
   128     gBrowser.removeCurrentTab();
   129     tab2 = null;
   131     expect(DESTROYING, tab1.linkedBrowser.contentWindow);
   132     expect(HIDDEN, tab1.linkedBrowser.contentWindow);
   133     expect(BEFORE_DESTROYED, tab1.linkedBrowser.contentWindow);
   134     expect(DESTROYED, tab1.linkedBrowser.contentWindow);
   135     after(DESTROYED, nextStep);
   137     gBrowser.removeCurrentTab();
   138     tab1 = null;
   139   },
   140   function step8_cleanup() {
   141     is(gBrowser.selectedTab, tab0, "Should be back to the first tab");
   143     cleanup();
   144   }
   145 ];
   147 function cleanup() {
   148   if (tab1) {
   149     gBrowser.removeTab(tab1);
   150     tab1 = null;
   151   }
   152   if (tab2) {
   153     gBrowser.removeTab(tab2);
   154     tab2 = null;
   155   }
   157   Services.obs.removeObserver(notification, STARTUP);
   158   Services.obs.removeObserver(notification, INITIALIZING);
   159   Services.obs.removeObserver(notification, INITIALIZED);
   160   Services.obs.removeObserver(notification, DESTROYING);
   161   Services.obs.removeObserver(notification, BEFORE_DESTROYED);
   162   Services.obs.removeObserver(notification, DESTROYED);
   163   Services.obs.removeObserver(notification, SHOWN);
   164   Services.obs.removeObserver(notification, HIDDEN);
   166   finish();
   167 }
   169 function nextStep() {
   170   let step = testSteps.shift();
   171   info("Executing " + step.name);
   172   step();
   173 }

mercurial