diff options
author | Matt A. Tobin <email@mattatobin.com> | 2018-02-09 11:10:00 -0500 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2018-02-09 11:10:00 -0500 |
commit | f164d9124708b50789dbb6959e1de96cc5697c48 (patch) | |
tree | 6dffd12e08c5383130df0252fb69cd6d6330794f /toolkit/components/webextensions/test/mochitest/test_chrome_ext_downloads_saveAs.html | |
parent | 30de4018913f0cdaea19d1dd12ecd8209e2ed08e (diff) | |
download | UXP-f164d9124708b50789dbb6959e1de96cc5697c48.tar UXP-f164d9124708b50789dbb6959e1de96cc5697c48.tar.gz UXP-f164d9124708b50789dbb6959e1de96cc5697c48.tar.lz UXP-f164d9124708b50789dbb6959e1de96cc5697c48.tar.xz UXP-f164d9124708b50789dbb6959e1de96cc5697c48.zip |
Rename Toolkit's webextensions component directory to better reflect what it is.
Diffstat (limited to 'toolkit/components/webextensions/test/mochitest/test_chrome_ext_downloads_saveAs.html')
-rw-r--r-- | toolkit/components/webextensions/test/mochitest/test_chrome_ext_downloads_saveAs.html | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/toolkit/components/webextensions/test/mochitest/test_chrome_ext_downloads_saveAs.html b/toolkit/components/webextensions/test/mochitest/test_chrome_ext_downloads_saveAs.html new file mode 100644 index 000000000..c1aaae035 --- /dev/null +++ b/toolkit/components/webextensions/test/mochitest/test_chrome_ext_downloads_saveAs.html @@ -0,0 +1,68 @@ +<!doctype html> +<html> +<head> + <title>Test downloads.download() saveAs option</title> + <script src="chrome://mochikit/content/tests/SimpleTest/SpawnTask.js"></script> + <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + <script src="chrome://mochikit/content/tests/SimpleTest/ExtensionTestUtils.js"></script> + <link rel="stylesheet" href="chrome://mochikit/contents/tests/SimpleTest/test.css"/> +</head> +<body> + +<script type="text/javascript"> +"use strict"; + +add_task(function* test_downloads_saveAs() { + function background() { + const url = URL.createObjectURL(new Blob(["file content"])); + browser.test.onMessage.addListener(async () => { + try { + let id = await browser.downloads.download({url, saveAs: true}); + browser.downloads.onChanged.addListener(delta => { + if (delta.state.current === "complete") { + browser.test.sendMessage("done", {ok: true, id}); + } + }); + } catch ({message}) { + browser.test.sendMessage("done", {ok: false, message}); + } + }); + browser.test.sendMessage("ready"); + } + + const {MockFilePicker} = SpecialPowers; + const manifest = {background, manifest: {permissions: ["downloads"]}}; + const extension = ExtensionTestUtils.loadExtension(manifest); + + MockFilePicker.init(window); + MockFilePicker.useAnyFile(); + const [file] = MockFilePicker.returnFiles; + + yield extension.startup(); + yield extension.awaitMessage("ready"); + + extension.sendMessage("download"); + let result = yield extension.awaitMessage("done"); + + ok(result.ok, "downloads.download() works with saveAs"); + is(file.fileSize, 12, "downloaded file is the correct size"); + file.remove(false); + + // Test the user canceling the save dialog. + MockFilePicker.returnValue = MockFilePicker.returnCancel; + + extension.sendMessage("download"); + result = yield extension.awaitMessage("done"); + + ok(!result.ok, "download rejected if the user cancels the dialog"); + is(result.message, "Download canceled by the user", "with the correct message"); + ok(!file.exists(), "file was not downloaded"); + + yield extension.unload(); + MockFilePicker.cleanup(); +}); + +</script> + +</body> +</html> |