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 if the clear button empties the request menu. michael@0: */ michael@0: michael@0: function test() { michael@0: initNetMonitor(SIMPLE_URL).then(([aTab, aDebuggee, aMonitor]) => { michael@0: info("Starting test... "); michael@0: michael@0: let { document, $, NetMonitorView } = aMonitor.panelWin; michael@0: let { RequestsMenu } = NetMonitorView; michael@0: let detailsPane = $("#details-pane"); michael@0: let detailsPaneToggleButton = $('#details-pane-toggle'); michael@0: let clearButton = $('#requests-menu-clear-button'); michael@0: michael@0: RequestsMenu.lazyUpdate = false; michael@0: michael@0: // Make sure we start in a sane state michael@0: assertNoRequestState(RequestsMenu, detailsPaneToggleButton); michael@0: michael@0: // Load one request and assert it shows up in the lis michael@0: aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.NETWORK_EVENT, () => { michael@0: assertSingleRequestState(RequestsMenu, detailsPaneToggleButton); michael@0: michael@0: // Click clear and make sure the requests are gone michael@0: EventUtils.sendMouseEvent({ type: "click" }, clearButton); michael@0: assertNoRequestState(RequestsMenu, detailsPaneToggleButton); michael@0: michael@0: // Load a second request and make sure they still show up michael@0: aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.NETWORK_EVENT, () => { michael@0: assertSingleRequestState(RequestsMenu, detailsPaneToggleButton); michael@0: michael@0: // Make sure we can now open the details pane michael@0: NetMonitorView.toggleDetailsPane({ visible: true, animated: false }); michael@0: ok(!detailsPane.hasAttribute("pane-collapsed") && michael@0: !detailsPaneToggleButton.hasAttribute("pane-collapsed"), michael@0: "The details pane should be visible after clicking the toggle button."); michael@0: michael@0: // Click clear and make sure the details pane closes michael@0: EventUtils.sendMouseEvent({ type: "click" }, clearButton); michael@0: assertNoRequestState(RequestsMenu, detailsPaneToggleButton); michael@0: ok(detailsPane.hasAttribute("pane-collapsed") && michael@0: detailsPaneToggleButton.hasAttribute("pane-collapsed"), michael@0: "The details pane should not be visible clicking 'clear'."); michael@0: michael@0: teardown(aMonitor).then(finish); michael@0: }); michael@0: michael@0: aDebuggee.location.reload(); michael@0: }); michael@0: michael@0: aDebuggee.location.reload(); michael@0: }); michael@0: michael@0: /** michael@0: * Asserts the state of the network monitor when one request has loaded michael@0: */ michael@0: function assertSingleRequestState(RequestsMenu, detailsPaneToggleButton) { michael@0: is(RequestsMenu.itemCount, 1, michael@0: "The request menu should have one item at this point."); michael@0: is(detailsPaneToggleButton.hasAttribute("disabled"), false, michael@0: "The pane toggle button should be enabled after a request is made."); michael@0: } michael@0: michael@0: /** michael@0: * Asserts the state of the network monitor when no requests have loaded michael@0: */ michael@0: function assertNoRequestState(RequestsMenu, detailsPaneToggleButton) { michael@0: is(RequestsMenu.itemCount, 0, michael@0: "The request menu should be empty at this point."); michael@0: is(detailsPaneToggleButton.hasAttribute("disabled"), true, michael@0: "The pane toggle button should be disabled when the request menu is cleared."); michael@0: } michael@0: }