summaryrefslogtreecommitdiffstats
path: root/netwerk/test/unit_ipc/test_alt-data_cross_process_wrap.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /netwerk/test/unit_ipc/test_alt-data_cross_process_wrap.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/unit_ipc/test_alt-data_cross_process_wrap.js')
-rw-r--r--netwerk/test/unit_ipc/test_alt-data_cross_process_wrap.js96
1 files changed, 96 insertions, 0 deletions
diff --git a/netwerk/test/unit_ipc/test_alt-data_cross_process_wrap.js b/netwerk/test/unit_ipc/test_alt-data_cross_process_wrap.js
new file mode 100644
index 0000000000..336b9e3129
--- /dev/null
+++ b/netwerk/test/unit_ipc/test_alt-data_cross_process_wrap.js
@@ -0,0 +1,96 @@
+// needs to be rooted
+var cacheFlushObserver = {
+ observe() {
+ cacheFlushObserver = null;
+ do_send_remote_message("flushed");
+ },
+};
+
+// We get this from the child a bit later
+var url = null;
+
+// needs to be rooted
+var cacheFlushObserver2 = {
+ observe() {
+ cacheFlushObserver2 = null;
+ openAltChannel();
+ },
+};
+
+function run_test() {
+ do_get_profile();
+ do_await_remote_message("flush").then(() => {
+ Services.cache2
+ .QueryInterface(Ci.nsICacheTesting)
+ .flush(cacheFlushObserver);
+ });
+
+ do_await_remote_message("done").then(() => {
+ sendCommand("URL;", load_channel);
+ });
+
+ run_test_in_child("../unit/test_alt-data_cross_process.js");
+}
+
+function load_channel(channelUrl) {
+ ok(channelUrl);
+ url = channelUrl; // save this to open the alt data channel later
+ var chan = make_channel(channelUrl);
+ var cc = chan.QueryInterface(Ci.nsICacheInfoChannel);
+ cc.preferAlternativeDataType("text/binary", "", Ci.nsICacheInfoChannel.ASYNC);
+ chan.asyncOpen(new ChannelListener(readTextData, null));
+}
+
+function make_channel(channelUrl, callback, ctx) {
+ return NetUtil.newChannel({
+ uri: channelUrl,
+ loadUsingSystemPrincipal: true,
+ });
+}
+
+function readTextData(request, buffer) {
+ var cc = request.QueryInterface(Ci.nsICacheInfoChannel);
+ // Since we are in a different process from what that generated the alt-data,
+ // we should receive the original data, not processed content.
+ Assert.equal(cc.alternativeDataType, "");
+ Assert.equal(buffer, "response body");
+
+ // Now let's generate some alt-data in the parent, and make sure we can get it
+ var altContent = "altContentParentGenerated";
+ executeSoon(() => {
+ var os = cc.openAlternativeOutputStream(
+ "text/parent-binary",
+ altContent.length
+ );
+ os.write(altContent, altContent.length);
+ os.close();
+
+ executeSoon(() => {
+ Services.cache2
+ .QueryInterface(Ci.nsICacheTesting)
+ .flush(cacheFlushObserver2);
+ });
+ });
+}
+
+function openAltChannel() {
+ var chan = make_channel(url);
+ var cc = chan.QueryInterface(Ci.nsICacheInfoChannel);
+ cc.preferAlternativeDataType(
+ "text/parent-binary",
+ "",
+ Ci.nsICacheInfoChannel.ASYNC
+ );
+ chan.asyncOpen(new ChannelListener(readAltData, null));
+}
+
+function readAltData(request, buffer) {
+ var cc = request.QueryInterface(Ci.nsICacheInfoChannel);
+
+ // This was generated in the parent, so it's OK to get it.
+ Assert.equal(buffer, "altContentParentGenerated");
+ Assert.equal(cc.alternativeDataType, "text/parent-binary");
+
+ // FINISH
+ do_send_remote_message("finish");
+}