Path: blob/trunk/javascript/selenium-webdriver/test/firefox/addon_test.js
2884 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617'use strict'1819const assert = require('node:assert')20const { Browser } = require('selenium-webdriver/index')21const { Pages, suite } = require('../../lib/test')22const { locate } = require('../../lib/test/resources')23const { until, By } = require('selenium-webdriver/index')2425const EXT_XPI = locate('common/extensions/webextensions-selenium-example.xpi')26const EXT_UNSIGNED_ZIP = locate('common/extensions/webextensions-selenium-example-unsigned.zip')27const EXT_SIGNED_ZIP = locate('common/extensions/webextensions-selenium-example.zip')28const EXT_UNSIGNED_DIR = locate('common/extensions/webextensions-selenium-example')29const EXT_SIGNED_DIR = locate('common/extensions/webextensions-selenium-example')3031suite(32function (env) {33describe('firefox', function () {34let driver3536beforeEach(function () {37driver = null38})3940afterEach(function () {41return driver && driver.quit()42})4344describe('installAddon', function () {45beforeEach(function () {46driver = env.builder().build()47})4849it('installs and uninstalls by xpi file', async function () {50await driver.get(Pages.blankPage)51await verifyWebExtensionNotInstalled()5253let id = await driver.installAddon(EXT_XPI)5455await driver.navigate().refresh()56await verifyWebExtensionWasInstalled()5758await driver.uninstallAddon(id)59await driver.navigate().refresh()60await verifyWebExtensionNotInstalled()61})6263it('installs and uninstalls by unsigned zip file', async function () {64await driver.get(Pages.blankPage)65await verifyWebExtensionNotInstalled()6667let id = await driver.installAddon(EXT_UNSIGNED_ZIP, true)6869await driver.navigate().refresh()70await verifyWebExtensionWasInstalled()7172await driver.uninstallAddon(id)73await driver.navigate().refresh()74await verifyWebExtensionNotInstalled()75})7677it('installs and uninstalls by signed zip file', async function () {78await driver.get(Pages.blankPage)79await verifyWebExtensionNotInstalled()8081let id = await driver.installAddon(EXT_SIGNED_ZIP)8283await driver.navigate().refresh()84await verifyWebExtensionWasInstalled()8586await driver.uninstallAddon(id)87await driver.navigate().refresh()88await verifyWebExtensionNotInstalled()89})9091it('installs and uninstalls by unsigned directory', async function () {92await driver.get(Pages.blankPage)93await verifyWebExtensionNotInstalled()9495let id = await driver.installAddon(EXT_UNSIGNED_DIR, true)9697await driver.navigate().refresh()98await verifyWebExtensionWasInstalled()99100await driver.uninstallAddon(id)101await driver.navigate().refresh()102await verifyWebExtensionNotInstalled()103})104105it('installs and uninstalls by signed directory', async function () {106await driver.get(Pages.blankPage)107await verifyWebExtensionNotInstalled()108109let id = await driver.installAddon(EXT_SIGNED_DIR, true)110111await driver.navigate().refresh()112await verifyWebExtensionWasInstalled()113114await driver.uninstallAddon(id)115await driver.navigate().refresh()116await verifyWebExtensionNotInstalled()117})118})119120async function verifyWebExtensionNotInstalled() {121let found = await driver.findElements({122id: 'webextensions-selenium-example',123})124assert.strictEqual(found.length, 0)125}126127async function verifyWebExtensionWasInstalled() {128let footer = await driver.wait(until.elementLocated(By.id('webextensions-selenium-example')), 5000)129130let text = await footer.getText()131assert.strictEqual(text, 'Content injected by webextensions-selenium-example')132}133})134},135{ browsers: [Browser.FIREFOX] },136)137138139