Bug 1420744 - Extensions downloads.download api with saveAs flag, skips file picker in android r=aswan
☠☠ backed out by 2c0daf489bc9 ☠ ☠
authorArshad Kazmi <arshadkazmi42@gmail.com>
Mon, 01 Oct 2018 16:59:10 +0000
changeset 494770 0d3748a0ad24606a4debc37726b0743ab4676734
parent 494769 fac0c84719b7184da4d04e11f2d6e2c629327fe3
child 494771 677786af21883f02d5eb6ba33505c52ea4daf11c
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1420744
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1420744 - Extensions downloads.download api with saveAs flag, skips file picker in android r=aswan Differential Revision: https://phabricator.services.mozilla.com/D7118
mobile/android/components/extensions/test/mochitest/mochitest.ini
mobile/android/components/extensions/test/mochitest/test_ext_downloads_saveAs.html
toolkit/components/extensions/parent/ext-downloads.js
--- a/mobile/android/components/extensions/test/mochitest/mochitest.ini
+++ b/mobile/android/components/extensions/test/mochitest/mochitest.ini
@@ -9,16 +9,17 @@ support-files =
   file_bypass_cache.sjs
   file_dummy.html
   file_iframe_document.html
   file_slowed_document.sjs
   head.js
 tags = webextensions
 
 [test_ext_all_apis.html]
+[test_ext_downloads_saveAs.html]
 [test_ext_tab_runtimeConnect.html]
 [test_ext_tabs_captureVisibleTab.html]
 [test_ext_tabs_create.html]
 [test_ext_tabs_events.html]
 [test_ext_tabs_executeScript.html]
 [test_ext_tabs_executeScript_bad.html]
 skip-if = true # Currently fails in emulator runs
 [test_ext_tabs_executeScript_good.html]
new file mode 100644
--- /dev/null
+++ b/mobile/android/components/extensions/test/mochitest/test_ext_downloads_saveAs.html
@@ -0,0 +1,45 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Downloads Test</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/AddTask.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
+  <script type="text/javascript" src="head.js"></script>
+  <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+
+<script type="text/javascript">
+"use strict";
+
+// saveAs is not implemented on Fennec but this tests that a call to download() that supplies that option passes anyway.
+add_task(async function testDownload() {
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {permissions: ["downloads"]},
+
+    background: async function() {
+      const url = URL.createObjectURL(new Blob(["file content"]));
+      const id = await browser.downloads.download({
+        url,
+        saveAs: true,
+      });
+
+      browser.downloads.onChanged.addListener(delta => {
+        if (delta.id == id && delta.state.current === "complete") {
+          browser.test.notifyPass("downloadPass");
+        }
+      });
+    },
+  });
+
+  await extension.startup();
+
+  await extension.awaitFinish("downloadPass");
+
+  await extension.unload();
+});
+</script>
+
+</body>
+</html>
--- a/toolkit/components/extensions/parent/ext-downloads.js
+++ b/toolkit/components/extensions/parent/ext-downloads.js
@@ -506,17 +506,17 @@ this.downloads = class extends Extension
                   }
                   break;
 
                 case "overwrite":
                   break;
               }
             }
 
-            if (!saveAs) {
+            if (!saveAs || AppConstants.platform === "android") {
               return target;
             }
 
             const window = Services.wm.getMostRecentWindow("navigator:browser");
             const basename = OS.Path.basename(target);
             const ext = basename.match(/\.([^.]+)$/);
 
             // Setup the file picker Save As dialog.