Skip to content

Commit

Permalink
node/selenium-webdriver/firefox.js: accept zip webextensions (#7464)
Browse files Browse the repository at this point in the history
Firefox allow loading zipped WebExtensions
  • Loading branch information
glacambre authored Mar 4, 2020
1 parent 7cbe4ae commit 4ea3119
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
5 changes: 3 additions & 2 deletions javascript/node/selenium-webdriver/firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Binary file not shown.
24 changes: 18 additions & 6 deletions javascript/node/selenium-webdriver/test/firefox_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
'[email protected]';
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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();

Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
});
});
});

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4ea3119

Please sign in to comment.