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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// Tests bug 567127 - Add install button to the add-ons manager
var MockFilePicker = SpecialPowers.MockFilePicker;
MockFilePicker.init(window.browsingContext);
async function checkInstallConfirmation(...names) {
let notificationCount = 0;
let observer = {
observe(aSubject, aTopic, aData) {
var installInfo = aSubject.wrappedJSObject;
isnot(
installInfo.browser,
null,
"Notification should have non-null browser"
);
Assert.deepEqual(
installInfo.installs[0].installTelemetryInfo,
{
source: "about:addons",
method: "install-from-file",
},
"Got the expected installTelemetryInfo"
);
notificationCount++;
},
};
Services.obs.addObserver(observer, "addon-install-started");
let results = [];
let promise = promisePopupNotificationShown("addon-webext-permissions");
for (let i = 0; i < names.length; i++) {
let panel = await promise;
let name = panel.getAttribute("name");
results.push(name);
info(`Saw install for ${name}`);
if (results.length < names.length) {
info(
`Waiting for installs for ${names.filter(n => !results.includes(n))}`
);
promise = promisePopupNotificationShown("addon-webext-permissions");
}
panel.secondaryButton.click();
}
Assert.deepEqual(results.sort(), names.sort(), "Got expected installs");
is(
notificationCount,
names.length,
`Saw ${names.length} addon-install-started notification`
);
Services.obs.removeObserver(observer, "addon-install-started");
}
add_task(async function test_install_from_file() {
let win = await loadInitialView("extension");
var filePaths = [
get_addon_file_url("browser_dragdrop1.xpi"),
get_addon_file_url("browser_dragdrop2.xpi"),
];
for (let uri of filePaths) {
Assert.notEqual(uri.file, null, `Should have file for ${uri.spec}`);
ok(uri.file instanceof Ci.nsIFile, `Should have nsIFile for ${uri.spec}`);
}
MockFilePicker.setFiles(filePaths.map(aPath => aPath.file));
// Set handler that executes the core test after the window opens,
// and resolves the promise when the window closes
let pInstallURIClosed = checkInstallConfirmation(
"Drag Drop test 1",
"Drag Drop test 2"
);
win.document
.querySelector('#page-options [action="install-from-file"]')
.click();
await pInstallURIClosed;
MockFilePicker.cleanup();
await closeView(win);
});
add_task(async function test_install_disabled() {
let win = await loadInitialView("extension");
let doc = win.document;
let pageOptionsMenu = doc.querySelector("addon-page-options panel-list");
function openPageOptions() {
let opened = BrowserTestUtils.waitForEvent(pageOptionsMenu, "shown");
pageOptionsMenu.open = true;
return opened;
}
function closePageOptions() {
let closed = BrowserTestUtils.waitForEvent(pageOptionsMenu, "hidden");
pageOptionsMenu.open = false;
return closed;
}
await openPageOptions();
let installButton = doc.querySelector('[action="install-from-file"]');
ok(!installButton.hidden, "The install button is shown");
await closePageOptions();
await SpecialPowers.pushPrefEnv({ set: [[PREF_XPI_ENABLED, false]] });
await openPageOptions();
ok(installButton.hidden, "The install button is now hidden");
await closePageOptions();
await SpecialPowers.popPrefEnv();
await openPageOptions();
ok(!installButton.hidden, "The install button is shown again");
await closePageOptions();
await closeView(win);
});
|