diff --git a/lib/BrowserFetcher.js b/lib/BrowserFetcher.js index e373148c..ecb174b4 100644 --- a/lib/BrowserFetcher.js +++ b/lib/BrowserFetcher.js @@ -28,13 +28,42 @@ const ProxyAgent = require('https-proxy-agent'); const getProxyForUrl = require('proxy-from-env').getProxyForUrl; const DEFAULT_DOWNLOAD_HOST = 'https://storage.googleapis.com'; + +const supportedPlatforms = ['mac', 'linux', 'win32', 'win64']; const downloadURLs = { - linux: '%s/chromium-browser-snapshots/Linux_x64/%d/chrome-linux.zip', - mac: '%s/chromium-browser-snapshots/Mac/%d/chrome-mac.zip', - win32: '%s/chromium-browser-snapshots/Win/%d/chrome-win32.zip', - win64: '%s/chromium-browser-snapshots/Win_x64/%d/chrome-win32.zip', + linux: '%s/chromium-browser-snapshots/Linux_x64/%d/%s.zip', + mac: '%s/chromium-browser-snapshots/Mac/%d/%s.zip', + win32: '%s/chromium-browser-snapshots/Win/%d/%s.zip', + win64: '%s/chromium-browser-snapshots/Win_x64/%d/%s.zip', }; +/** + * @param {string} platform + * @param {string} revision + * @return {string} + */ +function archiveName(platform, revision) { + if (platform === 'linux') + return 'chrome-linux'; + if (platform === 'mac') + return 'chrome-mac'; + if (platform === 'win32' || platform === 'win64') { + // Windows archive name changed at r591479. + return parseInt(revision, 10) > 591479 ? 'chrome-win' : 'chrome-win32'; + } + return null; +} + +/** + * @param {string} platform + * @param {string} host + * @param {string} revision + * @return {string} + */ +function downloadURL(platform, host, revision) { + return util.format(downloadURLs[platform], host, revision, archiveName(platform, revision)); +} + const readdirAsync = helper.promisify(fs.readdir.bind(fs)); const mkdirAsync = helper.promisify(fs.mkdir.bind(fs)); const unlinkAsync = helper.promisify(fs.unlink.bind(fs)); @@ -66,7 +95,6 @@ class BrowserFetcher { this._platform = os.arch() === 'x64' ? 'win64' : 'win32'; assert(this._platform, 'Unsupported platform: ' + os.platform()); } - const supportedPlatforms = ['mac', 'linux', 'win32', 'win64']; assert(supportedPlatforms.includes(this._platform), 'Unsupported platform: ' + this._platform); } @@ -82,8 +110,7 @@ class BrowserFetcher { * @return {!Promise} */ canDownload(revision) { - const url = util.format(downloadURLs[this._platform], this._downloadHost, revision); - + const url = downloadURL(this._platform, this._downloadHost, revision); let resolve; const promise = new Promise(x => resolve = x); const request = httpRequest(url, 'HEAD', response => { @@ -102,8 +129,7 @@ class BrowserFetcher { * @return {!Promise} */ async download(revision, progressCallback) { - let url = downloadURLs[this._platform]; - url = util.format(url, this._downloadHost, revision); + const url = downloadURL(this._platform, this._downloadHost, revision); const zipPath = path.join(this._downloadsFolder, `download-${this._platform}-${revision}.zip`); const folderPath = this._getFolderPath(revision); if (await existsAsync(folderPath)) @@ -151,15 +177,14 @@ class BrowserFetcher { const folderPath = this._getFolderPath(revision); let executablePath = ''; if (this._platform === 'mac') - executablePath = path.join(folderPath, 'chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium'); + executablePath = path.join(folderPath, archiveName(this._platform, revision), 'Chromium.app', 'Contents', 'MacOS', 'Chromium'); else if (this._platform === 'linux') - executablePath = path.join(folderPath, 'chrome-linux', 'chrome'); + executablePath = path.join(folderPath, archiveName(this._platform, revision), 'chrome'); else if (this._platform === 'win32' || this._platform === 'win64') - executablePath = path.join(folderPath, 'chrome-win32', 'chrome.exe'); + executablePath = path.join(folderPath, archiveName(this._platform, revision), 'chrome.exe'); else throw new Error('Unsupported platform: ' + this._platform); - let url = downloadURLs[this._platform]; - url = util.format(url, this._downloadHost, revision); + const url = downloadURL(this._platform, this._downloadHost, revision); const local = fs.existsSync(folderPath); return {revision, executablePath, folderPath, local, url}; } @@ -185,7 +210,7 @@ function parseFolderPath(folderPath) { if (splits.length !== 2) return null; const [platform, revision] = splits; - if (!downloadURLs[platform]) + if (!supportedPlatforms.includes(platform)) return null; return {platform, revision}; }