michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Tests if requests render correct information in the menu UI. michael@0: */ michael@0: michael@0: function test() { michael@0: initNetMonitor(SIMPLE_SJS).then(([aTab, aDebuggee, aMonitor]) => { michael@0: info("Starting test... "); michael@0: michael@0: let { L10N, NetMonitorView } = aMonitor.panelWin; michael@0: let { RequestsMenu } = NetMonitorView; michael@0: michael@0: RequestsMenu.lazyUpdate = false; michael@0: michael@0: waitForNetworkEvents(aMonitor, 1) michael@0: .then(() => teardown(aMonitor)) michael@0: .then(finish); michael@0: michael@0: aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.NETWORK_EVENT, () => { michael@0: is(RequestsMenu.selectedItem, null, michael@0: "There shouldn't be any selected item in the requests menu."); michael@0: is(RequestsMenu.itemCount, 1, michael@0: "The requests menu should not be empty after the first request."); michael@0: is(NetMonitorView.detailsPaneHidden, true, michael@0: "The details pane should still be hidden after the first request."); michael@0: michael@0: let requestItem = RequestsMenu.getItemAtIndex(0); michael@0: let target = requestItem.target; michael@0: michael@0: is(typeof requestItem.value, "string", michael@0: "The attached request id is incorrect."); michael@0: isnot(requestItem.value, "", michael@0: "The attached request id should not be empty."); michael@0: michael@0: is(typeof requestItem.attachment.startedDeltaMillis, "number", michael@0: "The attached startedDeltaMillis is incorrect."); michael@0: is(requestItem.attachment.startedDeltaMillis, 0, michael@0: "The attached startedDeltaMillis should be zero."); michael@0: michael@0: is(typeof requestItem.attachment.startedMillis, "number", michael@0: "The attached startedMillis is incorrect."); michael@0: isnot(requestItem.attachment.startedMillis, 0, michael@0: "The attached startedMillis should not be zero."); michael@0: michael@0: is(requestItem.attachment.requestHeaders, undefined, michael@0: "The requestHeaders should not yet be set."); michael@0: is(requestItem.attachment.requestCookies, undefined, michael@0: "The requestCookies should not yet be set."); michael@0: is(requestItem.attachment.requestPostData, undefined, michael@0: "The requestPostData should not yet be set."); michael@0: michael@0: is(requestItem.attachment.responseHeaders, undefined, michael@0: "The responseHeaders should not yet be set."); michael@0: is(requestItem.attachment.responseCookies, undefined, michael@0: "The responseCookies should not yet be set."); michael@0: michael@0: is(requestItem.attachment.httpVersion, undefined, michael@0: "The httpVersion should not yet be set."); michael@0: is(requestItem.attachment.status, undefined, michael@0: "The status should not yet be set."); michael@0: is(requestItem.attachment.statusText, undefined, michael@0: "The statusText should not yet be set."); michael@0: michael@0: is(requestItem.attachment.headersSize, undefined, michael@0: "The headersSize should not yet be set."); michael@0: is(requestItem.attachment.contentSize, undefined, michael@0: "The contentSize should not yet be set."); michael@0: michael@0: is(requestItem.attachment.mimeType, undefined, michael@0: "The mimeType should not yet be set."); michael@0: is(requestItem.attachment.responseContent, undefined, michael@0: "The responseContent should not yet be set."); michael@0: michael@0: is(requestItem.attachment.totalTime, undefined, michael@0: "The totalTime should not yet be set."); michael@0: is(requestItem.attachment.eventTimings, undefined, michael@0: "The eventTimings should not yet be set."); michael@0: michael@0: verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS); michael@0: }); michael@0: michael@0: aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_REQUEST_HEADERS, () => { michael@0: let requestItem = RequestsMenu.getItemAtIndex(0); michael@0: michael@0: ok(requestItem.attachment.requestHeaders, michael@0: "There should be a requestHeaders attachment available."); michael@0: ok(requestItem.attachment.requestHeaders.headers.length >= 6, michael@0: "The requestHeaders attachment has an incorrect |headers| property."); michael@0: // Can't test for an exact total number of headers, because it seems to michael@0: // vary across pgo/non-pgo builds. michael@0: isnot(requestItem.attachment.requestHeaders.headersSize, 0, michael@0: "The requestHeaders attachment has an incorrect |headersSize| property."); michael@0: // Can't test for the exact request headers size because the value may michael@0: // vary across platforms ("User-Agent" header differs). michael@0: michael@0: verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS); michael@0: }); michael@0: michael@0: aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_REQUEST_COOKIES, () => { michael@0: let requestItem = RequestsMenu.getItemAtIndex(0); michael@0: michael@0: ok(requestItem.attachment.requestCookies, michael@0: "There should be a requestCookies attachment available."); michael@0: is(requestItem.attachment.requestCookies.cookies.length, 0, michael@0: "The requestCookies attachment has an incorrect |cookies| property."); michael@0: michael@0: verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS); michael@0: }); michael@0: michael@0: aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_REQUEST_POST_DATA, () => { michael@0: ok(false, "Trap listener: this request doesn't have any post data.") michael@0: }); michael@0: michael@0: aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_RESPONSE_HEADERS, () => { michael@0: let requestItem = RequestsMenu.getItemAtIndex(0); michael@0: michael@0: ok(requestItem.attachment.responseHeaders, michael@0: "There should be a responseHeaders attachment available."); michael@0: is(requestItem.attachment.responseHeaders.headers.length, 6, michael@0: "The responseHeaders attachment has an incorrect |headers| property."); michael@0: is(requestItem.attachment.responseHeaders.headersSize, 173, michael@0: "The responseHeaders attachment has an incorrect |headersSize| property."); michael@0: michael@0: verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS); michael@0: }); michael@0: michael@0: aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_RESPONSE_COOKIES, () => { michael@0: let requestItem = RequestsMenu.getItemAtIndex(0); michael@0: michael@0: ok(requestItem.attachment.responseCookies, michael@0: "There should be a responseCookies attachment available."); michael@0: is(requestItem.attachment.responseCookies.cookies.length, 0, michael@0: "The responseCookies attachment has an incorrect |cookies| property."); michael@0: michael@0: verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS); michael@0: }); michael@0: michael@0: aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.STARTED_RECEIVING_RESPONSE, () => { michael@0: let requestItem = RequestsMenu.getItemAtIndex(0); michael@0: michael@0: is(requestItem.attachment.httpVersion, "HTTP/1.1", michael@0: "The httpVersion attachment has an incorrect value."); michael@0: is(requestItem.attachment.status, "200", michael@0: "The status attachment has an incorrect value."); michael@0: is(requestItem.attachment.statusText, "Och Aye", michael@0: "The statusText attachment has an incorrect value."); michael@0: is(requestItem.attachment.headersSize, 173, michael@0: "The headersSize attachment has an incorrect value."); michael@0: michael@0: verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, { michael@0: status: "200", michael@0: statusText: "Och Aye" michael@0: }); michael@0: }); michael@0: michael@0: aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.UPDATING_RESPONSE_CONTENT, () => { michael@0: let requestItem = RequestsMenu.getItemAtIndex(0); michael@0: michael@0: is(requestItem.attachment.contentSize, "12", michael@0: "The contentSize attachment has an incorrect value."); michael@0: is(requestItem.attachment.mimeType, "text/plain; charset=utf-8", michael@0: "The mimeType attachment has an incorrect value."); michael@0: michael@0: verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, { michael@0: type: "plain", michael@0: fullMimeType: "text/plain; charset=utf-8", michael@0: size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.01), michael@0: }); michael@0: }); michael@0: michael@0: aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_RESPONSE_CONTENT, () => { michael@0: let requestItem = RequestsMenu.getItemAtIndex(0); michael@0: michael@0: ok(requestItem.attachment.responseContent, michael@0: "There should be a responseContent attachment available."); michael@0: is(requestItem.attachment.responseContent.content.mimeType, "text/plain; charset=utf-8", michael@0: "The responseContent attachment has an incorrect |content.mimeType| property."); michael@0: is(requestItem.attachment.responseContent.content.text, "Hello world!", michael@0: "The responseContent attachment has an incorrect |content.text| property."); michael@0: is(requestItem.attachment.responseContent.content.size, 12, michael@0: "The responseContent attachment has an incorrect |content.size| property."); michael@0: michael@0: verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, { michael@0: type: "plain", michael@0: fullMimeType: "text/plain; charset=utf-8", michael@0: size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.01), michael@0: }); michael@0: }); michael@0: michael@0: aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.UPDATING_EVENT_TIMINGS, () => { michael@0: let requestItem = RequestsMenu.getItemAtIndex(0); michael@0: michael@0: is(typeof requestItem.attachment.totalTime, "number", michael@0: "The attached totalTime is incorrect."); michael@0: ok(requestItem.attachment.totalTime >= 0, michael@0: "The attached totalTime should be positive."); michael@0: michael@0: is(typeof requestItem.attachment.endedMillis, "number", michael@0: "The attached endedMillis is incorrect."); michael@0: ok(requestItem.attachment.endedMillis >= 0, michael@0: "The attached endedMillis should be positive."); michael@0: michael@0: verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, { michael@0: time: true michael@0: }); michael@0: }); michael@0: michael@0: aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_EVENT_TIMINGS, () => { michael@0: let requestItem = RequestsMenu.getItemAtIndex(0); michael@0: michael@0: ok(requestItem.attachment.eventTimings, michael@0: "There should be a eventTimings attachment available."); michael@0: is(typeof requestItem.attachment.eventTimings.timings.blocked, "number", michael@0: "The eventTimings attachment has an incorrect |timings.blocked| property."); michael@0: is(typeof requestItem.attachment.eventTimings.timings.dns, "number", michael@0: "The eventTimings attachment has an incorrect |timings.dns| property."); michael@0: is(typeof requestItem.attachment.eventTimings.timings.connect, "number", michael@0: "The eventTimings attachment has an incorrect |timings.connect| property."); michael@0: is(typeof requestItem.attachment.eventTimings.timings.send, "number", michael@0: "The eventTimings attachment has an incorrect |timings.send| property."); michael@0: is(typeof requestItem.attachment.eventTimings.timings.wait, "number", michael@0: "The eventTimings attachment has an incorrect |timings.wait| property."); michael@0: is(typeof requestItem.attachment.eventTimings.timings.receive, "number", michael@0: "The eventTimings attachment has an incorrect |timings.receive| property."); michael@0: is(typeof requestItem.attachment.eventTimings.totalTime, "number", michael@0: "The eventTimings attachment has an incorrect |totalTime| property."); michael@0: michael@0: verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, { michael@0: time: true michael@0: }); michael@0: }); michael@0: michael@0: aDebuggee.location.reload(); michael@0: }); michael@0: }