tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_1836872_docs_google_com.py (2109B)


      1 import pytest
      2 
      3 URL = "https://docs.google.com/document/d/1MUJpu1E-wR1Gq-a8csdzXbOXf4mSzNuMQGxoPPBqK1w/edit"
      4 
      5 FONT_BUTTON_CSS = "#docs-font-family .goog-toolbar-menu-button-inner-box"
      6 FONT_MENU_WITH_SUBMENU_CSS = (
      7    ".goog-menu-vertical.docs-fontmenu .docs-submenuitem:has(.goog-submenu-arrow)"
      8 )
      9 
     10 
     11 async def are_font_submenus_accessible(client):
     12    await client.navigate(URL)
     13 
     14    # wait for the submenus to be ready (added to the DOM)
     15    client.await_css(FONT_MENU_WITH_SUBMENU_CSS)
     16 
     17    # open a submenu
     18    client.await_css(FONT_BUTTON_CSS, is_displayed=True).click()
     19    menuitem = client.await_css(FONT_MENU_WITH_SUBMENU_CSS, is_displayed=True)
     20    font = client.execute_script(
     21        """
     22        const [menuitem] = arguments;
     23 
     24        // get the name of the font, which helps us know which panel to wait for docs to create
     25        const font = menuitem.querySelector("span[style]").style.fontFamily.replace("--Menu", "");
     26 
     27        // trigger a mouseover on the menu item so docs opens the panel
     28        menuitem.dispatchEvent(new MouseEvent("mouseover", {
     29          bubbles: true,
     30          cancelable: true,
     31          view: window,
     32        }));
     33 
     34        return font;
     35    """,
     36        menuitem,
     37    )
     38 
     39    # wait for the on-hover popup to actually be created and displayed
     40    popup = client.await_xpath(f"//*[contains(@style, '{font}')]", is_displayed=True)
     41    assert popup
     42 
     43    return client.execute_script(
     44        """
     45        const menuitem_arrow = arguments[0].querySelector(".goog-submenu-arrow");
     46        const popup = arguments[1].closest(".goog-menu.goog-menu-vertical");
     47        return popup.getBoundingClientRect().left < menuitem_arrow.getBoundingClientRect().right;
     48    """,
     49        menuitem,
     50        popup,
     51    )
     52 
     53 
     54 @pytest.mark.skip_platforms("android")
     55 @pytest.mark.asyncio
     56 @pytest.mark.with_interventions
     57 async def test_enabled(client):
     58    assert await are_font_submenus_accessible(client)
     59 
     60 
     61 @pytest.mark.skip_platforms("android")
     62 @pytest.mark.asyncio
     63 @pytest.mark.without_interventions
     64 async def test_disabled(client):
     65    assert not await are_font_submenus_accessible(client)