This repository has been archived by the owner on Jan 19, 2022. It is now read-only.
/
test_utils.js
81 lines (71 loc) · 2.37 KB
/
test_utils.js
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
const {Cc, Ci} = require("chrome");
const URL = require("url");
const tabs = require("tabs");
// implicitly run our main() entry-point
require("fx-share-addon/main").main();
exports.finalize = function(test, fn) {
let onDone = test.onDone;
test.onDone = function(test) {
fn(function() {
onDone(test);
});
}
}
exports.getContentWindow = function() {
let wm = Cc["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator);
return wm.getMostRecentWindow("navigator:browser").document.commandDispatcher.focusedWindow;
}
// Return the URL of content in our 'test' directory.
exports.getTestUrl = function(testPage) {
let lastSlash = this.module.uri.lastIndexOf("/");
let resourceUrl = this.module.uri.substr(0, lastSlash+1) + testPage;
// return the file:// as F1 disables itself for resource:// urls.
return URL.fromFilename(URL.toFilename(resourceUrl));
}
exports.createTab = function(url, callback) {
tabs.open({
url: url,
onOpen: function onOpen(tab) {
tab.on('ready', function(tab){
callback(tab);
});
}
});
}
exports.removeCurrentTab = function(callback) {
let tab = tabs.activeTab;
tab.on('close', callback);
tab.close();
}
function getSharePanel(args) {
let wm = Cc["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator);
let topWindow = wm.getMostRecentWindow("navigator:browser");
let tab = topWindow.gBrowser.selectedTab;
let browser = topWindow.gBrowser.getBrowserForTab(tab);
// instead of constructing the object explicitly, we go via the services API
// so it knows the created panel is associated with the contentWindow/service.
let services = topWindow.apps._services;
let activity = {
action: "link.send",
type: "link.send", // fixme
data: args || {}
}
// first pretend to invoke a service so our panel is created.
return services.get(activity, function () {;});
}
exports.getSharePanel = getSharePanel;
exports.createSharePanel = function(contentWindow) {
let panel = getSharePanel();
panel.show();
return panel;
};
exports.getShareButton = function(topWindow) {
if (!topWindow) {
let wm = Cc["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator);
topWindow = wm.getMostRecentWindow("navigator:browser");
}
return topWindow.document.getElementById("share-button");
}