Bug 1535964 - create test for mailbox: URLs. r=valentin
authorJorg K <jorgk@jorgk.com>
Sat, 23 Mar 2019 09:02:56 +0100
changeset 26148 3496ec1acebe
parent 26147 3e648008d386
child 26149 f9d9f70bc490
push id15696
push usermozilla@jorgk.com
push dateSat, 23 Mar 2019 08:18:55 +0000
treeherdercomm-central@34cf7d8564ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1535964
Bug 1535964 - create test for mailbox: URLs. r=valentin
mailnews/local/test/unit/test_mailboxURL.js
mailnews/local/test/unit/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/mailnews/local/test/unit/test_mailboxURL.js
@@ -0,0 +1,82 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * Tests for mailbox: URLs.
+ */
+
+var mailboxFile = Services.dirsvc.get("TmpD", Ci.nsIFile);
+mailboxFile.append("mailFolder");
+mailboxFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o600);
+var mailboxFileName = Services.io.newFileURI(mailboxFile).pathQueryRef;
+
+var mailboxURLs =
+  [
+    {
+      url: "mailbox://user@domain@example.com/folder?number=1",
+      spec: "mailbox://user%40domain@example.com/folder?number=1",
+      host: "example.com",
+      port: -1,
+      scheme: "mailbox",
+      pathQueryRef: "/folder?number=1",
+      prePath: "mailbox://user%40domain@example.com",
+    },
+    {
+      url: "mailbox://nobody@Local%20Folders/folder?number=2",
+      spec: "mailbox://nobody@local%20folders/folder?number=2",
+      host: "local%20folders",
+      port: -1,
+      scheme: "mailbox",
+      pathQueryRef: "/folder?number=2",
+      prePath: "mailbox://nobody@local%20folders",
+    },
+    {
+      url: "mailbox://" + mailboxFileName + "?number=3",
+      spec: "mailbox://" + mailboxFileName + "?number=3",
+      host: "",
+      port: -1,
+      scheme: "mailbox",
+      pathQueryRef: mailboxFileName + "?number=3",
+      prePath: "mailbox://",
+    },
+  ];
+
+function run_test() {
+  registerCleanupFunction(teardown);
+  var url;
+
+  // Test - get and check urls.
+  var part = 0;
+  for (part = 0; part < mailboxURLs.length; part++) {
+    dump(`url: ${mailboxURLs[part].url}\n`);
+    url = Services.io.newURI(mailboxURLs[part].url);
+
+    Assert.equal(url.spec, mailboxURLs[part].spec);
+    Assert.equal(url.scheme, mailboxURLs[part].scheme);
+    Assert.equal(url.host, mailboxURLs[part].host);
+    Assert.equal(url.port, mailboxURLs[part].port);
+    Assert.equal(url.pathQueryRef, mailboxURLs[part].pathQueryRef);
+    Assert.equal(url.prePath, mailboxURLs[part].prePath);
+  }
+
+  // Test - Check changing values.
+  dump("Other Tests\n");
+
+  // We can set the username on the URLs with a host.
+  url = Services.io.newURI("mailbox://user@domain@example.com/folder?number=1");
+  url.mutate().setUsername("john").finalize();
+  url = Services.io.newURI("mailbox://nobody@Local%20Folders/folder?number=2");
+  url.mutate().setUsername("jane").finalize();
+
+  // It should throw on our file-style URLs.
+  url = Services.io.newURI("mailbox://" + mailboxFileName + "?number=3");
+  try {
+    url.mutate().setUsername("noway").finalize();
+    do_throw("Should not be able to set username on file-style mailbox: URL");
+  } catch (ex) {
+    Assert.equal(ex.result, Cr.NS_ERROR_UNEXPECTED);
+  }
+}
+
+function teardown() {
+  if (mailboxFile.exists())
+    mailboxFile.remove(false);
+}
--- a/mailnews/local/test/unit/xpcshell.ini
+++ b/mailnews/local/test/unit/xpcshell.ini
@@ -5,16 +5,17 @@ support-files = data/*
 
 [test_bug457168.js]
 [test_duplicateKey.js]
 [test_fileName.js]
 [test_folderLoaded.js]
 [test_localFolder.js]
 [test_mailboxContentLength.js]
 [test_mailboxProtocol.js]
+[test_mailboxURL.js]
 [test_movemailDownload.js]
 skip-if = os == "win"
 [test_msgCopy.js]
 [test_msgIDParsing.js]
 [test_nsIMsgLocalMailFolder.js]
 [test_nsIMsgParseMailMsgState.js]
 [test_nsIMsgPluggableStore.js]
 [test_over2GBMailboxes.js]