1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/tilt/test/browser_tilt_02_notifications-seq.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,101 @@ 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 tabEvents = ""; 1.9 + 1.10 +function test() { 1.11 + if (!isTiltEnabled()) { 1.12 + info("Skipping notifications test because Tilt isn't enabled."); 1.13 + return; 1.14 + } 1.15 + if (!isWebGLSupported()) { 1.16 + info("Skipping notifications test because WebGL isn't supported."); 1.17 + return; 1.18 + } 1.19 + 1.20 + requestLongerTimeout(10); 1.21 + waitForExplicitFinish(); 1.22 + 1.23 + createTab(function() { 1.24 + Services.obs.addObserver(finalize, DESTROYED, false); 1.25 + Services.obs.addObserver(obs_STARTUP, STARTUP, false); 1.26 + Services.obs.addObserver(obs_INITIALIZING, INITIALIZING, false); 1.27 + Services.obs.addObserver(obs_INITIALIZED, INITIALIZED, false); 1.28 + Services.obs.addObserver(obs_DESTROYING, DESTROYING, false); 1.29 + Services.obs.addObserver(obs_BEFORE_DESTROYED, BEFORE_DESTROYED, false); 1.30 + Services.obs.addObserver(obs_DESTROYED, DESTROYED, false); 1.31 + 1.32 + info("Starting up the Tilt notifications test."); 1.33 + createTilt({}, false, function suddenDeath() 1.34 + { 1.35 + info("Tilt could not be initialized properly."); 1.36 + cleanup(); 1.37 + }); 1.38 + }); 1.39 +} 1.40 + 1.41 +function obs_STARTUP(win) { 1.42 + info("Handling the STARTUP notification."); 1.43 + is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window"); 1.44 + tabEvents += "STARTUP;"; 1.45 +} 1.46 + 1.47 +function obs_INITIALIZING(win) { 1.48 + info("Handling the INITIALIZING notification."); 1.49 + is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window"); 1.50 + tabEvents += "INITIALIZING;"; 1.51 +} 1.52 + 1.53 +function obs_INITIALIZED(win) { 1.54 + info("Handling the INITIALIZED notification."); 1.55 + is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window"); 1.56 + tabEvents += "INITIALIZED;"; 1.57 + 1.58 + Tilt.destroy(Tilt.currentWindowId, true); 1.59 +} 1.60 + 1.61 +function obs_DESTROYING(win) { 1.62 + info("Handling the DESTROYING( notification."); 1.63 + is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window"); 1.64 + tabEvents += "DESTROYING;"; 1.65 +} 1.66 + 1.67 +function obs_BEFORE_DESTROYED(win) { 1.68 + info("Handling the BEFORE_DESTROYED notification."); 1.69 + is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window"); 1.70 + tabEvents += "BEFORE_DESTROYED;"; 1.71 +} 1.72 + 1.73 +function obs_DESTROYED(win) { 1.74 + info("Handling the DESTROYED notification."); 1.75 + is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window"); 1.76 + tabEvents += "DESTROYED;"; 1.77 +} 1.78 + 1.79 +function finalize(win) { 1.80 + if (!tabEvents) { 1.81 + return; 1.82 + } 1.83 + 1.84 + is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window"); 1.85 + is(tabEvents, "STARTUP;INITIALIZING;INITIALIZED;DESTROYING;BEFORE_DESTROYED;DESTROYED;", 1.86 + "The notifications weren't fired in the correct order."); 1.87 + 1.88 + cleanup(); 1.89 +} 1.90 + 1.91 +function cleanup() { 1.92 + info("Cleaning up the notifications test."); 1.93 + 1.94 + Services.obs.removeObserver(finalize, DESTROYED); 1.95 + Services.obs.removeObserver(obs_INITIALIZING, INITIALIZING); 1.96 + Services.obs.removeObserver(obs_INITIALIZED, INITIALIZED); 1.97 + Services.obs.removeObserver(obs_DESTROYING, DESTROYING); 1.98 + Services.obs.removeObserver(obs_BEFORE_DESTROYED, BEFORE_DESTROYED); 1.99 + Services.obs.removeObserver(obs_DESTROYED, DESTROYED); 1.100 + Services.obs.removeObserver(obs_STARTUP, STARTUP); 1.101 + 1.102 + gBrowser.removeCurrentTab(); 1.103 + finish(); 1.104 +}