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

Delta Between Two Patch Sets: test/runners/chromium_download.js

Issue 29720661: Issue 6391 - Allow running the browser unit tests with Firefox (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Created March 12, 2018, 8:23 p.m.
Right Patch Set: Update Firefox version in README Created Aug. 3, 2018, 4:15 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « test/runners/.eslintrc.json ('k') | test/runners/chromium_process.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 "use strict";
19
20 const fs = require("fs");
21 const path = require("path");
22
23 const {download, unzipArchive} = require("./download");
24
25 function getChromiumExecutable(chromiumDir)
26 {
27 switch (process.platform)
28 {
29 case "win32":
30 return path.join(chromiumDir, "chrome-win32", "chrome.exe");
31 case "linux":
32 return path.join(chromiumDir, "chrome-linux", "chrome");
33 case "darwin":
34 return path.join(chromiumDir, "chrome-mac", "Chromium.app", "Contents",
35 "MacOS", "Chromium");
36 default:
37 throw new Error("Unexpected platform");
38 }
39 }
40
41 function ensureChromium(chromiumRevision)
42 {
43 let {platform} = process;
44 if (platform == "win32")
45 platform += "-" + process.arch;
46 let buildTypes = {
47 "win32-ia32": ["Win", "chrome-win32.zip"],
48 "win32-x64": ["Win_x64", "chrome-win32.zip"],
49 "linux": ["Linux_x64", "chrome-linux.zip"],
50 "darwin": ["Mac", "chrome-mac.zip"]
51 };
52
53 if (!buildTypes.hasOwnProperty(platform))
54 {
55 let err = new Error(`Cannot run browser tests, ${platform} is unsupported`);
56 return Promise.reject(err);
57 }
58
59 return Promise.resolve().then(() =>
60 {
61 let snapshotsDir = path.join(__dirname, "..", "..", "chromium-snapshots");
62 let chromiumDir = path.join(snapshotsDir,
63 `chromium-${platform}-${chromiumRevision}`);
64 if (fs.existsSync(chromiumDir))
65 return chromiumDir;
66
67 if (!fs.existsSync(path.dirname(chromiumDir)))
68 fs.mkdirSync(path.dirname(chromiumDir));
69
70 let [dir, fileName] = buildTypes[platform];
71 let archive = path.join(snapshotsDir, "download-cache",
72 `${chromiumRevision}-${fileName}`);
73
74 return Promise.resolve()
75 .then(() =>
76 {
77 if (!fs.existsSync(archive))
78 {
79 console.info("Downloading Chromium...");
80 return download(
81 `https://www.googleapis.com/download/storage/v1/b/chromium-browser-s napshots/o/${dir}%2F${chromiumRevision}%2F${fileName}?alt=media`,
82 archive);
83 }
84 console.info(`Reusing cached archive ${archive}`);
85 })
86 .then(() => unzipArchive(archive, chromiumDir))
87 .then(() => chromiumDir);
88 }).then(dir => getChromiumExecutable(dir));
89 }
90
91 module.exports.ensureChromium = ensureChromium;
LEFTRIGHT

Powered by Google App Engine
This is Rietveld