|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Test if the summary text displayed in the network requests menu footer |
|
6 * is correct. |
|
7 */ |
|
8 |
|
9 function test() { |
|
10 requestLongerTimeout(2); |
|
11 let { PluralForm } = Cu.import("resource://gre/modules/PluralForm.jsm", {}); |
|
12 |
|
13 initNetMonitor(FILTERING_URL).then(([aTab, aDebuggee, aMonitor]) => { |
|
14 info("Starting test... "); |
|
15 |
|
16 let { $, L10N, NetMonitorView } = aMonitor.panelWin; |
|
17 let { RequestsMenu } = NetMonitorView; |
|
18 |
|
19 RequestsMenu.lazyUpdate = false; |
|
20 testStatus(); |
|
21 |
|
22 waitForNetworkEvents(aMonitor, 8).then(() => { |
|
23 testStatus(); |
|
24 |
|
25 EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-html-button")); |
|
26 testStatus(); |
|
27 |
|
28 EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-css-button")); |
|
29 testStatus(); |
|
30 |
|
31 EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-js-button")); |
|
32 testStatus(); |
|
33 |
|
34 EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-xhr-button")); |
|
35 testStatus(); |
|
36 |
|
37 EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-fonts-button")); |
|
38 testStatus(); |
|
39 |
|
40 EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-images-button")); |
|
41 testStatus(); |
|
42 |
|
43 EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-media-button")); |
|
44 testStatus(); |
|
45 |
|
46 EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-flash-button")); |
|
47 testStatus(); |
|
48 |
|
49 info("Performing more requests."); |
|
50 aDebuggee.performRequests('{ "getMedia": true, "getFlash": true }'); |
|
51 return waitForNetworkEvents(aMonitor, 8); |
|
52 }) |
|
53 .then(() => { |
|
54 testStatus(); |
|
55 |
|
56 EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-html-button")); |
|
57 testStatus(); |
|
58 |
|
59 EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-css-button")); |
|
60 testStatus(); |
|
61 |
|
62 EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-js-button")); |
|
63 testStatus(); |
|
64 |
|
65 EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-xhr-button")); |
|
66 testStatus(); |
|
67 |
|
68 EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-fonts-button")); |
|
69 testStatus(); |
|
70 |
|
71 EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-images-button")); |
|
72 testStatus(); |
|
73 |
|
74 EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-media-button")); |
|
75 testStatus(); |
|
76 |
|
77 EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-flash-button")); |
|
78 testStatus(); |
|
79 |
|
80 teardown(aMonitor).then(finish); |
|
81 }) |
|
82 |
|
83 function testStatus() { |
|
84 let summary = $("#requests-menu-network-summary-label"); |
|
85 let value = summary.getAttribute("value"); |
|
86 info("Current summary: " + value); |
|
87 |
|
88 let visibleItems = RequestsMenu.visibleItems; |
|
89 let visibleRequestsCount = visibleItems.length; |
|
90 let totalRequestsCount = RequestsMenu.itemCount; |
|
91 info("Current requests: " + visibleRequestsCount + " of " + totalRequestsCount + "."); |
|
92 |
|
93 if (!totalRequestsCount || !visibleRequestsCount) { |
|
94 is(value, L10N.getStr("networkMenu.empty"), |
|
95 "The current summary text is incorrect, expected an 'empty' label."); |
|
96 return; |
|
97 } |
|
98 |
|
99 let totalBytes = RequestsMenu._getTotalBytesOfRequests(visibleItems); |
|
100 let totalMillis = |
|
101 RequestsMenu._getNewestRequest(visibleItems).attachment.endedMillis - |
|
102 RequestsMenu._getOldestRequest(visibleItems).attachment.startedMillis; |
|
103 |
|
104 info("Computed total bytes: " + totalBytes); |
|
105 info("Computed total millis: " + totalMillis); |
|
106 |
|
107 is(value, PluralForm.get(visibleRequestsCount, L10N.getStr("networkMenu.summary")) |
|
108 .replace("#1", visibleRequestsCount) |
|
109 .replace("#2", L10N.numberWithDecimals((totalBytes || 0) / 1024, 2)) |
|
110 .replace("#3", L10N.numberWithDecimals((totalMillis || 0) / 1000, 2)) |
|
111 , "The current summary text is incorrect.") |
|
112 } |
|
113 |
|
114 aDebuggee.performRequests('{ "getMedia": true, "getFlash": true }'); |
|
115 }); |
|
116 } |