diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /netwerk/test/unit_ipc | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/unit_ipc')
62 files changed, 1478 insertions, 0 deletions
diff --git a/netwerk/test/unit_ipc/child_channel_id.js b/netwerk/test/unit_ipc/child_channel_id.js new file mode 100644 index 0000000000..1c9f948151 --- /dev/null +++ b/netwerk/test/unit_ipc/child_channel_id.js @@ -0,0 +1,47 @@ +/** + * Send HTTP requests and notify the parent about their channelId + */ +/* global NetUtil, ChannelListener */ + +let shouldQuit = false; + +function run_test() { + // keep the event loop busy and the test alive until a "finish" command + // is issued by parent + do_timeout(100, function keepAlive() { + if (!shouldQuit) { + do_timeout(100, keepAlive); + } + }); +} + +function makeRequest(uri) { + let requestChannel = NetUtil.newChannel({ + uri, + loadUsingSystemPrincipal: true, + }); + requestChannel.asyncOpen(new ChannelListener(checkResponse, requestChannel)); + requestChannel.QueryInterface(Ci.nsIHttpChannel); + dump(`Child opened request: ${uri}, channelId=${requestChannel.channelId}\n`); +} + +function checkResponse(request, buffer, requestChannel) { + // notify the parent process about the original request channel + requestChannel.QueryInterface(Ci.nsIHttpChannel); + do_send_remote_message(`request:${requestChannel.channelId}`); + + // the response channel can be different (if it was redirected) + let responseChannel = request.QueryInterface(Ci.nsIHttpChannel); + + let uri = responseChannel.URI.spec; + let origUri = responseChannel.originalURI.spec; + let id = responseChannel.channelId; + dump(`Child got response to: ${uri} (orig=${origUri}), channelId=${id}\n`); + + // notify the parent process about this channel's ID + do_send_remote_message(`response:${id}`); +} + +function finish() { + shouldQuit = true; +} diff --git a/netwerk/test/unit_ipc/child_cookie_header.js b/netwerk/test/unit_ipc/child_cookie_header.js new file mode 100644 index 0000000000..4686f509f4 --- /dev/null +++ b/netwerk/test/unit_ipc/child_cookie_header.js @@ -0,0 +1,93 @@ +/* global NetUtil, ChannelListener */ + +"use strict"; + +function inChildProcess() { + return ( + // eslint-disable-next-line mozilla/use-services + Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime) + .processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT + ); +} + +let uri = null; +function makeChan() { + return NetUtil.newChannel({ + uri, + loadUsingSystemPrincipal: true, + }).QueryInterface(Ci.nsIHttpChannel); +} + +function OpenChannelPromise(aChannel, aClosure) { + return new Promise(resolve => { + function processResponse(request, buffer, context) { + aClosure(request.QueryInterface(Ci.nsIHttpChannel), buffer, context); + resolve(); + } + aChannel.asyncOpen(new ChannelListener(processResponse, null)); + }); +} + +// This test doesn't do much, except to communicate with the parent, and get +// URL we need to connect to. +add_task(async function setup() { + ok(inChildProcess(), "Sanity check. This should run in the child process"); + // Initialize the URL. Parent runs the server + do_send_remote_message("start-test"); + uri = await do_await_remote_message("start-test-done"); +}); + +// This test performs a request, and checks that no cookie header are visible +// to the child process +add_task(async function test1() { + let chan = makeChan(); + + await OpenChannelPromise(chan, (request, buffer) => { + equal(buffer, "response"); + Assert.throws( + () => request.getRequestHeader("Cookie"), + /NS_ERROR_NOT_AVAILABLE/, + "Cookie header should not be visible on request in the child" + ); + Assert.throws( + () => request.getResponseHeader("Set-Cookie"), + /NS_ERROR_NOT_AVAILABLE/, + "Cookie header should not be visible on response in the child" + ); + }); + + // We also check that a cookie was saved by the Set-Cookie header + // in the parent. + do_send_remote_message("check-cookie-count"); + let count = await do_await_remote_message("check-cookie-count-done"); + equal(count, 1); +}); + +// This test communicates with the parent, to locally save a new cookie. +// Then it performs another request, makes sure no cookie headers are visible, +// after which it checks that both cookies are visible to the parent. +add_task(async function test2() { + do_send_remote_message("set-cookie"); + await do_await_remote_message("set-cookie-done"); + + let chan = makeChan(); + await OpenChannelPromise(chan, (request, buffer) => { + equal(buffer, "response"); + Assert.throws( + () => request.getRequestHeader("Cookie"), + /NS_ERROR_NOT_AVAILABLE/, + "Cookie header should not be visible on request in the child" + ); + Assert.throws( + () => request.getResponseHeader("Set-Cookie"), + /NS_ERROR_NOT_AVAILABLE/, + "Cookie header should not be visible on response in the child" + ); + }); + + // We should have two cookies. One set by the Set-Cookie header sent by the + // server, and one that was manually set in the parent. + do_send_remote_message("second-check-cookie-count"); + let count = await do_await_remote_message("second-check-cookie-count-done"); + equal(count, 2); +}); diff --git a/netwerk/test/unit_ipc/child_dns_by_type_resolve.js b/netwerk/test/unit_ipc/child_dns_by_type_resolve.js new file mode 100644 index 0000000000..d09d29a73e --- /dev/null +++ b/netwerk/test/unit_ipc/child_dns_by_type_resolve.js @@ -0,0 +1,22 @@ +/* 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"; + +/* import-globals-from ../unit/head_trr.js */ + +let test_answer = "bXkgdm9pY2UgaXMgbXkgcGFzc3dvcmQ="; +let test_answer_addr = "127.0.0.1"; + +add_task(async function testTXTResolve() { + // use the h2 server as DOH provider + let { inRecord, inStatus } = await new TRRDNSListener("_esni.example.com", { + type: Ci.nsIDNSService.RESOLVE_TYPE_TXT, + }); + Assert.equal(inStatus, Cr.NS_OK, "status OK"); + let answer = inRecord + .QueryInterface(Ci.nsIDNSTXTRecord) + .getRecordsAsOneString(); + Assert.equal(answer, test_answer, "got correct answer"); +}); diff --git a/netwerk/test/unit_ipc/child_is_proxy_used.js b/netwerk/test/unit_ipc/child_is_proxy_used.js new file mode 100644 index 0000000000..216963ec19 --- /dev/null +++ b/netwerk/test/unit_ipc/child_is_proxy_used.js @@ -0,0 +1,24 @@ +"use strict"; + +/* global NetUtil, ChannelListener, CL_ALLOW_UNKNOWN_CL */ + +add_task(async function check_proxy() { + do_send_remote_message("start-test"); + let URL = await do_await_remote_message("start-test-done"); + let chan = NetUtil.newChannel({ + uri: URL, + loadUsingSystemPrincipal: true, + }).QueryInterface(Ci.nsIHttpChannel); + + let { req, buff } = await channelOpenPromise(chan, CL_ALLOW_UNKNOWN_CL); + equal(buff, "content"); + equal(req.QueryInterface(Ci.nsIHttpChannelInternal).isProxyUsed, true); +}); + +function channelOpenPromise(chan, flags) { + return new Promise(resolve => { + chan.asyncOpen( + new ChannelListener((req, buff) => resolve({ req, buff }), null, flags) + ); + }); +} diff --git a/netwerk/test/unit_ipc/child_veto_in_parent.js b/netwerk/test/unit_ipc/child_veto_in_parent.js new file mode 100644 index 0000000000..faf278aa92 --- /dev/null +++ b/netwerk/test/unit_ipc/child_veto_in_parent.js @@ -0,0 +1,51 @@ +/* import-globals-from ../unit/head_trr.js */ + +"use strict"; + +const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js"); + +XPCOMUtils.defineLazyGetter(this, "URL", function() { + return "http://localhost:" + httpServer.identity.primaryPort; +}); + +var httpServer = null; +// Need to randomize, because apparently no one clears our cache +var randomPath = "/redirect/" + Math.random(); + +XPCOMUtils.defineLazyGetter(this, "randomURI", function() { + return URL + randomPath; +}); + +function make_channel(url, callback, ctx) { + return NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true }); +} + +const responseBody = "response body"; + +function redirectHandler(metadata, response) { + response.setStatusLine(metadata.httpVersion, 301, "Moved"); + response.setHeader("Location", URL + "/content", false); +} + +function contentHandler(metadata, response) { + response.setHeader("Content-Type", "text/plain"); + response.bodyOutputStream.write(responseBody, responseBody.length); +} + +add_task(async function doStuff() { + httpServer = new HttpServer(); + httpServer.registerPathHandler(randomPath, redirectHandler); + httpServer.registerPathHandler("/content", contentHandler); + httpServer.start(-1); + + let chan = make_channel(randomURI); + let [req, buff] = await new Promise(resolve => + chan.asyncOpen( + new ChannelListener((aReq, aBuff) => resolve([aReq, aBuff]), null) + ) + ); + Assert.equal(buff, ""); + Assert.equal(req.status, Cr.NS_OK); + await httpServer.stop(); + await do_send_remote_message("child-test-done"); +}); diff --git a/netwerk/test/unit_ipc/head_channels_clone.js b/netwerk/test/unit_ipc/head_channels_clone.js new file mode 100644 index 0000000000..f287c6f76f --- /dev/null +++ b/netwerk/test/unit_ipc/head_channels_clone.js @@ -0,0 +1,10 @@ +/* import-globals-from ../unit/head_channels.js */ +// Load standard base class for network tests into child process +// + +var { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm"); +var { XPCOMUtils } = ChromeUtils.importESModule( + "resource://gre/modules/XPCOMUtils.sys.mjs" +); + +load("../unit/head_channels.js"); diff --git a/netwerk/test/unit_ipc/head_http3_clone.js b/netwerk/test/unit_ipc/head_http3_clone.js new file mode 100644 index 0000000000..4b4e1155ef --- /dev/null +++ b/netwerk/test/unit_ipc/head_http3_clone.js @@ -0,0 +1,8 @@ +/* import-globals-from ../unit/head_http3.js */ + +var { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm"); +var { XPCOMUtils } = ChromeUtils.importESModule( + "resource://gre/modules/XPCOMUtils.sys.mjs" +); + +load("../unit/head_http3.js"); diff --git a/netwerk/test/unit_ipc/head_trr_clone.js b/netwerk/test/unit_ipc/head_trr_clone.js new file mode 100644 index 0000000000..e52c380f19 --- /dev/null +++ b/netwerk/test/unit_ipc/head_trr_clone.js @@ -0,0 +1,8 @@ +/* import-globals-from ../unit/head_trr.js */ + +var { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm"); +var { XPCOMUtils } = ChromeUtils.importESModule( + "resource://gre/modules/XPCOMUtils.sys.mjs" +); + +load("../unit/head_trr.js"); diff --git a/netwerk/test/unit_ipc/test_XHR_redirects.js b/netwerk/test/unit_ipc/test_XHR_redirects.js new file mode 100644 index 0000000000..472817a9ec --- /dev/null +++ b/netwerk/test/unit_ipc/test_XHR_redirects.js @@ -0,0 +1,3 @@ +function run_test() { + run_test_in_child("../unit/test_XHR_redirects.js"); +} diff --git a/netwerk/test/unit_ipc/test_alt-data_closeWithStatus_wrap.js b/netwerk/test/unit_ipc/test_alt-data_closeWithStatus_wrap.js new file mode 100644 index 0000000000..a9d45a3f12 --- /dev/null +++ b/netwerk/test/unit_ipc/test_alt-data_closeWithStatus_wrap.js @@ -0,0 +1,17 @@ +// needs to be rooted +var cacheFlushObserver = { + observe() { + cacheFlushObserver = null; + do_send_remote_message("flushed"); + }, +}; + +function run_test() { + do_get_profile(); + do_await_remote_message("flush").then(() => { + Services.cache2 + .QueryInterface(Ci.nsICacheTesting) + .flush(cacheFlushObserver); + }); + run_test_in_child("../unit/test_alt-data_closeWithStatus.js"); +} diff --git a/netwerk/test/unit_ipc/test_alt-data_cross_process_wrap.js b/netwerk/test/unit_ipc/test_alt-data_cross_process_wrap.js new file mode 100644 index 0000000000..336b9e3129 --- /dev/null +++ b/netwerk/test/unit_ipc/test_alt-data_cross_process_wrap.js @@ -0,0 +1,96 @@ +// needs to be rooted +var cacheFlushObserver = { + observe() { + cacheFlushObserver = null; + do_send_remote_message("flushed"); + }, +}; + +// We get this from the child a bit later +var url = null; + +// needs to be rooted +var cacheFlushObserver2 = { + observe() { + cacheFlushObserver2 = null; + openAltChannel(); + }, +}; + +function run_test() { + do_get_profile(); + do_await_remote_message("flush").then(() => { + Services.cache2 + .QueryInterface(Ci.nsICacheTesting) + .flush(cacheFlushObserver); + }); + + do_await_remote_message("done").then(() => { + sendCommand("URL;", load_channel); + }); + + run_test_in_child("../unit/test_alt-data_cross_process.js"); +} + +function load_channel(channelUrl) { + ok(channelUrl); + url = channelUrl; // save this to open the alt data channel later + var chan = make_channel(channelUrl); + var cc = chan.QueryInterface(Ci.nsICacheInfoChannel); + cc.preferAlternativeDataType("text/binary", "", Ci.nsICacheInfoChannel.ASYNC); + chan.asyncOpen(new ChannelListener(readTextData, null)); +} + +function make_channel(channelUrl, callback, ctx) { + return NetUtil.newChannel({ + uri: channelUrl, + loadUsingSystemPrincipal: true, + }); +} + +function readTextData(request, buffer) { + var cc = request.QueryInterface(Ci.nsICacheInfoChannel); + // Since we are in a different process from what that generated the alt-data, + // we should receive the original data, not processed content. + Assert.equal(cc.alternativeDataType, ""); + Assert.equal(buffer, "response body"); + + // Now let's generate some alt-data in the parent, and make sure we can get it + var altContent = "altContentParentGenerated"; + executeSoon(() => { + var os = cc.openAlternativeOutputStream( + "text/parent-binary", + altContent.length + ); + os.write(altContent, altContent.length); + os.close(); + + executeSoon(() => { + Services.cache2 + .QueryInterface(Ci.nsICacheTesting) + .flush(cacheFlushObserver2); + }); + }); +} + +function openAltChannel() { + var chan = make_channel(url); + var cc = chan.QueryInterface(Ci.nsICacheInfoChannel); + cc.preferAlternativeDataType( + "text/parent-binary", + "", + Ci.nsICacheInfoChannel.ASYNC + ); + chan.asyncOpen(new ChannelListener(readAltData, null)); +} + +function readAltData(request, buffer) { + var cc = request.QueryInterface(Ci.nsICacheInfoChannel); + + // This was generated in the parent, so it's OK to get it. + Assert.equal(buffer, "altContentParentGenerated"); + Assert.equal(cc.alternativeDataType, "text/parent-binary"); + + // FINISH + do_send_remote_message("finish"); +} diff --git a/netwerk/test/unit_ipc/test_alt-data_simple_wrap.js b/netwerk/test/unit_ipc/test_alt-data_simple_wrap.js new file mode 100644 index 0000000000..ae4f12fde9 --- /dev/null +++ b/netwerk/test/unit_ipc/test_alt-data_simple_wrap.js @@ -0,0 +1,17 @@ +// needs to be rooted +var cacheFlushObserver = { + observe() { + cacheFlushObserver = null; + do_send_remote_message("flushed"); + }, +}; + +function run_test() { + do_get_profile(); + do_await_remote_message("flush").then(() => { + Services.cache2 + .QueryInterface(Ci.nsICacheTesting) + .flush(cacheFlushObserver); + }); + run_test_in_child("../unit/test_alt-data_simple.js"); +} diff --git a/netwerk/test/unit_ipc/test_alt-data_stream_wrap.js b/netwerk/test/unit_ipc/test_alt-data_stream_wrap.js new file mode 100644 index 0000000000..1eee2f2434 --- /dev/null +++ b/netwerk/test/unit_ipc/test_alt-data_stream_wrap.js @@ -0,0 +1,3 @@ +function run_test() { + run_test_in_child("../unit/test_alt-data_stream.js"); +} diff --git a/netwerk/test/unit_ipc/test_cache-entry-id_wrap.js b/netwerk/test/unit_ipc/test_cache-entry-id_wrap.js new file mode 100644 index 0000000000..0358fc1e8d --- /dev/null +++ b/netwerk/test/unit_ipc/test_cache-entry-id_wrap.js @@ -0,0 +1,13 @@ +function run_test() { + do_get_profile(); + run_test_in_child("../unit/test_cache-entry-id.js"); + + do_await_remote_message("flush").then(() => { + let p = new Promise(resolve => { + Services.cache2.QueryInterface(Ci.nsICacheTesting).flush(resolve); + }); + p.then(() => { + do_send_remote_message("flushed"); + }); + }); +} diff --git a/netwerk/test/unit_ipc/test_cache_jar_wrap.js b/netwerk/test/unit_ipc/test_cache_jar_wrap.js new file mode 100644 index 0000000000..fa2bb82a8d --- /dev/null +++ b/netwerk/test/unit_ipc/test_cache_jar_wrap.js @@ -0,0 +1,4 @@ +function run_test() { + run_test_in_child("../unit/head_cache2.js"); + run_test_in_child("../unit/test_cache_jar.js"); +} diff --git a/netwerk/test/unit_ipc/test_cacheflags_wrap.js b/netwerk/test/unit_ipc/test_cacheflags_wrap.js new file mode 100644 index 0000000000..eda3004532 --- /dev/null +++ b/netwerk/test/unit_ipc/test_cacheflags_wrap.js @@ -0,0 +1,8 @@ +// +// Run test script in content process instead of chrome (xpcshell's default) +// + +function run_test() { + do_get_profile(); + run_test_in_child("../unit/test_cacheflags.js"); +} diff --git a/netwerk/test/unit_ipc/test_channel_close_wrap.js b/netwerk/test/unit_ipc/test_channel_close_wrap.js new file mode 100644 index 0000000000..ead9999579 --- /dev/null +++ b/netwerk/test/unit_ipc/test_channel_close_wrap.js @@ -0,0 +1,3 @@ +function run_test() { + run_test_in_child("../unit/test_channel_close.js"); +} diff --git a/netwerk/test/unit_ipc/test_channel_id.js b/netwerk/test/unit_ipc/test_channel_id.js new file mode 100644 index 0000000000..01599509bb --- /dev/null +++ b/netwerk/test/unit_ipc/test_channel_id.js @@ -0,0 +1,107 @@ +const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js"); + +/* + * Test that when doing HTTP requests, the nsIHttpChannel is detected in + * both parent and child and shares the same channelId across processes. + */ + +let httpserver; +let port; + +function startHttpServer() { + httpserver = new HttpServer(); + + httpserver.registerPathHandler("/resource", (metadata, response) => { + response.setStatusLine(metadata.httpVersion, 200, "OK"); + response.setHeader("Content-Type", "text/plain", false); + response.setHeader("Cache-Control", "no-cache", false); + response.bodyOutputStream.write("data", 4); + }); + + httpserver.registerPathHandler("/redirect", (metadata, response) => { + response.setStatusLine(metadata.httpVersion, 302, "Redirect"); + response.setHeader("Location", "/resource", false); + response.setHeader("Cache-Control", "no-cache", false); + }); + + httpserver.start(-1); + port = httpserver.identity.primaryPort; +} + +function stopHttpServer(next) { + httpserver.stop(next); +} + +let expectedParentChannels = []; +let expectedChildMessages = []; + +let maybeFinishWaitForParentChannels; +let parentChannelsDone = new Promise(resolve => { + maybeFinishWaitForParentChannels = () => { + if (!expectedParentChannels.length) { + dump("All expected parent channels were detected\n"); + resolve(); + } + }; +}); + +function observer(subject, topic, data) { + let channel = subject.QueryInterface(Ci.nsIHttpChannel); + + let uri = channel.URI.spec; + let origUri = channel.originalURI.spec; + let id = channel.channelId; + dump(`Parent detected channel: ${uri} (orig=${origUri}): channelId=${id}\n`); + + // did we expect a new channel? + let expected = expectedParentChannels.shift(); + Assert.ok(!!expected); + + // Start waiting for the messages about request/response from child + for (let event of expected) { + let message = `${event}:${id}`; + dump(`Expecting message from child: ${message}\n`); + + let messagePromise = do_await_remote_message(message).then(() => { + dump(`Expected message from child arrived: ${message}\n`); + }); + expectedChildMessages.push(messagePromise); + } + + // If we don't expect any further parent channels, finish the parent wait + maybeFinishWaitForParentChannels(); +} + +function run_test() { + startHttpServer(); + Services.obs.addObserver(observer, "http-on-modify-request"); + run_test_in_child("child_channel_id.js", makeRequests); +} + +function makeRequests() { + // First, a normal request without any redirect. Expect one channel detected + // in parent, used by both request and response. + expectedParentChannels.push(["request", "response"]); + sendCommand(`makeRequest("http://localhost:${port}/resource");`); + + // Second request will be redirected. Expect two channels, one with the + // original request, then the redirected one which gets the final response. + expectedParentChannels.push(["request"], ["response"]); + sendCommand(`makeRequest("http://localhost:${port}/redirect");`); + + waitForParentChannels(); +} + +function waitForParentChannels() { + parentChannelsDone.then(waitForChildMessages); +} + +function waitForChildMessages() { + dump(`Waiting for ${expectedChildMessages.length} child messages\n`); + Promise.all(expectedChildMessages).then(finish); +} + +function finish() { + Services.obs.removeObserver(observer, "http-on-modify-request"); + sendCommand("finish();", () => stopHttpServer(do_test_finished)); +} diff --git a/netwerk/test/unit_ipc/test_channel_priority_wrap.js b/netwerk/test/unit_ipc/test_channel_priority_wrap.js new file mode 100644 index 0000000000..c443d221d0 --- /dev/null +++ b/netwerk/test/unit_ipc/test_channel_priority_wrap.js @@ -0,0 +1,47 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js"); + +let httpserver; +let port; + +function startHttpServer() { + httpserver = new HttpServer(); + + httpserver.registerPathHandler("/resource", (metadata, response) => { + response.setStatusLine(metadata.httpVersion, 200, "OK"); + response.setHeader("Content-Type", "text/plain", false); + response.setHeader("Cache-Control", "no-cache", false); + response.bodyOutputStream.write("data", 4); + }); + + httpserver.registerPathHandler("/redirect", (metadata, response) => { + response.setStatusLine(metadata.httpVersion, 302, "Redirect"); + response.setHeader("Location", "/resource", false); + response.setHeader("Cache-Control", "no-cache", false); + }); + + httpserver.start(-1); + port = httpserver.identity.primaryPort; +} + +function stopHttpServer() { + httpserver.stop(() => {}); +} + +function run_test() { + // jshint ignore:line + registerCleanupFunction(stopHttpServer); + + run_test_in_child("../unit/test_channel_priority.js", () => { + startHttpServer(); + sendCommand(`configPort(${port});`); + do_await_remote_message("finished").then(() => { + do_test_finished(); + }); + }); +} diff --git a/netwerk/test/unit_ipc/test_chunked_responses_wrap.js b/netwerk/test/unit_ipc/test_chunked_responses_wrap.js new file mode 100644 index 0000000000..72bb40554c --- /dev/null +++ b/netwerk/test/unit_ipc/test_chunked_responses_wrap.js @@ -0,0 +1,7 @@ +// +// Run test script in content process instead of chrome (xpcshell's default) +// + +function run_test() { + run_test_in_child("../unit/test_chunked_responses.js"); +} diff --git a/netwerk/test/unit_ipc/test_cookie_header_stripped.js b/netwerk/test/unit_ipc/test_cookie_header_stripped.js new file mode 100644 index 0000000000..19ee275bbf --- /dev/null +++ b/netwerk/test/unit_ipc/test_cookie_header_stripped.js @@ -0,0 +1,92 @@ +"use strict"; + +const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js"); + +const TEST_DOMAIN = "www.example.com"; +XPCOMUtils.defineLazyGetter(this, "URL", function() { + return ( + "http://" + TEST_DOMAIN + ":" + httpserv.identity.primaryPort + "/path" + ); +}); + +const responseBody1 = "response"; +function requestHandler(metadata, response) { + response.setHeader("Content-Type", "text/plain"); + response.setHeader("Set-Cookie", "tom=cool; Max-Age=10", true); + response.bodyOutputStream.write(responseBody1, responseBody1.length); +} + +let httpserv = null; + +function run_test() { + httpserv = new HttpServer(); + httpserv.registerPathHandler("/path", requestHandler); + httpserv.start(-1); + httpserv.identity.add("http", TEST_DOMAIN, httpserv.identity.primaryPort); + + registerCleanupFunction(() => { + Services.cookies.removeCookiesWithOriginAttributes("{}", TEST_DOMAIN); + Services.prefs.clearUserPref("network.dns.localDomains"); + Services.prefs.clearUserPref("network.cookie.cookieBehavior"); + Services.prefs.clearUserPref( + "network.cookieJarSettings.unblocked_for_testing" + ); + + httpserv.stop(); + httpserv = null; + }); + + Services.prefs.setBoolPref( + "network.cookieJarSettings.unblocked_for_testing", + true + ); + Services.prefs.setCharPref("network.dns.localDomains", TEST_DOMAIN); + Services.prefs.setIntPref("network.cookie.cookieBehavior", 0); + Services.cookies.removeCookiesWithOriginAttributes("{}", TEST_DOMAIN); + + // Sends back the URL to the child script + do_await_remote_message("start-test").then(() => { + do_send_remote_message("start-test-done", URL); + }); + + // Sends back the cookie count for the domain + // Should only be one - from Set-Cookie + do_await_remote_message("check-cookie-count").then(() => { + do_send_remote_message( + "check-cookie-count-done", + Services.cookies.countCookiesFromHost(TEST_DOMAIN) + ); + }); + + // Sends back the cookie count for the domain + // There should be 2 cookies. One from the Set-Cookie header, the other set + // manually. + do_await_remote_message("second-check-cookie-count").then(() => { + do_send_remote_message( + "second-check-cookie-count-done", + Services.cookies.countCookiesFromHost(TEST_DOMAIN) + ); + }); + + // Sets a cookie for the test domain + do_await_remote_message("set-cookie").then(() => { + const expiry = Date.now() + 24 * 60 * 60; + Services.cookies.add( + TEST_DOMAIN, + "/", + "cookieName", + "cookieValue", + false, + false, + false, + expiry, + {}, + Ci.nsICookie.SAMESITE_NONE, + Ci.nsICookie.SCHEME_HTTPS + ); + do_send_remote_message("set-cookie-done"); + }); + + // Run the actual test logic + run_test_in_child("child_cookie_header.js"); +} diff --git a/netwerk/test/unit_ipc/test_cookiejars_wrap.js b/netwerk/test/unit_ipc/test_cookiejars_wrap.js new file mode 100644 index 0000000000..dfdb69602c --- /dev/null +++ b/netwerk/test/unit_ipc/test_cookiejars_wrap.js @@ -0,0 +1,9 @@ +function run_test() { + // Allow all cookies. + Services.prefs.setBoolPref( + "network.cookieJarSettings.unblocked_for_testing", + true + ); + Services.prefs.setIntPref("network.cookie.cookieBehavior", 0); + run_test_in_child("../unit/test_cookiejars.js"); +} diff --git a/netwerk/test/unit_ipc/test_dns_by_type_resolve_wrap.js b/netwerk/test/unit_ipc/test_dns_by_type_resolve_wrap.js new file mode 100644 index 0000000000..72b8f96880 --- /dev/null +++ b/netwerk/test/unit_ipc/test_dns_by_type_resolve_wrap.js @@ -0,0 +1,52 @@ +"use strict"; + +let h2Port; + +function setup() { + h2Port = Services.env.get("MOZHTTP2_PORT"); + Assert.notEqual(h2Port, null); + Assert.notEqual(h2Port, ""); + + // Set to allow the cert presented by our H2 server + do_get_profile(); + + Services.prefs.setBoolPref("network.http.http2.enabled", true); + // the TRR server is on 127.0.0.1 + Services.prefs.setCharPref("network.trr.bootstrapAddr", "127.0.0.1"); + + // make all native resolve calls "secretly" resolve localhost instead + Services.prefs.setBoolPref("network.dns.native-is-localhost", true); + + // 0 - off, 1 - race, 2 TRR first, 3 TRR only, 4 shadow + Services.prefs.setBoolPref("network.trr.wait-for-portal", false); + // don't confirm that TRR is working, just go! + Services.prefs.setCharPref("network.trr.confirmationNS", "skip"); + + // So we can change the pref without clearing the cache to check a pushed + // record with a TRR path that fails. + Services.prefs.setBoolPref("network.trr.clear-cache-on-pref-change", false); + + // The moz-http2 cert is for foo.example.com and is signed by http2-ca.pem + // so add that cert to the trust list as a signing cert. // the foo.example.com domain name. + const certdb = Cc["@mozilla.org/security/x509certdb;1"].getService( + Ci.nsIX509CertDB + ); + + // XXX(valentin): It would be nice to just call trr_test_setup() here, but + // the relative path here makes it awkward. Would be nice to fix someday. + addCertFromFile(certdb, "../unit/http2-ca.pem", "CTu,u,u"); +} + +setup(); +registerCleanupFunction(() => { + trr_clear_prefs(); +}); + +function run_test() { + Services.prefs.setCharPref( + "network.trr.uri", + "https://foo.example.com:" + h2Port + "/doh" + ); + Services.prefs.setIntPref("network.trr.mode", 2); // TRR first + run_test_in_child("child_dns_by_type_resolve.js"); +} diff --git a/netwerk/test/unit_ipc/test_dns_cancel_wrap.js b/netwerk/test/unit_ipc/test_dns_cancel_wrap.js new file mode 100644 index 0000000000..2f38aa4ecb --- /dev/null +++ b/netwerk/test/unit_ipc/test_dns_cancel_wrap.js @@ -0,0 +1,7 @@ +// +// Run test script in content process instead of chrome (xpcshell's default) +// + +function run_test() { + run_test_in_child("../unit/test_dns_cancel.js"); +} diff --git a/netwerk/test/unit_ipc/test_dns_service_wrap.js b/netwerk/test/unit_ipc/test_dns_service_wrap.js new file mode 100644 index 0000000000..fdbecf16d3 --- /dev/null +++ b/netwerk/test/unit_ipc/test_dns_service_wrap.js @@ -0,0 +1,7 @@ +// +// Run test script in content process instead of chrome (xpcshell's default) +// + +function run_test() { + run_test_in_child("../unit/test_dns_service.js"); +} diff --git a/netwerk/test/unit_ipc/test_duplicate_headers_wrap.js b/netwerk/test/unit_ipc/test_duplicate_headers_wrap.js new file mode 100644 index 0000000000..6225d593d9 --- /dev/null +++ b/netwerk/test/unit_ipc/test_duplicate_headers_wrap.js @@ -0,0 +1,7 @@ +// +// Run test script in content process instead of chrome (xpcshell's default) +// + +function run_test() { + run_test_in_child("../unit/test_duplicate_headers.js"); +} diff --git a/netwerk/test/unit_ipc/test_event_sink_wrap.js b/netwerk/test/unit_ipc/test_event_sink_wrap.js new file mode 100644 index 0000000000..908c971f8a --- /dev/null +++ b/netwerk/test/unit_ipc/test_event_sink_wrap.js @@ -0,0 +1,7 @@ +// +// Run test script in content process instead of chrome (xpcshell's default) +// + +function run_test() { + run_test_in_child("../unit/test_event_sink.js"); +} diff --git a/netwerk/test/unit_ipc/test_getHost_wrap.js b/netwerk/test/unit_ipc/test_getHost_wrap.js new file mode 100644 index 0000000000..f74ab7d152 --- /dev/null +++ b/netwerk/test/unit_ipc/test_getHost_wrap.js @@ -0,0 +1,3 @@ +function run_test() { + run_test_in_child("../unit/test_getHost.js"); +} diff --git a/netwerk/test/unit_ipc/test_gio_protocol_wrap.js b/netwerk/test/unit_ipc/test_gio_protocol_wrap.js new file mode 100644 index 0000000000..f6aa6b83e8 --- /dev/null +++ b/netwerk/test/unit_ipc/test_gio_protocol_wrap.js @@ -0,0 +1,21 @@ +// +// Run test script in content process instead of chrome (xpcshell's default) +// +// + +function run_test() { + Services.prefs.setCharPref( + "network.gio.supported-protocols", + "localtest:,recent:" + ); + + do_await_remote_message("gio-allow-test-protocols").then(port => { + do_send_remote_message("gio-allow-test-protocols-done"); + }); + + run_test_in_child("../unit/test_gio_protocol.js"); +} + +registerCleanupFunction(() => { + Services.prefs.clearUserPref("network.gio.supported-protocols"); +}); diff --git a/netwerk/test/unit_ipc/test_head_wrap.js b/netwerk/test/unit_ipc/test_head_wrap.js new file mode 100644 index 0000000000..13f0702e55 --- /dev/null +++ b/netwerk/test/unit_ipc/test_head_wrap.js @@ -0,0 +1,7 @@ +// +// Run test script in content process instead of chrome (xpcshell's default) +// + +function run_test() { + run_test_in_child("../unit/test_head.js"); +} diff --git a/netwerk/test/unit_ipc/test_headers_wrap.js b/netwerk/test/unit_ipc/test_headers_wrap.js new file mode 100644 index 0000000000..e0bae4080d --- /dev/null +++ b/netwerk/test/unit_ipc/test_headers_wrap.js @@ -0,0 +1,7 @@ +// +// Run test script in content process instead of chrome (xpcshell's default) +// + +function run_test() { + run_test_in_child("../unit/test_headers.js"); +} diff --git a/netwerk/test/unit_ipc/test_http3_prio_disabled_wrap.js b/netwerk/test/unit_ipc/test_http3_prio_disabled_wrap.js new file mode 100644 index 0000000000..38988cd450 --- /dev/null +++ b/netwerk/test/unit_ipc/test_http3_prio_disabled_wrap.js @@ -0,0 +1,20 @@ +// +// Run test script in content process instead of chrome (xpcshell's default) +// + +registerCleanupFunction(async () => { + Services.prefs.clearUserPref("network.http.http3.priority"); + http3_clear_prefs(); +}); + +// setup will be called before the child process tests +add_task(async function setup() { + await http3_setup_tests("h3-29"); +}); + +async function run_test() { + // test priority urgency and incremental with priority disabled + Services.prefs.setBoolPref("network.http.http3.priority", false); + run_test_in_child("../unit/test_http3_prio_disabled.js"); + run_next_test(); // only pumps next async task from this file +} diff --git a/netwerk/test/unit_ipc/test_http3_prio_enabled_wrap.js b/netwerk/test/unit_ipc/test_http3_prio_enabled_wrap.js new file mode 100644 index 0000000000..dcff09fcba --- /dev/null +++ b/netwerk/test/unit_ipc/test_http3_prio_enabled_wrap.js @@ -0,0 +1,20 @@ +// +// Run test script in content process instead of chrome (xpcshell's default) +// + +registerCleanupFunction(async () => { + Services.prefs.clearUserPref("network.http.http3.priority"); + http3_clear_prefs(); +}); + +// setup will be called before the child process tests +add_task(async function setup() { + await http3_setup_tests("h3-29"); +}); + +async function run_test() { + // test priority urgency and incremental with priority enabled + Services.prefs.setBoolPref("network.http.http3.priority", true); + run_test_in_child("../unit/test_http3_prio_enabled.js"); + run_next_test(); // only pumps next async task from this file +} diff --git a/netwerk/test/unit_ipc/test_httpcancel_wrap.js b/netwerk/test/unit_ipc/test_httpcancel_wrap.js new file mode 100644 index 0000000000..f56d0e198b --- /dev/null +++ b/netwerk/test/unit_ipc/test_httpcancel_wrap.js @@ -0,0 +1,48 @@ +"use strict"; + +const ReferrerInfo = Components.Constructor( + "@mozilla.org/referrer-info;1", + "nsIReferrerInfo", + "init" +); + +let observer = null; + +function run_test() { + do_await_remote_message("register-observer").then(() => { + observer = { + QueryInterface: ChromeUtils.generateQI(["nsIObserver"]), + + observe(subject, topic, data) { + subject = subject.QueryInterface(Ci.nsIRequest); + subject.cancel(Cr.NS_BINDING_ABORTED); + + // ENSURE_CALLED_BEFORE_CONNECT: setting values should still work + try { + subject.QueryInterface(Ci.nsIHttpChannel); + let currentReferrer = subject.getRequestHeader("Referer"); + Assert.equal(currentReferrer, "http://site1.com/"); + let uri = Services.io.newURI("http://site2.com"); + subject.referrerInfo = new ReferrerInfo( + Ci.nsIReferrerInfo.EMPTY, + true, + uri + ); + } catch (ex) { + do_throw("Exception: " + ex); + } + }, + }; + + Services.obs.addObserver(observer, "http-on-modify-request"); + do_send_remote_message("register-observer-done"); + }); + + do_await_remote_message("unregister-observer").then(() => { + Services.obs.removeObserver(observer, "http-on-modify-request"); + + do_send_remote_message("unregister-observer-done"); + }); + + run_test_in_child("../unit/test_httpcancel.js"); +} diff --git a/netwerk/test/unit_ipc/test_httpsuspend_wrap.js b/netwerk/test/unit_ipc/test_httpsuspend_wrap.js new file mode 100644 index 0000000000..0b013bd957 --- /dev/null +++ b/netwerk/test/unit_ipc/test_httpsuspend_wrap.js @@ -0,0 +1,3 @@ +function run_test() { + run_test_in_child("../unit/test_httpsuspend.js"); +} diff --git a/netwerk/test/unit_ipc/test_is_proxy_used.js b/netwerk/test/unit_ipc/test_is_proxy_used.js new file mode 100644 index 0000000000..2678ffa1b8 --- /dev/null +++ b/netwerk/test/unit_ipc/test_is_proxy_used.js @@ -0,0 +1,32 @@ +"use strict"; +/* global NodeHTTPServer, NodeHTTPProxyServer*/ + +add_task(async function run_test() { + let proxy = new NodeHTTPProxyServer(); + await proxy.start(); + registerCleanupFunction(async () => { + await proxy.stop(); + }); + + let server = new NodeHTTPServer(); + + await server.start(); + registerCleanupFunction(async () => { + await server.stop(); + }); + + await server.registerPathHandler("/test", (req, resp) => { + let content = "content"; + resp.writeHead(200); + resp.end(content); + }); + + do_await_remote_message("start-test").then(() => { + do_send_remote_message( + "start-test-done", + `http://localhost:${server.port()}/test` + ); + }); + + run_test_in_child("child_is_proxy_used.js"); +}); diff --git a/netwerk/test/unit_ipc/test_multipart_streamconv_wrap.js b/netwerk/test/unit_ipc/test_multipart_streamconv_wrap.js new file mode 100644 index 0000000000..b116f095ba --- /dev/null +++ b/netwerk/test/unit_ipc/test_multipart_streamconv_wrap.js @@ -0,0 +1,3 @@ +function run_test() { + run_test_in_child("../unit/test_multipart_streamconv.js"); +} diff --git a/netwerk/test/unit_ipc/test_orb_empty_header_wrap.js b/netwerk/test/unit_ipc/test_orb_empty_header_wrap.js new file mode 100644 index 0000000000..dec6c53fee --- /dev/null +++ b/netwerk/test/unit_ipc/test_orb_empty_header_wrap.js @@ -0,0 +1,8 @@ +// +// Run test script in content process instead of chrome (xpcshell's default) +// +// setup will be called before the child process tests +function run_test() { + Services.prefs.setBoolPref("browser.opaqueResponseBlocking", true); + run_test_in_child("../unit/test_orb_empty_header.js"); +} diff --git a/netwerk/test/unit_ipc/test_original_sent_received_head_wrap.js b/netwerk/test/unit_ipc/test_original_sent_received_head_wrap.js new file mode 100644 index 0000000000..91a8a00f09 --- /dev/null +++ b/netwerk/test/unit_ipc/test_original_sent_received_head_wrap.js @@ -0,0 +1,7 @@ +// +// Run test script in content process instead of chrome (xpcshell's default) +// + +function run_test() { + run_test_in_child("../unit/test_original_sent_received_head.js"); +} diff --git a/netwerk/test/unit_ipc/test_post_wrap.js b/netwerk/test/unit_ipc/test_post_wrap.js new file mode 100644 index 0000000000..27afae5b40 --- /dev/null +++ b/netwerk/test/unit_ipc/test_post_wrap.js @@ -0,0 +1,3 @@ +function run_test() { + run_test_in_child("../unit/test_post.js"); +} diff --git a/netwerk/test/unit_ipc/test_predictor_wrap.js b/netwerk/test/unit_ipc/test_predictor_wrap.js new file mode 100644 index 0000000000..7f69051304 --- /dev/null +++ b/netwerk/test/unit_ipc/test_predictor_wrap.js @@ -0,0 +1,44 @@ +// This is the bit that runs in the parent process when the test begins. Here's +// what happens: +// +// - Load the entire single-process test in the parent +// - Setup the test harness within the child process +// - Send a command to the child to have the single-process test loaded there, as well +// - Send a command to the child to make the predictor available +// - run_test_real in the parent +// - run_test_real does a bunch of pref-setting and other fun things on the parent +// - once all that's done, it calls run_next_test IN THE PARENT +// - every time run_next_test is called, it is called IN THE PARENT +// - the test that gets started then does any parent-side setup that's necessary +// - once the parent-side setup is done, it calls continue_<testname> IN THE CHILD +// - when the test is done running on the child, the child calls predictor.reset +// this causes some code to be run on the parent which, when complete, sends an +// obserer service notification IN THE PARENT, which causes run_next_test to be +// called again, bumping us up to the top of the loop outlined here +// - when the final test is done, cleanup happens IN THE PARENT and we're done +// +// This is a little confusing, but it's what we have to do in order to have some +// things that must run on the parent (the setup - opening cache entries, etc) +// but with most of the test running on the child (calls to the predictor api, +// verification, etc). +// +/* import-globals-from ../unit/test_predictor.js */ + +function run_test() { + var test_path = do_get_file("../unit/test_predictor.js").path.replace( + /\\/g, + "/" + ); + load(test_path); + do_load_child_test_harness(); + do_test_pending(); + sendCommand('load("' + test_path + '");', function() { + sendCommand( + 'predictor = Cc["@mozilla.org/network/predictor;1"].getService(Ci.nsINetworkPredictor);', + function() { + run_test_real(); + do_test_finished(); + } + ); + }); +} diff --git a/netwerk/test/unit_ipc/test_progress_wrap.js b/netwerk/test/unit_ipc/test_progress_wrap.js new file mode 100644 index 0000000000..c4a658c094 --- /dev/null +++ b/netwerk/test/unit_ipc/test_progress_wrap.js @@ -0,0 +1,3 @@ +function run_test() { + run_test_in_child("../unit/test_progress.js"); +} diff --git a/netwerk/test/unit_ipc/test_redirect-caching_canceled_wrap.js b/netwerk/test/unit_ipc/test_redirect-caching_canceled_wrap.js new file mode 100644 index 0000000000..8a12f4090e --- /dev/null +++ b/netwerk/test/unit_ipc/test_redirect-caching_canceled_wrap.js @@ -0,0 +1,7 @@ +// +// Run test script in content process instead of chrome (xpcshell's default) +// +// +function run_test() { + run_test_in_child("../unit/test_redirect-caching_canceled.js"); +} diff --git a/netwerk/test/unit_ipc/test_redirect-caching_failure_wrap.js b/netwerk/test/unit_ipc/test_redirect-caching_failure_wrap.js new file mode 100644 index 0000000000..f95cc399be --- /dev/null +++ b/netwerk/test/unit_ipc/test_redirect-caching_failure_wrap.js @@ -0,0 +1,11 @@ +// +// Run test script in content process instead of chrome (xpcshell's default) +// +// +function run_test() { + do_await_remote_message("disable-ports").then(_ => { + Services.prefs.setCharPref("network.security.ports.banned", "65400"); + do_send_remote_message("disable-ports-done"); + }); + run_test_in_child("../unit/test_redirect-caching_failure.js"); +} diff --git a/netwerk/test/unit_ipc/test_redirect-caching_passing_wrap.js b/netwerk/test/unit_ipc/test_redirect-caching_passing_wrap.js new file mode 100644 index 0000000000..6288bc311a --- /dev/null +++ b/netwerk/test/unit_ipc/test_redirect-caching_passing_wrap.js @@ -0,0 +1,7 @@ +// +// Run test script in content process instead of chrome (xpcshell's default) +// +// +function run_test() { + run_test_in_child("../unit/test_redirect-caching_passing.js"); +} diff --git a/netwerk/test/unit_ipc/test_redirect_canceled_wrap.js b/netwerk/test/unit_ipc/test_redirect_canceled_wrap.js new file mode 100644 index 0000000000..53fa9a5cfc --- /dev/null +++ b/netwerk/test/unit_ipc/test_redirect_canceled_wrap.js @@ -0,0 +1,7 @@ +// +// Run test script in content process instead of chrome (xpcshell's default) +// +// +function run_test() { + run_test_in_child("../unit/test_redirect_canceled.js"); +} diff --git a/netwerk/test/unit_ipc/test_redirect_different-protocol_wrap.js b/netwerk/test/unit_ipc/test_redirect_different-protocol_wrap.js new file mode 100644 index 0000000000..c45e7810ab --- /dev/null +++ b/netwerk/test/unit_ipc/test_redirect_different-protocol_wrap.js @@ -0,0 +1,7 @@ +// +// Run test script in content process instead of chrome (xpcshell's default) +// + +function run_test() { + run_test_in_child("../unit/test_redirect_different-protocol.js"); +} diff --git a/netwerk/test/unit_ipc/test_redirect_failure_wrap.js b/netwerk/test/unit_ipc/test_redirect_failure_wrap.js new file mode 100644 index 0000000000..ac935afe78 --- /dev/null +++ b/netwerk/test/unit_ipc/test_redirect_failure_wrap.js @@ -0,0 +1,8 @@ +// +// Run test script in content process instead of chrome (xpcshell's default) +// + +function run_test() { + Services.prefs.setCharPref("network.security.ports.banned", "65400"); + run_test_in_child("../unit/test_redirect_failure.js"); +} diff --git a/netwerk/test/unit_ipc/test_redirect_from_script_wrap.js b/netwerk/test/unit_ipc/test_redirect_from_script_wrap.js new file mode 100644 index 0000000000..74f77a9ea1 --- /dev/null +++ b/netwerk/test/unit_ipc/test_redirect_from_script_wrap.js @@ -0,0 +1,3 @@ +function run_test() { + run_test_in_child("../unit/test_redirect_from_script.js"); +} diff --git a/netwerk/test/unit_ipc/test_redirect_history_wrap.js b/netwerk/test/unit_ipc/test_redirect_history_wrap.js new file mode 100644 index 0000000000..38cdfa35ec --- /dev/null +++ b/netwerk/test/unit_ipc/test_redirect_history_wrap.js @@ -0,0 +1,7 @@ +// +// Run test script in content process instead of chrome (xpcshell's default) +// + +function run_test() { + run_test_in_child("../unit/test_redirect_history.js"); +} diff --git a/netwerk/test/unit_ipc/test_redirect_passing_wrap.js b/netwerk/test/unit_ipc/test_redirect_passing_wrap.js new file mode 100644 index 0000000000..597ac35fb4 --- /dev/null +++ b/netwerk/test/unit_ipc/test_redirect_passing_wrap.js @@ -0,0 +1,7 @@ +// +// Run test script in content process instead of chrome (xpcshell's default) +// + +function run_test() { + run_test_in_child("../unit/test_redirect_passing.js"); +} diff --git a/netwerk/test/unit_ipc/test_redirect_veto_parent.js b/netwerk/test/unit_ipc/test_redirect_veto_parent.js new file mode 100644 index 0000000000..c2fa3fa000 --- /dev/null +++ b/netwerk/test/unit_ipc/test_redirect_veto_parent.js @@ -0,0 +1,64 @@ +// +// Run test script in content process instead of chrome (xpcshell's default) +// +// + +let ChannelEventSink2 = { + _classDescription: "WebRequest channel event sink", + _classID: Components.ID("115062f8-92f1-11e5-8b7f-08001110f7ec"), + _contractID: "@mozilla.org/webrequest/channel-event-sink;1", + + QueryInterface: ChromeUtils.generateQI(["nsIChannelEventSink", "nsIFactory"]), + + init() { + Components.manager + .QueryInterface(Ci.nsIComponentRegistrar) + .registerFactory( + this._classID, + this._classDescription, + this._contractID, + this + ); + }, + + register() { + Services.catMan.addCategoryEntry( + "net-channel-event-sinks", + this._contractID, + this._contractID, + false, + true + ); + }, + + unregister() { + Components.manager + .QueryInterface(Ci.nsIComponentRegistrar) + .unregisterFactory(this._classID, ChannelEventSink2); + Services.catMan.deleteCategoryEntry( + "net-channel-event-sinks", + this._contractID, + false + ); + }, + + // nsIChannelEventSink implementation + asyncOnChannelRedirect(oldChannel, newChannel, flags, redirectCallback) { + // Abort the redirection + redirectCallback.onRedirectVerifyCallback(Cr.NS_ERROR_NO_INTERFACE); + }, + + // nsIFactory implementation + createInstance(iid) { + return this.QueryInterface(iid); + }, +}; + +add_task(async function run_test() { + ChannelEventSink2.init(); + ChannelEventSink2.register(); + + run_test_in_child("child_veto_in_parent.js"); + await do_await_remote_message("child-test-done"); + ChannelEventSink2.unregister(); +}); diff --git a/netwerk/test/unit_ipc/test_redirect_veto_wrap.js b/netwerk/test/unit_ipc/test_redirect_veto_wrap.js new file mode 100644 index 0000000000..554683d944 --- /dev/null +++ b/netwerk/test/unit_ipc/test_redirect_veto_wrap.js @@ -0,0 +1,7 @@ +// +// Run test script in content process instead of chrome (xpcshell's default) +// +// +function run_test() { + run_test_in_child("../unit/test_redirect_veto.js"); +} diff --git a/netwerk/test/unit_ipc/test_reentrancy_wrap.js b/netwerk/test/unit_ipc/test_reentrancy_wrap.js new file mode 100644 index 0000000000..18f2509159 --- /dev/null +++ b/netwerk/test/unit_ipc/test_reentrancy_wrap.js @@ -0,0 +1,3 @@ +function run_test() { + run_test_in_child("../unit/test_reentrancy.js"); +} diff --git a/netwerk/test/unit_ipc/test_reply_without_content_type_wrap.js b/netwerk/test/unit_ipc/test_reply_without_content_type_wrap.js new file mode 100644 index 0000000000..f2d90c33d0 --- /dev/null +++ b/netwerk/test/unit_ipc/test_reply_without_content_type_wrap.js @@ -0,0 +1,7 @@ +// +// Run test script in content process instead of chrome (xpcshell's default) +// + +function run_test() { + run_test_in_child("../unit/test_reply_without_content_type.js"); +} diff --git a/netwerk/test/unit_ipc/test_resumable_channel_wrap.js b/netwerk/test/unit_ipc/test_resumable_channel_wrap.js new file mode 100644 index 0000000000..573ab25b64 --- /dev/null +++ b/netwerk/test/unit_ipc/test_resumable_channel_wrap.js @@ -0,0 +1,3 @@ +function run_test() { + run_test_in_child("../unit/test_resumable_channel.js"); +} diff --git a/netwerk/test/unit_ipc/test_simple_wrap.js b/netwerk/test/unit_ipc/test_simple_wrap.js new file mode 100644 index 0000000000..8c6957e944 --- /dev/null +++ b/netwerk/test/unit_ipc/test_simple_wrap.js @@ -0,0 +1,7 @@ +// +// Run test script in content process instead of chrome (xpcshell's default) +// + +function run_test() { + run_test_in_child("../unit/test_simple.js"); +} diff --git a/netwerk/test/unit_ipc/test_trackingProtection_annotateChannels_wrap1.js b/netwerk/test/unit_ipc/test_trackingProtection_annotateChannels_wrap1.js new file mode 100644 index 0000000000..fc2736045a --- /dev/null +++ b/netwerk/test/unit_ipc/test_trackingProtection_annotateChannels_wrap1.js @@ -0,0 +1,26 @@ +const { UrlClassifierTestUtils } = ChromeUtils.import( + "resource://testing-common/UrlClassifierTestUtils.jsm" +); + +function run_test() { + do_get_profile(); + Services.prefs.setBoolPref( + "privacy.trackingprotection.annotate_channels", + false + ); + Services.prefs.setBoolPref( + "privacy.trackingprotection.lower_network_priority", + false + ); + do_test_pending(); + UrlClassifierTestUtils.addTestTrackers().then(() => { + run_test_in_child( + "../unit/test_trackingProtection_annotateChannels.js", + () => { + UrlClassifierTestUtils.cleanupTestTrackers(); + do_test_finished(); + } + ); + do_test_finished(); + }); +} diff --git a/netwerk/test/unit_ipc/test_trackingProtection_annotateChannels_wrap2.js b/netwerk/test/unit_ipc/test_trackingProtection_annotateChannels_wrap2.js new file mode 100644 index 0000000000..829e068347 --- /dev/null +++ b/netwerk/test/unit_ipc/test_trackingProtection_annotateChannels_wrap2.js @@ -0,0 +1,26 @@ +const { UrlClassifierTestUtils } = ChromeUtils.import( + "resource://testing-common/UrlClassifierTestUtils.jsm" +); + +function run_test() { + do_get_profile(); + Services.prefs.setBoolPref( + "privacy.trackingprotection.annotate_channels", + true + ); + Services.prefs.setBoolPref( + "privacy.trackingprotection.lower_network_priority", + true + ); + do_test_pending(); + UrlClassifierTestUtils.addTestTrackers().then(() => { + run_test_in_child( + "../unit/test_trackingProtection_annotateChannels.js", + () => { + UrlClassifierTestUtils.cleanupTestTrackers(); + do_test_finished(); + } + ); + do_test_finished(); + }); +} diff --git a/netwerk/test/unit_ipc/test_trr_httpssvc_wrap.js b/netwerk/test/unit_ipc/test_trr_httpssvc_wrap.js new file mode 100644 index 0000000000..11d933a71a --- /dev/null +++ b/netwerk/test/unit_ipc/test_trr_httpssvc_wrap.js @@ -0,0 +1,88 @@ +"use strict"; + +let h2Port; +let prefs; + +function setup() { + h2Port = Services.env.get("MOZHTTP2_PORT"); + Assert.notEqual(h2Port, null); + Assert.notEqual(h2Port, ""); + + // Set to allow the cert presented by our H2 server + do_get_profile(); + prefs = Services.prefs; + + prefs.setBoolPref("network.security.esni.enabled", false); + prefs.setBoolPref("network.http.http2.enabled", true); + // the TRR server is on 127.0.0.1 + prefs.setCharPref("network.trr.bootstrapAddr", "127.0.0.1"); + + // make all native resolve calls "secretly" resolve localhost instead + prefs.setBoolPref("network.dns.native-is-localhost", true); + + // 0 - off, 1 - race, 2 TRR first, 3 TRR only, 4 shadow + prefs.setIntPref("network.trr.mode", 3); // TRR first + prefs.setBoolPref("network.trr.wait-for-portal", false); + // don't confirm that TRR is working, just go! + prefs.setCharPref("network.trr.confirmationNS", "skip"); + + // So we can change the pref without clearing the cache to check a pushed + // record with a TRR path that fails. + prefs.setBoolPref("network.trr.clear-cache-on-pref-change", false); + + // The moz-http2 cert is for foo.example.com and is signed by http2-ca.pem + // so add that cert to the trust list as a signing cert. // the foo.example.com domain name. + const certdb = Cc["@mozilla.org/security/x509certdb;1"].getService( + Ci.nsIX509CertDB + ); + addCertFromFile(certdb, "../unit/http2-ca.pem", "CTu,u,u"); +} + +setup(); +registerCleanupFunction(() => { + prefs.clearUserPref("network.security.esni.enabled"); + prefs.clearUserPref("network.http.http2.enabled"); + prefs.clearUserPref("network.dns.localDomains"); + prefs.clearUserPref("network.dns.native-is-localhost"); + prefs.clearUserPref("network.trr.mode"); + prefs.clearUserPref("network.trr.uri"); + prefs.clearUserPref("network.trr.credentials"); + prefs.clearUserPref("network.trr.wait-for-portal"); + prefs.clearUserPref("network.trr.allow-rfc1918"); + prefs.clearUserPref("network.trr.useGET"); + prefs.clearUserPref("network.trr.confirmationNS"); + prefs.clearUserPref("network.trr.bootstrapAddr"); + prefs.clearUserPref("network.trr.temp_blocklist_duration_sec"); + prefs.clearUserPref("network.trr.request-timeout"); + prefs.clearUserPref("network.trr.clear-cache-on-pref-change"); + prefs.clearUserPref("network.dns.port_prefixed_qname_https_rr"); +}); + +function run_test() { + prefs.setIntPref("network.trr.mode", 3); + prefs.setCharPref( + "network.trr.uri", + "https://foo.example.com:" + h2Port + "/httpssvc" + ); + + do_await_remote_message("mode3-port").then(port => { + prefs.setIntPref("network.trr.mode", 3); + prefs.setCharPref( + "network.trr.uri", + `https://foo.example.com:${port}/dns-query` + ); + do_send_remote_message("mode3-port-done"); + }); + + do_await_remote_message("clearCache").then(() => { + Services.dns.clearCache(true); + do_send_remote_message("clearCache-done"); + }); + + do_await_remote_message("set-port-prefixed-pref").then(() => { + prefs.setBoolPref("network.dns.port_prefixed_qname_https_rr", true); + do_send_remote_message("set-port-prefixed-pref-done"); + }); + + run_test_in_child("../unit/test_trr_httpssvc.js"); +} diff --git a/netwerk/test/unit_ipc/test_xmlhttprequest_wrap.js b/netwerk/test/unit_ipc/test_xmlhttprequest_wrap.js new file mode 100644 index 0000000000..00b4a0b85f --- /dev/null +++ b/netwerk/test/unit_ipc/test_xmlhttprequest_wrap.js @@ -0,0 +1,3 @@ +function run_test() { + run_test_in_child("../unit/test_xmlhttprequest.js"); +} diff --git a/netwerk/test/unit_ipc/xpcshell.ini b/netwerk/test/unit_ipc/xpcshell.ini new file mode 100644 index 0000000000..77e2ea92b3 --- /dev/null +++ b/netwerk/test/unit_ipc/xpcshell.ini @@ -0,0 +1,182 @@ +[DEFAULT] +head = head_channels_clone.js head_trr_clone.js head_http3_clone.js ../unit/head_servers.js +skip-if = socketprocess_networking +support-files = + child_channel_id.js + !/netwerk/test/unit/test_XHR_redirects.js + !/netwerk/test/unit/test_bug528292.js + !/netwerk/test/unit/test_cache-entry-id.js + !/netwerk/test/unit/test_cache_jar.js + !/netwerk/test/unit/test_cacheflags.js + !/netwerk/test/unit/test_channel_close.js + !/netwerk/test/unit/test_cookiejars.js + !/netwerk/test/unit/test_dns_cancel.js + !/netwerk/test/unit/test_dns_service.js + !/netwerk/test/unit/test_duplicate_headers.js + !/netwerk/test/unit/test_event_sink.js + !/netwerk/test/unit/test_getHost.js + !/netwerk/test/unit/test_gio_protocol.js + !/netwerk/test/unit/test_head.js + !/netwerk/test/unit/test_headers.js + !/netwerk/test/unit/test_httpsuspend.js + !/netwerk/test/unit/test_post.js + !/netwerk/test/unit/test_predictor.js + !/netwerk/test/unit/test_progress.js + !/netwerk/test/unit/test_redirect_veto.js + !/netwerk/test/unit/test_redirect-caching_canceled.js + !/netwerk/test/unit/test_redirect-caching_failure.js + !/netwerk/test/unit/test_redirect-caching_passing.js + !/netwerk/test/unit/test_redirect_canceled.js + !/netwerk/test/unit/test_redirect_different-protocol.js + !/netwerk/test/unit/test_redirect_failure.js + !/netwerk/test/unit/test_redirect_from_script.js + !/netwerk/test/unit/test_redirect_history.js + !/netwerk/test/unit/test_redirect_passing.js + !/netwerk/test/unit/test_reentrancy.js + !/netwerk/test/unit/test_reply_without_content_type.js + !/netwerk/test/unit/test_resumable_channel.js + !/netwerk/test/unit/test_simple.js + !/netwerk/test/unit/test_trackingProtection_annotateChannels.js + !/netwerk/test/unit/test_xmlhttprequest.js + !/netwerk/test/unit/head_channels.js + !/netwerk/test/unit/head_trr.js + !/netwerk/test/unit/head_cache2.js + !/netwerk/test/unit/data/image.png + !/netwerk/test/unit/data/system_root.lnk + !/netwerk/test/unit/data/test_psl.txt + !/netwerk/test/unit/data/test_readline1.txt + !/netwerk/test/unit/data/test_readline2.txt + !/netwerk/test/unit/data/test_readline3.txt + !/netwerk/test/unit/data/test_readline4.txt + !/netwerk/test/unit/data/test_readline5.txt + !/netwerk/test/unit/data/test_readline6.txt + !/netwerk/test/unit/data/test_readline7.txt + !/netwerk/test/unit/data/test_readline8.txt + !/netwerk/test/unit/data/signed_win.exe + !/netwerk/test/unit/test_alt-data_simple.js + !/netwerk/test/unit/test_alt-data_stream.js + !/netwerk/test/unit/test_alt-data_closeWithStatus.js + !/netwerk/test/unit/test_channel_priority.js + !/netwerk/test/unit/test_multipart_streamconv.js + !/netwerk/test/unit/test_original_sent_received_head.js + !/netwerk/test/unit/test_alt-data_cross_process.js + !/netwerk/test/unit/test_httpcancel.js + !/netwerk/test/unit/test_trr_httpssvc.js + !/netwerk/test/unit/test_http3_prio_enabled.js + !/netwerk/test/unit/test_http3_prio_disabled.js + !/netwerk/test/unit/test_http3_prio_helpers.js + !/netwerk/test/unit/http2-ca.pem + !/netwerk/test/unit/test_orb_empty_header.js + child_is_proxy_used.js + child_cookie_header.js + child_dns_by_type_resolve.js + child_veto_in_parent.js + + +[test_cookie_header_stripped.js] +[test_cacheflags_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_cache-entry-id_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_cache_jar_wrap.js] +[test_channel_close_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_chunked_responses_wrap.js] +prefs = + network.allow_raw_sockets_in_content_processes=true + security.allow_eval_with_system_principal=true +[test_cookiejars_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_dns_cancel_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_dns_service_wrap.js] +[test_duplicate_headers_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_event_sink_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_gio_protocol_wrap.js] +skip-if = (toolkit != 'gtk') +[test_head_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_headers_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_httpsuspend_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_post_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_predictor_wrap.js] +[test_progress_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_redirect-caching_canceled_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_redirect-caching_failure_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_redirect-caching_passing_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_redirect_canceled_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_redirect_failure_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +# Do not test the channel.redirectTo() API under e10s until 827269 is resolved +[test_redirect_from_script_wrap.js] +skip-if = true +[test_redirect_veto_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_redirect_veto_parent.js] +prefs = network.allow_raw_sockets_in_content_processes=true +run-sequentially = doesn't play nice with others. +[test_redirect_passing_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_redirect_different-protocol_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_reentrancy_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_resumable_channel_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_simple_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_http3_prio_disabled_wrap.js] +skip-if = + os == 'android' + os == 'win' && msix # https://bugzilla.mozilla.org/show_bug.cgi?id=1807925 +run-sequentially = http3server +[test_http3_prio_enabled_wrap.js] +skip-if = + os == 'android' + os == 'win' && msix # https://bugzilla.mozilla.org/show_bug.cgi?id=1807925 +run-sequentially = http3server +[test_xmlhttprequest_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_XHR_redirects.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_redirect_history_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_reply_without_content_type_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_getHost_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_alt-data_simple_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_alt-data_stream_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_alt-data_closeWithStatus_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_original_sent_received_head_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_channel_id.js] +[test_trackingProtection_annotateChannels_wrap1.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_trackingProtection_annotateChannels_wrap2.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_channel_priority_wrap.js] +[test_multipart_streamconv_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_alt-data_cross_process_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_httpcancel_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true +[test_dns_by_type_resolve_wrap.js] +[test_trr_httpssvc_wrap.js] +skip-if = os == "android" +[test_orb_empty_header_wrap.js] +[test_is_proxy_used.js] |