Skip to content

Commit 25d3431

Browse files
committed
fix tests as per new implementation
1 parent f5d47fa commit 25d3431

File tree

3 files changed

+165
-157
lines changed

3 files changed

+165
-157
lines changed

py/test/selenium/webdriver/chrome/fedcm_tests.py

Lines changed: 0 additions & 141 deletions
This file was deleted.
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Licensed to the Software Freedom Conservancy (SFC) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The SFC licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
import pytest
19+
20+
from selenium.common.exceptions import NoAlertPresentException
21+
22+
23+
@pytest.mark.xfail_safari(reason="FedCM not supported")
24+
@pytest.mark.xfail_firefox(reason="FedCM not supported")
25+
@pytest.mark.xfail_ie(reason="FedCM not supported")
26+
class TestFedCM:
27+
@pytest.fixture(autouse=True)
28+
def setup(self, driver, webserver):
29+
driver.get(webserver.where_is("fedcm/fedcm.html", localhost=True))
30+
self.dialog = driver.dialog
31+
32+
def test_no_dialog_title(driver):
33+
with pytest.raises(NoAlertPresentException):
34+
driver.dialog.title
35+
36+
def test_no_dialog_subtitle(driver):
37+
with pytest.raises(NoAlertPresentException):
38+
driver.dialog.subtitle
39+
40+
def test_no_dialog_type(driver):
41+
with pytest.raises(NoAlertPresentException):
42+
driver.dialog.type
43+
44+
def test_no_dialog_get_accounts(driver):
45+
with pytest.raises(NoAlertPresentException):
46+
driver.dialog.get_accounts()
47+
48+
def test_no_dialog_select_account(driver):
49+
with pytest.raises(NoAlertPresentException):
50+
driver.dialog.select_account(1)
51+
52+
def test_no_dialog_cancel(driver):
53+
with pytest.raises(NoAlertPresentException):
54+
driver.dialog.cancel()
55+
56+
def test_no_dialog_click_continue(driver):
57+
with pytest.raises(NoAlertPresentException):
58+
driver.dialog.click_continue()
59+
60+
def test_trigger_and_verify_dialog_title(self, driver):
61+
driver.execute_script("triggerFedCm();")
62+
dialog = driver.fedcm_dialog()
63+
assert dialog.title == "Sign in to localhost with localhost"
64+
65+
def test_trigger_and_verify_dialog_subtitle(self, driver):
66+
driver.execute_script("triggerFedCm();")
67+
dialog = driver.fedcm_dialog()
68+
assert dialog.subtitle is None
69+
70+
def test_trigger_and_verify_dialog_type(self, driver):
71+
driver.execute_script("triggerFedCm();")
72+
dialog = driver.fedcm_dialog()
73+
assert dialog.type == "AccountChooser"
74+
75+
def test_trigger_and_verify_account_list(self, driver):
76+
driver.execute_script("triggerFedCm();")
77+
dialog = driver.fedcm_dialog()
78+
accounts = dialog.get_accounts()
79+
assert len(accounts) > 0
80+
assert accounts[0].name == "John Doe"
81+
82+
def test_select_account(self, driver):
83+
driver.execute_script("triggerFedCm();")
84+
dialog = driver.fedcm_dialog()
85+
dialog.select_account(1)
86+
driver.fedcm_dialog() # Wait for dialog to become interactable
87+
# dialog.click_continue()
88+
89+
def test_dialog_cancel(self, driver):
90+
driver.execute_script("triggerFedCm();")
91+
dialog = driver.fedcm_dialog()
92+
dialog.cancel()
93+
with pytest.raises(NoAlertPresentException):
94+
dialog.title
95+
96+
def test_enable_fedcm_delay(self, driver):
97+
driver.fedcm.enable_delay()
98+
99+
def test_disable_fedcm_delay(self, driver):
100+
driver.fedcm.disable_delay()
101+
102+
def test_fedcm_cooldown_reset(self, driver):
103+
driver.fedcm_cooldown()
104+
105+
def test_fedcm_no_dialog_type_present(self, driver):
106+
with pytest.raises(NoAlertPresentException):
107+
driver.fedcm.dialog_type
108+
109+
def test_fedcm_no_title_present(self, driver):
110+
with pytest.raises(NoAlertPresentException):
111+
driver.fedcm.title
112+
113+
def test_fedcm_no_subtitle_present(self, driver):
114+
with pytest.raises(NoAlertPresentException):
115+
driver.fedcm.subtitle
116+
117+
def test_fedcm_no_account_list_present(self, driver):
118+
with pytest.raises(NoAlertPresentException):
119+
driver.fedcm.account_list()
120+
121+
def test_fedcm_no_select_account_present(self, driver):
122+
with pytest.raises(NoAlertPresentException):
123+
driver.fedcm.select_account(1)
124+
125+
def test_fedcm_no_cancel_dialog_present(self, driver):
126+
with pytest.raises(NoAlertPresentException):
127+
driver.fedcm.cancel_dialog()
128+
129+
def test_fedcm_no_click_continue_present(self, driver):
130+
with pytest.raises(NoAlertPresentException):
131+
driver.fedcm.click_continue()
132+
133+
def test_verify_dialog_type_after_cooldown_reset(self, driver):
134+
driver.fedcm_cooldown()
135+
driver.execute_script("triggerFedCm();")
136+
dialog = driver.fedcm_dialog()
137+
assert dialog.type == "AccountChooser"

