browser/devtools/netmonitor/test/browser_net_footer-summary.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.

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

mercurial