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

Unified Diff: test/runners/chromium_process.js

Issue 29720661: Issue 6391 - Allow running the browser unit tests with Firefox (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Support using chromium with webdriver. Created March 16, 2018, 8: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
« no previous file with comments | « test/runners/chromium_download.js ('k') | test/runners/chromiumwd_process.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/runners/chromium_process.js
===================================================================
rename from chromium_process.js
rename to test/runners/chromium_process.js
--- a/chromium_process.js
+++ b/test/runners/chromium_process.js
@@ -17,23 +17,24 @@
/* eslint-env node */
/* eslint no-console: "off" */
"use strict";
const childProcess = require("child_process");
const fs = require("fs");
-const https = require("https");
const os = require("os");
const path = require("path");
const remoteInterface = require("chrome-remote-interface");
-const extractZip = require("extract-zip");
+const {ensureChromium} = require("./chromium_download");
+
+// Chromium 60.0.3082.x
const CHROMIUM_REVISION = 467222;
function rmdir(dirPath)
{
for (let file of fs.readdirSync(dirPath))
{
let filePath = path.join(dirPath, file);
try
@@ -54,133 +55,16 @@
fs.rmdirSync(dirPath);
}
catch (error)
{
console.error(error);
}
}
-function getChromiumExecutable(chromiumDir)
-{
- switch (process.platform)
- {
- case "win32":
- return path.join(chromiumDir, "chrome-win32", "chrome.exe");
- case "linux":
- return path.join(chromiumDir, "chrome-linux", "chrome");
- case "darwin":
- return path.join(chromiumDir, "chrome-mac", "Chromium.app", "Contents",
- "MacOS", "Chromium");
- default:
- throw new Error("Unexpected platform");
- }
-}
-
-function ensureChromium()
-{
- let {platform} = process;
- if (platform == "win32")
- platform += "-" + process.arch;
- let buildTypes = {
- "win32-ia32": ["Win", "chrome-win32.zip"],
- "win32-x64": ["Win_x64", "chrome-win32.zip"],
- "linux": ["Linux_x64", "chrome-linux.zip"],
- "darwin": ["Mac", "chrome-mac.zip"]
- };
-
- if (!buildTypes.hasOwnProperty(platform))
- {
- let err = new Error(`Cannot run browser tests, ${platform} is unsupported`);
- return Promise.reject(err);
- }
-
-
- return Promise.resolve().then(() =>
- {
- let snapshotsDir = path.join(__dirname, "chromium-snapshots");
- let chromiumDir = path.join(snapshotsDir,
- `chromium-${platform}-${CHROMIUM_REVISION}`);
- if (fs.existsSync(chromiumDir))
- return chromiumDir;
-
- if (!fs.existsSync(path.dirname(chromiumDir)))
- fs.mkdirSync(path.dirname(chromiumDir));
-
- let [dir, fileName] = buildTypes[platform];
- let archive = path.join(snapshotsDir, "download-cache",
- `${CHROMIUM_REVISION}-${fileName}`);
-
- return Promise.resolve()
- .then(() =>
- {
- if (!fs.existsSync(archive))
- {
- let url = `https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/${dir}%2F${CHROMIUM_REVISION}%2F${fileName}?alt=media`;
- console.info("Downloading Chromium...");
- return download(url, archive);
- }
- console.info(`Reusing cached archive ${archive}`);
- })
- .then(() => unzipArchive(archive, chromiumDir))
- .then(() => chromiumDir);
- }).then(dir => getChromiumExecutable(dir));
-}
-
-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();
- });
- });
-}
-
function startChromium(chromiumPath)
{
fs.chmodSync(chromiumPath, fs.constants.S_IRWXU);
let dataDir = fs.mkdtempSync(path.join(os.tmpdir(), "chromium-data"));
let child = null;
return {
kill: () => child && child.kill(),
@@ -251,16 +135,18 @@
function runScript(script, scriptName, scriptArgs)
{
return connectRemoteInterface().then(async client =>
{
try
{
let {Runtime, Log, Console} = client;
+ console.log("\nTests in Chromium (Remote Interface)\n");
+
await Log.enable();
Log.entryAdded(({entry}) =>
{
reportMessage(entry.text, entry.level);
});
await Console.enable();
Console.messageAdded(({message}) =>
@@ -301,17 +187,17 @@
{
client.close();
}
});
}
module.exports = function(script, scriptName, ...scriptArgs)
{
- return ensureChromium().then(chromiumPath =>
+ return ensureChromium(CHROMIUM_REVISION).then(chromiumPath =>
{
let child = startChromium(chromiumPath);
return Promise.race([
child.done,
runScript(script, scriptName, scriptArgs)
]).then(result =>
{
child.kill();
« no previous file with comments | « test/runners/chromium_download.js ('k') | test/runners/chromiumwd_process.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld