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/unit/test_suspend_channel_on_examine.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/unit/test_suspend_channel_on_examine.js')
-rw-r--r-- | netwerk/test/unit/test_suspend_channel_on_examine.js | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/netwerk/test/unit/test_suspend_channel_on_examine.js b/netwerk/test/unit/test_suspend_channel_on_examine.js new file mode 100644 index 0000000000..7667026a56 --- /dev/null +++ b/netwerk/test/unit/test_suspend_channel_on_examine.js @@ -0,0 +1,76 @@ +// This file tests async handling of a channel suspended in http-on-modify-request. +"use strict"; + +const { HttpServer } = ChromeUtils.importESModule( + "resource://testing-common/httpd.sys.mjs" +); + +var obs = Services.obs; + +var baseUrl; + +function responseHandler(metadata, response) { + var text = "testing"; + response.setHeader("Content-Type", "text/plain", false); + response.setHeader("Set-Cookie", "chewy", false); + response.bodyOutputStream.write(text, text.length); +} + +function onExamineListener(callback) { + obs.addObserver( + { + observe(subject, topic, data) { + obs.removeObserver(this, "http-on-examine-response"); + callback(subject.QueryInterface(Ci.nsIHttpChannel)); + }, + }, + "http-on-examine-response" + ); +} + +function startChannelRequest(uri, flags, callback) { + var chan = NetUtil.newChannel({ + uri, + loadUsingSystemPrincipal: true, + }); + chan.asyncOpen(new ChannelListener(callback, null, flags)); +} + +// We first make a request that we'll cancel asynchronously. The response will +// still contain the set-cookie header. Then verify the cookie was not actually +// retained. +add_test(function testAsyncCancel() { + onExamineListener(chan => { + // Suspend the channel then yield to make this async. + chan.suspend(); + Promise.resolve().then(() => { + chan.cancel(Cr.NS_BINDING_ABORTED); + chan.resume(); + }); + }); + startChannelRequest(baseUrl, CL_EXPECT_FAILURE, (request, data, context) => { + Assert.ok(!data, "no response"); + + Assert.equal( + Services.cookies.countCookiesFromHost("localhost"), + 0, + "no cookies set" + ); + + executeSoon(run_next_test); + }); +}); + +function run_test() { + var httpServer = new HttpServer(); + httpServer.registerPathHandler("/", responseHandler); + httpServer.start(-1); + + baseUrl = `http://localhost:${httpServer.identity.primaryPort}`; + + run_next_test(); + + registerCleanupFunction(function () { + httpServer.stop(() => {}); + }); +} |