| Index: test/firefox.js | 
| diff --git a/test/firefox.js b/test/firefox.js | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..78c64cd58def81b14e136d19ad2acee8f1f0634c | 
| --- /dev/null | 
| +++ b/test/firefox.js | 
| @@ -0,0 +1,130 @@ | 
| +/* | 
| 
 
Sebastian Noack
2018/08/22 18:16:38
Why not calling it test_runner.js and put it under
 
tlucas
2018/08/22 20:24:01
From what i saw, there's virtually no code from ad
 
Sebastian Noack
2018/08/22 20:54:35
Fair enough. Still what is the advantage of the di
 
tlucas
2018/08/23 08:47:27
With the current implementation of the packagers,
 
Sebastian Noack
2018/08/23 16:38:44
Well changing buildtools to not include test_runne
 
tlucas
2018/08/24 10:25:08
For the buildtools, same argument as somewhere els
 
 | 
| + * This file is part of Adblock Plus <https://adblockplus.org/>, | 
| + * Copyright (C) 2006-present eyeo GmbH | 
| + * | 
| + * Adblock Plus is free software: you can redistribute it and/or modify | 
| + * it under the terms of the GNU General Public License version 3 as | 
| + * published by the Free Software Foundation. | 
| + * | 
| + * Adblock Plus is distributed in the hope that it will be useful, | 
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
| + * GNU General Public License for more details. | 
| + * | 
| + * You should have received a copy of the GNU General Public License | 
| + * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 
| + */ | 
| + | 
| +"use strict"; | 
| + | 
| +const {ensureFirefox} = require("../adblockpluscore/test/runners/" + | 
| + "firefox_download"); | 
| +const webdriver = require("selenium-webdriver"); | 
| +const By = webdriver.By; | 
| 
 
Sebastian Noack
2018/08/22 18:16:38
Nit: Use desctrucuring.
 
tlucas
2018/08/22 20:24:02
I assume you expected something like (with the com
 
Sebastian Noack
2018/08/22 20:54:35
Better:
  const {By, until} = webdriver;
 
tlucas
2018/08/23 08:47:28
Done.
 
 | 
| +const until = webdriver.until; | 
| 
 
Sebastian Noack
2018/08/22 18:16:38
Nit: This seems to be unused.
 
tlucas
2018/08/22 20:24:01
It's used in line 86;
...
       driver.wait(unti
 
Sebastian Noack
2018/08/22 20:54:35
My bad.
 
 | 
| + | 
| +const FIREFOX_VERSION = "57.0"; | 
| + | 
| +const Command = require("selenium-webdriver/lib/command").Command; | 
| +const path = require("path"); | 
| +const firefox = require("selenium-webdriver/firefox"); | 
| + | 
| +exports.runFirefox = function(test) | 
| +{ | 
| + test.expect(14); | 
| 
 
Sebastian Noack
2018/08/22 18:16:38
Where is this number coming from?
 
tlucas
2018/08/22 20:24:01
It's the number of test-groups for qunit, when run
 
Sebastian Noack
2018/08/22 20:54:35
So that means whenever the number of qunit tests c
 
tlucas
2018/08/23 08:47:27
The only drawback of not using expect() is, we wou
 
 | 
| + // https://stackoverflow.com/a/45045036 | 
| + function installWebExt(driver, extension) | 
| + { | 
| + let cmd = new Command("moz-install-web-ext") | 
| + .setParameter("path", path.resolve(extension)) | 
| + .setParameter("temporary", true); | 
| + | 
| + driver.getExecutor() | 
| + .defineCommand(cmd.getName(), "POST", | 
| + "/session/:sessionId/moz/addon/install"); | 
| + | 
| + return driver.schedule(cmd, "installWebExt(" + extension + ")"); | 
| + } | 
| + | 
| + // Spawn the Firefox process in headless mode | 
| 
 
Sebastian Noack
2018/08/22 18:16:38
Nit: This comment seems redundant to me.
 
tlucas
2018/08/22 20:24:01
Done.
 
 | 
| + | 
| + ensureFirefox(FIREFOX_VERSION).then(firefoxPath => | 
| + { | 
| + let binary = new firefox.Binary(firefoxPath); | 
| + | 
| + binary.addArguments("-headless"); | 
| + | 
| + let options = new firefox.Options() | 
| + .setBinary(binary); | 
| + | 
| + let driver = new webdriver.Builder() | 
| + .forBrowser("firefox") | 
| + .setFirefoxOptions(options) | 
| + .build(); | 
| + | 
| + installWebExt(driver, "./devenv.gecko"); | 
| + | 
| + driver.wait(() => | 
| + { | 
| + // Wait for the firstrun-page to be loaded | 
| + return driver.getAllWindowHandles().then(handles => | 
| + { | 
| + if (handles.length > 1) | 
| + { | 
| + driver.switchTo().window(handles[1]); | 
| + return true; | 
| + } | 
| + return false; | 
| + }); | 
| + }).then(() => | 
| + { | 
| + // Navigate to the qunit index | 
| + driver.executeScript("location.href = \"qunit/index.html\";"); | 
| 
 
Sebastian Noack
2018/08/22 18:16:38
Wouldn't driver.navigate().to() be more appropriat
 
tlucas
2018/08/22 20:24:02
driver.navigate().to() expects absolute URLs, so w
 
Sebastian Noack
2018/08/22 20:54:35
Acknowledged.
 
 | 
| + }).then(() => | 
| + { | 
| + // Wait for qunit-results to be present | 
| + driver.wait(until.elementLocated(By.id("qunit-testresult"))); | 
| + }).then(() => | 
| + { | 
| + // Wait for tests to finish | 
| + driver.wait(() => | 
| + { | 
| + return driver.findElement(By.id("qunit-testresult")) | 
| 
 
Sebastian Noack
2018/08/22 18:16:38
Nit: return + braces are redundant.
 
tlucas
2018/08/22 20:24:01
Could you help me out here, what should it look li
 
Sebastian Noack
2018/08/22 20:54:35
Sorry, I thought for some reason Hubert was the au
 
tlucas
2018/08/23 08:47:27
Done. (also for the braces / return around "Wait f
 
 | 
| + .getAttribute("innerHTML").then(data => | 
| + { | 
| + return data.search("Tests completed") >= 0; | 
| + }); | 
| + }); | 
| + }).then(() => | 
| + { | 
| + // Find passed tests | 
| + driver.findElements(By.css("#qunit-tests .pass .test-name")) | 
| + .then(elements => | 
| + { | 
| + elements.forEach(elem => | 
| 
 
Sebastian Noack
2018/08/22 18:16:38
Nit: We prefer for..of loops over forEach().
 
tlucas
2018/08/22 20:24:01
Done.
 
 | 
| + { | 
| + elem.getAttribute("innerHTML").then(data => | 
| + { | 
| + test.ok(true, data); | 
| + }); | 
| + }); | 
| + }); | 
| + // Find failed tests | 
| + driver.findElements(By.css("#qunit-tests .fail .test-name")) | 
| + .then(elements => | 
| + { | 
| + elements.forEach(elem => | 
| 
 
Sebastian Noack
2018/08/22 18:16:38
Nit: See above.
 
tlucas
2018/08/22 20:24:01
Done.
 
 | 
| + { | 
| + elem.getAttribute("innerHTML").then(data => | 
| + { | 
| + test.ok(false, "Undefined error in " + data); | 
| + }); | 
| + }); | 
| + }); | 
| + }).then(() => | 
| + { | 
| + driver.quit(); | 
| + test.done(); | 
| + }); | 
| + }); | 
| +}; |