|
| 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" |
0 commit comments