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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial