Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node/selenium-webdriver/firefox.js: accept zip webextensions #7464

Merged
merged 1 commit into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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