From 51a4219bb52e303fda52d100045de607aef4d09d Mon Sep 17 00:00:00 2001 From: glacambre Date: Sun, 4 Aug 2019 14:23:59 +0200 Subject: [PATCH] node/selenium-webdriver/firefox.js: accept zip webextensions Prior to this commit, the node.js firefox driver prevented loading webextensions the name of which did not end in '.xpi'. This was not very ergonomic as web-ext, the webextension-building tool created by Mozilla , produces files the name of which ends in '.zip' by default. --- javascript/node/selenium-webdriver/firefox.js | 5 ++-- .../lib/test/data/firefox/webextension.zip | Bin 0 -> 4692 bytes .../selenium-webdriver/test/firefox_test.js | 24 +++++++++++++----- 3 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 javascript/node/selenium-webdriver/lib/test/data/firefox/webextension.zip diff --git a/javascript/node/selenium-webdriver/firefox.js b/javascript/node/selenium-webdriver/firefox.js index ba3fe31963c14..1c7543aa3bd22 100644 --- a/javascript/node/selenium-webdriver/firefox.js +++ b/javascript/node/selenium-webdriver/firefox.js @@ -156,8 +156,9 @@ class AddonFormatError extends Error { * installed. */ async function installExtension(extension, dir) { - if (extension.slice(-4) !== '.xpi') { - throw Error('Path ath is not a xpi file: ' + extension); + const ext = extension.slice(-4); + if (ext !== '.xpi' && ext !== '.zip') { + throw Error('File name does not end in ".zip" or ".xpi": ' + ext); } let archive = await zip.load(extension); diff --git a/javascript/node/selenium-webdriver/lib/test/data/firefox/webextension.zip b/javascript/node/selenium-webdriver/lib/test/data/firefox/webextension.zip new file mode 100644 index 0000000000000000000000000000000000000000..34b0ae3913f78f6d184a3114cd2fc91561a32105 GIT binary patch literal 4692 zcmZ`-by!sWwjR1c35S%DX6TRx=^m7BBot&oT4ZRD24N&*2th&wM1-NFB!nRbB&Aat z=^WyW-*?aP9`ASee%5dAXFqGL{k|*ySPQI;gG&tn00;q2O0TpO+NSx5$N+%HHvoWN zUv*Utl|Y($YJw2==gzLKb^@MWb~7gacVBH!<;eA!cFo%EQhwd-V~H2Pe@9zo(sek3 z-(K>ju!H`+IEUWmMQQra9(0o4GxvuAPciso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7@gB zA^;go(f?C-V-Wmh|IhvXxBaj43C8|E-TwQx|J+=^%{a*aXth5%|5<|nHVwg&rug5S le;4GR9{x<}Zx8$!;{T9fur?n4FC~1;?S~0%*RS{h{sjiDbXoua literal 0 HcmV?d00001 diff --git a/javascript/node/selenium-webdriver/test/firefox_test.js b/javascript/node/selenium-webdriver/test/firefox_test.js index e64e5bd8623b9..549e6cf3b87d2 100644 --- a/javascript/node/selenium-webdriver/test/firefox_test.js +++ b/javascript/node/selenium-webdriver/test/firefox_test.js @@ -28,8 +28,10 @@ const {Context} = require('../firefox'); const {Pages, suite, ignore} = require('../lib/test'); -const WEBEXTENSION_EXTENSION = +const WEBEXTENSION_EXTENSION_XPI = path.join(__dirname, '../lib/test/data/firefox/webextension.xpi'); +const WEBEXTENSION_EXTENSION_ZIP = + path.join(__dirname, '../lib/test/data/firefox/webextension.zip'); const WEBEXTENSION_EXTENSION_ID = 'webextensions-selenium-example@example.com.xpi'; @@ -57,7 +59,7 @@ suite(function(env) { await io.mkdir(extensionsDir); await io.write( path.join(extensionsDir, WEBEXTENSION_EXTENSION_ID), - await io.read(WEBEXTENSION_EXTENSION)); + await io.read(WEBEXTENSION_EXTENSION_XPI)); }); before(async function createProfileWithUserPrefs() { @@ -133,7 +135,7 @@ suite(function(env) { describe('addExtensions', function() { it('can add extension to brand new profile', async function() { let options = new firefox.Options(); - options.addExtensions(WEBEXTENSION_EXTENSION); + options.addExtensions(WEBEXTENSION_EXTENSION_XPI); driver = env.builder().setFirefoxOptions(options).build(); @@ -143,7 +145,7 @@ suite(function(env) { it('can add extension to custom profile', async function() { let options = new firefox.Options() - .addExtensions(WEBEXTENSION_EXTENSION) + .addExtensions(WEBEXTENSION_EXTENSION_XPI) .setProfile(profileWithUserPrefs); driver = env.builder().setFirefoxOptions(options).build(); @@ -155,7 +157,7 @@ suite(function(env) { it('can addExtensions and setPreference', async function() { let options = new firefox.Options() - .addExtensions(WEBEXTENSION_EXTENSION) + .addExtensions(WEBEXTENSION_EXTENSION_XPI) .setPreference('general.useragent.override', 'foo;bar') driver = env.builder().setFirefoxOptions(options).build(); @@ -164,6 +166,16 @@ suite(function(env) { await verifyWebExtensionWasInstalled(); await verifyUserAgentWasChanged(); }); + + it('can load .zip webextensions', async function() { + let options = new firefox.Options(); + options.addExtensions(WEBEXTENSION_EXTENSION_ZIP); + + driver = env.builder().setFirefoxOptions(options).build(); + + await driver.get(Pages.echoPage); + await verifyWebExtensionWasInstalled(); + }); }); }); @@ -199,7 +211,7 @@ suite(function(env) { await driver.get(Pages.echoPage); await verifyWebExtensionNotInstalled(); - let id = await driver.installAddon(WEBEXTENSION_EXTENSION); + let id = await driver.installAddon(WEBEXTENSION_EXTENSION_XPI); await driver.sleep(1000); // Give extension time to install (yuck). await driver.get(Pages.echoPage);