summaryrefslogtreecommitdiffstats
path: root/dom/serviceworkers/test/browser_download.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /dom/serviceworkers/test/browser_download.js
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/serviceworkers/test/browser_download.js')
-rw-r--r--dom/serviceworkers/test/browser_download.js93
1 files changed, 93 insertions, 0 deletions
diff --git a/dom/serviceworkers/test/browser_download.js b/dom/serviceworkers/test/browser_download.js
new file mode 100644
index 0000000000..0c69a48d17
--- /dev/null
+++ b/dom/serviceworkers/test/browser_download.js
@@ -0,0 +1,93 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+var gTestRoot = getRootDirectory(gTestPath).replace(
+ "chrome://mochitests/content/",
+ "http://mochi.test:8888/"
+);
+
+function getFile(aFilename) {
+ if (aFilename.startsWith("file:")) {
+ var url = NetUtil.newURI(aFilename).QueryInterface(Ci.nsIFileURL);
+ return url.file.clone();
+ }
+
+ var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
+ file.initWithPath(aFilename);
+ return file;
+}
+
+function windowObserver(win, topic) {
+ if (topic !== "domwindowopened") {
+ return;
+ }
+
+ win.addEventListener(
+ "load",
+ function () {
+ if (
+ win.document.documentURI ===
+ "chrome://mozapps/content/downloads/unknownContentType.xhtml"
+ ) {
+ executeSoon(function () {
+ let dialog = win.document.getElementById("unknownContentType");
+ let button = dialog.getButton("accept");
+ button.disabled = false;
+ dialog.acceptDialog();
+ });
+ }
+ },
+ { once: true }
+ );
+}
+
+function test() {
+ waitForExplicitFinish();
+
+ Services.ww.registerNotification(windowObserver);
+
+ SpecialPowers.pushPrefEnv(
+ {
+ set: [
+ ["dom.serviceWorkers.enabled", true],
+ ["dom.serviceWorkers.exemptFromPerDomainMax", true],
+ ["dom.serviceWorkers.testing.enabled", true],
+ ],
+ },
+ function () {
+ var url = gTestRoot + "download/window.html";
+ var tab = BrowserTestUtils.addTab(gBrowser);
+ gBrowser.selectedTab = tab;
+
+ Downloads.getList(Downloads.ALL)
+ .then(function (downloadList) {
+ var downloadListener;
+
+ function downloadVerifier(aDownload) {
+ if (aDownload.succeeded) {
+ var file = getFile(aDownload.target.path);
+ ok(file.exists(), "download completed");
+ is(file.fileSize, 33, "downloaded file has correct size");
+ file.remove(false);
+ downloadList.remove(aDownload).catch(console.error);
+ downloadList.removeView(downloadListener).catch(console.error);
+ gBrowser.removeTab(tab);
+ Services.ww.unregisterNotification(windowObserver);
+
+ executeSoon(finish);
+ }
+ }
+
+ downloadListener = {
+ onDownloadAdded: downloadVerifier,
+ onDownloadChanged: downloadVerifier,
+ };
+
+ return downloadList.addView(downloadListener);
+ })
+ .then(function () {
+ BrowserTestUtils.startLoadingURIString(gBrowser, url);
+ });
+ }
+ );
+}