diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /netwerk/test/browser/browser_NetUtil.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/browser/browser_NetUtil.js')
-rw-r--r-- | netwerk/test/browser/browser_NetUtil.js | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/netwerk/test/browser/browser_NetUtil.js b/netwerk/test/browser/browser_NetUtil.js new file mode 100644 index 0000000000..09875a5280 --- /dev/null +++ b/netwerk/test/browser/browser_NetUtil.js @@ -0,0 +1,111 @@ +/* +Any copyright is dedicated to the Public Domain. +http://creativecommons.org/publicdomain/zero/1.0/ +*/ +"use strict"; + +function test() { + waitForExplicitFinish(); + + // We overload this test to include verifying that httpd.js is + // importable as a testing-only JS module. + ChromeUtils.importESModule("resource://testing-common/httpd.sys.mjs"); + + nextTest(); +} + +function nextTest() { + if (tests.length) { + executeSoon(tests.shift()); + } else { + executeSoon(finish); + } +} + +var tests = [test_asyncFetchBadCert]; + +function test_asyncFetchBadCert() { + // Try a load from an untrusted cert, with errors supressed + NetUtil.asyncFetch( + { + uri: "https://untrusted.example.com", + loadUsingSystemPrincipal: true, + }, + function (aInputStream, aStatusCode, aRequest) { + ok(!Components.isSuccessCode(aStatusCode), "request failed"); + ok(aRequest instanceof Ci.nsIHttpChannel, "request is an nsIHttpChannel"); + + // Now try again with a channel whose notificationCallbacks doesn't suprress errors + let channel = NetUtil.newChannel({ + uri: "https://untrusted.example.com", + loadUsingSystemPrincipal: true, + }); + channel.notificationCallbacks = { + QueryInterface: ChromeUtils.generateQI([ + "nsIProgressEventSink", + "nsIInterfaceRequestor", + ]), + getInterface(aIID) { + return this.QueryInterface(aIID); + }, + onProgress() {}, + onStatus() {}, + }; + NetUtil.asyncFetch( + channel, + function (aInputStream, aStatusCode, aRequest) { + ok(!Components.isSuccessCode(aStatusCode), "request failed"); + ok( + aRequest instanceof Ci.nsIHttpChannel, + "request is an nsIHttpChannel" + ); + + // Now try a valid request + NetUtil.asyncFetch( + { + uri: "https://example.com", + loadUsingSystemPrincipal: true, + }, + function (aInputStream, aStatusCode, aRequest) { + info("aStatusCode for valid request: " + aStatusCode); + ok(Components.isSuccessCode(aStatusCode), "request succeeded"); + ok( + aRequest instanceof Ci.nsIHttpChannel, + "request is an nsIHttpChannel" + ); + ok(aRequest.requestSucceeded, "HTTP request succeeded"); + + nextTest(); + } + ); + } + ); + } + ); +} + +function WindowListener(aURL, aCallback) { + this.callback = aCallback; + this.url = aURL; +} +WindowListener.prototype = { + onOpenWindow(aXULWindow) { + var domwindow = aXULWindow.docShell.domWindow; + var self = this; + domwindow.addEventListener( + "load", + function () { + if (domwindow.document.location.href != self.url) { + return; + } + + // Allow other window load listeners to execute before passing to callback + executeSoon(function () { + self.callback(domwindow); + }); + }, + { once: true } + ); + }, + onCloseWindow(aXULWindow) {}, +}; |