From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- comm/chat/protocols/xmpp/test/test_xmppXml.js | 103 ++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 comm/chat/protocols/xmpp/test/test_xmppXml.js (limited to 'comm/chat/protocols/xmpp/test/test_xmppXml.js') diff --git a/comm/chat/protocols/xmpp/test/test_xmppXml.js b/comm/chat/protocols/xmpp/test/test_xmppXml.js new file mode 100644 index 0000000000..1b6ea9a175 --- /dev/null +++ b/comm/chat/protocols/xmpp/test/test_xmppXml.js @@ -0,0 +1,103 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +var { Stanza } = ChromeUtils.importESModule( + "resource:///modules/xmpp-xml.sys.mjs" +); + +var TEST_DATA = [ + { + input: { + name: "message", + namespace: Stanza.NS.client, + attributes: { + jid: "user@domain", + type: null, + }, + data: [], + }, + XmlOutput: '', + stringOutput: '\n', + isError: false, + description: "Ignore attribute with null value", + }, + { + input: { + name: "message", + namespace: Stanza.NS.client, + attributes: { + jid: "user@domain", + type: undefined, + }, + data: [], + }, + XmlOutput: '', + stringOutput: '\n', + isError: false, + description: "Ignore attribute with undefined value", + }, + { + input: { + name: "message", + namespace: undefined, + attributes: {}, + data: [], + }, + XmlOutput: "", + stringOutput: "\n", + isError: false, + description: "Ignore namespace with undefined value", + }, + { + input: { + name: undefined, + attributes: {}, + data: [], + }, + XmlOutput: "", + stringOutput: "", + isError: true, + description: "Node must have a name", + }, + { + input: { + name: "message", + attributes: {}, + data: "test message", + }, + XmlOutput: "test message", + stringOutput: "\n test message\n\n", + isError: false, + description: "Node with text content", + }, +]; + +function testXMLNode() { + for (let current of TEST_DATA) { + try { + let result = Stanza.node( + current.input.name, + current.input.namespace, + current.input.attributes, + current.input.data + ); + equal(result.getXML(), current.XmlOutput, current.description); + equal( + result.convertToString(), + current.stringOutput, + current.description + ); + equal(current.isError, false); + } catch (e) { + equal(current.isError, true, current.description); + } + } + + run_next_test(); +} + +function run_test() { + add_test(testXMLNode); + + run_next_test(); +} -- cgit v1.2.3