browser_remoteWebNavigation_postdata.js (1698B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 function makeInputStream(aString) { 6 let stream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance( 7 Ci.nsIStringInputStream 8 ); 9 stream.setByteStringData(aString); 10 return stream; // XPConnect will QI this to nsIInputStream for us. 11 } 12 13 add_task(async function test_remoteWebNavigation_postdata() { 14 let { HttpServer } = ChromeUtils.importESModule( 15 "resource://testing-common/httpd.sys.mjs" 16 ); 17 let { CommonUtils } = ChromeUtils.importESModule( 18 "resource://services-common/utils.sys.mjs" 19 ); 20 21 let server = new HttpServer(); 22 server.start(-1); 23 24 await new Promise(resolve => { 25 server.registerPathHandler("/test", (request, response) => { 26 let body = CommonUtils.readBytesFromInputStream(request.bodyInputStream); 27 is(body, "success", "request body is correct"); 28 is(request.method, "POST", "request was a post"); 29 response.write("Received from POST: " + body); 30 resolve(); 31 }); 32 33 let i = server.identity; 34 let path = 35 i.primaryScheme + "://" + i.primaryHost + ":" + i.primaryPort + "/test"; 36 37 let postdata = 38 "Content-Length: 7\r\n" + 39 "Content-Type: application/x-www-form-urlencoded\r\n" + 40 "\r\n" + 41 "success"; 42 43 openTrustedLinkIn(path, "tab", { 44 allowThirdPartyFixup: null, 45 postData: makeInputStream(postdata), 46 }); 47 }); 48 BrowserTestUtils.removeTab(gBrowser.selectedTab); 49 50 await new Promise(resolve => { 51 server.stop(function () { 52 resolve(); 53 }); 54 }); 55 });