diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /devtools/shared/transport/tests/xpcshell/test_bulk_error.js | |
parent | Initial commit. (diff) | |
download | firefox-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 'devtools/shared/transport/tests/xpcshell/test_bulk_error.js')
-rw-r--r-- | devtools/shared/transport/tests/xpcshell/test_bulk_error.js | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/devtools/shared/transport/tests/xpcshell/test_bulk_error.js b/devtools/shared/transport/tests/xpcshell/test_bulk_error.js new file mode 100644 index 0000000000..52cc826e51 --- /dev/null +++ b/devtools/shared/transport/tests/xpcshell/test_bulk_error.js @@ -0,0 +1,94 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +function run_test() { + initTestDevToolsServer(); + add_test_bulk_actor(); + + add_task(async function () { + await test_string_error(socket_transport, json_reply); + await test_string_error(local_transport, json_reply); + DevToolsServer.destroy(); + }); + + run_next_test(); +} + +/** * Sample Bulk Actor ***/ +const { Actor } = require("resource://devtools/shared/protocol/Actor.js"); +class TestBulkActor extends Actor { + constructor(conn) { + super(conn); + + this.typeName = "testBulk"; + this.requestTypes = { + jsonReply: this.jsonReply, + }; + } + + jsonReply({ length, reader, reply, done }) { + Assert.equal(length, really_long().length); + + return { + allDone: true, + }; + } +} + +function add_test_bulk_actor() { + ActorRegistry.addGlobalActor( + { + constructorName: "TestBulkActor", + constructorFun: TestBulkActor, + }, + "testBulk" + ); +} + +/** * Tests ***/ + +var test_string_error = async function (transportFactory, onReady) { + const transport = await transportFactory(); + + const client = new DevToolsClient(transport); + await client.connect(); + const response = await client.mainRoot.rootForm; + + await onReady(client, response); + client.close(); + transport.close(); +}; + +/** * Reply Types ***/ + +function json_reply(client, response) { + const reallyLong = really_long(); + + const request = client.startBulkRequest({ + actor: response.testBulk, + type: "jsonReply", + length: reallyLong.length, + }); + + // Send bulk data to server + return new Promise(resolve => { + request.on("bulk-send-ready", ({ writer, done }) => { + const input = Cc["@mozilla.org/io/string-input-stream;1"].createInstance( + Ci.nsIStringInputStream + ); + input.setData(reallyLong, reallyLong.length); + try { + writer.copyFrom(input, () => { + input.close(); + done(); + }); + do_throw(new Error("Copying should fail, the stream is not async.")); + } catch (e) { + Assert.ok(true); + resolve(); + } + }); + }); +} |