Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Errors
- This test gets skipped with pattern: verify
- This test failed 1 times in the preceding 30 days. quicksearch this test
- Manifest: devtools/shared/webconsole/test/chrome/chrome.toml
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf8">
<title>Test for the network actor (GET request)</title>
<script type="text/javascript" src="common.js"></script>
<!-- Any copyright is dedicated to the Public Domain.
</head>
<body>
<p>Test for the network actor (GET request)</p>
<iframe src="http://example.com/chrome/devtools/shared/webconsole/test/chrome/network_requests_iframe.html"></iframe>
<script class="testbody" type="text/javascript">
"use strict";
SimpleTest.waitForExplicitFinish();
async function startTest()
{
await SpecialPowers.pushPrefEnv({
'set': [
['network.cookie.sameSite.laxByDefault', false],
]
});
const commands = await createCommandsForTab();
const resourceCommand = commands.resourceCommand;
info("test network GET request");
const resource = await new Promise(resolve => {
resourceCommand
.watchResources([resourceCommand.TYPES.NETWORK_EVENT], {
onAvailable: () => {},
onUpdated: resourceUpdate => {
resolve(resourceUpdate[0].resource);
},
})
.then(() => {
// Spawn the network request after we started watching
const iframe = document.querySelector("iframe").contentWindow;
iframe.wrappedJSObject.testXhrGet(null, "data.json?" + Date.now());
});
});
const { client } = commands;
const netActor = resource.actor;
info("checking request headers");
const requestHeadersPacket = await client.request({ to: netActor, type: "getRequestHeaders" });
ok(!!requestHeadersPacket.headers.length, `request headers > 0 (${requestHeadersPacket.headers.length})`);
ok(requestHeadersPacket.headersSize > 0, `request headersSize > 0 (${requestHeadersPacket.headersSize})`);
ok(!!requestHeadersPacket.rawHeaders, "request rawHeaders available");
checkHeadersOrCookies(requestHeadersPacket.headers, {
Referer: /network_requests_iframe\.html/,
Cookie: /bug768096/,
});
checkRawHeaders(requestHeadersPacket.rawHeaders, {
Referer: /network_requests_iframe\.html/,
Cookie: /bug768096/,
});
info("checking request cookies");
const requestCookiesPacket = await client.request({ to: netActor, type: "getRequestCookies" });
is(requestCookiesPacket.cookies.length, 3, "request cookies length");
checkHeadersOrCookies(requestCookiesPacket.cookies, {
foobar: "fooval",
});
info("checking request POST data");
const postDataPacket = await client.request({ to: netActor, type: "getRequestPostData" });
ok(!postDataPacket.postData.text, "no request POST data");
ok(!postDataPacket.postDataDiscarded, "request POST data was not discarded");
info("checking response headers");
const responseHeaderPacket = await client.request({ to: netActor, type: "getResponseHeaders" });
ok(!!responseHeaderPacket.headers.length, "response headers > 0");
ok(responseHeaderPacket.headersSize > 0, "response headersSize > 0");
ok(!!responseHeaderPacket.rawHeaders, "response rawHeaders available");
checkHeadersOrCookies(responseHeaderPacket.headers, {
"content-type": /^application\/(json|octet-stream)$/,
"content-length": /^\d+$/,
});
checkRawHeaders(responseHeaderPacket.rawHeaders, {
"content-type": /^application\/(json|octet-stream)$/,
"content-length": /^\d+$/,
});
info("checking response cookies");
const responseCookiesPacket = await client.request({ to: netActor, type: "getResponseCookies" });
is(responseCookiesPacket.cookies.length, 0, "response cookies length");
info("checking response content");
const responseContentPacket = await client.request({ to: netActor, type: "getResponseContent" });
ok(responseContentPacket.content.text, "response content text");
ok(!responseContentPacket.contentDiscarded, "response content was not discarded");
info("checking event timings");
const eventTimingPacket = await client.request({ to: netActor, type: "getEventTimings" });
checkObject(eventTimingPacket, {
timings: {
blocked: /^-1|\d+$/,
dns: /^-1|\d+$/,
connect: /^-1|\d+$/,
send: /^-1|\d+$/,
wait: /^-1|\d+$/,
receive: /^-1|\d+$/,
},
totalTime: /^\d+$/,
});
await commands.destroy();
SpecialPowers.clearUserPref("network.cookie.sameSite.laxByDefault");
SimpleTest.finish();
}
addEventListener("load", startTest, { once: true});
</script>
</body>
</html>