forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[rb] Add FedCM support to the ruby selenium client (SeleniumHQ#13796)
Co-authored-by: aguspe <[email protected]>
- Loading branch information
1 parent
87996aa
commit 018fa6a
Showing
16 changed files
with
599 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
rb/lib/selenium/webdriver/common/driver_extensions/has_fedcm_dialog.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
# Licensed to the Software Freedom Conservancy (SFC) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The SFC licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
module Selenium | ||
module WebDriver | ||
module DriverExtensions | ||
module HasFedCmDialog | ||
# Disables the promise rejection delay for FedCm. | ||
# | ||
# FedCm by default delays promise resolution in failure cases for privacy reasons. | ||
# This method allows turning it off to let tests run faster where this is not relevant. | ||
def enable_fedcm_delay=(enable) | ||
@bridge.fedcm_delay(enable) | ||
end | ||
|
||
# Resets the FedCm dialog cooldown. | ||
# | ||
# If a user agent triggers a cooldown when the account chooser is dismissed, | ||
# this method resets that cooldown so that the dialog can be triggered again immediately. | ||
def reset_fedcm_cooldown | ||
@bridge.reset_fedcm_cooldown | ||
end | ||
|
||
def fedcm_dialog | ||
@fedcm_dialog ||= FedCM::Dialog.new(@bridge) | ||
end | ||
|
||
def wait_for_fedcm_dialog(timeout: 5, interval: 0.2, message: nil, ignore: nil) | ||
wait = Wait.new(timeout: timeout, interval: interval, message: message, ignore: ignore) | ||
wait.until do | ||
fedcm_dialog if fedcm_dialog.type | ||
rescue Error::NoSuchAlertError | ||
nil | ||
end | ||
end | ||
end # HasFedCmDialog | ||
end # DriverExtensions | ||
end # WebDriver | ||
end # Selenium |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
# Licensed to the Software Freedom Conservancy (SFC) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The SFC licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
module Selenium | ||
module WebDriver | ||
module FedCM | ||
autoload :Account, 'fedcm/account' | ||
autoload :Dialog, 'fedcm/dialog' | ||
end # FedCM | ||
end # WebDriver | ||
end # Selenium |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
# Licensed to the Software Freedom Conservancy (SFC) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The SFC licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
module Selenium | ||
module WebDriver | ||
module FedCM | ||
# Represents an account displayed in a FedCm account list. | ||
# See: https://fedidcg.github.io/FedCM/#dictdef-identityprovideraccount | ||
# https://fedidcg.github.io/FedCM/#webdriver-accountlist | ||
class Account | ||
LOGIN_STATE_SIGNIN = 'SignIn' | ||
LOGIN_STATE_SIGNUP = 'SignUp' | ||
|
||
attr_reader :account_id, :email, :name, :given_name, :picture_url, | ||
:idp_config_url, :login_state, :terms_of_service_url, :privacy_policy_url | ||
|
||
# Initializes a new account with the provided attributes. | ||
# | ||
# @param [Hash] | ||
def initialize(**args) | ||
@account_id = args['accountId'] | ||
@email = args['email'] | ||
@name = args['name'] | ||
@given_name = args['givenName'] | ||
@picture_url = args['pictureUrl'] | ||
@idp_config_url = args['idpConfigUrl'] | ||
@login_state = args['loginState'] | ||
@terms_of_service_url = args['termsOfServiceUrl'] | ||
@privacy_policy_url = args['privacyPolicyUrl'] | ||
end | ||
end # Account | ||
end # FedCM | ||
end # WebDriver | ||
end # Selenium |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# frozen_string_literal: true | ||
|
||
# Licensed to the Software Freedom Conservancy (SFC) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The SFC licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
module Selenium | ||
module WebDriver | ||
module FedCM | ||
class Dialog | ||
def initialize(bridge) | ||
@bridge = bridge | ||
end | ||
|
||
DIALOG_TYPE_ACCOUNT_LIST = 'AccountChooser' | ||
DIALOG_TYPE_AUTO_REAUTH = 'AutoReauthn' | ||
|
||
# Closes the dialog as if the user had clicked X. | ||
def click | ||
@bridge.click_fedcm_dialog_button | ||
end | ||
|
||
# Closes the dialog as if the user had clicked X. | ||
def cancel | ||
@bridge.cancel_fedcm_dialog | ||
end | ||
|
||
# Selects an account as if the user had clicked on it. | ||
# | ||
# @param [Integer] index The index of the account to select from the list returned by get_accounts. | ||
def select_account(index) | ||
@bridge.select_fedcm_account index | ||
end | ||
|
||
# Returns the type of the open dialog. | ||
# | ||
# One of DIALOG_TYPE_ACCOUNT_LIST and DIALOG_TYPE_AUTO_REAUTH. | ||
def type | ||
@bridge.fedcm_dialog_type | ||
end | ||
|
||
# Returns the title of the dialog. | ||
def title | ||
@bridge.fedcm_title | ||
end | ||
|
||
# Returns the subtitle of the dialog or nil if none. | ||
def subtitle | ||
@bridge.fedcm_subtitle | ||
end | ||
|
||
# Returns the accounts shown in the account chooser. | ||
# | ||
# If this is an auto reauth dialog, returns the single account that is being signed in. | ||
def accounts | ||
@bridge.fedcm_account_list.map { |account| Account.new(**account) } | ||
end | ||
end # Dialog | ||
end # FedCM | ||
end # WebDriver | ||
end # Selenium |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module Selenium | ||
module WebDriver | ||
module FedCM | ||
# Represents an account displayed in a FedCm account list. | ||
# See: https://fedidcg.github.io/FedCM/#dictdef-identityprovideraccount | ||
# https://fedidcg.github.io/FedCM/#webdriver-accountlist | ||
class Account | ||
@account_id: String | ||
|
||
@email: String | ||
|
||
@name: String | ||
|
||
@given_name: String | ||
|
||
@picture_url: String | ||
|
||
@idp_config_url: String | ||
|
||
@login_state: String | ||
|
||
@terms_of_service_url: String | ||
|
||
@privacy_policy_url: String | ||
|
||
LOGIN_STATE_SIGNIN: String | ||
|
||
LOGIN_STATE_SIGNUP: String | ||
|
||
attr_reader account_id: String | ||
|
||
attr_reader email: String | ||
|
||
attr_reader name: String | ||
|
||
attr_reader given_name: String | ||
|
||
attr_reader picture_url: String | ||
|
||
attr_reader idp_config_url: String | ||
|
||
attr_reader login_state: String | ||
|
||
attr_reader terms_of_service_url: String | ||
|
||
attr_reader privacy_policy_url: String | ||
|
||
def initialize: (**untyped args) -> void | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Selenium | ||
module WebDriver | ||
module FedCM | ||
class Dialog | ||
DIALOG_TYPE_ACCOUNT_LIST: String | ||
DIALOG_TYPE_AUTO_REAUTH: String | ||
|
||
@bridge: Remote::Bridge | ||
|
||
def accounts: -> Array[Account] | ||
|
||
def cancel: -> Remote::Response? | ||
|
||
def click: -> untyped | ||
|
||
def select_account: (Integer index) -> Remote::Response? | ||
|
||
def subtitle: -> (String | Remote::Response)? | ||
|
||
def title: -> (String | Remote::Response) | ||
|
||
def type: -> (String | Remote::Response) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.