|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Tests if the clear button empties the request menu. |
|
6 */ |
|
7 |
|
8 function test() { |
|
9 initNetMonitor(SIMPLE_URL).then(([aTab, aDebuggee, aMonitor]) => { |
|
10 info("Starting test... "); |
|
11 |
|
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'); |
|
17 |
|
18 RequestsMenu.lazyUpdate = false; |
|
19 |
|
20 // Make sure we start in a sane state |
|
21 assertNoRequestState(RequestsMenu, detailsPaneToggleButton); |
|
22 |
|
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); |
|
26 |
|
27 // Click clear and make sure the requests are gone |
|
28 EventUtils.sendMouseEvent({ type: "click" }, clearButton); |
|
29 assertNoRequestState(RequestsMenu, detailsPaneToggleButton); |
|
30 |
|
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); |
|
34 |
|
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."); |
|
40 |
|
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'."); |
|
47 |
|
48 teardown(aMonitor).then(finish); |
|
49 }); |
|
50 |
|
51 aDebuggee.location.reload(); |
|
52 }); |
|
53 |
|
54 aDebuggee.location.reload(); |
|
55 }); |
|
56 |
|
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 } |
|
66 |
|
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 } |