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

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

mercurial