2012-10-05 06:40:57 -07:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset="utf8">
|
|
|
|
<title>Test for the network actor (POST request)</title>
|
|
|
|
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<script type="text/javascript;version=1.8" src="common.js"></script>
|
|
|
|
<!-- Any copyright is dedicated to the Public Domain.
|
|
|
|
- http://creativecommons.org/publicdomain/zero/1.0/ -->
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<p>Test for the network actor (POST request)</p>
|
|
|
|
|
|
|
|
<iframe src="http://example.com/chrome/toolkit/devtools/webconsole/test/network_requests_iframe.html"></iframe>
|
|
|
|
|
|
|
|
<script class="testbody" type="text/javascript;version=1.8">
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
function startTest()
|
|
|
|
{
|
|
|
|
removeEventListener("load", startTest);
|
|
|
|
|
|
|
|
attachConsole(["NetworkActivity"], onAttach, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onAttach(aState, aResponse)
|
|
|
|
{
|
|
|
|
info("enable network request and response body logging");
|
|
|
|
|
|
|
|
onSetPreferences = onSetPreferences.bind(null, aState);
|
|
|
|
aState.client.setPreferences({
|
|
|
|
"NetworkMonitor.saveRequestAndResponseBodies": true,
|
|
|
|
}, onSetPreferences);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onSetPreferences(aState, aResponse)
|
|
|
|
{
|
|
|
|
is(aResponse.updated.length, 1, "updated prefs length");
|
|
|
|
is(aResponse.updated[0], "NetworkMonitor.saveRequestAndResponseBodies",
|
|
|
|
"updated prefs length");
|
|
|
|
|
|
|
|
info("test network POST request");
|
|
|
|
|
|
|
|
onNetworkEvent = onNetworkEvent.bind(null, aState);
|
|
|
|
aState.dbgClient.addListener("networkEvent", onNetworkEvent);
|
|
|
|
onNetworkEventUpdate = onNetworkEventUpdate.bind(null, aState);
|
|
|
|
aState.dbgClient.addListener("networkEventUpdate", onNetworkEventUpdate);
|
|
|
|
|
|
|
|
let iframe = document.querySelector("iframe").contentWindow;
|
|
|
|
iframe.wrappedJSObject.testXhrPost();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onNetworkEvent(aState, aType, aPacket)
|
|
|
|
{
|
|
|
|
is(aPacket.from, aState.actor, "network event actor");
|
|
|
|
|
|
|
|
info("checking the network event packet");
|
|
|
|
|
|
|
|
let netActor = aPacket.eventActor;
|
|
|
|
|
|
|
|
checkObject(netActor, {
|
|
|
|
actor: /[a-z]/,
|
|
|
|
startedDateTime: /^\d+\-\d+\-\d+T.+$/,
|
|
|
|
url: /data\.json/,
|
|
|
|
method: "POST",
|
|
|
|
});
|
|
|
|
|
|
|
|
aState.netActor = netActor.actor;
|
|
|
|
|
|
|
|
aState.dbgClient.removeListener("networkEvent", onNetworkEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
let updates = [];
|
|
|
|
|
|
|
|
function onNetworkEventUpdate(aState, aType, aPacket)
|
|
|
|
{
|
|
|
|
info("received networkEventUpdate " + aPacket.updateType);
|
|
|
|
is(aPacket.from, aState.netActor, "networkEventUpdate actor");
|
|
|
|
|
|
|
|
updates.push(aPacket.updateType);
|
|
|
|
|
|
|
|
let expectedPacket = null;
|
|
|
|
|
|
|
|
switch (aPacket.updateType) {
|
|
|
|
case "requestHeaders":
|
|
|
|
case "responseHeaders":
|
|
|
|
ok(aPacket.headers > 0, "headers > 0");
|
|
|
|
ok(aPacket.headersSize > 0, "headersSize > 0");
|
|
|
|
break;
|
|
|
|
case "requestCookies":
|
|
|
|
expectedPacket = {
|
2013-01-08 13:25:57 -08:00
|
|
|
cookies: 3,
|
2012-10-05 06:40:57 -07:00
|
|
|
};
|
|
|
|
break;
|
|
|
|
case "requestPostData":
|
|
|
|
ok(aPacket.dataSize > 0, "dataSize > 0");
|
|
|
|
ok(!aPacket.discardRequestBody, "discardRequestBody");
|
|
|
|
break;
|
|
|
|
case "responseStart":
|
|
|
|
expectedPacket = {
|
|
|
|
response: {
|
|
|
|
httpVersion: /^HTTP\/\d\.\d$/,
|
|
|
|
status: 200,
|
|
|
|
statusText: "OK",
|
|
|
|
headersSize: /^\d+$/,
|
|
|
|
discardResponseBody: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case "responseCookies":
|
|
|
|
expectedPacket = {
|
|
|
|
cookies: 0,
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case "responseContent":
|
|
|
|
expectedPacket = {
|
2012-11-05 08:41:59 -08:00
|
|
|
mimeType: "application/json",
|
2012-10-05 06:40:57 -07:00
|
|
|
contentSize: /^\d+$/,
|
|
|
|
discardResponseBody: false,
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case "eventTimings":
|
|
|
|
expectedPacket = {
|
|
|
|
totalTime: /^\d+$/,
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ok(false, "unknown network event update type: " +
|
|
|
|
aPacket.updateType);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expectedPacket) {
|
|
|
|
info("checking the packet content");
|
|
|
|
checkObject(aPacket, expectedPacket);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (updates.indexOf("responseContent") > -1 &&
|
|
|
|
updates.indexOf("eventTimings") > -1) {
|
|
|
|
aState.dbgClient.removeListener("networkEventUpdate",
|
|
|
|
onNetworkEvent);
|
|
|
|
|
|
|
|
onRequestHeaders = onRequestHeaders.bind(null, aState);
|
|
|
|
aState.client.getRequestHeaders(aState.netActor,
|
|
|
|
onRequestHeaders);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onRequestHeaders(aState, aResponse)
|
|
|
|
{
|
|
|
|
info("checking request headers");
|
|
|
|
|
|
|
|
ok(aResponse.headers.length > 0, "request headers > 0");
|
|
|
|
ok(aResponse.headersSize > 0, "request headersSize > 0");
|
|
|
|
|
|
|
|
checkHeadersOrCookies(aResponse.headers, {
|
|
|
|
Referer: /network_requests_iframe\.html/,
|
|
|
|
Cookie: /bug768096/,
|
|
|
|
});
|
|
|
|
|
|
|
|
onRequestCookies = onRequestCookies.bind(null, aState);
|
|
|
|
aState.client.getRequestCookies(aState.netActor,
|
|
|
|
onRequestCookies);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onRequestCookies(aState, aResponse)
|
|
|
|
{
|
|
|
|
info("checking request cookies");
|
|
|
|
|
2013-01-08 13:25:57 -08:00
|
|
|
is(aResponse.cookies.length, 3, "request cookies length");
|
2012-10-05 06:40:57 -07:00
|
|
|
|
|
|
|
checkHeadersOrCookies(aResponse.cookies, {
|
|
|
|
foobar: "fooval",
|
|
|
|
omgfoo: "bug768096",
|
2013-01-08 13:25:57 -08:00
|
|
|
badcookie: "bug826798=st3fan",
|
2012-10-05 06:40:57 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
onRequestPostData = onRequestPostData.bind(null, aState);
|
|
|
|
aState.client.getRequestPostData(aState.netActor,
|
|
|
|
onRequestPostData);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onRequestPostData(aState, aResponse)
|
|
|
|
{
|
|
|
|
info("checking request POST data");
|
|
|
|
|
|
|
|
checkObject(aResponse, {
|
|
|
|
postData: {
|
2012-11-05 08:41:59 -08:00
|
|
|
text: /^Hello world! foobaz barr.+foobaz barr$/,
|
2012-10-05 06:40:57 -07:00
|
|
|
},
|
|
|
|
postDataDiscarded: false,
|
|
|
|
});
|
|
|
|
|
2012-11-05 08:41:59 -08:00
|
|
|
is(aResponse.postData.text.length, 552, "postData text length");
|
|
|
|
|
2012-10-05 06:40:57 -07:00
|
|
|
onResponseHeaders = onResponseHeaders.bind(null, aState);
|
|
|
|
aState.client.getResponseHeaders(aState.netActor,
|
|
|
|
onResponseHeaders);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onResponseHeaders(aState, aResponse)
|
|
|
|
{
|
|
|
|
info("checking response headers");
|
|
|
|
|
|
|
|
ok(aResponse.headers.length > 0, "response headers > 0");
|
|
|
|
ok(aResponse.headersSize > 0, "response headersSize > 0");
|
|
|
|
|
|
|
|
checkHeadersOrCookies(aResponse.headers, {
|
|
|
|
"Content-Type": /^application\/(json|octet-stream)$/,
|
|
|
|
"Content-Length": /^\d+$/,
|
|
|
|
});
|
|
|
|
|
|
|
|
onResponseCookies = onResponseCookies.bind(null, aState);
|
|
|
|
aState.client.getResponseCookies(aState.netActor,
|
|
|
|
onResponseCookies);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onResponseCookies(aState, aResponse)
|
|
|
|
{
|
|
|
|
info("checking response cookies");
|
|
|
|
|
|
|
|
is(aResponse.cookies.length, 0, "response cookies length");
|
|
|
|
|
|
|
|
onResponseContent = onResponseContent.bind(null, aState);
|
|
|
|
aState.client.getResponseContent(aState.netActor,
|
|
|
|
onResponseContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onResponseContent(aState, aResponse)
|
|
|
|
{
|
|
|
|
info("checking response content");
|
|
|
|
|
|
|
|
checkObject(aResponse, {
|
|
|
|
content: {
|
|
|
|
text: /"test JSON data"/,
|
|
|
|
},
|
|
|
|
contentDiscarded: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
onEventTimings = onEventTimings.bind(null, aState);
|
|
|
|
aState.client.getEventTimings(aState.netActor,
|
|
|
|
onEventTimings);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onEventTimings(aState, aResponse)
|
|
|
|
{
|
|
|
|
info("checking event timings");
|
|
|
|
|
|
|
|
checkObject(aResponse, {
|
|
|
|
timings: {
|
|
|
|
blocked: /^-1|\d+$/,
|
|
|
|
dns: /^-1|\d+$/,
|
|
|
|
connect: /^-1|\d+$/,
|
|
|
|
send: /^-1|\d+$/,
|
|
|
|
wait: /^-1|\d+$/,
|
|
|
|
receive: /^-1|\d+$/,
|
|
|
|
},
|
|
|
|
totalTime: /^\d+$/,
|
|
|
|
});
|
|
|
|
|
|
|
|
closeDebugger(aState, function() {
|
|
|
|
SimpleTest.finish();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
addEventListener("load", startTest);
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|