From 85e560e9dd64a7c2ddaea27783fb36514b5d2df4 Mon Sep 17 00:00:00 2001 From: Christian Biesinger Date: Mon, 3 Jun 2024 18:11:22 -0400 Subject: [PATCH] Add clickDialogButton methods for FedCM This builds on commit 7ad44eef93a2797fdfa14f05f0ff0bb8c4a2525f The specification for clickdialogbutton is here: https://fedidcg.github.io/FedCM/#webdriver-clickdialogbutton The version that takes an index is specified here: https://github.com/fedidcg/FedCM/pull/610 Bug #12088 --- common/src/web/fedcm/client_metadata.json | 4 +-- common/src/web/fedcm/privacy_policy.html | 4 +++ .../FederatedCredentialManagementDialog.java | 20 ++++++++++++++ .../selenium/remote/FedCmDialogImpl.java | 11 ++++++++ .../FederatedCredentialManagementTest.java | 27 +++++++++++++++++++ 5 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 common/src/web/fedcm/privacy_policy.html diff --git a/common/src/web/fedcm/client_metadata.json b/common/src/web/fedcm/client_metadata.json index ddde867a9f7bf..bd59185c97cd6 100644 --- a/common/src/web/fedcm/client_metadata.json +++ b/common/src/web/fedcm/client_metadata.json @@ -1,4 +1,4 @@ { - "privacy_policy_url": "https://rp.example/privacy_policy.html", - "terms_of_service_url": "https://rp.example/terms_of_service.html" + "privacy_policy_url": "privacy_policy.html", + "terms_of_service_url": "terms_of_service.html" } diff --git a/common/src/web/fedcm/privacy_policy.html b/common/src/web/fedcm/privacy_policy.html new file mode 100644 index 0000000000000..1e1d4b57604dd --- /dev/null +++ b/common/src/web/fedcm/privacy_policy.html @@ -0,0 +1,4 @@ + +Privacy Policy + +This is the privacy policy. diff --git a/java/src/org/openqa/selenium/federatedcredentialmanagement/FederatedCredentialManagementDialog.java b/java/src/org/openqa/selenium/federatedcredentialmanagement/FederatedCredentialManagementDialog.java index 04de4e4758e5d..d4fb9234e2cca 100644 --- a/java/src/org/openqa/selenium/federatedcredentialmanagement/FederatedCredentialManagementDialog.java +++ b/java/src/org/openqa/selenium/federatedcredentialmanagement/FederatedCredentialManagementDialog.java @@ -29,6 +29,11 @@ public interface FederatedCredentialManagementDialog { String DIALOG_TYPE_ACCOUNT_LIST = "AccountChooser"; String DIALOG_TYPE_AUTO_REAUTH = "AutoReauthn"; + String BUTTON_CONFIRM_IDP_LOGIN_CONTINUE = "ConfirmIdpLoginContinue"; + // The following buttons need an account index. + String BUTTON_TERMS_OF_SERVICE = "TermsOfService"; + String BUTTON_PRIVACY_POLICY = "PrivacyPolicy"; + /** Closes the dialog as if the user had clicked X. */ void cancelDialog(); @@ -58,4 +63,19 @@ public interface FederatedCredentialManagementDialog { *

If this is an auto reauth dialog, returns the single account that is being signed in. */ List getAccounts(); + + /** + * Clicks a button on the dialog. + * + * @param button The button to click. + */ + void clickButton(String button); + + /** + * Clicks a button on the dialog that requires an account index. + * + * @param button The button to click. + * @param index The account index, if needed by the specified button. + */ + void clickButton(String button, int index); } diff --git a/java/src/org/openqa/selenium/remote/FedCmDialogImpl.java b/java/src/org/openqa/selenium/remote/FedCmDialogImpl.java index d61b1a1acccbb..ebb2c14698bb4 100644 --- a/java/src/org/openqa/selenium/remote/FedCmDialogImpl.java +++ b/java/src/org/openqa/selenium/remote/FedCmDialogImpl.java @@ -70,4 +70,15 @@ public List getAccounts() { } return accounts; } + + @Override + public void clickButton(String button) { + executeMethod.execute(DriverCommand.CLICK_DIALOG, Map.of("dialogButton", button)); + } + + @Override + public void clickButton(String button, int index) { + executeMethod.execute(DriverCommand.CLICK_DIALOG, + Map.of("dialogButton", button, "index", index)); + } } diff --git a/java/test/org/openqa/selenium/federatedcredentialmanagement/FederatedCredentialManagementTest.java b/java/test/org/openqa/selenium/federatedcredentialmanagement/FederatedCredentialManagementTest.java index 8bf947f4ca584..838639b7d72f3 100644 --- a/java/test/org/openqa/selenium/federatedcredentialmanagement/FederatedCredentialManagementTest.java +++ b/java/test/org/openqa/selenium/federatedcredentialmanagement/FederatedCredentialManagementTest.java @@ -138,4 +138,31 @@ void testSelectAccount() { response = jsAwareDriver.executeScript("return await promise"); assertThat(response).asInstanceOf(MAP).containsEntry("token", "a token"); } + + void testClickDialogButton() { + fedcmDriver.setDelayEnabled(false); + assertNull(fedcmDriver.getFederatedCredentialManagementDialog()); + + Object response = triggerFedCm(); + + waitForDialog(); + + FederatedCredentialManagementDialog dialog = + fedcmDriver.getFederatedCredentialManagementDialog(); + + assertEquals("Sign in to localhost with localhost", dialog.getTitle()); + assertEquals("AccountChooser", dialog.getDialogType()); + + dialog.clickButton(dialog.BUTTON_PRIVACY_POLICY); + int windowCount = localDriver.getWindowHandles().size(); + WebDriverWait wait = new WebDriverWait(localDriver, Duration.ofSeconds(5)); + wait.until( + driver -> + driver.getWindowHandles().size() > windowCount); + + dialog.selectAccount(0); + + response = jsAwareDriver.executeScript("return await promise"); + assertThat(response).asInstanceOf(MAP).containsEntry("token", "a token"); + } }