From b227119f4ba0ff3a0413efbfdd929ffb408c05b2 Mon Sep 17 00:00:00 2001 From: Nika Layzell Date: Tue, 2 Feb 2021 23:26:16 +0000 Subject: [PATCH] Bug 1681529 - Part 1: Add a test for reloading a page with a large postdata payload, r=peterv Without the other patches in this series, this test fails with both with and without Fission enabled, for two different reasons. With Fission disabled, the second reload request appears as empty, due to us being unable to rewind the postData nsIInputStream. With Fission enabled, the second reload request causes crashes due to the nsMIMEInputStream's invariant of requiring a seekable stream is invalidated, causing the nsICloneableInputStream implementation to misbehave. Differential Revision: https://phabricator.services.mozilla.com/D101800 --- .../navigation/file_reload_large_postdata.sjs | 46 ++++++++++++++ docshell/test/navigation/mochitest.ini | 3 + .../test_reload_large_postdata.html | 61 +++++++++++++++++++ ipc/glue/IPCStreamUtils.cpp | 2 + 4 files changed, 112 insertions(+) create mode 100644 docshell/test/navigation/file_reload_large_postdata.sjs create mode 100644 docshell/test/navigation/test_reload_large_postdata.html diff --git a/docshell/test/navigation/file_reload_large_postdata.sjs b/docshell/test/navigation/file_reload_large_postdata.sjs new file mode 100644 index 000000000000..385d43d99f8f --- /dev/null +++ b/docshell/test/navigation/file_reload_large_postdata.sjs @@ -0,0 +1,46 @@ +/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set sts=2 sw=2 et tw=80 ft=javascript: */ +"use strict"; + +const BinaryInputStream = Components.Constructor( + "@mozilla.org/binaryinputstream;1", + "nsIBinaryInputStream", + "setInputStream" +); + +Cu.importGlobalProperties(["URLSearchParams"]); + +function readStream(inputStream) { + let available = 0; + let result = []; + while ((available = inputStream.available()) > 0) { + result.push(inputStream.readBytes(available)); + } + return result.join(""); +} + +function handleRequest(request, response) { + let rv = (() => { + try { + if (request.method != "POST") { + return "ERROR: not a POST request"; + } + + let body = new URLSearchParams( + readStream(new BinaryInputStream(request.bodyInputStream)) + ); + return body.get("payload").length; + } catch (e) { + return "ERROR: Exception: " + e; + } + })(); + + response.setHeader("Content-Type", "text/html", false); + response.setHeader("Cache-Control", "no-cache", false); + response.write(` + + `); +} diff --git a/docshell/test/navigation/mochitest.ini b/docshell/test/navigation/mochitest.ini index 693121ca10ca..18d6a233a660 100644 --- a/docshell/test/navigation/mochitest.ini +++ b/docshell/test/navigation/mochitest.ini @@ -119,3 +119,6 @@ skip-if = true # This was disabled for a few years now anyway, bug 1677544 [test_triggeringprincipal_iframe_iframe_window_open.html] [test_contentpolicy_block_window.html] [test_rate_limit_location_change.html] +[test_reload_large_postdata.html] +support-files = + file_reload_large_postdata.sjs diff --git a/docshell/test/navigation/test_reload_large_postdata.html b/docshell/test/navigation/test_reload_large_postdata.html new file mode 100644 index 000000000000..15fae33ac3ff --- /dev/null +++ b/docshell/test/navigation/test_reload_large_postdata.html @@ -0,0 +1,61 @@ + + + + + + + +

+ +
+ +
+ +
+
+
+ + diff --git a/ipc/glue/IPCStreamUtils.cpp b/ipc/glue/IPCStreamUtils.cpp index fba98891fe2e..6d3e1868168e 100644 --- a/ipc/glue/IPCStreamUtils.cpp +++ b/ipc/glue/IPCStreamUtils.cpp @@ -40,6 +40,8 @@ bool SerializeInputStreamWithFdsChild(nsIIPCSerializableInputStream* aStream, MOZ_RELEASE_ASSERT(aStream); MOZ_ASSERT(aManager); + // If you change this size, please also update the payload size in + // test_reload_large_postdata.html. const uint64_t kTooLargeStream = 1024 * 1024; uint32_t sizeUsed = 0;