Thu, 22 Jan 2015 13:21:57 +0100
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 tabEvents = ""; |
michael@0 | 6 | |
michael@0 | 7 | function test() { |
michael@0 | 8 | if (!isTiltEnabled()) { |
michael@0 | 9 | info("Skipping notifications test because Tilt isn't enabled."); |
michael@0 | 10 | return; |
michael@0 | 11 | } |
michael@0 | 12 | if (!isWebGLSupported()) { |
michael@0 | 13 | info("Skipping notifications test because WebGL isn't supported."); |
michael@0 | 14 | return; |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | requestLongerTimeout(10); |
michael@0 | 18 | waitForExplicitFinish(); |
michael@0 | 19 | |
michael@0 | 20 | createTab(function() { |
michael@0 | 21 | Services.obs.addObserver(finalize, DESTROYED, false); |
michael@0 | 22 | Services.obs.addObserver(obs_STARTUP, STARTUP, false); |
michael@0 | 23 | Services.obs.addObserver(obs_INITIALIZING, INITIALIZING, false); |
michael@0 | 24 | Services.obs.addObserver(obs_INITIALIZED, INITIALIZED, false); |
michael@0 | 25 | Services.obs.addObserver(obs_DESTROYING, DESTROYING, false); |
michael@0 | 26 | Services.obs.addObserver(obs_BEFORE_DESTROYED, BEFORE_DESTROYED, false); |
michael@0 | 27 | Services.obs.addObserver(obs_DESTROYED, DESTROYED, false); |
michael@0 | 28 | |
michael@0 | 29 | info("Starting up the Tilt notifications test."); |
michael@0 | 30 | createTilt({}, false, function suddenDeath() |
michael@0 | 31 | { |
michael@0 | 32 | info("Tilt could not be initialized properly."); |
michael@0 | 33 | cleanup(); |
michael@0 | 34 | }); |
michael@0 | 35 | }); |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | function obs_STARTUP(win) { |
michael@0 | 39 | info("Handling the STARTUP notification."); |
michael@0 | 40 | is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window"); |
michael@0 | 41 | tabEvents += "STARTUP;"; |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | function obs_INITIALIZING(win) { |
michael@0 | 45 | info("Handling the INITIALIZING notification."); |
michael@0 | 46 | is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window"); |
michael@0 | 47 | tabEvents += "INITIALIZING;"; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | function obs_INITIALIZED(win) { |
michael@0 | 51 | info("Handling the INITIALIZED notification."); |
michael@0 | 52 | is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window"); |
michael@0 | 53 | tabEvents += "INITIALIZED;"; |
michael@0 | 54 | |
michael@0 | 55 | Tilt.destroy(Tilt.currentWindowId, true); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | function obs_DESTROYING(win) { |
michael@0 | 59 | info("Handling the DESTROYING( notification."); |
michael@0 | 60 | is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window"); |
michael@0 | 61 | tabEvents += "DESTROYING;"; |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | function obs_BEFORE_DESTROYED(win) { |
michael@0 | 65 | info("Handling the BEFORE_DESTROYED notification."); |
michael@0 | 66 | is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window"); |
michael@0 | 67 | tabEvents += "BEFORE_DESTROYED;"; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | function obs_DESTROYED(win) { |
michael@0 | 71 | info("Handling the DESTROYED notification."); |
michael@0 | 72 | is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window"); |
michael@0 | 73 | tabEvents += "DESTROYED;"; |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | function finalize(win) { |
michael@0 | 77 | if (!tabEvents) { |
michael@0 | 78 | return; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | is(win, gBrowser.selectedBrowser.contentWindow, "Saw the correct window"); |
michael@0 | 82 | is(tabEvents, "STARTUP;INITIALIZING;INITIALIZED;DESTROYING;BEFORE_DESTROYED;DESTROYED;", |
michael@0 | 83 | "The notifications weren't fired in the correct order."); |
michael@0 | 84 | |
michael@0 | 85 | cleanup(); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | function cleanup() { |
michael@0 | 89 | info("Cleaning up the notifications test."); |
michael@0 | 90 | |
michael@0 | 91 | Services.obs.removeObserver(finalize, DESTROYED); |
michael@0 | 92 | Services.obs.removeObserver(obs_INITIALIZING, INITIALIZING); |
michael@0 | 93 | Services.obs.removeObserver(obs_INITIALIZED, INITIALIZED); |
michael@0 | 94 | Services.obs.removeObserver(obs_DESTROYING, DESTROYING); |
michael@0 | 95 | Services.obs.removeObserver(obs_BEFORE_DESTROYED, BEFORE_DESTROYED); |
michael@0 | 96 | Services.obs.removeObserver(obs_DESTROYED, DESTROYED); |
michael@0 | 97 | Services.obs.removeObserver(obs_STARTUP, STARTUP); |
michael@0 | 98 | |
michael@0 | 99 | gBrowser.removeCurrentTab(); |
michael@0 | 100 | finish(); |
michael@0 | 101 | } |