2 * Send HTTP requests and notify the parent about their channelId
4 /* global NetUtil, ChannelListener */
6 let shouldQuit = false;
9 // keep the event loop busy and the test alive until a "finish" command
10 // is issued by parent
11 do_timeout(100, function keepAlive() {
13 do_timeout(100, keepAlive);
18 function makeRequest(uri) {
19 let requestChannel = NetUtil.newChannel({
21 loadUsingSystemPrincipal: true,
23 requestChannel.asyncOpen(new ChannelListener(checkResponse, requestChannel));
24 requestChannel.QueryInterface(Ci.nsIHttpChannel);
25 dump(`Child opened request: ${uri}, channelId=${requestChannel.channelId}\n`);
28 function checkResponse(request, buffer, requestChannel) {
29 // notify the parent process about the original request channel
30 requestChannel.QueryInterface(Ci.nsIHttpChannel);
31 do_send_remote_message(`request:${requestChannel.channelId}`);
33 // the response channel can be different (if it was redirected)
34 let responseChannel = request.QueryInterface(Ci.nsIHttpChannel);
36 let uri = responseChannel.URI.spec;
37 let origUri = responseChannel.originalURI.spec;
38 let id = responseChannel.channelId;
39 dump(`Child got response to: ${uri} (orig=${origUri}), channelId=${id}\n`);
41 // notify the parent process about this channel's ID
42 do_send_remote_message(`response:${id}`);