michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: "use strict"; michael@0: michael@0: let tab0, tab1; michael@0: let testStep = -1; michael@0: let tabEvents = ""; michael@0: michael@0: function test() { michael@0: if (!isTiltEnabled()) { michael@0: info("Skipping notifications test because Tilt isn't enabled."); michael@0: return; michael@0: } michael@0: if (!isWebGLSupported()) { michael@0: info("Skipping notifications test because WebGL isn't supported."); michael@0: return; michael@0: } michael@0: michael@0: requestLongerTimeout(10); michael@0: waitForExplicitFinish(); michael@0: michael@0: gBrowser.tabContainer.addEventListener("TabSelect", tabSelect, false); michael@0: createNewTab(); michael@0: } michael@0: michael@0: function createNewTab() { michael@0: tab0 = gBrowser.selectedTab; michael@0: michael@0: tab1 = createTab(function() { michael@0: Services.obs.addObserver(finalize, DESTROYED, false); michael@0: Services.obs.addObserver(tab_STARTUP, STARTUP, false); michael@0: Services.obs.addObserver(tab_INITIALIZING, INITIALIZING, false); michael@0: Services.obs.addObserver(tab_DESTROYING, DESTROYING, false); michael@0: Services.obs.addObserver(tab_SHOWN, SHOWN, false); michael@0: Services.obs.addObserver(tab_HIDDEN, HIDDEN, false); michael@0: michael@0: info("Starting up the Tilt notifications test."); michael@0: createTilt({ michael@0: onTiltOpen: function() michael@0: { michael@0: testStep = 0; michael@0: tabSelect(); michael@0: } michael@0: }, false, function suddenDeath() michael@0: { michael@0: info("Tilt could not be initialized properly."); michael@0: cleanup(); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function tab_STARTUP(win) { michael@0: info("Handling the STARTUP notification."); michael@0: is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window"); michael@0: tabEvents += "STARTUP;"; michael@0: } michael@0: michael@0: function tab_INITIALIZING(win) { michael@0: info("Handling the INITIALIZING notification."); michael@0: is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window"); michael@0: tabEvents += "INITIALIZING;"; michael@0: } michael@0: michael@0: function tab_DESTROYING(win) { michael@0: info("Handling the DESTROYING notification."); michael@0: is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window"); michael@0: tabEvents += "DESTROYING;"; michael@0: } michael@0: michael@0: function tab_SHOWN(win) { michael@0: info("Handling the SHOWN notification."); michael@0: is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window"); michael@0: tabEvents += "SHOWN;"; michael@0: } michael@0: michael@0: function tab_HIDDEN(win) { michael@0: info("Handling the HIDDEN notification."); michael@0: is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window"); michael@0: tabEvents += "HIDDEN;"; michael@0: } michael@0: michael@0: let testSteps = [ michael@0: function step0() { michael@0: info("Selecting tab0."); michael@0: gBrowser.selectedTab = tab0; michael@0: }, michael@0: function step1() { michael@0: info("Selecting tab1."); michael@0: gBrowser.selectedTab = tab1; michael@0: }, michael@0: function step2() { michael@0: info("Killing it."); michael@0: Tilt.destroy(Tilt.currentWindowId, true); michael@0: } michael@0: ]; michael@0: michael@0: function finalize(win) { michael@0: if (!tabEvents) { michael@0: return; michael@0: } michael@0: michael@0: is(win, tab1.linkedBrowser.contentWindow, "Saw the correct window"); michael@0: michael@0: is(tabEvents, "STARTUP;INITIALIZING;HIDDEN;SHOWN;DESTROYING;", michael@0: "The notifications weren't fired in the correct order."); michael@0: michael@0: cleanup(); michael@0: } michael@0: michael@0: function cleanup() { michael@0: info("Cleaning up the notifications test."); michael@0: michael@0: tab0 = null; michael@0: tab1 = null; michael@0: michael@0: Services.obs.removeObserver(finalize, DESTROYED); michael@0: Services.obs.removeObserver(tab_INITIALIZING, INITIALIZING); michael@0: Services.obs.removeObserver(tab_DESTROYING, DESTROYING); michael@0: Services.obs.removeObserver(tab_SHOWN, SHOWN); michael@0: Services.obs.removeObserver(tab_HIDDEN, HIDDEN); michael@0: Services.obs.removeObserver(tab_STARTUP, STARTUP); michael@0: michael@0: gBrowser.tabContainer.removeEventListener("TabSelect", tabSelect); michael@0: gBrowser.removeCurrentTab(); michael@0: finish(); michael@0: } michael@0: michael@0: function tabSelect() { michael@0: if (testStep !== -1) { michael@0: executeSoon(testSteps[testStep]); michael@0: testStep++; michael@0: } michael@0: }