Path: blob/trunk/javascript/selenium-webdriver/test/fedcm/fedcm_test.js
3220 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')21const { ignore, Pages, suite } = require('../../lib/test')22const { By } = require('selenium-webdriver/index')2324suite(25function (env) {26let driver2728beforeEach(async function () {29driver = await env.builder().build()30})3132afterEach(async function () {33await driver.quit()34})3536// Failing due to - https://issues.chromium.org/u/0/issues/425801332, enable when Chrome 140 is released37ignore(env.browsers(Browser.CHROME, Browser.EDGE)).describe('Federated Credential Management Test', function () {38it('credential management dialog should appear', async function () {39await driver.get(Pages.fedcm)4041let triggerButton = await driver.findElement(By.id('triggerButton'))42await triggerButton.click()4344let dialog4546await driver.wait(47async () => {48try {49dialog = await driver.getFederalCredentialManagementDialog()50return (await dialog.type()) === 'AccountChooser'51} catch (error) {52return false53}54},5510000,56'Expected dialog type to be "AccountChooser"',572000,58)5960assert.equal(await dialog.type(), 'AccountChooser')61let title = await dialog.title()62assert.equal(title.includes('Sign in to'), true)63})6465it('can dismiss dialog', async function () {66await driver.get(Pages.fedcm)6768let triggerButton = await driver.findElement(By.id('triggerButton'))69await triggerButton.click()7071let dialog = await driver.getFederalCredentialManagementDialog()7273await driver.wait(74async () => {75try {76return (await dialog.type()) === 'AccountChooser'77} catch (error) {78return false79}80},8110000,82'Expected dialog type to be "AccountChooser"',832000,84)8586assert.equal(await dialog.type(), 'AccountChooser')87let title = await dialog.title()88assert.equal(title.includes('Sign in to'), true)8990await dialog.dismiss()9192try {93await dialog.type()94assert.fail('Above command should throw error')95} catch (error) {96assert.equal(error.message.includes('no such alert'), true)97}98})99100it('can select account', async function () {101await driver.get(Pages.fedcm)102103let triggerButton = await driver.findElement(By.id('triggerButton'))104await triggerButton.click()105106let dialog = await driver.getFederalCredentialManagementDialog()107108await driver.wait(109async () => {110try {111return (await dialog.type()) === 'AccountChooser'112} catch (error) {113return false114}115},11610000,117'Expected dialog type to be "AccountChooser"',1182000,119)120121assert.equal(await dialog.type(), 'AccountChooser')122let title = await dialog.title()123assert.equal(title.includes('Sign in to'), true)124125await dialog.selectAccount(1)126})127128it('can get account list', async function () {129await driver.get(Pages.fedcm)130131let triggerButton = await driver.findElement(By.id('triggerButton'))132await triggerButton.click()133134let dialog = await driver.getFederalCredentialManagementDialog()135136await driver.wait(137async () => {138try {139return (await dialog.type()) === 'AccountChooser'140} catch (error) {141return false142}143},14410000,145'Expected dialog type to be "AccountChooser"',1462000,147)148149assert.equal(await dialog.type(), 'AccountChooser')150let title = await dialog.title()151assert.equal(title.includes('Sign in to'), true)152153const accounts = await dialog.accounts()154155assert.equal(accounts.length, 2)156157const account1 = accounts[0]158const account2 = accounts[1]159160assert.strictEqual(account1.name, 'John Doe')161assert.strictEqual(account1.email, '[email protected]')162assert.strictEqual(account1.accountId, '1234')163assert.strictEqual(account1.givenName, 'John')164assert(account1.idpConfigUrl.includes('/fedcm/config.json'), true)165assert.strictEqual(account1.pictureUrl, 'https://idp.example/profile/123')166assert.strictEqual(account1.loginState, 'SignUp')167assert.strictEqual(account1.termsOfServiceUrl, 'https://rp.example/terms_of_service.html')168assert.strictEqual(account1.privacyPolicyUrl, 'https://rp.example/privacy_policy.html')169170assert.strictEqual(account2.name, 'Aisha Ahmad')171assert.strictEqual(account2.email, '[email protected]')172assert.strictEqual(account2.accountId, '5678')173assert.strictEqual(account2.givenName, 'Aisha')174assert(account2.idpConfigUrl.includes('/fedcm/config.json'), true)175assert.strictEqual(account2.pictureUrl, 'https://idp.example/profile/567')176assert.strictEqual(account2.loginState, 'SignUp')177assert.strictEqual(account2.termsOfServiceUrl, 'https://rp.example/terms_of_service.html')178assert.strictEqual(account2.privacyPolicyUrl, 'https://rp.example/privacy_policy.html')179})180})181},182{ browsers: [Browser.CHROME, Browser.EDGE] },183)184185186