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

Side by Side Diff: test/runners/firefox_download.js

Issue 29720661: Issue 6391 - Allow running the browser unit tests with Firefox (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Added firefox download Created March 19, 2018, 8:37 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/runners/download.js ('k') | test/runners/firefox_process.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 /* eslint-env node */
19 /* eslint no-console: "off" */
20
21 "use strict";
22
23 const {exec} = require("child_process");
24 const fs = require("fs");
25 const path = require("path");
26
27 const {ncp} = require("ncp");
28
29 const {download} = require("./download");
30
31 const {platform} = process;
32
33 // macOS specific
34 const dmg = platform == "darwin" ? require("dmg") : null;
35
36 function extractTar(archive, browserDir)
37 {
38 return new Promise((resolve, reject) =>
39 {
40 fs.mkdirSync(browserDir);
41 exec(["tar", "-jxf", archive, "-C", browserDir].join(" "),
42 err =>
43 {
44 if (err)
45 reject(err);
46 else
47 resolve();
48 });
49 });
50 }
51
52 function extractDmg(archive, browserDir)
53 {
54 return new Promise((resolve, reject) =>
55 {
56 dmg.mount(archive, (err, mpath) =>
57 {
58 if (err)
59 reject(err);
60 else
61 {
62 let files = fs.readdirSync(mpath);
63 let target = files.find(file => /\.app/.test(file));
64 let source = path.join(mpath, target);
65 fs.mkdirSync(browserDir);
66 ncp(source, path.join(browserDir, target), ncperr =>
67 {
68 dmg.unmount(mpath, dmgerr =>
69 {
70 if (dmgerr)
71 console.error(`Error unmounting DMG: ${dmgerr}`);
72 });
73 if (ncperr)
74 {
75 console.error(`Error copying ${source} to ${browserDir}`);
76 reject(ncperr);
77 }
78 else
79 resolve();
80 });
81 }
82 });
83 });
84 }
85
86 function extractArchive(archive, browserDir)
87 {
88 switch (platform)
89 {
90 // case "win32":
91 // return unzipArchive(archive, browserDir);
92 case "linux":
93 return extractTar(archive, browserDir);
94 case "darwin":
95 return extractDmg(archive, browserDir);
96 default:
97 throw new Error("Unexpected platform");
98 }
99 }
100
101 function getFirefoxExecutable(browserDir)
102 {
103 switch (platform)
104 {
105 // case "win32":
106 // return path.join(browserDir, "firefox", "firefox.exe");
107 case "linux":
108 return path.join(browserDir, "firefox", "firefox");
109 case "darwin":
110 return path.join(browserDir, "Firefox.app", "Contents",
111 "MacOS", "firefox");
112 default:
113 throw new Error("Unexpected platform");
114 }
115 }
116
117 function ensureFirefox(firefoxVersion)
118 {
119 let targetPlatform = platform;
120 if (platform == "win32")
121 targetPlatform += "-" + process.arch;
122 let buildTypes = {
123 "win32-ia32": ["win32-EME-free", `Firefox Setup ${firefoxVersion}.exe`],
124 "win32-x64": ["win64-EME-free", `Firefox Setup ${firefoxVersion}.exe`],
125 "linux": ["linux-x86_64", `firefox-${firefoxVersion}.tar.bz2`],
126 "darwin": ["mac-EME-free", `Firefox ${firefoxVersion}.dmg`]
127 };
128
129 if (!buildTypes.hasOwnProperty(targetPlatform))
130 {
131 let err = new Error(`Cannot run browser tests, ${targetPlatform} is unsuppor ted`);
132 return Promise.reject(err);
133 }
134
135 return Promise.resolve().then(() =>
136 {
137 let snapshotsDir = path.join(__dirname, "..", "..", "firefox-snapshots");
138 let browserDir = path.join(snapshotsDir,
139 `firefox-${targetPlatform}-${firefoxVersion}`);
140 if (fs.existsSync(browserDir))
141 return browserDir;
142
143 if (!fs.existsSync(path.dirname(browserDir)))
144 fs.mkdirSync(path.dirname(browserDir));
145
146 let [buildPlatform, fileName] = buildTypes[targetPlatform];
147 let archive = path.join(snapshotsDir, "download-cache", fileName);
148
149 return Promise.resolve()
150 .then(() =>
151 {
152 if (!fs.existsSync(archive))
153 {
154 let url = `https://archive.mozilla.org/pub/firefox/releases/${firefoxV ersion}/${buildPlatform}/en-US/${fileName}`;
155 console.info("Downloading Firefox...");
156 return download(url, archive);
157 }
158 console.info(`Reusing cached archive ${archive}`);
159 })
160 .then(() => extractArchive(archive, browserDir))
161 .then(() => browserDir);
162 }).then(dir => getFirefoxExecutable(dir));
163 }
164
165 module.exports.ensureFirefox = ensureFirefox;
OLDNEW
« no previous file with comments | « test/runners/download.js ('k') | test/runners/firefox_process.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld