Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / netwerk / test / unit_ipc / child_channel_id.js
blob1c9f948151a6dd46a6981f2653cc6e48dd68a2ec
1 /**
2  * Send HTTP requests and notify the parent about their channelId
3  */
4 /* global NetUtil, ChannelListener */
6 let shouldQuit = false;
8 function run_test() {
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() {
12     if (!shouldQuit) {
13       do_timeout(100, keepAlive);
14     }
15   });
18 function makeRequest(uri) {
19   let requestChannel = NetUtil.newChannel({
20     uri,
21     loadUsingSystemPrincipal: true,
22   });
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}`);
45 function finish() {
46   shouldQuit = true;