browser/devtools/netmonitor/test/browser_net_clear.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/netmonitor/test/browser_net_clear.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,76 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Tests if the clear button empties the request menu.
     1.9 + */
    1.10 +
    1.11 +function test() {
    1.12 +  initNetMonitor(SIMPLE_URL).then(([aTab, aDebuggee, aMonitor]) => {
    1.13 +    info("Starting test... ");
    1.14 +
    1.15 +    let { document, $, NetMonitorView } = aMonitor.panelWin;
    1.16 +    let { RequestsMenu } = NetMonitorView;
    1.17 +    let detailsPane = $("#details-pane");
    1.18 +    let detailsPaneToggleButton = $('#details-pane-toggle');
    1.19 +    let clearButton = $('#requests-menu-clear-button');
    1.20 +
    1.21 +    RequestsMenu.lazyUpdate = false;
    1.22 +
    1.23 +    // Make sure we start in a sane state
    1.24 +    assertNoRequestState(RequestsMenu, detailsPaneToggleButton);
    1.25 +
    1.26 +    // Load one request and assert it shows up in the lis
    1.27 +    aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.NETWORK_EVENT, () => {
    1.28 +      assertSingleRequestState(RequestsMenu, detailsPaneToggleButton);
    1.29 +
    1.30 +      // Click clear and make sure the requests are gone
    1.31 +      EventUtils.sendMouseEvent({ type: "click" }, clearButton);
    1.32 +      assertNoRequestState(RequestsMenu, detailsPaneToggleButton);
    1.33 +
    1.34 +      // Load a second request and make sure they still show up
    1.35 +      aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.NETWORK_EVENT, () => {
    1.36 +        assertSingleRequestState(RequestsMenu, detailsPaneToggleButton);
    1.37 +
    1.38 +        // Make sure we can now open the details pane
    1.39 +        NetMonitorView.toggleDetailsPane({ visible: true, animated: false });
    1.40 +        ok(!detailsPane.hasAttribute("pane-collapsed") &&
    1.41 +          !detailsPaneToggleButton.hasAttribute("pane-collapsed"),
    1.42 +          "The details pane should be visible after clicking the toggle button.");
    1.43 +
    1.44 +        // Click clear and make sure the details pane closes
    1.45 +        EventUtils.sendMouseEvent({ type: "click" }, clearButton);
    1.46 +        assertNoRequestState(RequestsMenu, detailsPaneToggleButton);
    1.47 +        ok(detailsPane.hasAttribute("pane-collapsed") &&
    1.48 +          detailsPaneToggleButton.hasAttribute("pane-collapsed"),
    1.49 +          "The details pane should not be visible clicking 'clear'.");
    1.50 +
    1.51 +        teardown(aMonitor).then(finish);
    1.52 +      });
    1.53 +
    1.54 +      aDebuggee.location.reload();
    1.55 +    });
    1.56 +
    1.57 +    aDebuggee.location.reload();
    1.58 +  });
    1.59 +
    1.60 +  /**
    1.61 +   * Asserts the state of the network monitor when one request has loaded
    1.62 +   */
    1.63 +  function assertSingleRequestState(RequestsMenu, detailsPaneToggleButton) {
    1.64 +    is(RequestsMenu.itemCount, 1,
    1.65 +      "The request menu should have one item at this point.");
    1.66 +    is(detailsPaneToggleButton.hasAttribute("disabled"), false,
    1.67 +      "The pane toggle button should be enabled after a request is made.");
    1.68 +  }
    1.69 +
    1.70 +  /**
    1.71 +   * Asserts the state of the network monitor when no requests have loaded
    1.72 +   */
    1.73 +  function assertNoRequestState(RequestsMenu, detailsPaneToggleButton) {
    1.74 +    is(RequestsMenu.itemCount, 0,
    1.75 +      "The request menu should be empty at this point.");
    1.76 +    is(detailsPaneToggleButton.hasAttribute("disabled"), true,
    1.77 +      "The pane toggle button should be disabled when the request menu is cleared.");
    1.78 +  }
    1.79 +}

mercurial