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, tab2; michael@0: let testStep = -1; michael@0: michael@0: let expected = []; michael@0: function expect(notification, win) { michael@0: expected.push({ notification: notification, window: win }); michael@0: } michael@0: michael@0: function notification(win, topic) { michael@0: if (expected.length == 0) { michael@0: is(topic, null, "Shouldn't see a notification"); michael@0: return; michael@0: } michael@0: michael@0: let { notification, window } = expected.shift(); michael@0: is(topic, notification, "Saw the expected notification"); michael@0: is(win, window, "Saw the expected window"); michael@0: } michael@0: michael@0: function after(notification, callback) { michael@0: function observer() { michael@0: Services.obs.removeObserver(observer, notification); michael@0: executeSoon(callback); michael@0: } michael@0: Services.obs.addObserver(observer, notification, false); michael@0: } michael@0: michael@0: function test() { michael@0: if (!isTiltEnabled()) { michael@0: info("Skipping tab switch test because Tilt isn't enabled."); michael@0: return; michael@0: } michael@0: if (!isWebGLSupported()) { michael@0: info("Skipping tab switch test because WebGL isn't supported."); michael@0: return; michael@0: } michael@0: michael@0: Services.obs.addObserver(notification, STARTUP, false); michael@0: Services.obs.addObserver(notification, INITIALIZING, false); michael@0: Services.obs.addObserver(notification, INITIALIZED, false); michael@0: Services.obs.addObserver(notification, DESTROYING, false); michael@0: Services.obs.addObserver(notification, BEFORE_DESTROYED, false); michael@0: Services.obs.addObserver(notification, DESTROYED, false); michael@0: Services.obs.addObserver(notification, SHOWN, false); michael@0: Services.obs.addObserver(notification, HIDDEN, false); michael@0: michael@0: waitForExplicitFinish(); michael@0: michael@0: tab0 = gBrowser.selectedTab; michael@0: nextStep(); michael@0: } michael@0: michael@0: function createTab2() { michael@0: } michael@0: michael@0: let testSteps = [ michael@0: function step0() { michael@0: tab1 = createTab(function() { michael@0: expect(STARTUP, tab1.linkedBrowser.contentWindow); michael@0: expect(INITIALIZING, tab1.linkedBrowser.contentWindow); michael@0: expect(INITIALIZED, tab1.linkedBrowser.contentWindow); michael@0: after(INITIALIZED, nextStep); michael@0: 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: function step1() { michael@0: expect(HIDDEN, tab1.linkedBrowser.contentWindow); michael@0: michael@0: tab2 = createTab(function() { michael@0: expect(STARTUP, tab2.linkedBrowser.contentWindow); michael@0: expect(INITIALIZING, tab2.linkedBrowser.contentWindow); michael@0: expect(INITIALIZED, tab2.linkedBrowser.contentWindow); michael@0: after(INITIALIZED, nextStep); michael@0: 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: function step2() { michael@0: expect(HIDDEN, tab2.linkedBrowser.contentWindow); michael@0: after(HIDDEN, nextStep); michael@0: michael@0: gBrowser.selectedTab = tab0; michael@0: }, michael@0: function step3() { michael@0: expect(SHOWN, tab2.linkedBrowser.contentWindow); michael@0: after(SHOWN, nextStep); michael@0: michael@0: gBrowser.selectedTab = tab2; michael@0: }, michael@0: function step4() { michael@0: expect(HIDDEN, tab2.linkedBrowser.contentWindow); michael@0: expect(SHOWN, tab1.linkedBrowser.contentWindow); michael@0: after(SHOWN, nextStep); michael@0: michael@0: gBrowser.selectedTab = tab1; michael@0: }, michael@0: function step5() { michael@0: expect(HIDDEN, tab1.linkedBrowser.contentWindow); michael@0: expect(SHOWN, tab2.linkedBrowser.contentWindow); michael@0: after(SHOWN, nextStep); michael@0: michael@0: gBrowser.selectedTab = tab2; michael@0: }, michael@0: function step6() { michael@0: expect(DESTROYING, tab2.linkedBrowser.contentWindow); michael@0: expect(BEFORE_DESTROYED, tab2.linkedBrowser.contentWindow); michael@0: expect(DESTROYED, tab2.linkedBrowser.contentWindow); michael@0: after(DESTROYED, nextStep); michael@0: michael@0: Tilt.destroy(Tilt.currentWindowId, true); michael@0: }, michael@0: function step7() { michael@0: expect(SHOWN, tab1.linkedBrowser.contentWindow); michael@0: michael@0: gBrowser.removeCurrentTab(); michael@0: tab2 = null; michael@0: michael@0: expect(DESTROYING, tab1.linkedBrowser.contentWindow); michael@0: expect(HIDDEN, tab1.linkedBrowser.contentWindow); michael@0: expect(BEFORE_DESTROYED, tab1.linkedBrowser.contentWindow); michael@0: expect(DESTROYED, tab1.linkedBrowser.contentWindow); michael@0: after(DESTROYED, nextStep); michael@0: michael@0: gBrowser.removeCurrentTab(); michael@0: tab1 = null; michael@0: }, michael@0: function step8_cleanup() { michael@0: is(gBrowser.selectedTab, tab0, "Should be back to the first tab"); michael@0: michael@0: cleanup(); michael@0: } michael@0: ]; michael@0: michael@0: function cleanup() { michael@0: if (tab1) { michael@0: gBrowser.removeTab(tab1); michael@0: tab1 = null; michael@0: } michael@0: if (tab2) { michael@0: gBrowser.removeTab(tab2); michael@0: tab2 = null; michael@0: } michael@0: michael@0: Services.obs.removeObserver(notification, STARTUP); michael@0: Services.obs.removeObserver(notification, INITIALIZING); michael@0: Services.obs.removeObserver(notification, INITIALIZED); michael@0: Services.obs.removeObserver(notification, DESTROYING); michael@0: Services.obs.removeObserver(notification, BEFORE_DESTROYED); michael@0: Services.obs.removeObserver(notification, DESTROYED); michael@0: Services.obs.removeObserver(notification, SHOWN); michael@0: Services.obs.removeObserver(notification, HIDDEN); michael@0: michael@0: finish(); michael@0: } michael@0: michael@0: function nextStep() { michael@0: let step = testSteps.shift(); michael@0: info("Executing " + step.name); michael@0: step(); michael@0: }