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
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { EnterprisePolicyTesting } = ChromeUtils.importESModule(
"resource://testing-common/EnterprisePolicyTesting.sys.mjs"
);
ChromeUtils.defineESModuleGetters(this, {
DownloadsViewUI: "resource:///modules/DownloadsViewUI.sys.mjs",
});
const { TelemetryTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/TelemetryTestUtils.sys.mjs"
);
add_task(async function test_download_opens_on_click() {
Services.telemetry.clearScalars();
await EnterprisePolicyTesting.setupPolicyEngineWithJson({
policies: {
ExemptDomainFileTypePairsFromFileTypeDownloadWarnings: [
{
file_extension: "jnlp",
domains: ["localhost"],
},
],
},
});
startServer();
mustInterruptResponses();
let download = await promiseInterruptibleDownload(".jnlp");
let publicList = await Downloads.getList(Downloads.PUBLIC);
await publicList.add(download);
let oldLaunchFile = DownloadIntegration.launchFile;
let waitForLaunchFileCalled = new Promise(resolve => {
DownloadIntegration.launchFile = () => {
ok(true, "The file should be launched with an external application");
resolve();
};
});
registerCleanupFunction(async function () {
DownloadIntegration.launchFile = oldLaunchFile;
await task_resetState();
Services.telemetry.clearScalars();
});
TelemetryTestUtils.assertScalar(
TelemetryTestUtils.getProcessScalars("parent"),
"downloads.file_opened",
undefined,
"File opened from panel should not be initialized"
);
download.start();
await promiseDownloadHasProgress(download, 50);
await task_openPanel();
let listbox = document.getElementById("downloadsListBox");
ok(listbox, "Download list box present");
await TestUtils.waitForCondition(() => {
return listbox.childElementCount == 1;
});
info("All downloads show in the listbox.itemChildren ", listbox.itemChildren);
ok(
listbox.itemChildren[0].classList.contains("openWhenFinished"),
"Download should have clickable style when in progress"
);
ok(!download.launchWhenSucceeded, "launchWhenSucceeded should set to false");
ok(!download._launchedFromPanel, "LaunchFromPanel should set to false");
EventUtils.synthesizeMouseAtCenter(listbox.itemChildren[0], {});
ok(
download.launchWhenSucceeded,
"Should open the file when download is finished"
);
ok(download._launchedFromPanel, "File was scheduled to launch from panel");
continueResponses();
await download.refresh();
await promiseDownloadHasProgress(download, 100);
await waitForLaunchFileCalled;
TelemetryTestUtils.assertScalar(
TelemetryTestUtils.getProcessScalars("parent"),
"downloads.file_opened",
1,
"File opened from panel should be incremented"
);
});
|