Path: blob/trunk/javascript/selenium-webdriver/test/chrome/permission_test.js
2885 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 chrome = require('selenium-webdriver/chrome')21const test = require('../../lib/test')22const { ignore } = require('../../lib/test')23const { Browser } = require('selenium-webdriver/index')2425test.suite(26function (env) {27// Chrome unable to set "prompt" due to: https://bugs.chromium.org/p/chromedriver/issues/detail?id=435028describe('setPermission', () => {29ignore(env.browsers(Browser.CHROME)).it('can set permission', async function () {30const driver = await env.builder().build()3132await driver.get(test.Pages.clicksPage)3334await driver.setPermission('clipboard-read', 'prompt')35assert.strictEqual(await checkPermission(driver, 'clipboard-read'), 'prompt')3637await driver.setPermission('clipboard-read', 'granted')38assert.strictEqual(await checkPermission(driver, 'clipboard-read'), 'granted')3940await driver.quit()41})4243ignore(env.browsers(Browser.CHROME)).it('can set permission in headless mode', async function () {44const driver = await env.builder().setChromeOptions(new chrome.Options().addArguments('-headless')).build()4546await driver.get(test.Pages.clicksPage)4748await driver.setPermission('clipboard-read', 'prompt')49assert.strictEqual(await checkPermission(driver, 'clipboard-read'), 'prompt')5051await driver.setPermission('clipboard-read', 'granted')52assert.strictEqual(await checkPermission(driver, 'clipboard-read'), 'granted')5354await driver.quit()55})56})57},58{ browsers: ['chrome'] },59)6061const checkPermission = (driver, permission) => {62return driver.executeAsyncScript((permission, callback) => {63// eslint-disable-next-line64navigator.permissions.query({ name: permission }).then((result) => callback(result.state))65}, permission)66}676869