Skip to content

Commit

Permalink
[FedCM] Implement Chromedriver support for opening links
Browse files Browse the repository at this point in the history
This treats links as buttons for simplicity.

Validate-Test-Flakiness: skip
Bug: 1513520
Change-Id: I7067157ea22c8add8aaf4d4fee852cdf9268ec16
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5225543
Reviewed-by: Yi Gu <yigu@chromium.org>
Reviewed-by: Vladimir Nechaev <nechaev@chromium.org>
Commit-Queue: Christian Biesinger <cbiesinger@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1250868}
  • Loading branch information
cbiesinger authored and Chromium LUCI CQ committed Jan 23, 2024
1 parent 2f54c85 commit 04dd7f1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
4 changes: 3 additions & 1 deletion client/chromedriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,10 @@ def SelectAccount(self, index):
params = {'accountIndex': index}
return self.ExecuteCommand(Command.SELECT_ACCOUNT, params)

def ClickFedCmDialogButton(self, dialogButton):
def ClickFedCmDialogButton(self, dialogButton, index=None):
params = {'dialogButton': dialogButton}
if index is not None:
params['index'] = index
return self.ExecuteCommand(Command.CLICK_FEDCM_DIALOG_BUTTON, params)

def GetAccounts(self):
Expand Down
16 changes: 15 additions & 1 deletion fedcm_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,21 @@ Status ExecuteClickDialogButton(Session* session,

base::Value::Dict command_params;
command_params.Set("dialogId", tracker->GetLastDialogId());
command_params.Set("dialogButton", *params.FindString("dialogButton"));

std::string button = *params.FindString("dialogButton");
if (button == "TermsOfService" || button == "PrivacyPolicy") {
absl::optional<int> index = params.FindInt("index");
if (!index) {
return Status(kInvalidArgument, "index must be specified");
}
command_params.Set("accountIndex", *index);
command_params.Set("accountUrlType", button);
std::unique_ptr<base::Value> result;
return web_view->SendCommandAndGetResult("FedCm.openUrl", command_params,
&result);
}

command_params.Set("dialogButton", button);

std::unique_ptr<base::Value> result;
status = web_view->SendCommandAndGetResult("FedCm.clickDialogButton",
Expand Down
25 changes: 25 additions & 0 deletions test/run_py_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7788,6 +7788,31 @@ def testClickErrorMoreDetails(self):
self._https_server.GetUrl("localhost") +
"/chromedriver/fedcm/more_details.html", error)


def testClickPrivacyPolicy(self):
self._driver.Load(self._https_server.GetUrl() + "/fedcm.html")

self._driver.SetDelayEnabled(False)
self._driver.ResetCooldown()

self.assertRaises(chromedriver.NoSuchAlert, self._driver.GetAccounts)
self._driver.ExecuteScript("callFedCm()")
self.assertTrue(self.WaitForCondition(self.FedCmDialogCondition))

accounts = self._driver.GetAccounts()
self.assertEqual('AccountChooser', self._driver.GetDialogType())
self.assertEqual(2, len(accounts))

self._driver.ClickFedCmDialogButton("PrivacyPolicy", 1)
# The dialog should not have closed.
self.assertEqual('AccountChooser', self._driver.GetDialogType())

# Make sure that a popup actually opened.
self.assertTrue(self.WaitForCondition(self.FedCmPopupWindowCondition))

self._driver.CancelFedCmDialog()


# 'Z' in the beginning is to make test executed in the end of suite.
class ZChromeStartRetryCountTest(unittest.TestCase):

Expand Down

0 comments on commit 04dd7f1

Please sign in to comment.