py/test/unit/selenium/webdriver/common/fedcm/dialog_tests.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# under the License.
1717

1818
from unittest.mock import Mock
19+
from unittest.mock import patch
1920

2021
import pytest
2122

@@ -28,47 +29,58 @@ def mock_driver():
2829

2930

3031
@pytest.fixture
31-
def dialog(mock_driver):
32+
def fedcm(mock_driver):
33+
fedcm = Mock()
34+
mock_driver.fedcm = fedcm
35+
return fedcm
36+
37+
38+
@pytest.fixture
39+
def dialog(mock_driver, fedcm):
3240
return Dialog(mock_driver)
3341

3442

35-
def test_click_continue(dialog, mock_driver):
43+
def test_click_continue(dialog, fedcm):
3644
dialog.click_continue()
37-
mock_driver.click_fedcm_dialog_button.assert_called_once()
45+
fedcm.click_continue.assert_called_once()
3846

3947

40-
def test_cancel(dialog, mock_driver):
48+
def test_cancel(dialog, fedcm):
4149
dialog.cancel()
42-
mock_driver.cancel_fedcm_dialog.assert_called_once()
50+
fedcm.cancel_dialog.assert_called_once()
4351

4452

45-
def test_select_account(dialog, mock_driver):
53+
def test_select_account(dialog, fedcm):
4654
dialog.select_account(1)
47-
mock_driver.select_fedcm_account.assert_called_once_with(1)
55+
fedcm.select_account.assert_called_once_with(1)
4856

4957

50-
def test_type(dialog, mock_driver):
51-
mock_driver.get_fedcm_dialog_type.return_value = "AccountChooser"
58+
def test_type(dialog, fedcm):
59+
fedcm.dialog_type = "AccountChooser"
5260
assert dialog.type == "AccountChooser"
5361

5462

55-
def test_title(dialog, mock_driver):
56-
mock_driver.get_fedcm_title.return_value = "Sign in"
63+
def test_title(dialog, fedcm):
64+
fedcm.title = "Sign in"
5765
assert dialog.title == "Sign in"
5866

5967

60-
def test_subtitle(dialog, mock_driver):
61-
mock_driver.get_fedcm_subtitle.return_value = {"subtitle": "Choose an account"}
68+
def test_subtitle(dialog, fedcm):
69+
fedcm.subtitle = {"subtitle": "Choose an account"}
6270
assert dialog.subtitle == "Choose an account"
6371

6472

65-
def test_get_accounts(dialog, mock_driver):
73+
def test_get_accounts(dialog, fedcm):
6674
accounts_data = [
6775
{"name": "Account1", "email": "[email protected]"},
6876
{"name": "Account2", "email": "[email protected]"},
6977
]
70-
mock_driver.get_fedcm_account_list.return_value = accounts_data
71-
accounts = dialog.get_accounts()
78+
fedcm.account_list = accounts_data
79+
80+
with patch("selenium.webdriver.common.fedcm.account.Account") as MockAccount:
81+
MockAccount.return_value = Mock() # Mock the Account instance
82+
accounts = dialog.get_accounts()
83+
7284
assert len(accounts) == 2
7385
assert accounts[0].name == "Account1"
7486
assert accounts[0].email == "[email protected]"

0 commit comments

Comments
 (0)