browser/devtools/netmonitor/test/browser_net_clear.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 /**
     5  * Tests if the clear button empties the request menu.
     6  */
     8 function test() {
     9   initNetMonitor(SIMPLE_URL).then(([aTab, aDebuggee, aMonitor]) => {
    10     info("Starting test... ");
    12     let { document, $, NetMonitorView } = aMonitor.panelWin;
    13     let { RequestsMenu } = NetMonitorView;
    14     let detailsPane = $("#details-pane");
    15     let detailsPaneToggleButton = $('#details-pane-toggle');
    16     let clearButton = $('#requests-menu-clear-button');
    18     RequestsMenu.lazyUpdate = false;
    20     // Make sure we start in a sane state
    21     assertNoRequestState(RequestsMenu, detailsPaneToggleButton);
    23     // Load one request and assert it shows up in the lis
    24     aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.NETWORK_EVENT, () => {
    25       assertSingleRequestState(RequestsMenu, detailsPaneToggleButton);
    27       // Click clear and make sure the requests are gone
    28       EventUtils.sendMouseEvent({ type: "click" }, clearButton);
    29       assertNoRequestState(RequestsMenu, detailsPaneToggleButton);
    31       // Load a second request and make sure they still show up
    32       aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.NETWORK_EVENT, () => {
    33         assertSingleRequestState(RequestsMenu, detailsPaneToggleButton);
    35         // Make sure we can now open the details pane
    36         NetMonitorView.toggleDetailsPane({ visible: true, animated: false });
    37         ok(!detailsPane.hasAttribute("pane-collapsed") &&
    38           !detailsPaneToggleButton.hasAttribute("pane-collapsed"),
    39           "The details pane should be visible after clicking the toggle button.");
    41         // Click clear and make sure the details pane closes
    42         EventUtils.sendMouseEvent({ type: "click" }, clearButton);
    43         assertNoRequestState(RequestsMenu, detailsPaneToggleButton);
    44         ok(detailsPane.hasAttribute("pane-collapsed") &&
    45           detailsPaneToggleButton.hasAttribute("pane-collapsed"),
    46           "The details pane should not be visible clicking 'clear'.");
    48         teardown(aMonitor).then(finish);
    49       });
    51       aDebuggee.location.reload();
    52     });
    54     aDebuggee.location.reload();
    55   });
    57   /**
    58    * Asserts the state of the network monitor when one request has loaded
    59    */
    60   function assertSingleRequestState(RequestsMenu, detailsPaneToggleButton) {
    61     is(RequestsMenu.itemCount, 1,
    62       "The request menu should have one item at this point.");
    63     is(detailsPaneToggleButton.hasAttribute("disabled"), false,
    64       "The pane toggle button should be enabled after a request is made.");
    65   }
    67   /**
    68    * Asserts the state of the network monitor when no requests have loaded
    69    */
    70   function assertNoRequestState(RequestsMenu, detailsPaneToggleButton) {
    71     is(RequestsMenu.itemCount, 0,
    72       "The request menu should be empty at this point.");
    73     is(detailsPaneToggleButton.hasAttribute("disabled"), true,
    74       "The pane toggle button should be disabled when the request menu is cleared.");
    75   }
    76 }

mercurial