1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/netmonitor/test/browser_net_footer-summary.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,116 @@ 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 + * Test if the summary text displayed in the network requests menu footer 1.9 + * is correct. 1.10 + */ 1.11 + 1.12 +function test() { 1.13 + requestLongerTimeout(2); 1.14 + let { PluralForm } = Cu.import("resource://gre/modules/PluralForm.jsm", {}); 1.15 + 1.16 + initNetMonitor(FILTERING_URL).then(([aTab, aDebuggee, aMonitor]) => { 1.17 + info("Starting test... "); 1.18 + 1.19 + let { $, L10N, NetMonitorView } = aMonitor.panelWin; 1.20 + let { RequestsMenu } = NetMonitorView; 1.21 + 1.22 + RequestsMenu.lazyUpdate = false; 1.23 + testStatus(); 1.24 + 1.25 + waitForNetworkEvents(aMonitor, 8).then(() => { 1.26 + testStatus(); 1.27 + 1.28 + EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-html-button")); 1.29 + testStatus(); 1.30 + 1.31 + EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-css-button")); 1.32 + testStatus(); 1.33 + 1.34 + EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-js-button")); 1.35 + testStatus(); 1.36 + 1.37 + EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-xhr-button")); 1.38 + testStatus(); 1.39 + 1.40 + EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-fonts-button")); 1.41 + testStatus(); 1.42 + 1.43 + EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-images-button")); 1.44 + testStatus(); 1.45 + 1.46 + EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-media-button")); 1.47 + testStatus(); 1.48 + 1.49 + EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-flash-button")); 1.50 + testStatus(); 1.51 + 1.52 + info("Performing more requests."); 1.53 + aDebuggee.performRequests('{ "getMedia": true, "getFlash": true }'); 1.54 + return waitForNetworkEvents(aMonitor, 8); 1.55 + }) 1.56 + .then(() => { 1.57 + testStatus(); 1.58 + 1.59 + EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-html-button")); 1.60 + testStatus(); 1.61 + 1.62 + EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-css-button")); 1.63 + testStatus(); 1.64 + 1.65 + EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-js-button")); 1.66 + testStatus(); 1.67 + 1.68 + EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-xhr-button")); 1.69 + testStatus(); 1.70 + 1.71 + EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-fonts-button")); 1.72 + testStatus(); 1.73 + 1.74 + EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-images-button")); 1.75 + testStatus(); 1.76 + 1.77 + EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-media-button")); 1.78 + testStatus(); 1.79 + 1.80 + EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-filter-flash-button")); 1.81 + testStatus(); 1.82 + 1.83 + teardown(aMonitor).then(finish); 1.84 + }) 1.85 + 1.86 + function testStatus() { 1.87 + let summary = $("#requests-menu-network-summary-label"); 1.88 + let value = summary.getAttribute("value"); 1.89 + info("Current summary: " + value); 1.90 + 1.91 + let visibleItems = RequestsMenu.visibleItems; 1.92 + let visibleRequestsCount = visibleItems.length; 1.93 + let totalRequestsCount = RequestsMenu.itemCount; 1.94 + info("Current requests: " + visibleRequestsCount + " of " + totalRequestsCount + "."); 1.95 + 1.96 + if (!totalRequestsCount || !visibleRequestsCount) { 1.97 + is(value, L10N.getStr("networkMenu.empty"), 1.98 + "The current summary text is incorrect, expected an 'empty' label."); 1.99 + return; 1.100 + } 1.101 + 1.102 + let totalBytes = RequestsMenu._getTotalBytesOfRequests(visibleItems); 1.103 + let totalMillis = 1.104 + RequestsMenu._getNewestRequest(visibleItems).attachment.endedMillis - 1.105 + RequestsMenu._getOldestRequest(visibleItems).attachment.startedMillis; 1.106 + 1.107 + info("Computed total bytes: " + totalBytes); 1.108 + info("Computed total millis: " + totalMillis); 1.109 + 1.110 + is(value, PluralForm.get(visibleRequestsCount, L10N.getStr("networkMenu.summary")) 1.111 + .replace("#1", visibleRequestsCount) 1.112 + .replace("#2", L10N.numberWithDecimals((totalBytes || 0) / 1024, 2)) 1.113 + .replace("#3", L10N.numberWithDecimals((totalMillis || 0) / 1000, 2)) 1.114 + , "The current summary text is incorrect.") 1.115 + } 1.116 + 1.117 + aDebuggee.performRequests('{ "getMedia": true, "getFlash": true }'); 1.118 + }); 1.119 +}