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 0000000000000..34b0ae3913f78 Binary files /dev/null and b/javascript/node/selenium-webdriver/lib/test/data/firefox/webextension.zip differ 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);