|
| 1 | +/* |
| 2 | + * Licensed to the Software Freedom Conservancy (SFC) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The SFC licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +'use strict' |
| 21 | + |
| 22 | +const assert = require('assert') |
| 23 | +const { Browser } = require('../../index') |
| 24 | +const { Pages, suite } = require('../../lib/test') |
| 25 | +const { locate } = require('../../lib/test/resources') |
| 26 | +const { until, By } = require('../../index') |
| 27 | + |
| 28 | +const EXT_XPI = locate('common/extensions/webextensions-selenium-example.xpi') |
| 29 | +const EXT_UNSIGNED_ZIP = locate('common/extensions/webextensions-selenium-example-unsigned.zip') |
| 30 | +const EXT_SIGNED_ZIP = locate('common/extensions/webextensions-selenium-example.zip') |
| 31 | +const EXT_UNSIGNED_DIR = locate('common/extensions/webextensions-selenium-example') |
| 32 | +const EXT_SIGNED_DIR = locate('common/extensions/webextensions-selenium-example') |
| 33 | + |
| 34 | +suite( |
| 35 | + function (env) { |
| 36 | + describe('firefox', function () { |
| 37 | + let driver |
| 38 | + |
| 39 | + beforeEach(function () { |
| 40 | + driver = null |
| 41 | + }) |
| 42 | + |
| 43 | + afterEach(function () { |
| 44 | + return driver && driver.quit() |
| 45 | + }) |
| 46 | + |
| 47 | + describe('installAddon', function () { |
| 48 | + beforeEach(function () { |
| 49 | + driver = env.builder().build() |
| 50 | + }) |
| 51 | + |
| 52 | + it('installs and uninstalls by xpi file', async function () { |
| 53 | + await driver.get(Pages.blankPage) |
| 54 | + await verifyWebExtensionNotInstalled() |
| 55 | + |
| 56 | + let id = await driver.installAddon(EXT_XPI) |
| 57 | + |
| 58 | + await driver.navigate().refresh() |
| 59 | + await verifyWebExtensionWasInstalled() |
| 60 | + |
| 61 | + await driver.uninstallAddon(id) |
| 62 | + await driver.navigate().refresh() |
| 63 | + await verifyWebExtensionNotInstalled() |
| 64 | + }) |
| 65 | + |
| 66 | + it('installs and uninstalls by unsigned zip file', async function () { |
| 67 | + await driver.get(Pages.blankPage) |
| 68 | + await verifyWebExtensionNotInstalled() |
| 69 | + |
| 70 | + let id = await driver.installAddon(EXT_UNSIGNED_ZIP, true) |
| 71 | + |
| 72 | + await driver.navigate().refresh() |
| 73 | + await verifyWebExtensionWasInstalled() |
| 74 | + |
| 75 | + await driver.uninstallAddon(id) |
| 76 | + await driver.navigate().refresh() |
| 77 | + await verifyWebExtensionNotInstalled() |
| 78 | + }) |
| 79 | + |
| 80 | + it('installs and uninstalls by signed zip file', async function () { |
| 81 | + await driver.get(Pages.blankPage) |
| 82 | + await verifyWebExtensionNotInstalled() |
| 83 | + |
| 84 | + let id = await driver.installAddon(EXT_SIGNED_ZIP) |
| 85 | + |
| 86 | + await driver.navigate().refresh() |
| 87 | + await verifyWebExtensionWasInstalled() |
| 88 | + |
| 89 | + await driver.uninstallAddon(id) |
| 90 | + await driver.navigate().refresh() |
| 91 | + await verifyWebExtensionNotInstalled() |
| 92 | + }) |
| 93 | + |
| 94 | + it('installs and uninstalls by unsigned directory', async function () { |
| 95 | + await driver.get(Pages.blankPage) |
| 96 | + await verifyWebExtensionNotInstalled() |
| 97 | + |
| 98 | + let id = await driver.installAddon(EXT_UNSIGNED_DIR, true) |
| 99 | + |
| 100 | + await driver.navigate().refresh() |
| 101 | + await verifyWebExtensionWasInstalled() |
| 102 | + |
| 103 | + await driver.uninstallAddon(id) |
| 104 | + await driver.navigate().refresh() |
| 105 | + await verifyWebExtensionNotInstalled() |
| 106 | + }) |
| 107 | + |
| 108 | + it('installs and uninstalls by signed directory', async function () { |
| 109 | + await driver.get(Pages.blankPage) |
| 110 | + await verifyWebExtensionNotInstalled() |
| 111 | + |
| 112 | + let id = await driver.installAddon(EXT_SIGNED_DIR, true) |
| 113 | + |
| 114 | + await driver.navigate().refresh() |
| 115 | + await verifyWebExtensionWasInstalled() |
| 116 | + |
| 117 | + await driver.uninstallAddon(id) |
| 118 | + await driver.navigate().refresh() |
| 119 | + await verifyWebExtensionNotInstalled() |
| 120 | + }) |
| 121 | + }) |
| 122 | + |
| 123 | + async function verifyWebExtensionNotInstalled() { |
| 124 | + let found = await driver.findElements({ |
| 125 | + id: 'webextensions-selenium-example', |
| 126 | + }) |
| 127 | + assert.strictEqual(found.length, 0) |
| 128 | + } |
| 129 | + |
| 130 | + async function verifyWebExtensionWasInstalled() { |
| 131 | + let footer = await driver.wait(until.elementLocated(By.id('webextensions-selenium-example')), 5000) |
| 132 | + |
| 133 | + let text = await footer.getText() |
| 134 | + assert.strictEqual(text, 'Content injected by webextensions-selenium-example') |
| 135 | + } |
| 136 | + }) |
| 137 | + }, |
| 138 | + { browsers: [Browser.FIREFOX] }, |
| 139 | +) |
0 commit comments