From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- ...9a-concurrent_read_resumable_entry_size_zero.js | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 netwerk/test/unit/test_cache2-29a-concurrent_read_resumable_entry_size_zero.js (limited to 'netwerk/test/unit/test_cache2-29a-concurrent_read_resumable_entry_size_zero.js') diff --git a/netwerk/test/unit/test_cache2-29a-concurrent_read_resumable_entry_size_zero.js b/netwerk/test/unit/test_cache2-29a-concurrent_read_resumable_entry_size_zero.js new file mode 100644 index 0000000000..014060ca83 --- /dev/null +++ b/netwerk/test/unit/test_cache2-29a-concurrent_read_resumable_entry_size_zero.js @@ -0,0 +1,74 @@ +/* + +Checkes if the concurrent cache read/write works when the write is interrupted because of max-entry-size limits +This test is using a resumable response. +- with a profile, set max-entry-size to 0 +- first channel makes a request for a resumable response +- second channel makes a request for the same resource, concurrent read happens +- first channel sets predicted data size on the entry, it's doomed +- second channel now must engage interrupted concurrent write algorithm and read the content again from the network +- both channels must deliver full content w/o errors + +*/ + +"use strict"; + +const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js"); + +var httpProtocolHandler = Cc[ + "@mozilla.org/network/protocol;1?name=http" +].getService(Ci.nsIHttpProtocolHandler); + +XPCOMUtils.defineLazyGetter(this, "URL", function () { + return "http://localhost:" + httpServer.identity.primaryPort; +}); + +var httpServer = null; + +function make_channel(url, callback, ctx) { + return NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true }); +} + +const responseBody = "response body"; + +function contentHandler(metadata, response) { + response.setHeader("Content-Type", "text/plain"); + response.setHeader("ETag", "Just testing"); + response.setHeader("Cache-Control", "max-age=99999"); + response.setHeader("Accept-Ranges", "bytes"); + response.setHeader("Content-Length", "" + responseBody.length); + if (metadata.hasHeader("If-Range")) { + response.setStatusLine(metadata.httpVersion, 206, "Partial Content"); + response.setHeader("Content-Range", "0-12/13"); + } + response.bodyOutputStream.write(responseBody, responseBody.length); +} + +function run_test() { + do_get_profile(); + + Services.prefs.setIntPref("browser.cache.disk.max_entry_size", 0); + Services.prefs.setBoolPref("network.http.rcwn.enabled", false); + + httpServer = new HttpServer(); + httpServer.registerPathHandler("/content", contentHandler); + httpServer.start(-1); + + httpProtocolHandler.EnsureHSTSDataReady().then(function () { + var chan1 = make_channel(URL + "/content"); + chan1.asyncOpen(new ChannelListener(firstTimeThrough, null)); + var chan2 = make_channel(URL + "/content"); + chan2.asyncOpen(new ChannelListener(secondTimeThrough, null)); + }); + + do_test_pending(); +} + +function firstTimeThrough(request, buffer) { + Assert.equal(buffer, responseBody); +} + +function secondTimeThrough(request, buffer) { + Assert.equal(buffer, responseBody); + httpServer.stop(do_test_finished); +} -- cgit v1.2.3