From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- netwerk/test/unit/test_304_headers.js | 89 +++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 netwerk/test/unit/test_304_headers.js (limited to 'netwerk/test/unit/test_304_headers.js') diff --git a/netwerk/test/unit/test_304_headers.js b/netwerk/test/unit/test_304_headers.js new file mode 100644 index 0000000000..662216e299 --- /dev/null +++ b/netwerk/test/unit/test_304_headers.js @@ -0,0 +1,89 @@ +"use strict"; + +const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js"); + +XPCOMUtils.defineLazyGetter(this, "URL", function() { + return `http://localhost:${httpServer.identity.primaryPort}/test`; +}); + +let httpServer = null; + +function make_channel(url) { + return NetUtil.newChannel({ + uri: url, + loadUsingSystemPrincipal: true, + }).QueryInterface(Ci.nsIHttpChannel); +} + +function contentHandler(metadata, response) { + response.seizePower(); + let etag = ""; + try { + etag = metadata.getHeader("If-None-Match"); + } catch (ex) {} + + if (etag == "test-etag1") { + response.write("HTTP/1.1 304 Not Modified\r\n"); + + response.write("Link: ; param1=value1\r\n"); + response.write("Link: ; param2=value2\r\n"); + response.write("Link: ; param1=value1\r\n"); + response.write("\r\n"); + response.finish(); + return; + } + + response.write("HTTP/1.1 200 OK\r\n"); + + response.write("ETag: test-etag1\r\n"); + response.write("Link: ; param1=value1\r\n"); + response.write("Link: ; param2=value2\r\n"); + response.write("Link: ; param1=value1\r\n"); + response.write("\r\n"); + response.finish(); +} + +add_task(async function test() { + httpServer = new HttpServer(); + httpServer.registerPathHandler("/test", contentHandler); + httpServer.start(-1); + registerCleanupFunction(async () => { + await httpServer.stop(); + }); + + let chan = make_channel(Services.io.newURI(URL)); + chan.requestMethod = "HEAD"; + await new Promise(resolve => { + chan.asyncOpen({ + onStopRequest(req, status) { + equal(status, Cr.NS_OK); + equal(req.QueryInterface(Ci.nsIHttpChannel).responseStatus, 200); + equal( + req.QueryInterface(Ci.nsIHttpChannel).getResponseHeader("Link"), + "; param1=value1, ; param2=value2, ; param1=value1" + ); + resolve(); + }, + onStartRequest(req) {}, + onDataAvailable() {}, + }); + }); + + chan = make_channel(Services.io.newURI(URL)); + chan.requestMethod = "HEAD"; + await new Promise(resolve => { + chan.asyncOpen({ + onStopRequest(req, status) { + equal(status, Cr.NS_OK); + equal(req.QueryInterface(Ci.nsIHttpChannel).responseStatus, 200); + equal( + req.QueryInterface(Ci.nsIHttpChannel).getResponseHeader("Link"), + "; param1=value1, ; param2=value2, ; param1=value1" + ); + resolve(); + }, + onStartRequest(req) {}, + onDataAvailable() {}, + }); + }); +}); -- cgit v1.2.3