summaryrefslogtreecommitdiffstats
path: root/comm/chat/protocols/xmpp/test/test_xmppXml.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /comm/chat/protocols/xmpp/test/test_xmppXml.js
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'comm/chat/protocols/xmpp/test/test_xmppXml.js')
-rw-r--r--comm/chat/protocols/xmpp/test/test_xmppXml.js103
1 files changed, 103 insertions, 0 deletions
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: '<message xmlns="jabber:client" jid="user@domain"/>',
+ stringOutput: '<message xmlns="jabber:client" jid="user@domain"/>\n',
+ isError: false,
+ description: "Ignore attribute with null value",
+ },
+ {
+ input: {
+ name: "message",
+ namespace: Stanza.NS.client,
+ attributes: {
+ jid: "user@domain",
+ type: undefined,
+ },
+ data: [],
+ },
+ XmlOutput: '<message xmlns="jabber:client" jid="user@domain"/>',
+ stringOutput: '<message xmlns="jabber:client" jid="user@domain"/>\n',
+ isError: false,
+ description: "Ignore attribute with undefined value",
+ },
+ {
+ input: {
+ name: "message",
+ namespace: undefined,
+ attributes: {},
+ data: [],
+ },
+ XmlOutput: "<message/>",
+ stringOutput: "<message/>\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: "<message>test message</message>",
+ stringOutput: "<message>\n test message\n</message>\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();
+}