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
|
/*
* Tests that the mail-set-sender observer, used by extensions to modify the
* outgoing server, works.
*
* This is adapted from test_messageHeaders.js
*/
var CompFields = CC(
"@mozilla.org/messengercompose/composefields;1",
Ci.nsIMsgCompFields
);
// nsIObserver implementation.
var gData = "";
var observer = {
observe(aSubject, aTopic, aData) {
if (aTopic == "mail-set-sender") {
Assert.ok(aSubject instanceof Ci.nsIMsgCompose);
gData = aData;
}
},
};
add_task(async function testObserver() {
let fields = new CompFields();
let identity = getSmtpIdentity(
"from@tinderbox.invalid",
getBasicSmtpServer()
);
identity.fullName = "Observer Tester";
fields.to = "Emile <nobody@tinderbox.invalid>";
fields.cc = "Alex <alex@tinderbox.invalid>";
fields.subject = "Let's test the observer";
await richCreateMessage(fields, [], identity);
// observer data should have:
// (no account), Ci.nsIMsgSend.nsMsgSaveAsDraft, identity.key
Assert.equal(gData, ",4,id1");
// Now try with an account
await richCreateMessage(fields, [], identity, localAccountUtils.msgAccount);
// observer data should have:
// (local account key), Ci.nsIMsgSend.nsMsgSaveAsDraft, identity.key
Assert.equal(gData, "account1,4,id1");
});
function run_test() {
// Ensure we have at least one mail account
localAccountUtils.loadLocalMailAccount();
Services.obs.addObserver(observer, "mail-set-sender");
run_next_test();
}
|