|
| 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 | +from typing import List |
| 19 | +from typing import Optional |
| 20 | + |
| 21 | +from .command import Command |
| 22 | + |
| 23 | + |
| 24 | +class FedCM: |
| 25 | + def __init__(self, driver) -> None: |
| 26 | + self._driver = driver |
| 27 | + |
| 28 | + @property |
| 29 | + def title(self) -> str: |
| 30 | + """Gets the title of the dialog.""" |
| 31 | + return self._driver.execute(Command.GET_FEDCM_TITLE)["value"].get("title") |
| 32 | + |
| 33 | + @property |
| 34 | + def subtitle(self) -> Optional[str]: |
| 35 | + """Gets the subtitle of the dialog.""" |
| 36 | + return self._driver.execute(Command.GET_FEDCM_TITLE)["value"].get("subtitle") |
| 37 | + |
| 38 | + @property |
| 39 | + def dialog_type(self) -> str: |
| 40 | + """Gets the type of the dialog currently being shown.""" |
| 41 | + return self._driver.execute(Command.GET_FEDCM_DIALOG_TYPE).get("value") |
| 42 | + |
| 43 | + @property |
| 44 | + def account_list(self) -> List[dict]: |
| 45 | + """Gets the list of accounts shown in the dialog.""" |
| 46 | + return self._driver.execute(Command.GET_FEDCM_ACCOUNT_LIST).get("value") |
| 47 | + |
| 48 | + def select_account(self, index: int) -> None: |
| 49 | + """Selects an account from the dialog by index.""" |
| 50 | + self._driver.execute(Command.SELECT_FEDCM_ACCOUNT, {"accountIndex": index}) |
| 51 | + |
| 52 | + def click_continue(self) -> None: |
| 53 | + """Clicks the continue button in the dialog.""" |
| 54 | + self._driver.execute(Command.CLICK_FEDCM_DIALOG_BUTTON, {"dialogButton": "ConfirmIdpLoginContinue"}) |
| 55 | + |
| 56 | + def cancel_dialog(self) -> None: |
| 57 | + """Cancels/dismisses the FedCM dialog.""" |
| 58 | + self._driver.execute(Command.CANCEL_FEDCM_DIALOG) |
| 59 | + |
| 60 | + def enable_delay(self) -> None: |
| 61 | + """Re-enables the promise rejection delay for FedCM.""" |
| 62 | + self._driver.execute(Command.SET_FEDCM_DELAY, {"enabled": True}) |
| 63 | + |
| 64 | + def disable_delay(self) -> None: |
| 65 | + """Disables the promise rejection delay for FedCM.""" |
| 66 | + self._driver.execute(Command.SET_FEDCM_DELAY, {"enabled": False}) |
| 67 | + |
| 68 | + def reset_cooldown(self) -> None: |
| 69 | + """Resets the FedCM dialog cooldown, allowing immediate retriggers.""" |
| 70 | + self._driver.execute(Command.RESET_FEDCM_COOLDOWN) |
0 commit comments