-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-selfdestruct.js
More file actions
81 lines (67 loc) · 2.57 KB
/
test-selfdestruct.js
File metadata and controls
81 lines (67 loc) · 2.57 KB
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
/* vim:set ts=2 sw=2 sts=2 expandtab */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
"use strict";
// code based on test/test-addon-installer.js from sdk
const { Cc, Ci, Cu } = require("chrome");
const AddonInstaller = require("sdk/addon/installer");
const observers = require("sdk/deprecated/observer-service");
const { setTimeout } = require("sdk/timers");
const tmp = require("sdk/test/tmp-file");
const system = require("sdk/system");
const testFolderURL = module.uri.split('test-selfdestruct')[0]; // so gross to hardwire name, sorry.
const ADDON_URL = testFolderURL + "fixtures/self-destruct/self-destruct.xpi";
const ADDON_PATH = tmp.createFromURL(ADDON_URL);
const micropilot = require("micropilot");
exports["test self destruct removes addon"] = function(assert,done){
let ADDON_URL = testFolderURL + "fixtures/self-destruct/self-destruct.xpi";
let ADDON_PATH = tmp.createFromURL(ADDON_URL);
function eventsObserver(subject, data) {
if (subject == "install") {
observers.notify("test-selfdestruct-die-now","die");
};
if (subject == "uninstall") {
done(); // the addon uninstalled
}
}
observers.add("test-selfdestruct", eventsObserver, false);
// Install the test addon
AddonInstaller.install(ADDON_PATH).then(
function onInstalled(id) {
assert.equal(id, "self-destruct-addon@mozilla.com", "`id` is valid");
// signal the addon to die
observers.notify("test-selfdestruct-die-now","die");
},
function onFailure(code) {
assert.fail("Install failed: "+code);
observers.remove("test-selfdestruct", eventsObserver);
done();
}
)
};
exports["test kill other addon by name"] = function(assert,done){
let ADDON_URL = testFolderURL + "fixtures/addon-install-unit-test@mozilla.com.xpi";
let ADDON_PATH = tmp.createFromURL(ADDON_URL);
// Install the test addon
AddonInstaller.install(ADDON_PATH).then(
function onInstalled(id) {
assert.equal(id, "addon-install-unit-test@mozilla.com", "`id` is valid");
// signal the addon to die
micropilot.killaddon(id).then(done);
},
function onFailure(code) {
assert.fail("Install failed: "+code);
done();
}
)
};
if (require("sdk/system/xul-app").is("Fennec")) {
module.exports = {
"test Unsupported Test": function UnsupportedTest (assert) {
assert.pass("Skipping this test until Fennec support is implemented.");
}
}
}
require("test").run(exports);