Source code

Revision control

Other Tools

1
<!DOCTYPE HTML>
2
<html>
3
<head>
4
<title>Downloads Test</title>
5
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
6
<script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
7
<script type="text/javascript" src="head.js"></script>
8
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
9
</head>
10
<body>
11
12
<script type="text/javascript">
13
"use strict";
14
15
// saveAs is not implemented on Fennec but this tests that a call to download() that supplies that option passes anyway.
16
add_task(async function testDownload() {
17
let extension = ExtensionTestUtils.loadExtension({
18
manifest: {permissions: ["downloads"]},
19
20
background: async function() {
21
const url = URL.createObjectURL(new Blob(["file content"]));
22
const id = await browser.downloads.download({
23
url,
24
saveAs: true,
25
});
26
27
browser.downloads.onChanged.addListener(delta => {
28
if (delta.id == id && delta.state.current === "complete") {
29
browser.test.notifyPass("downloadPass");
30
}
31
});
32
},
33
});
34
35
await extension.startup();
36
37
await extension.awaitFinish("downloadPass");
38
39
await extension.unload();
40
});
41
</script>
42
43
</body>
44
</html>