1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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);
}
}
|