/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ "use strict"; const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm"); Cu.importGlobalProperties(["URLSearchParams"]); function loadHTMLFromFile(path) { // Load the HTML to return in the response from file. // Since it's relative to the cwd of the test runner, we start there and // append to get to the actual path of the file. const testHTMLFile = // eslint-disable-next-line mozilla/use-services Cc["@mozilla.org/file/directory_service;1"] .getService(Ci.nsIProperties) .get("CurWorkD", Ci.nsIFile); const dirs = path.split("/"); for (let i = 0; i < dirs.length; i++) { testHTMLFile.append(dirs[i]); } const testHTMLFileStream = Cc[ "@mozilla.org/network/file-input-stream;1" ].createInstance(Ci.nsIFileInputStream); testHTMLFileStream.init(testHTMLFile, -1, 0, 0); const testHTML = NetUtil.readInputStreamToString( testHTMLFileStream, testHTMLFileStream.available() ); return testHTML; } /** * document-builder.sjs can be used to dynamically build documents that will be used in * mochitests. It does handle the following GET parameters: * - file: The path to an (X)HTML file whose content will be used as a response. * Example: document-builder.sjs?file=/tests/dom/security/test/csp/file_web_manifest_mixed_content.html * - html: A string representation of the HTML document you want to get. * Example: document-builder.sjs?html=