1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/netmonitor/test/browser_net_simple-request-data.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,237 @@ 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 + * Tests if requests render correct information in the menu UI. 1.9 + */ 1.10 + 1.11 +function test() { 1.12 + initNetMonitor(SIMPLE_SJS).then(([aTab, aDebuggee, aMonitor]) => { 1.13 + info("Starting test... "); 1.14 + 1.15 + let { L10N, NetMonitorView } = aMonitor.panelWin; 1.16 + let { RequestsMenu } = NetMonitorView; 1.17 + 1.18 + RequestsMenu.lazyUpdate = false; 1.19 + 1.20 + waitForNetworkEvents(aMonitor, 1) 1.21 + .then(() => teardown(aMonitor)) 1.22 + .then(finish); 1.23 + 1.24 + aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.NETWORK_EVENT, () => { 1.25 + is(RequestsMenu.selectedItem, null, 1.26 + "There shouldn't be any selected item in the requests menu."); 1.27 + is(RequestsMenu.itemCount, 1, 1.28 + "The requests menu should not be empty after the first request."); 1.29 + is(NetMonitorView.detailsPaneHidden, true, 1.30 + "The details pane should still be hidden after the first request."); 1.31 + 1.32 + let requestItem = RequestsMenu.getItemAtIndex(0); 1.33 + let target = requestItem.target; 1.34 + 1.35 + is(typeof requestItem.value, "string", 1.36 + "The attached request id is incorrect."); 1.37 + isnot(requestItem.value, "", 1.38 + "The attached request id should not be empty."); 1.39 + 1.40 + is(typeof requestItem.attachment.startedDeltaMillis, "number", 1.41 + "The attached startedDeltaMillis is incorrect."); 1.42 + is(requestItem.attachment.startedDeltaMillis, 0, 1.43 + "The attached startedDeltaMillis should be zero."); 1.44 + 1.45 + is(typeof requestItem.attachment.startedMillis, "number", 1.46 + "The attached startedMillis is incorrect."); 1.47 + isnot(requestItem.attachment.startedMillis, 0, 1.48 + "The attached startedMillis should not be zero."); 1.49 + 1.50 + is(requestItem.attachment.requestHeaders, undefined, 1.51 + "The requestHeaders should not yet be set."); 1.52 + is(requestItem.attachment.requestCookies, undefined, 1.53 + "The requestCookies should not yet be set."); 1.54 + is(requestItem.attachment.requestPostData, undefined, 1.55 + "The requestPostData should not yet be set."); 1.56 + 1.57 + is(requestItem.attachment.responseHeaders, undefined, 1.58 + "The responseHeaders should not yet be set."); 1.59 + is(requestItem.attachment.responseCookies, undefined, 1.60 + "The responseCookies should not yet be set."); 1.61 + 1.62 + is(requestItem.attachment.httpVersion, undefined, 1.63 + "The httpVersion should not yet be set."); 1.64 + is(requestItem.attachment.status, undefined, 1.65 + "The status should not yet be set."); 1.66 + is(requestItem.attachment.statusText, undefined, 1.67 + "The statusText should not yet be set."); 1.68 + 1.69 + is(requestItem.attachment.headersSize, undefined, 1.70 + "The headersSize should not yet be set."); 1.71 + is(requestItem.attachment.contentSize, undefined, 1.72 + "The contentSize should not yet be set."); 1.73 + 1.74 + is(requestItem.attachment.mimeType, undefined, 1.75 + "The mimeType should not yet be set."); 1.76 + is(requestItem.attachment.responseContent, undefined, 1.77 + "The responseContent should not yet be set."); 1.78 + 1.79 + is(requestItem.attachment.totalTime, undefined, 1.80 + "The totalTime should not yet be set."); 1.81 + is(requestItem.attachment.eventTimings, undefined, 1.82 + "The eventTimings should not yet be set."); 1.83 + 1.84 + verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS); 1.85 + }); 1.86 + 1.87 + aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_REQUEST_HEADERS, () => { 1.88 + let requestItem = RequestsMenu.getItemAtIndex(0); 1.89 + 1.90 + ok(requestItem.attachment.requestHeaders, 1.91 + "There should be a requestHeaders attachment available."); 1.92 + ok(requestItem.attachment.requestHeaders.headers.length >= 6, 1.93 + "The requestHeaders attachment has an incorrect |headers| property."); 1.94 + // Can't test for an exact total number of headers, because it seems to 1.95 + // vary across pgo/non-pgo builds. 1.96 + isnot(requestItem.attachment.requestHeaders.headersSize, 0, 1.97 + "The requestHeaders attachment has an incorrect |headersSize| property."); 1.98 + // Can't test for the exact request headers size because the value may 1.99 + // vary across platforms ("User-Agent" header differs). 1.100 + 1.101 + verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS); 1.102 + }); 1.103 + 1.104 + aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_REQUEST_COOKIES, () => { 1.105 + let requestItem = RequestsMenu.getItemAtIndex(0); 1.106 + 1.107 + ok(requestItem.attachment.requestCookies, 1.108 + "There should be a requestCookies attachment available."); 1.109 + is(requestItem.attachment.requestCookies.cookies.length, 0, 1.110 + "The requestCookies attachment has an incorrect |cookies| property."); 1.111 + 1.112 + verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS); 1.113 + }); 1.114 + 1.115 + aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_REQUEST_POST_DATA, () => { 1.116 + ok(false, "Trap listener: this request doesn't have any post data.") 1.117 + }); 1.118 + 1.119 + aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_RESPONSE_HEADERS, () => { 1.120 + let requestItem = RequestsMenu.getItemAtIndex(0); 1.121 + 1.122 + ok(requestItem.attachment.responseHeaders, 1.123 + "There should be a responseHeaders attachment available."); 1.124 + is(requestItem.attachment.responseHeaders.headers.length, 6, 1.125 + "The responseHeaders attachment has an incorrect |headers| property."); 1.126 + is(requestItem.attachment.responseHeaders.headersSize, 173, 1.127 + "The responseHeaders attachment has an incorrect |headersSize| property."); 1.128 + 1.129 + verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS); 1.130 + }); 1.131 + 1.132 + aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_RESPONSE_COOKIES, () => { 1.133 + let requestItem = RequestsMenu.getItemAtIndex(0); 1.134 + 1.135 + ok(requestItem.attachment.responseCookies, 1.136 + "There should be a responseCookies attachment available."); 1.137 + is(requestItem.attachment.responseCookies.cookies.length, 0, 1.138 + "The responseCookies attachment has an incorrect |cookies| property."); 1.139 + 1.140 + verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS); 1.141 + }); 1.142 + 1.143 + aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.STARTED_RECEIVING_RESPONSE, () => { 1.144 + let requestItem = RequestsMenu.getItemAtIndex(0); 1.145 + 1.146 + is(requestItem.attachment.httpVersion, "HTTP/1.1", 1.147 + "The httpVersion attachment has an incorrect value."); 1.148 + is(requestItem.attachment.status, "200", 1.149 + "The status attachment has an incorrect value."); 1.150 + is(requestItem.attachment.statusText, "Och Aye", 1.151 + "The statusText attachment has an incorrect value."); 1.152 + is(requestItem.attachment.headersSize, 173, 1.153 + "The headersSize attachment has an incorrect value."); 1.154 + 1.155 + verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, { 1.156 + status: "200", 1.157 + statusText: "Och Aye" 1.158 + }); 1.159 + }); 1.160 + 1.161 + aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.UPDATING_RESPONSE_CONTENT, () => { 1.162 + let requestItem = RequestsMenu.getItemAtIndex(0); 1.163 + 1.164 + is(requestItem.attachment.contentSize, "12", 1.165 + "The contentSize attachment has an incorrect value."); 1.166 + is(requestItem.attachment.mimeType, "text/plain; charset=utf-8", 1.167 + "The mimeType attachment has an incorrect value."); 1.168 + 1.169 + verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, { 1.170 + type: "plain", 1.171 + fullMimeType: "text/plain; charset=utf-8", 1.172 + size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.01), 1.173 + }); 1.174 + }); 1.175 + 1.176 + aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_RESPONSE_CONTENT, () => { 1.177 + let requestItem = RequestsMenu.getItemAtIndex(0); 1.178 + 1.179 + ok(requestItem.attachment.responseContent, 1.180 + "There should be a responseContent attachment available."); 1.181 + is(requestItem.attachment.responseContent.content.mimeType, "text/plain; charset=utf-8", 1.182 + "The responseContent attachment has an incorrect |content.mimeType| property."); 1.183 + is(requestItem.attachment.responseContent.content.text, "Hello world!", 1.184 + "The responseContent attachment has an incorrect |content.text| property."); 1.185 + is(requestItem.attachment.responseContent.content.size, 12, 1.186 + "The responseContent attachment has an incorrect |content.size| property."); 1.187 + 1.188 + verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, { 1.189 + type: "plain", 1.190 + fullMimeType: "text/plain; charset=utf-8", 1.191 + size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.01), 1.192 + }); 1.193 + }); 1.194 + 1.195 + aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.UPDATING_EVENT_TIMINGS, () => { 1.196 + let requestItem = RequestsMenu.getItemAtIndex(0); 1.197 + 1.198 + is(typeof requestItem.attachment.totalTime, "number", 1.199 + "The attached totalTime is incorrect."); 1.200 + ok(requestItem.attachment.totalTime >= 0, 1.201 + "The attached totalTime should be positive."); 1.202 + 1.203 + is(typeof requestItem.attachment.endedMillis, "number", 1.204 + "The attached endedMillis is incorrect."); 1.205 + ok(requestItem.attachment.endedMillis >= 0, 1.206 + "The attached endedMillis should be positive."); 1.207 + 1.208 + verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, { 1.209 + time: true 1.210 + }); 1.211 + }); 1.212 + 1.213 + aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_EVENT_TIMINGS, () => { 1.214 + let requestItem = RequestsMenu.getItemAtIndex(0); 1.215 + 1.216 + ok(requestItem.attachment.eventTimings, 1.217 + "There should be a eventTimings attachment available."); 1.218 + is(typeof requestItem.attachment.eventTimings.timings.blocked, "number", 1.219 + "The eventTimings attachment has an incorrect |timings.blocked| property."); 1.220 + is(typeof requestItem.attachment.eventTimings.timings.dns, "number", 1.221 + "The eventTimings attachment has an incorrect |timings.dns| property."); 1.222 + is(typeof requestItem.attachment.eventTimings.timings.connect, "number", 1.223 + "The eventTimings attachment has an incorrect |timings.connect| property."); 1.224 + is(typeof requestItem.attachment.eventTimings.timings.send, "number", 1.225 + "The eventTimings attachment has an incorrect |timings.send| property."); 1.226 + is(typeof requestItem.attachment.eventTimings.timings.wait, "number", 1.227 + "The eventTimings attachment has an incorrect |timings.wait| property."); 1.228 + is(typeof requestItem.attachment.eventTimings.timings.receive, "number", 1.229 + "The eventTimings attachment has an incorrect |timings.receive| property."); 1.230 + is(typeof requestItem.attachment.eventTimings.totalTime, "number", 1.231 + "The eventTimings attachment has an incorrect |totalTime| property."); 1.232 + 1.233 + verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, { 1.234 + time: true 1.235 + }); 1.236 + }); 1.237 + 1.238 + aDebuggee.location.reload(); 1.239 + }); 1.240 +}