fune/netwerk/test/unit_ipc/child_channel_id.js
Kris Maglione 918ed6c474 Bug 1431533: Part 5a - Auto-rewrite code to use ChromeUtils import methods. r=florian
This was done using the following script:
37e3803c7a/processors/chromeutils-import.jsm

MozReview-Commit-ID: 1Nc3XDu0wGl

--HG--
extra : source : 12fc4dee861c812fd2bd032c63ef17af61800c70
extra : intermediate-source : 34c999fa006bffe8705cf50c54708aa21a962e62
extra : histedit_source : b2be2c5e5d226e6c347312456a6ae339c1e634b0
2018-01-29 15:20:18 -08:00

45 lines
1.4 KiB
JavaScript

/**
* Send HTTP requests and notify the parent about their channelId
*/
ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
let shouldQuit = false;
function run_test() {
// keep the event loop busy and the test alive until a "finish" command
// is issued by parent
do_timeout(100, function keepAlive() {
if (!shouldQuit) {
do_timeout(100, keepAlive);
}
});
}
function makeRequest(uri) {
let requestChannel = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true});
requestChannel.asyncOpen2(new ChannelListener(checkResponse, requestChannel));
requestChannel.QueryInterface(Ci.nsIHttpChannel);
dump(`Child opened request: ${uri}, channelId=${requestChannel.channelId}\n`);
}
function checkResponse(request, buffer, requestChannel) {
// notify the parent process about the original request channel
requestChannel.QueryInterface(Ci.nsIHttpChannel);
do_send_remote_message(`request:${requestChannel.channelId}`);
// the response channel can be different (if it was redirected)
let responseChannel = request.QueryInterface(Ci.nsIHttpChannel);
let uri = responseChannel.URI.spec;
let origUri = responseChannel.originalURI.spec;
let id = responseChannel.channelId;
dump(`Child got response to: ${uri} (orig=${origUri}), channelId=${id}\n`);
// notify the parent process about this channel's ID
do_send_remote_message(`response:${id}`);
}
function finish() {
shouldQuit = true;
}