Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test/runners/download.js

Issue 29720661: Issue 6391 - Allow running the browser unit tests with Firefox (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Revert to default to the chrome remote interface (instead of webdriver) Created July 31, 2018, 4:56 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/runners/download.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/test/runners/download.js
@@ -0,0 +1,80 @@
+/*
+ * This file is part of Adblock Plus <https://adblockplus.org/>,
+ * Copyright (C) 2006-present eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+"use strict";
+
+const fs = require("fs");
+const https = require("https");
+const path = require("path");
+
+const extractZip = require("extract-zip");
+
+function download(url, destFile)
+{
+ return new Promise((resolve, reject) =>
+ {
+ let cacheDir = path.dirname(destFile);
+ if (!fs.existsSync(cacheDir))
+ fs.mkdirSync(cacheDir);
+ let tempDest = destFile + "-" + process.pid;
+ let writable = fs.createWriteStream(tempDest);
+
+ https.get(url, response =>
+ {
+ if (response.statusCode != 200)
+ {
+ reject(
+ new Error(`Unexpected server response: ${response.statusCode}`));
+ response.resume();
+ return;
+ }
+
+ response.pipe(writable)
+ .on("error", error =>
+ {
+ writable.close();
+ fs.unlinkSync(tempDest);
+ reject(error);
+ })
+ .on("close", () =>
+ {
+ writable.close();
+ fs.renameSync(tempDest, destFile);
+ resolve();
+ });
+ }).on("error", reject);
+ });
+}
+
+function unzipArchive(archive, destDir)
+{
+ return new Promise((resolve, reject) =>
+ {
+ extractZip(archive, {dir: destDir}, err =>
+ {
+ if (err)
+ reject(err);
+ else
+ resolve();
+ });
+ });
+}
+
+module.exports = {
+ download,
+ unzipArchive
+};

Powered by Google App Engine
This is Rietveld