browser/devtools/tilt/test/browser_tilt_02_notifications-tabs.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-tabs.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,173 @@
     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, tab2;
     1.9 +let testStep = -1;
    1.10 +
    1.11 +let expected = [];
    1.12 +function expect(notification, win) {
    1.13 +  expected.push({ notification: notification, window: win });
    1.14 +}
    1.15 +
    1.16 +function notification(win, topic) {
    1.17 +  if (expected.length == 0) {
    1.18 +    is(topic, null, "Shouldn't see a notification");
    1.19 +    return;
    1.20 +  }
    1.21 +
    1.22 +  let { notification, window } = expected.shift();
    1.23 +  is(topic, notification, "Saw the expected notification");
    1.24 +  is(win, window, "Saw the expected window");
    1.25 +}
    1.26 +
    1.27 +function after(notification, callback) {
    1.28 +  function observer() {
    1.29 +    Services.obs.removeObserver(observer, notification);
    1.30 +    executeSoon(callback);
    1.31 +  }
    1.32 +  Services.obs.addObserver(observer, notification, false);
    1.33 +}
    1.34 +
    1.35 +function test() {
    1.36 +  if (!isTiltEnabled()) {
    1.37 +    info("Skipping tab switch test because Tilt isn't enabled.");
    1.38 +    return;
    1.39 +  }
    1.40 +  if (!isWebGLSupported()) {
    1.41 +    info("Skipping tab switch test because WebGL isn't supported.");
    1.42 +    return;
    1.43 +  }
    1.44 +
    1.45 +  Services.obs.addObserver(notification, STARTUP, false);
    1.46 +  Services.obs.addObserver(notification, INITIALIZING, false);
    1.47 +  Services.obs.addObserver(notification, INITIALIZED, false);
    1.48 +  Services.obs.addObserver(notification, DESTROYING, false);
    1.49 +  Services.obs.addObserver(notification, BEFORE_DESTROYED, false);
    1.50 +  Services.obs.addObserver(notification, DESTROYED, false);
    1.51 +  Services.obs.addObserver(notification, SHOWN, false);
    1.52 +  Services.obs.addObserver(notification, HIDDEN, false);
    1.53 +
    1.54 +  waitForExplicitFinish();
    1.55 +
    1.56 +  tab0 = gBrowser.selectedTab;
    1.57 +  nextStep();
    1.58 +}
    1.59 +
    1.60 +function createTab2() {
    1.61 +}
    1.62 +
    1.63 +let testSteps = [
    1.64 +  function step0() {
    1.65 +    tab1 = createTab(function() {
    1.66 +      expect(STARTUP, tab1.linkedBrowser.contentWindow);
    1.67 +      expect(INITIALIZING, tab1.linkedBrowser.contentWindow);
    1.68 +      expect(INITIALIZED, tab1.linkedBrowser.contentWindow);
    1.69 +      after(INITIALIZED, nextStep);
    1.70 +
    1.71 +      createTilt({}, false, function suddenDeath()
    1.72 +      {
    1.73 +        info("Tilt could not be initialized properly.");
    1.74 +        cleanup();
    1.75 +      });
    1.76 +    });
    1.77 +  },
    1.78 +  function step1() {
    1.79 +    expect(HIDDEN, tab1.linkedBrowser.contentWindow);
    1.80 +
    1.81 +    tab2 = createTab(function() {
    1.82 +      expect(STARTUP, tab2.linkedBrowser.contentWindow);
    1.83 +      expect(INITIALIZING, tab2.linkedBrowser.contentWindow);
    1.84 +      expect(INITIALIZED, tab2.linkedBrowser.contentWindow);
    1.85 +      after(INITIALIZED, nextStep);
    1.86 +
    1.87 +      createTilt({}, false, function suddenDeath()
    1.88 +      {
    1.89 +        info("Tilt could not be initialized properly.");
    1.90 +        cleanup();
    1.91 +      });
    1.92 +    });
    1.93 +  },
    1.94 +  function step2() {
    1.95 +    expect(HIDDEN, tab2.linkedBrowser.contentWindow);
    1.96 +    after(HIDDEN, nextStep);
    1.97 +
    1.98 +    gBrowser.selectedTab = tab0;
    1.99 +  },
   1.100 +  function step3() {
   1.101 +    expect(SHOWN, tab2.linkedBrowser.contentWindow);
   1.102 +    after(SHOWN, nextStep);
   1.103 +
   1.104 +    gBrowser.selectedTab = tab2;
   1.105 +  },
   1.106 +  function step4() {
   1.107 +    expect(HIDDEN, tab2.linkedBrowser.contentWindow);
   1.108 +    expect(SHOWN, tab1.linkedBrowser.contentWindow);
   1.109 +    after(SHOWN, nextStep);
   1.110 +
   1.111 +    gBrowser.selectedTab = tab1;
   1.112 +  },
   1.113 +  function step5() {
   1.114 +    expect(HIDDEN, tab1.linkedBrowser.contentWindow);
   1.115 +    expect(SHOWN, tab2.linkedBrowser.contentWindow);
   1.116 +    after(SHOWN, nextStep);
   1.117 +
   1.118 +    gBrowser.selectedTab = tab2;
   1.119 +  },
   1.120 +  function step6() {
   1.121 +    expect(DESTROYING, tab2.linkedBrowser.contentWindow);
   1.122 +    expect(BEFORE_DESTROYED, tab2.linkedBrowser.contentWindow);
   1.123 +    expect(DESTROYED, tab2.linkedBrowser.contentWindow);
   1.124 +    after(DESTROYED, nextStep);
   1.125 +
   1.126 +    Tilt.destroy(Tilt.currentWindowId, true);
   1.127 +  },
   1.128 +  function step7() {
   1.129 +    expect(SHOWN, tab1.linkedBrowser.contentWindow);
   1.130 +
   1.131 +    gBrowser.removeCurrentTab();
   1.132 +    tab2 = null;
   1.133 +
   1.134 +    expect(DESTROYING, tab1.linkedBrowser.contentWindow);
   1.135 +    expect(HIDDEN, tab1.linkedBrowser.contentWindow);
   1.136 +    expect(BEFORE_DESTROYED, tab1.linkedBrowser.contentWindow);
   1.137 +    expect(DESTROYED, tab1.linkedBrowser.contentWindow);
   1.138 +    after(DESTROYED, nextStep);
   1.139 +
   1.140 +    gBrowser.removeCurrentTab();
   1.141 +    tab1 = null;
   1.142 +  },
   1.143 +  function step8_cleanup() {
   1.144 +    is(gBrowser.selectedTab, tab0, "Should be back to the first tab");
   1.145 +
   1.146 +    cleanup();
   1.147 +  }
   1.148 +];
   1.149 +
   1.150 +function cleanup() {
   1.151 +  if (tab1) {
   1.152 +    gBrowser.removeTab(tab1);
   1.153 +    tab1 = null;
   1.154 +  }
   1.155 +  if (tab2) {
   1.156 +    gBrowser.removeTab(tab2);
   1.157 +    tab2 = null;
   1.158 +  }
   1.159 +
   1.160 +  Services.obs.removeObserver(notification, STARTUP);
   1.161 +  Services.obs.removeObserver(notification, INITIALIZING);
   1.162 +  Services.obs.removeObserver(notification, INITIALIZED);
   1.163 +  Services.obs.removeObserver(notification, DESTROYING);
   1.164 +  Services.obs.removeObserver(notification, BEFORE_DESTROYED);
   1.165 +  Services.obs.removeObserver(notification, DESTROYED);
   1.166 +  Services.obs.removeObserver(notification, SHOWN);
   1.167 +  Services.obs.removeObserver(notification, HIDDEN);
   1.168 +
   1.169 +  finish();
   1.170 +}
   1.171 +
   1.172 +function nextStep() {
   1.173 +  let step = testSteps.shift();
   1.174 +  info("Executing " + step.name);
   1.175 +  step();
   1.176 +}

mercurial