child_veto_in_parent.js (1560B)
1 /* import-globals-from ../unit/head_trr.js */ 2 3 "use strict"; 4 5 const { HttpServer } = ChromeUtils.importESModule( 6 "resource://testing-common/httpd.sys.mjs" 7 ); 8 9 ChromeUtils.defineLazyGetter(this, "URL", function () { 10 return "http://localhost:" + httpServer.identity.primaryPort; 11 }); 12 13 var httpServer = null; 14 // Need to randomize, because apparently no one clears our cache 15 var randomPath = "/redirect/" + Math.random(); 16 17 ChromeUtils.defineLazyGetter(this, "randomURI", function () { 18 return URL + randomPath; 19 }); 20 21 function make_channel(url) { 22 return NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true }); 23 } 24 25 const responseBody = "response body"; 26 27 function redirectHandler(metadata, response) { 28 response.setStatusLine(metadata.httpVersion, 301, "Moved"); 29 response.setHeader("Location", URL + "/content", false); 30 } 31 32 function contentHandler(metadata, response) { 33 response.setHeader("Content-Type", "text/plain"); 34 response.bodyOutputStream.write(responseBody, responseBody.length); 35 } 36 37 add_task(async function doStuff() { 38 httpServer = new HttpServer(); 39 httpServer.registerPathHandler(randomPath, redirectHandler); 40 httpServer.registerPathHandler("/content", contentHandler); 41 httpServer.start(-1); 42 43 let chan = make_channel(randomURI); 44 let [req, buff] = await new Promise(resolve => 45 chan.asyncOpen( 46 new ChannelListener((aReq, aBuff) => resolve([aReq, aBuff]), null) 47 ) 48 ); 49 Assert.equal(buff, ""); 50 Assert.equal(req.status, Cr.NS_OK); 51 await httpServer.stop(); 52 await do_send_remote_message("child-test-done"); 53 });