michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Tests that event listeners are fetched when the events tab is selected michael@0: * or while sources are fetched and the events tab is focused. michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_event-listeners-02.html"; michael@0: michael@0: function test() { michael@0: initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { michael@0: let gDebugger = aPanel.panelWin; michael@0: let gView = gDebugger.DebuggerView; michael@0: let gEvents = gView.EventListeners; michael@0: michael@0: Task.spawn(function() { michael@0: yield waitForSourceShown(aPanel, ".html"); michael@0: yield testFetchOnFocus(); michael@0: yield testFetchOnReloadWhenFocused(); michael@0: yield testFetchOnReloadWhenNotFocused(); michael@0: yield closeDebuggerAndFinish(aPanel); michael@0: }); michael@0: michael@0: function testFetchOnFocus() { michael@0: return Task.spawn(function() { michael@0: let fetched = waitForDebuggerEvents(aPanel, gDebugger.EVENTS.EVENT_LISTENERS_FETCHED); michael@0: michael@0: gView.toggleInstrumentsPane({ visible: true, animated: false }, 1); michael@0: is(gView.instrumentsPaneHidden, false, michael@0: "The instruments pane should be visible now."); michael@0: is(gView.instrumentsPaneTab, "events-tab", michael@0: "The events tab should be selected."); michael@0: michael@0: yield fetched; michael@0: michael@0: ok(true, michael@0: "Event listeners were fetched when the events tab was selected"); michael@0: is(gEvents.itemCount, 4, michael@0: "There should be 4 events displayed in the view."); michael@0: }); michael@0: } michael@0: michael@0: function testFetchOnReloadWhenFocused() { michael@0: return Task.spawn(function() { michael@0: let fetched = waitForDebuggerEvents(aPanel, gDebugger.EVENTS.EVENT_LISTENERS_FETCHED); michael@0: michael@0: let reloading = once(gDebugger.gTarget, "will-navigate"); michael@0: let reloaded = waitForSourcesAfterReload(); michael@0: gDebugger.DebuggerController._target.activeTab.reload(); michael@0: michael@0: yield reloading; michael@0: michael@0: is(gEvents.itemCount, 0, michael@0: "There should be no events displayed in the view while reloading."); michael@0: ok(true, michael@0: "Event listeners were removed when the target started navigating."); michael@0: michael@0: yield reloaded; michael@0: michael@0: is(gView.instrumentsPaneHidden, false, michael@0: "The instruments pane should still be visible."); michael@0: is(gView.instrumentsPaneTab, "events-tab", michael@0: "The events tab should still be selected."); michael@0: michael@0: yield fetched; michael@0: michael@0: is(gEvents.itemCount, 4, michael@0: "There should be 4 events displayed in the view after reloading."); michael@0: ok(true, michael@0: "Event listeners were added back after the target finished navigating."); michael@0: }); michael@0: } michael@0: michael@0: function testFetchOnReloadWhenNotFocused() { michael@0: return Task.spawn(function() { michael@0: gDebugger.on(gDebugger.EVENTS.EVENT_LISTENERS_FETCHED, () => { michael@0: ok(false, "Shouldn't have fetched any event listeners."); michael@0: }); michael@0: gDebugger.on(gDebugger.EVENTS.EVENT_BREAKPOINTS_UPDATED, () => { michael@0: ok(false, "Shouldn't have updated any event breakpoints."); michael@0: }); michael@0: michael@0: gView.toggleInstrumentsPane({ visible: true, animated: false }, 0); michael@0: is(gView.instrumentsPaneHidden, false, michael@0: "The instruments pane should still be visible."); michael@0: is(gView.instrumentsPaneTab, "variables-tab", michael@0: "The variables tab should be selected."); michael@0: michael@0: let reloading = once(gDebugger.gTarget, "will-navigate"); michael@0: let reloaded = waitForSourcesAfterReload(); michael@0: gDebugger.DebuggerController._target.activeTab.reload(); michael@0: michael@0: yield reloading; michael@0: michael@0: is(gEvents.itemCount, 0, michael@0: "There should be no events displayed in the view while reloading."); michael@0: ok(true, michael@0: "Event listeners were removed when the target started navigating."); michael@0: michael@0: yield reloaded; michael@0: michael@0: is(gView.instrumentsPaneHidden, false, michael@0: "The instruments pane should still be visible."); michael@0: is(gView.instrumentsPaneTab, "variables-tab", michael@0: "The variables tab should still be selected."); michael@0: michael@0: // Just to be really sure that the events will never ever fire. michael@0: yield waitForTime(1000); michael@0: michael@0: is(gEvents.itemCount, 0, michael@0: "There should be no events displayed in the view after reloading."); michael@0: ok(true, michael@0: "Event listeners were not added after the target finished navigating."); michael@0: }); michael@0: } michael@0: michael@0: function waitForSourcesAfterReload() { michael@0: return promise.all([ michael@0: waitForDebuggerEvents(aPanel, gDebugger.EVENTS.NEW_SOURCE), michael@0: waitForDebuggerEvents(aPanel, gDebugger.EVENTS.SOURCES_ADDED), michael@0: waitForDebuggerEvents(aPanel, gDebugger.EVENTS.SOURCE_SHOWN) michael@0: ]); michael@0: } michael@0: }); michael@0: }