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 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: createTab(function() { michael@0: Services.obs.addObserver(finalize, DESTROYED, false); michael@0: Services.obs.addObserver(obs_STARTUP, STARTUP, false); michael@0: Services.obs.addObserver(obs_INITIALIZING, INITIALIZING, false); michael@0: Services.obs.addObserver(obs_INITIALIZED, INITIALIZED, false); michael@0: Services.obs.addObserver(obs_DESTROYING, DESTROYING, false); michael@0: Services.obs.addObserver(obs_BEFORE_DESTROYED, BEFORE_DESTROYED, false); michael@0: Services.obs.addObserver(obs_DESTROYED, DESTROYED, false); michael@0: michael@0: info("Starting up the Tilt notifications test."); michael@0: createTilt({}, 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 obs_STARTUP(win) { michael@0: info("Handling the STARTUP notification."); michael@0: is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window"); michael@0: tabEvents += "STARTUP;"; michael@0: } michael@0: michael@0: function obs_INITIALIZING(win) { michael@0: info("Handling the INITIALIZING notification."); michael@0: is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window"); michael@0: tabEvents += "INITIALIZING;"; michael@0: } michael@0: michael@0: function obs_INITIALIZED(win) { michael@0: info("Handling the INITIALIZED notification."); michael@0: is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window"); michael@0: tabEvents += "INITIALIZED;"; michael@0: michael@0: Tilt.destroy(Tilt.currentWindowId, true); michael@0: } michael@0: michael@0: function obs_DESTROYING(win) { michael@0: info("Handling the DESTROYING( notification."); michael@0: is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window"); michael@0: tabEvents += "DESTROYING;"; michael@0: } michael@0: michael@0: function obs_BEFORE_DESTROYED(win) { michael@0: info("Handling the BEFORE_DESTROYED notification."); michael@0: is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window"); michael@0: tabEvents += "BEFORE_DESTROYED;"; michael@0: } michael@0: michael@0: function obs_DESTROYED(win) { michael@0: info("Handling the DESTROYED notification."); michael@0: is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window"); michael@0: tabEvents += "DESTROYED;"; michael@0: } michael@0: michael@0: function finalize(win) { michael@0: if (!tabEvents) { michael@0: return; michael@0: } michael@0: michael@0: is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window"); michael@0: is(tabEvents, "STARTUP;INITIALIZING;INITIALIZED;DESTROYING;BEFORE_DESTROYED;DESTROYED;", 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: Services.obs.removeObserver(finalize, DESTROYED); michael@0: Services.obs.removeObserver(obs_INITIALIZING, INITIALIZING); michael@0: Services.obs.removeObserver(obs_INITIALIZED, INITIALIZED); michael@0: Services.obs.removeObserver(obs_DESTROYING, DESTROYING); michael@0: Services.obs.removeObserver(obs_BEFORE_DESTROYED, BEFORE_DESTROYED); michael@0: Services.obs.removeObserver(obs_DESTROYED, DESTROYED); michael@0: Services.obs.removeObserver(obs_STARTUP, STARTUP); michael@0: michael@0: gBrowser.removeCurrentTab(); michael@0: finish(); michael@0: }