Skip to content

Commit

Permalink
Add clickDialogButton methods for FedCM
Browse files Browse the repository at this point in the history
This builds on commit 7ad44ee

The specification for clickdialogbutton is here:
https://fedidcg.github.io/FedCM/#webdriver-clickdialogbutton

The version that takes an index is specified here:
w3c-fedid/FedCM#610

Bug SeleniumHQ#12088
  • Loading branch information
cbiesinger committed Jun 4, 2024
1 parent 53ed43c commit 46f33d8
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
4 changes: 2 additions & 2 deletions common/src/web/fedcm/client_metadata.json
Original file line number Diff line number Diff line change
@@ -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"
}
4 changes: 4 additions & 0 deletions common/src/web/fedcm/privacy_policy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!DOCTYPE html>
<title>Privacy Policy</title>

This is the privacy policy.
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -58,4 +63,19 @@ public interface FederatedCredentialManagementDialog {
* <p>If this is an auto reauth dialog, returns the single account that is being signed in.
*/
List<FederatedCredentialManagementAccount> 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);
}
11 changes: 11 additions & 0 deletions java/src/org/openqa/selenium/remote/FedCmDialogImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,15 @@ public List<FederatedCredentialManagementAccount> 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,35 @@ void testSelectAccount() {
response = jsAwareDriver.executeScript("return await promise");
assertThat(response).asInstanceOf(MAP).containsEntry("token", "a token");
}

@Test
@NotYetImplemented(
value = CHROME,
reason = "https://github.com/SeleniumHQ/selenium/pull/12096#issuecomment-2017760822")
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, 0);
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");
}
}

0 comments on commit 46f33d8

Please sign in to comment.