| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 mocha */ | |
| 19 | |
| 20 "use strict"; | 18 "use strict"; |
| 21 | 19 |
| 22 const glob = require("glob"); | 20 const glob = require("glob"); |
| 23 const path = require("path"); | 21 const path = require("path"); |
| 24 const {exec} = require("child_process"); | 22 const {exec} = require("child_process"); |
| 25 | 23 |
| 26 for (let browser of glob.sync("./test/browsers/*.js")) | 24 for (let browser of glob.sync("./test/browsers/*.js")) |
| 27 { | 25 { |
| 28 let module = require(path.resolve(browser)); | 26 let module = require(path.resolve(browser)); |
| 29 | 27 |
| 30 describe(module.platform, function() | 28 describe(module.platform, function() |
| 31 { | 29 { |
| 32 this.timeout(0); | 30 this.timeout(0); |
| 33 | 31 |
| 34 before(function() | 32 before(function() |
| 35 { | 33 { |
| 36 return new Promise((resolve, reject) => | 34 return Promise.all([ |
| 35 module.ensureBrowser(), | |
| 36 new Promise((resolve, reject) => | |
| 37 { | |
| 38 exec(`python build.py devenv -t ${module.platform}`, | |
| 39 (error, stdout, stderr) => | |
| 40 { | |
| 41 if (error) | |
| 42 { | |
| 43 console.error(stderr); | |
| 44 reject(error); | |
| 45 } | |
| 46 else resolve(stdout); | |
| 47 }); | |
| 48 }) | |
| 49 ]).then(([browserBinary]) => | |
| 37 { | 50 { |
| 38 exec(`python build.py devenv -t ${module.platform}`, | 51 this.driver = module.getDriver( |
| 39 (error, stdout, stderr) => | 52 browserBinary, |
| 40 { | 53 path.resolve(`./devenv.${module.platform}`) |
| 41 if (error) | 54 ); |
| 42 { | 55 return this.driver.wait(() => |
| 43 console.error(stderr); | 56 this.driver.getAllWindowHandles().then(handles => handles[1]) |
| 44 reject(error); | 57 ); |
| 45 } | 58 }).then(handle => |
| 46 else resolve(stdout); | 59 this.driver.switchTo().window(handle) |
| 47 }); | 60 ).then(() => |
| 48 }).then(() => module.getDriver( | 61 this.driver.executeScript("return location.origin;") |
| 49 path.resolve(`./devenv.${module.platform}`)).then(d => | 62 ).then(origin => |
| 50 { | 63 { |
| 51 this.driver = d; | 64 this.origin = origin; |
|
Sebastian Noack
2018/09/01 10:42:47
Nit: The reason we called the argument "d" (rather
tlucas
2018/09/01 11:54:23
Done.
| |
| 52 return this.driver.wait(() => | 65 }); |
| 53 this.driver.getAllWindowHandles().then(handles => handles[1]) | |
| 54 ); | |
| 55 }).then(handle => | |
| 56 this.driver.switchTo().window(handle) | |
| 57 ).then(() => | |
| 58 this.driver.executeScript("return location.origin;") | |
| 59 ).then(o => | |
| 60 { | |
| 61 this.origin = o; | |
| 62 this.platform = module.platform; | |
| 63 })); | |
| 64 }); | 66 }); |
| 65 | 67 |
| 66 for (let file of glob.sync("./test/wrappers/*.js")) | 68 for (let file of glob.sync("./test/wrappers/*.js")) |
| 67 { | 69 { |
| 68 // Reload the module(s) for every browser | 70 // Reload the module(s) for every browser |
| 69 delete require.cache[require.resolve(path.resolve(file))]; | 71 let modulePath = path.resolve(file); |
|
Sebastian Noack
2018/09/01 10:42:47
Why would they already be in cache? Isn't this the
tlucas
2018/09/01 11:54:24
We (want to) require them 2 times currently, once
Sebastian Noack
2018/09/01 12:26:33
Acknowledged.
| |
| 70 require(path.resolve(file)); | 72 delete require.cache[require.resolve(modulePath)]; |
| 73 require(modulePath); | |
| 71 } | 74 } |
| 72 | 75 |
| 73 after(function() | 76 after(function() |
| 74 { | 77 { |
| 75 this.driver.quit(); | 78 this.driver.quit(); |
| 76 }); | 79 }); |
| 77 }); | 80 }); |
| 78 } | 81 } |
| LEFT | RIGHT |