browser/devtools/netmonitor/test/browser_net_simple-request-data.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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 * Tests if requests render correct information in the menu UI.
michael@0 6 */
michael@0 7
michael@0 8 function test() {
michael@0 9 initNetMonitor(SIMPLE_SJS).then(([aTab, aDebuggee, aMonitor]) => {
michael@0 10 info("Starting test... ");
michael@0 11
michael@0 12 let { L10N, NetMonitorView } = aMonitor.panelWin;
michael@0 13 let { RequestsMenu } = NetMonitorView;
michael@0 14
michael@0 15 RequestsMenu.lazyUpdate = false;
michael@0 16
michael@0 17 waitForNetworkEvents(aMonitor, 1)
michael@0 18 .then(() => teardown(aMonitor))
michael@0 19 .then(finish);
michael@0 20
michael@0 21 aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.NETWORK_EVENT, () => {
michael@0 22 is(RequestsMenu.selectedItem, null,
michael@0 23 "There shouldn't be any selected item in the requests menu.");
michael@0 24 is(RequestsMenu.itemCount, 1,
michael@0 25 "The requests menu should not be empty after the first request.");
michael@0 26 is(NetMonitorView.detailsPaneHidden, true,
michael@0 27 "The details pane should still be hidden after the first request.");
michael@0 28
michael@0 29 let requestItem = RequestsMenu.getItemAtIndex(0);
michael@0 30 let target = requestItem.target;
michael@0 31
michael@0 32 is(typeof requestItem.value, "string",
michael@0 33 "The attached request id is incorrect.");
michael@0 34 isnot(requestItem.value, "",
michael@0 35 "The attached request id should not be empty.");
michael@0 36
michael@0 37 is(typeof requestItem.attachment.startedDeltaMillis, "number",
michael@0 38 "The attached startedDeltaMillis is incorrect.");
michael@0 39 is(requestItem.attachment.startedDeltaMillis, 0,
michael@0 40 "The attached startedDeltaMillis should be zero.");
michael@0 41
michael@0 42 is(typeof requestItem.attachment.startedMillis, "number",
michael@0 43 "The attached startedMillis is incorrect.");
michael@0 44 isnot(requestItem.attachment.startedMillis, 0,
michael@0 45 "The attached startedMillis should not be zero.");
michael@0 46
michael@0 47 is(requestItem.attachment.requestHeaders, undefined,
michael@0 48 "The requestHeaders should not yet be set.");
michael@0 49 is(requestItem.attachment.requestCookies, undefined,
michael@0 50 "The requestCookies should not yet be set.");
michael@0 51 is(requestItem.attachment.requestPostData, undefined,
michael@0 52 "The requestPostData should not yet be set.");
michael@0 53
michael@0 54 is(requestItem.attachment.responseHeaders, undefined,
michael@0 55 "The responseHeaders should not yet be set.");
michael@0 56 is(requestItem.attachment.responseCookies, undefined,
michael@0 57 "The responseCookies should not yet be set.");
michael@0 58
michael@0 59 is(requestItem.attachment.httpVersion, undefined,
michael@0 60 "The httpVersion should not yet be set.");
michael@0 61 is(requestItem.attachment.status, undefined,
michael@0 62 "The status should not yet be set.");
michael@0 63 is(requestItem.attachment.statusText, undefined,
michael@0 64 "The statusText should not yet be set.");
michael@0 65
michael@0 66 is(requestItem.attachment.headersSize, undefined,
michael@0 67 "The headersSize should not yet be set.");
michael@0 68 is(requestItem.attachment.contentSize, undefined,
michael@0 69 "The contentSize should not yet be set.");
michael@0 70
michael@0 71 is(requestItem.attachment.mimeType, undefined,
michael@0 72 "The mimeType should not yet be set.");
michael@0 73 is(requestItem.attachment.responseContent, undefined,
michael@0 74 "The responseContent should not yet be set.");
michael@0 75
michael@0 76 is(requestItem.attachment.totalTime, undefined,
michael@0 77 "The totalTime should not yet be set.");
michael@0 78 is(requestItem.attachment.eventTimings, undefined,
michael@0 79 "The eventTimings should not yet be set.");
michael@0 80
michael@0 81 verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS);
michael@0 82 });
michael@0 83
michael@0 84 aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_REQUEST_HEADERS, () => {
michael@0 85 let requestItem = RequestsMenu.getItemAtIndex(0);
michael@0 86
michael@0 87 ok(requestItem.attachment.requestHeaders,
michael@0 88 "There should be a requestHeaders attachment available.");
michael@0 89 ok(requestItem.attachment.requestHeaders.headers.length >= 6,
michael@0 90 "The requestHeaders attachment has an incorrect |headers| property.");
michael@0 91 // Can't test for an exact total number of headers, because it seems to
michael@0 92 // vary across pgo/non-pgo builds.
michael@0 93 isnot(requestItem.attachment.requestHeaders.headersSize, 0,
michael@0 94 "The requestHeaders attachment has an incorrect |headersSize| property.");
michael@0 95 // Can't test for the exact request headers size because the value may
michael@0 96 // vary across platforms ("User-Agent" header differs).
michael@0 97
michael@0 98 verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS);
michael@0 99 });
michael@0 100
michael@0 101 aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_REQUEST_COOKIES, () => {
michael@0 102 let requestItem = RequestsMenu.getItemAtIndex(0);
michael@0 103
michael@0 104 ok(requestItem.attachment.requestCookies,
michael@0 105 "There should be a requestCookies attachment available.");
michael@0 106 is(requestItem.attachment.requestCookies.cookies.length, 0,
michael@0 107 "The requestCookies attachment has an incorrect |cookies| property.");
michael@0 108
michael@0 109 verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS);
michael@0 110 });
michael@0 111
michael@0 112 aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_REQUEST_POST_DATA, () => {
michael@0 113 ok(false, "Trap listener: this request doesn't have any post data.")
michael@0 114 });
michael@0 115
michael@0 116 aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_RESPONSE_HEADERS, () => {
michael@0 117 let requestItem = RequestsMenu.getItemAtIndex(0);
michael@0 118
michael@0 119 ok(requestItem.attachment.responseHeaders,
michael@0 120 "There should be a responseHeaders attachment available.");
michael@0 121 is(requestItem.attachment.responseHeaders.headers.length, 6,
michael@0 122 "The responseHeaders attachment has an incorrect |headers| property.");
michael@0 123 is(requestItem.attachment.responseHeaders.headersSize, 173,
michael@0 124 "The responseHeaders attachment has an incorrect |headersSize| property.");
michael@0 125
michael@0 126 verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS);
michael@0 127 });
michael@0 128
michael@0 129 aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_RESPONSE_COOKIES, () => {
michael@0 130 let requestItem = RequestsMenu.getItemAtIndex(0);
michael@0 131
michael@0 132 ok(requestItem.attachment.responseCookies,
michael@0 133 "There should be a responseCookies attachment available.");
michael@0 134 is(requestItem.attachment.responseCookies.cookies.length, 0,
michael@0 135 "The responseCookies attachment has an incorrect |cookies| property.");
michael@0 136
michael@0 137 verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS);
michael@0 138 });
michael@0 139
michael@0 140 aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.STARTED_RECEIVING_RESPONSE, () => {
michael@0 141 let requestItem = RequestsMenu.getItemAtIndex(0);
michael@0 142
michael@0 143 is(requestItem.attachment.httpVersion, "HTTP/1.1",
michael@0 144 "The httpVersion attachment has an incorrect value.");
michael@0 145 is(requestItem.attachment.status, "200",
michael@0 146 "The status attachment has an incorrect value.");
michael@0 147 is(requestItem.attachment.statusText, "Och Aye",
michael@0 148 "The statusText attachment has an incorrect value.");
michael@0 149 is(requestItem.attachment.headersSize, 173,
michael@0 150 "The headersSize attachment has an incorrect value.");
michael@0 151
michael@0 152 verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, {
michael@0 153 status: "200",
michael@0 154 statusText: "Och Aye"
michael@0 155 });
michael@0 156 });
michael@0 157
michael@0 158 aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.UPDATING_RESPONSE_CONTENT, () => {
michael@0 159 let requestItem = RequestsMenu.getItemAtIndex(0);
michael@0 160
michael@0 161 is(requestItem.attachment.contentSize, "12",
michael@0 162 "The contentSize attachment has an incorrect value.");
michael@0 163 is(requestItem.attachment.mimeType, "text/plain; charset=utf-8",
michael@0 164 "The mimeType attachment has an incorrect value.");
michael@0 165
michael@0 166 verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, {
michael@0 167 type: "plain",
michael@0 168 fullMimeType: "text/plain; charset=utf-8",
michael@0 169 size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.01),
michael@0 170 });
michael@0 171 });
michael@0 172
michael@0 173 aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_RESPONSE_CONTENT, () => {
michael@0 174 let requestItem = RequestsMenu.getItemAtIndex(0);
michael@0 175
michael@0 176 ok(requestItem.attachment.responseContent,
michael@0 177 "There should be a responseContent attachment available.");
michael@0 178 is(requestItem.attachment.responseContent.content.mimeType, "text/plain; charset=utf-8",
michael@0 179 "The responseContent attachment has an incorrect |content.mimeType| property.");
michael@0 180 is(requestItem.attachment.responseContent.content.text, "Hello world!",
michael@0 181 "The responseContent attachment has an incorrect |content.text| property.");
michael@0 182 is(requestItem.attachment.responseContent.content.size, 12,
michael@0 183 "The responseContent attachment has an incorrect |content.size| property.");
michael@0 184
michael@0 185 verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, {
michael@0 186 type: "plain",
michael@0 187 fullMimeType: "text/plain; charset=utf-8",
michael@0 188 size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.01),
michael@0 189 });
michael@0 190 });
michael@0 191
michael@0 192 aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.UPDATING_EVENT_TIMINGS, () => {
michael@0 193 let requestItem = RequestsMenu.getItemAtIndex(0);
michael@0 194
michael@0 195 is(typeof requestItem.attachment.totalTime, "number",
michael@0 196 "The attached totalTime is incorrect.");
michael@0 197 ok(requestItem.attachment.totalTime >= 0,
michael@0 198 "The attached totalTime should be positive.");
michael@0 199
michael@0 200 is(typeof requestItem.attachment.endedMillis, "number",
michael@0 201 "The attached endedMillis is incorrect.");
michael@0 202 ok(requestItem.attachment.endedMillis >= 0,
michael@0 203 "The attached endedMillis should be positive.");
michael@0 204
michael@0 205 verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, {
michael@0 206 time: true
michael@0 207 });
michael@0 208 });
michael@0 209
michael@0 210 aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_EVENT_TIMINGS, () => {
michael@0 211 let requestItem = RequestsMenu.getItemAtIndex(0);
michael@0 212
michael@0 213 ok(requestItem.attachment.eventTimings,
michael@0 214 "There should be a eventTimings attachment available.");
michael@0 215 is(typeof requestItem.attachment.eventTimings.timings.blocked, "number",
michael@0 216 "The eventTimings attachment has an incorrect |timings.blocked| property.");
michael@0 217 is(typeof requestItem.attachment.eventTimings.timings.dns, "number",
michael@0 218 "The eventTimings attachment has an incorrect |timings.dns| property.");
michael@0 219 is(typeof requestItem.attachment.eventTimings.timings.connect, "number",
michael@0 220 "The eventTimings attachment has an incorrect |timings.connect| property.");
michael@0 221 is(typeof requestItem.attachment.eventTimings.timings.send, "number",
michael@0 222 "The eventTimings attachment has an incorrect |timings.send| property.");
michael@0 223 is(typeof requestItem.attachment.eventTimings.timings.wait, "number",
michael@0 224 "The eventTimings attachment has an incorrect |timings.wait| property.");
michael@0 225 is(typeof requestItem.attachment.eventTimings.timings.receive, "number",
michael@0 226 "The eventTimings attachment has an incorrect |timings.receive| property.");
michael@0 227 is(typeof requestItem.attachment.eventTimings.totalTime, "number",
michael@0 228 "The eventTimings attachment has an incorrect |totalTime| property.");
michael@0 229
michael@0 230 verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, {
michael@0 231 time: true
michael@0 232 });
michael@0 233 });
michael@0 234
michael@0 235 aDebuggee.location.reload();
michael@0 236 });
michael@0 237 }

mercurial