| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 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/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 /* eslint-env node */ | 18 /* eslint-env node */ |
| 19 /* eslint no-console: "off" */ | 19 /* eslint no-console: "off" */ |
| 20 | 20 |
| 21 "use strict"; | 21 "use strict"; |
| 22 | 22 |
| 23 const childProcess = require("child_process"); | 23 const childProcess = require("child_process"); |
| 24 const fs = require("fs"); | 24 const fs = require("fs"); |
| 25 const https = require("https"); | 25 const https = require("https"); |
| 26 const os = require("os"); | 26 const os = require("os"); |
| 27 const path = require("path"); | 27 const path = require("path"); |
| 28 const process = require("process"); | |
|
Wladimir Palant
2017/05/18 11:18:27
You don't need this require, process is a global v
hub
2017/05/18 13:22:37
Acknowledged.
| |
| 28 | 29 |
| 29 const remoteInterface = require("chrome-remote-interface"); | 30 const remoteInterface = require("chrome-remote-interface"); |
| 30 const unzip = require("unzip"); | 31 const extractZip = require("extract-zip"); |
| 31 | 32 |
| 32 const CHROMIUM_REVISION = 467222; | 33 const CHROMIUM_REVISION = 467222; |
| 33 | 34 |
| 34 function rmdir(dirPath) | 35 function rmdir(dirPath) |
| 35 { | 36 { |
| 36 for (let file of fs.readdirSync(dirPath)) | 37 for (let file of fs.readdirSync(dirPath)) |
| 37 { | 38 { |
| 38 let filePath = path.join(dirPath, file); | 39 let filePath = path.join(dirPath, file); |
| 39 try | 40 try |
| 40 { | 41 { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 "linux": ["Linux_x64", "chrome-linux.zip"], | 87 "linux": ["Linux_x64", "chrome-linux.zip"], |
| 87 "darwin": ["Mac", "chrome-mac.zip"] | 88 "darwin": ["Mac", "chrome-mac.zip"] |
| 88 }; | 89 }; |
| 89 | 90 |
| 90 if (!buildTypes.hasOwnProperty(platform)) | 91 if (!buildTypes.hasOwnProperty(platform)) |
| 91 { | 92 { |
| 92 let err = new Error(`Cannot run browser tests, ${platform} is unsupported`); | 93 let err = new Error(`Cannot run browser tests, ${platform} is unsupported`); |
| 93 return Promise.reject(err); | 94 return Promise.reject(err); |
| 94 } | 95 } |
| 95 | 96 |
| 96 let chromiumDir = path.join(__dirname, "chromium-snapshots", | |
| 97 `chromium-${platform}-${CHROMIUM_REVISION}`); | |
| 98 if (fs.existsSync(chromiumDir)) | |
| 99 return Promise.resolve(getChromiumExecutable(chromiumDir)); | |
| 100 | 97 |
| 101 if (!fs.existsSync(path.dirname(chromiumDir))) | |
| 102 fs.mkdirSync(path.dirname(chromiumDir)); | |
| 103 return new Promise((resolve, reject) => | 98 return new Promise((resolve, reject) => |
|
Wladimir Palant
2017/05/18 11:18:28
There is no async action here that isn't based on
hub
2017/05/18 13:22:37
Done.
| |
| 104 { | 99 { |
| 105 console.info("Downloading Chromium..."); | 100 const snapshotsDir = path.join(__dirname, "chromium-snapshots"); |
| 106 let [dir, fileName] = buildTypes[platform]; | 101 const chromiumDir = path.join(snapshotsDir, |
| 107 let url = `https://www.googleapis.com/download/storage/v1/b/chromium-browser -snapshots/o/${dir}%2F${CHROMIUM_REVISION}%2F${fileName}?alt=media`; | 102 `chromium-${platform}-${CHROMIUM_REVISION}`); |
| 108 https.get(url, response => | 103 if (fs.existsSync(chromiumDir)) |
| 104 resolve(chromiumDir); | |
| 105 else | |
| 109 { | 106 { |
| 110 if (response.statusCode != 200) | 107 if (!fs.existsSync(path.dirname(chromiumDir))) |
| 108 fs.mkdirSync(path.dirname(chromiumDir)); | |
| 109 | |
| 110 let [dir, fileName] = buildTypes[platform]; | |
| 111 const archive = path.join(snapshotsDir, "download-cache", | |
| 112 `${CHROMIUM_REVISION}-${fileName}`); | |
| 113 const url = `https://www.googleapis.com/download/storage/v1/b/chromium-bro wser-snapshots/o/${dir}%2F${CHROMIUM_REVISION}%2F${fileName}?alt=media`; | |
|
Wladimir Palant
2017/05/18 11:18:28
You changed a bunch more variables from let to con
hub
2017/05/18 13:22:37
I ended up using const like in C++ which is not ex
| |
| 114 | |
| 115 downloadCache(url, archive) | |
| 116 .then(() => unzipArchive(archive, chromiumDir)) | |
| 117 .then(() => resolve(chromiumDir)); | |
| 118 } | |
| 119 }).then(dir => getChromiumExecutable(dir)); | |
| 120 } | |
| 121 | |
| 122 function downloadCache(url, destArchive) | |
|
Wladimir Palant
2017/05/18 11:18:27
Nit: the function name sounds strange, downloadCac
hub
2017/05/18 13:22:37
fixing it.
| |
| 123 { | |
| 124 return new Promise((resolve, reject) => | |
| 125 { | |
| 126 if (fs.existsSync(destArchive)) | |
| 127 { | |
| 128 console.info(`Reusing cached archive ${destArchive}`); | |
| 129 resolve(); | |
| 130 } | |
| 131 else | |
| 132 { | |
| 133 console.info("Downloading Chromium..."); | |
| 134 let cacheDir = path.dirname(destArchive); | |
| 135 if (!fs.existsSync(cacheDir)) | |
| 136 fs.mkdirSync(cacheDir); | |
| 137 let tempDest = destArchive + "-" + process.pid; | |
| 138 let writable = fs.createWriteStream(tempDest); | |
| 139 | |
| 140 https.get(url, response => | |
| 111 { | 141 { |
| 112 reject(new Error(`Unexpected server response: ${response.statusCode}`)); | 142 if (response.statusCode != 200) |
| 113 response.resume(); | 143 { |
| 114 return; | 144 reject(new Error(`Unexpected server response: ${response.statusCode}`) ); |
|
Wladimir Palant
2017/05/18 11:18:28
I'm pretty sure that ESLint dislikes the length of
hub
2017/05/18 13:22:37
it does. Fixing.
| |
| 115 } | 145 response.resume(); |
| 146 return; | |
| 147 } | |
| 116 | 148 |
| 117 response.pipe(unzip.Extract({path: chromiumDir})) | 149 response.pipe(writable) |
| 118 .on("error", reject) | 150 .on("error", error => |
| 119 .on("close", () => resolve(getChromiumExecutable(chromiumDir))); | 151 { |
| 120 }).on("error", reject); | 152 fs.unlinkSync(tempDest); |
| 153 reject(error); | |
| 154 }) | |
| 155 .on("close", () => | |
| 156 { | |
| 157 writable.close(); | |
| 158 fs.renameSync(tempDest, destArchive); | |
| 159 resolve(); | |
| 160 }); | |
| 161 }).on("error", reject); | |
| 162 } | |
| 163 }); | |
| 164 } | |
| 165 | |
| 166 function unzipArchive(archive, destDir) | |
| 167 { | |
| 168 return new Promise((resolve, reject) => | |
| 169 { | |
| 170 extractZip(archive, {dir: destDir}, err => | |
| 171 { | |
| 172 if (err) | |
| 173 reject(err); | |
| 174 else | |
| 175 resolve(); | |
| 176 }); | |
| 121 }); | 177 }); |
| 122 } | 178 } |
| 123 | 179 |
| 124 function startChromium(chromiumPath) | 180 function startChromium(chromiumPath) |
| 125 { | 181 { |
| 126 fs.chmodSync(chromiumPath, fs.constants.S_IRWXU); | 182 fs.chmodSync(chromiumPath, fs.constants.S_IRWXU); |
| 127 | 183 |
| 128 let dataDir = fs.mkdtempSync(path.join(os.tmpdir(), "chromium-data")); | 184 let dataDir = fs.mkdtempSync(path.join(os.tmpdir(), "chromium-data")); |
| 129 let child = null; | 185 let child = null; |
| 130 return { | 186 return { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 { | 319 { |
| 264 child.kill(); | 320 child.kill(); |
| 265 return result; | 321 return result; |
| 266 }).catch(error => | 322 }).catch(error => |
| 267 { | 323 { |
| 268 child.kill(); | 324 child.kill(); |
| 269 throw error; | 325 throw error; |
| 270 }); | 326 }); |
| 271 }); | 327 }); |
| 272 }; | 328 }; |
| OLD | NEW |