diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/webcompat | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/webcompat')
47 files changed, 2239 insertions, 0 deletions
diff --git a/testing/webcompat/__init__.py b/testing/webcompat/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/testing/webcompat/__init__.py diff --git a/testing/webcompat/client.py b/testing/webcompat/client.py new file mode 100644 index 0000000000..a28d81c411 --- /dev/null +++ b/testing/webcompat/client.py @@ -0,0 +1,350 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import asyncio +import contextlib +import time + +import webdriver + + +class Client: + def __init__(self, session, event_loop): + self.session = session + self.event_loop = event_loop + self.content_blocker_loaded = False + + @property + def current_url(self): + return self.session.url + + @property + def alert(self): + return self.session.alert + + @property + def context(self): + return self.session.send_session_command("GET", "moz/context") + + @context.setter + def context(self, context): + self.session.send_session_command("POST", "moz/context", {"context": context}) + + @contextlib.contextmanager + def using_context(self, context): + orig_context = self.context + needs_change = context != orig_context + + if needs_change: + self.context = context + + try: + yield + finally: + if needs_change: + self.context = orig_context + + def wait_for_content_blocker(self): + if not self.content_blocker_loaded: + with self.using_context("chrome"): + self.session.execute_async_script( + """ + const done = arguments[0], + signal = "safebrowsing-update-finished"; + function finish() { + Services.obs.removeObserver(finish, signal); + done(); + } + Services.obs.addObserver(finish, signal); + """ + ) + self.content_blocker_loaded = True + + @property + def keyboard(self): + return self.session.actions.sequence("key", "keyboard_id") + + @property + def mouse(self): + return self.session.actions.sequence( + "pointer", "pointer_id", {"pointerType": "mouse"} + ) + + @property + def pen(self): + return self.session.actions.sequence( + "pointer", "pointer_id", {"pointerType": "touch"} + ) + + @property + def touch(self): + return self.session.actions.sequence( + "pointer", "pointer_id", {"pointerType": "pen"} + ) + + @property + def wheel(self): + return self.session.actions.sequence("wheel", "wheel_id") + + @property + def modifier_key(self): + if self.session.capabilities["platformName"] == "mac": + return "\ue03d" # meta (command) + else: + return "\ue009" # control + + async def navigate(self, url, timeout=None, await_console_message=None): + if timeout is not None: + old_timeout = self.session.timeouts.page_load + self.session.timeouts.page_load = timeout + if self.session.test_config.get("use_pbm") or self.session.test_config.get( + "use_strict_etp" + ): + print("waiting for content blocker...") + self.wait_for_content_blocker() + if await_console_message is not None: + console_message = self.promise_console_message(await_console_message) + await self.session.bidi_session.session.subscribe(events=["log.entryAdded"]) + try: + self.session.url = url + except webdriver.error.TimeoutException as e: + if timeout is None: + raise e + if await_console_message is not None: + await console_message + await self.session.bidi_session.session.unsubscribe( + events=["log.entryAdded"] + ) + if timeout is not None: + self.session.timeouts.page_load = old_timeout + + def back(self): + self.session.back() + + def switch_to_frame(self, frame): + return self.session.transport.send( + "POST", + "session/{session_id}/frame".format(**vars(self.session)), + {"id": frame}, + encoder=webdriver.protocol.Encoder, + decoder=webdriver.protocol.Decoder, + session=self.session, + ) + + def switch_frame(self, frame): + self.session.switch_frame(frame) + + async def load_page_and_wait_for_iframe( + self, url, finder, loads=1, timeout=None, **kwargs + ): + while loads > 0: + await self.navigate(url, **kwargs) + frame = self.await_element(finder, timeout=timeout) + loads -= 1 + self.switch_frame(frame) + return frame + + def promise_bidi_event(self, event_name: str, check_fn=None, timeout=5): + future = self.event_loop.create_future() + + async def on_event(method, data): + print("on_event", method, data) + if check_fn is not None and not check_fn(method, data): + return + remove_listener() + future.set_result(data) + + remove_listener = self.session.bidi_session.add_event_listener( + event_name, on_event + ) + return asyncio.wait_for(future, timeout=timeout) + + def promise_console_message(self, msg): + def check_messages(method, data): + if "text" in data: + if msg in data["text"]: + return True + if "args" in data and len(data["args"]) and "value" in data["args"][0]: + if msg in data["args"][0]["value"]: + return True + + return self.promise_bidi_event("log.entryAdded", check_messages) + + def execute_script(self, script, *args): + return self.session.execute_script(script, args=args) + + def execute_async_script(self, script, *args, **kwargs): + return self.session.execute_async_script(script, args, **kwargs) + + def clear_all_cookies(self): + self.session.transport.send( + "DELETE", "session/%s/cookie" % self.session.session_id + ) + + def _do_is_displayed_check(self, ele, is_displayed): + if ele is None: + return None + + if type(ele) in [list, tuple]: + return [x for x in ele if self._do_is_displayed_check(x, is_displayed)] + + if is_displayed is False and ele and self.is_displayed(ele): + return None + if is_displayed is True and ele and not self.is_displayed(ele): + return None + return ele + + def find_css(self, *args, all=False, is_displayed=None, **kwargs): + try: + ele = self.session.find.css(*args, all=all, **kwargs) + return self._do_is_displayed_check(ele, is_displayed) + except webdriver.error.NoSuchElementException: + return None + + def find_xpath(self, xpath, all=False, is_displayed=None): + route = "elements" if all else "element" + body = {"using": "xpath", "value": xpath} + try: + ele = self.session.send_session_command("POST", route, body) + return self._do_is_displayed_check(ele, is_displayed) + except webdriver.error.NoSuchElementException: + return None + + def find_text(self, text, is_displayed=None, **kwargs): + try: + ele = self.find_xpath(f"//*[contains(text(),'{text}')]", **kwargs) + return self._do_is_displayed_check(ele, is_displayed) + except webdriver.error.NoSuchElementException: + return None + + def find_element(self, finder, is_displayed=None, **kwargs): + ele = finder.find(self, **kwargs) + return self._do_is_displayed_check(ele, is_displayed) + + def await_css(self, selector, **kwargs): + return self.await_element(self.css(selector), **kwargs) + + def await_xpath(self, selector, **kwargs): + return self.await_element(self.xpath(selector), **kwargs) + + def await_text(self, selector, *args, **kwargs): + return self.await_element(self.text(selector), **kwargs) + + def await_element(self, finder, **kwargs): + return self.await_first_element_of([finder], **kwargs)[0] + + class css: + def __init__(self, selector): + self.selector = selector + + def find(self, client, **kwargs): + return client.find_css(self.selector, **kwargs) + + class xpath: + def __init__(self, selector): + self.selector = selector + + def find(self, client, **kwargs): + return client.find_xpath(self.selector, **kwargs) + + class text: + def __init__(self, selector): + self.selector = selector + + def find(self, client, **kwargs): + return client.find_text(self.selector, **kwargs) + + def await_first_element_of(self, finders, timeout=None, delay=0.25, **kwargs): + t0 = time.time() + + if timeout is None: + timeout = 10 + + found = [None for finder in finders] + + exc = None + while time.time() < t0 + timeout: + for i, finder in enumerate(finders): + try: + result = finder.find(self, **kwargs) + if result: + found[i] = result + return found + except webdriver.error.NoSuchElementException as e: + exc = e + time.sleep(delay) + raise exc if exc is not None else webdriver.error.NoSuchElementException + return found + + async def dom_ready(self, timeout=None): + if timeout is None: + timeout = 20 + + async def wait(): + return self.session.execute_async_script( + """ + const cb = arguments[0]; + setInterval(() => { + if (document.readyState === "complete") { + cb(); + } + }, 500); + """ + ) + + task = asyncio.create_task(wait()) + return await asyncio.wait_for(task, timeout) + + def is_float_cleared(self, elem1, elem2): + return self.session.execute_script( + """return (function(a, b) { + // Ensure that a is placed under b (and not to its right) + return a?.offsetTop >= b?.offsetTop + b?.offsetHeight && + a?.offsetLeft < b?.offsetLeft + b?.offsetWidth; + }(arguments[0], arguments[1]));""", + elem1, + elem2, + ) + + @contextlib.contextmanager + def assert_getUserMedia_called(self): + self.execute_script( + """ + navigator.mediaDevices.getUserMedia = + navigator.mozGetUserMedia = + navigator.getUserMedia = + () => { window.__gumCalled = true; }; + """ + ) + yield + assert self.execute_script("return window.__gumCalled === true;") + + def await_element_hidden(self, finder, timeout=None, delay=0.25): + t0 = time.time() + + if timeout is None: + timeout = 20 + + elem = finder.find(self) + while time.time() < t0 + timeout: + try: + if self.is_displayed(elem): + time.sleep(delay) + except webdriver.error.StaleElementReferenceException: + return + + def is_displayed(self, element): + if element is None: + return False + + return self.session.execute_script( + """ + const e = arguments[0], + s = window.getComputedStyle(e), + v = s.visibility === "visible", + o = Math.abs(parseFloat(s.opacity)); + return e.getClientRects().length && v && (isNaN(o) || o === 1.0); + """, + args=[element], + ) diff --git a/testing/webcompat/config.json.sample b/testing/webcompat/config.json.sample new file mode 100644 index 0000000000..8f1b2275e0 --- /dev/null +++ b/testing/webcompat/config.json.sample @@ -0,0 +1,5 @@ +{ + "bug number 1": {"username": "name", "password": "pass"}], + "bug number 2": {"username": "name", "password": "pass"}] +} + diff --git a/testing/webcompat/fixtures.py b/testing/webcompat/fixtures.py new file mode 100644 index 0000000000..5c527758b4 --- /dev/null +++ b/testing/webcompat/fixtures.py @@ -0,0 +1,191 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import asyncio +import json +import re +import subprocess + +import pytest +import webdriver + +from client import Client + +APS_PREF = "privacy.partition.always_partition_third_party_non_cookie_storage" +CB_PBM_PREF = "network.cookie.cookieBehavior.pbmode" +CB_PREF = "network.cookie.cookieBehavior" +INJECTIONS_PREF = "extensions.webcompat.perform_injections" +PBM_PREF = "browser.privatebrowsing.autostart" +PIP_OVERRIDES_PREF = "extensions.webcompat.enable_picture_in_picture_overrides" +SHIMS_PREF = "extensions.webcompat.enable_shims" +STRICT_ETP_PREF = "privacy.trackingprotection.enabled" +UA_OVERRIDES_PREF = "extensions.webcompat.perform_ua_overrides" + + +class WebDriver: + def __init__(self, config): + self.browser_binary = config.getoption("browser_binary") + self.webdriver_binary = config.getoption("webdriver_binary") + self.port = config.getoption("webdriver_port") + self.wsPort = config.getoption("webdriver_ws_port") + self.headless = config.getoption("headless") + self.proc = None + + def command_line_driver(self): + raise NotImplementedError + + def capabilities(self, test_config): + raise NotImplementedError + + def __enter__(self): + assert self.proc is None + self.proc = subprocess.Popen(self.command_line_driver()) + return self + + def __exit__(self, *args, **kwargs): + self.proc.kill() + + +class FirefoxWebDriver(WebDriver): + def command_line_driver(self): + return [ + self.webdriver_binary, + "--port", + str(self.port), + "--websocket-port", + str(self.wsPort), + "-vv", + ] + + def capabilities(self, test_config): + prefs = {} + + if "aps" in test_config: + prefs[APS_PREF] = test_config["aps"] + + if "use_interventions" in test_config: + value = test_config["use_interventions"] + prefs[INJECTIONS_PREF] = value + prefs[UA_OVERRIDES_PREF] = value + prefs[PIP_OVERRIDES_PREF] = value + + if "use_pbm" in test_config: + prefs[PBM_PREF] = test_config["use_pbm"] + + if "use_shims" in test_config: + prefs[SHIMS_PREF] = test_config["use_shims"] + + if "use_strict_etp" in test_config: + prefs[STRICT_ETP_PREF] = test_config["use_strict_etp"] + + if "without_tcp" in test_config: + cookieBehavior = 4 if test_config["without_tcp"] else 5 + prefs[CB_PREF] = cookieBehavior + prefs[CB_PBM_PREF] = cookieBehavior + + fx_options = {"binary": self.browser_binary, "prefs": prefs} + + if self.headless: + fx_options["args"] = ["--headless"] + + return { + "pageLoadStrategy": "normal", + "moz:firefoxOptions": fx_options, + } + + +@pytest.fixture(scope="session") +def should_do_2fa(request): + return request.config.getoption("do2fa", False) + + +@pytest.fixture(scope="session") +def config_file(request): + path = request.config.getoption("config") + if not path: + return None + with open(path) as f: + return json.load(f) + + +@pytest.fixture +def bug_number(request): + return re.findall("\d+", str(request.fspath.basename))[0] + + +@pytest.fixture +def credentials(bug_number, config_file): + if not config_file: + pytest.skip(f"login info required for bug #{bug_number}") + return None + + try: + credentials = config_file[bug_number] + except KeyError: + pytest.skip(f"no login for bug #{bug_number} found") + return + + return {"username": credentials["username"], "password": credentials["password"]} + + +@pytest.fixture(scope="session") +def driver(pytestconfig): + if pytestconfig.getoption("browser") == "firefox": + cls = FirefoxWebDriver + else: + assert False + + with cls(pytestconfig) as driver_instance: + yield driver_instance + + +@pytest.fixture(scope="session") +def event_loop(): + return asyncio.get_event_loop_policy().new_event_loop() + + +@pytest.fixture(scope="function") +async def client(session, event_loop): + return Client(session, event_loop) + + +@pytest.fixture(scope="function") +async def session(driver, test_config): + caps = driver.capabilities(test_config) + caps.update( + { + "acceptInsecureCerts": True, + "webSocketUrl": True, + } + ) + caps = {"alwaysMatch": caps} + print(caps) + + session = None + for i in range(0, 15): + try: + if not session: + session = webdriver.Session( + "localhost", driver.port, capabilities=caps, enable_bidi=True + ) + session.test_config = test_config + session.start() + break + except ConnectionRefusedError: + await asyncio.sleep(0.5) + + await session.bidi_session.start() + + yield session + + await session.bidi_session.end() + session.end() + + +@pytest.fixture(autouse=True) +def skip_platforms(bug_number, request, session): + platform = session.capabilities["platformName"] + if request.node.get_closest_marker("skip_platforms"): + if request.node.get_closest_marker("skip_platforms").args[0] == platform: + pytest.skip(f"Bug #{bug_number} skipped on platform ({platform})") diff --git a/testing/webcompat/interventions/__init__.py b/testing/webcompat/interventions/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/testing/webcompat/interventions/__init__.py diff --git a/testing/webcompat/interventions/conftest.py b/testing/webcompat/interventions/conftest.py new file mode 100644 index 0000000000..ac987c5039 --- /dev/null +++ b/testing/webcompat/interventions/conftest.py @@ -0,0 +1,51 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + +from ..fixtures import * # noqa: F403 + + +def pytest_generate_tests(metafunc): + """Generate tests based on markers.""" + + if "session" not in metafunc.fixturenames: + return + + marks = [mark.name for mark in metafunc.function.pytestmark] + + otherargs = {} + argvalues = [] + ids = [] + + if "skip_platforms" in marks: + for mark in metafunc.function.pytestmark: + if mark.name == "skip_platforms": + otherargs["skip_platforms"] = mark.args + + if "with_interventions" in marks: + argvalues.append([dict({"interventions": True}, **otherargs)]) + ids.append("with_interventions") + + if "without_interventions" in marks: + argvalues.append([dict({"interventions": False}, **otherargs)]) + ids.append("without_interventions") + + metafunc.parametrize(["session"], argvalues, ids=ids, indirect=True) + + +@pytest.fixture(scope="function") # noqa: F405 +async def test_config(request, driver): + params = request.node.callspec.params.get("session") + + use_interventions = params.get("interventions") + print(f"use_interventions {use_interventions}") + if use_interventions is None: + raise ValueError( + "Missing intervention marker in %s:%s" + % (request.fspath, request.function.__name__) + ) + + return { + "use_interventions": use_interventions, + } diff --git a/testing/webcompat/interventions/pytest.ini b/testing/webcompat/interventions/pytest.ini new file mode 100644 index 0000000000..89404d9751 --- /dev/null +++ b/testing/webcompat/interventions/pytest.ini @@ -0,0 +1,6 @@ +[pytest] +console_output_style = classic +markers = + skip_platforms: skip tests on specific platforms (mac, linux, windows) + with_interventions: enable web-compat interventions + without_interventions: disable web-compat interventions diff --git a/testing/webcompat/interventions/tests/__init__.py b/testing/webcompat/interventions/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/testing/webcompat/interventions/tests/__init__.py diff --git a/testing/webcompat/interventions/tests/test_1452707_absa.py b/testing/webcompat/interventions/tests/test_1452707_absa.py new file mode 100644 index 0000000000..2c0a1ad35a --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1452707_absa.py @@ -0,0 +1,19 @@ +import pytest + +URL = "https://ib.absa.co.za/absa-online/login.jsp" + + +@pytest.mark.asyncio +@pytest.mark.with_interventions +async def test_enabled(client): + await client.navigate(URL) + assert client.find_css("html.gecko") + + +@pytest.mark.asyncio +@pytest.mark.without_interventions +async def test_disabled(client): + await client.navigate(URL) + assert client.alert.text == "Browser unsupported" + client.alert.dismiss() + assert client.find_css("html.unknown") diff --git a/testing/webcompat/interventions/tests/test_1457335_histography.py b/testing/webcompat/interventions/tests/test_1457335_histography.py new file mode 100644 index 0000000000..a749644f1e --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1457335_histography.py @@ -0,0 +1,18 @@ +import pytest + +URL = "http://histography.io/" +SUPPORT_URL = "http://histography.io/browser_support.htm" + + +@pytest.mark.asyncio +@pytest.mark.with_interventions +async def test_enabled(client): + await client.navigate(URL) + assert client.current_url == URL + + +@pytest.mark.asyncio +@pytest.mark.without_interventions +async def test_disabled(client): + await client.navigate(URL) + assert client.current_url == SUPPORT_URL diff --git a/testing/webcompat/interventions/tests/test_1472075_bankofamerica.py b/testing/webcompat/interventions/tests/test_1472075_bankofamerica.py new file mode 100644 index 0000000000..cc534b2fb8 --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1472075_bankofamerica.py @@ -0,0 +1,19 @@ +import pytest + +URL = "https://www.bankofamerica.com/" + + +@pytest.mark.asyncio +@pytest.mark.skip_platforms("windows") +@pytest.mark.with_interventions +async def test_enabled(client): + await client.navigate(URL) + assert not client.find_css("#browserUpgradeNoticeBar") + + +@pytest.mark.asyncio +@pytest.mark.skip_platforms("windows") +@pytest.mark.without_interventions +async def test_disabled(client): + await client.navigate(URL) + assert client.is_displayed(client.await_css("#browserUpgradeNoticeBar")) diff --git a/testing/webcompat/interventions/tests/test_1570108_steamcommunity.py b/testing/webcompat/interventions/tests/test_1570108_steamcommunity.py new file mode 100644 index 0000000000..fe61dd5c2b --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1570108_steamcommunity.py @@ -0,0 +1,134 @@ +import pytest + +URL = "https://steamcommunity.com/chat" + + +USERID_CSS = "input[type='text'][class*='newlogindialog']" +PASSWORD_CSS = "input[type='password'][class*='newlogindialog']" +SIGNIN_CSS = "button[type='submit'][class*='newlogindialog']" +GEAR_CSS = ".friendListButton" +LOGIN_FAIL_XPATH = ( + "//*[contains(text(), 'try again') and " "contains(@class, 'FormError')]" +) +AUTH_CSS = "[class*='newlogindialog_ProtectingAccount']" +AUTH_DIGITS_CSS = "[class*='newlogindialog_SegmentedCharacterInput'] input[type='text']" +AUTH_RETRY_CSS = "[class*='newlogindialog_TryAgainButton']" +AUTH_RETRY_LOADER_CSS = "[class*='newlogindialog_Loading']" +RATE_TEXT = "too many login failures" +VOICE_XPATH = ( + "//*[contains(text(), 'Voice') and " + "contains(@class, 'pagedsettings_PagedSettingsDialog_PageListItem')]" +) +MIC_BUTTON_CSS = "button.LocalMicTestButton" +UNSUPPORTED_TEXT = "currently unsupported in Firefox" + + +async def do_2fa(client): + digits = client.find_css(AUTH_DIGITS_CSS, all=True) + assert len(digits) > 0 + + loader = client.css(AUTH_RETRY_LOADER_CSS) + if client.find_element(loader): + client.await_element_hidden(loader) + for digit in digits: + if digit.property("value"): + digit.send_keys(u"\ue003") # backspace + + code = input("**** Enter two-factor authentication code: ") + for i, digit in enumerate(code): + if len(digits) > i: + digits[i].send_keys(digit) + + client.await_element(loader, timeout=10) + client.await_element_hidden(loader) + + +async def load_mic_test(client, credentials, should_do_2fa): + await client.navigate(URL) + + async def login(): + userid = client.await_css(USERID_CSS) + password = client.find_css(PASSWORD_CSS) + submit = client.find_css(SIGNIN_CSS) + assert client.is_displayed(userid) + assert client.is_displayed(password) + assert client.is_displayed(submit) + + userid.send_keys(credentials["username"]) + password.send_keys(credentials["password"]) + submit.click() + + await login() + + while True: + auth, retry, gear, fail, rate = client.await_first_element_of( + [ + client.css(AUTH_CSS), + client.css(AUTH_RETRY_CSS), + client.css(GEAR_CSS), + client.xpath(LOGIN_FAIL_XPATH), + client.text(RATE_TEXT), + ], + is_displayed=True, + timeout=20, + ) + + if retry: + await do_2fa(client) + continue + + if rate: + pytest.skip( + "Too many Steam login attempts in a short time; try again later." + ) + return None + elif auth: + if should_do_2fa: + await do_2fa(client) + continue + + pytest.skip( + "Two-factor authentication requested; disable Steam Guard" + " or run this test with --do-2fa to live-input codes" + ) + return None + elif fail: + pytest.skip("Invalid login provided.") + return None + else: + break + + assert gear + gear.click() + + voice = client.await_xpath(VOICE_XPATH, is_displayed=True) + voice.click() + + mic_test = client.await_css(MIC_BUTTON_CSS, is_displayed=True) + return mic_test + + +@pytest.mark.asyncio +@pytest.mark.with_interventions +async def test_enabled(client, credentials, should_do_2fa): + mic_test = await load_mic_test(client, credentials, should_do_2fa) + if not mic_test: + return + + with client.assert_getUserMedia_called(): + mic_test.click() + + assert not client.find_text(UNSUPPORTED_TEXT) + + +@pytest.mark.asyncio +@pytest.mark.without_interventions +async def test_disabled(client, credentials, should_do_2fa): + mic_test = await load_mic_test(client, credentials, should_do_2fa) + if not mic_test: + return + + mic_test.click() + + unsupported = client.await_text(UNSUPPORTED_TEXT) + assert client.is_displayed(unsupported) diff --git a/testing/webcompat/interventions/tests/test_1575000_lloydsbank.py b/testing/webcompat/interventions/tests/test_1575000_lloydsbank.py new file mode 100644 index 0000000000..b8d163c99c --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1575000_lloydsbank.py @@ -0,0 +1,37 @@ +import pytest + +URL = ( + "https://apply.lloydsbank.co.uk/sales-content/cwa/l/pca/index-app.html" + "?product=classicaccountLTB#!b" +) + +NO_CSS = "[data-selector='existingCustomer-toggle-button-no']" +CONT_CSS = "[data-selector='ib-yes-continue-without-login-not-existing-customer-continue-button']" +CONT2_CSS = "[data-selector='beforeYouStart-continue-button']" +RADIO_CSS = "[name='aboutYou-gender-radio'] + span" + + +async def get_radio_position(client): + await client.navigate(URL) + client.await_css(NO_CSS).click() + client.await_css(CONT_CSS).click() + client.await_css(CONT2_CSS).click() + radio = client.await_css(RADIO_CSS) + return client.execute_script( + """ + return window.getComputedStyle(arguments[0]).position; + """, + radio, + ) + + +@pytest.mark.asyncio +@pytest.mark.with_interventions +async def test_enabled(client): + assert "relative" == await get_radio_position(client) + + +@pytest.mark.asyncio +@pytest.mark.without_interventions +async def test_disabled(client): + assert "relative" != await get_radio_position(client) diff --git a/testing/webcompat/interventions/tests/test_1577519_stream_directv_com.py b/testing/webcompat/interventions/tests/test_1577519_stream_directv_com.py new file mode 100644 index 0000000000..fde07de470 --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1577519_stream_directv_com.py @@ -0,0 +1,37 @@ +import pytest + +URL = "https://stream.directv.com/" +LOGIN_CSS = "#userID" +UNSUPPORTED_CSS = ".title-new-browse-ff" +DENIED_XPATH = "//h1[text()='Access Denied']" + + +async def check_site(client, should_pass): + await client.navigate(URL) + + denied, login, unsupported = client.await_first_element_of( + [ + client.xpath(DENIED_XPATH), + client.css(LOGIN_CSS), + client.css(UNSUPPORTED_CSS), + ], + is_displayed=True, + ) + + if denied: + pytest.skip("Region-locked, cannot test. Try using a VPN set to USA.") + return + + assert (should_pass and login) or (not should_pass and unsupported) + + +@pytest.mark.asyncio +@pytest.mark.with_interventions +async def test_enabled(client): + await check_site(client, should_pass=True) + + +@pytest.mark.asyncio +@pytest.mark.without_interventions +async def test_disabled(client): + await check_site(client, should_pass=False) diff --git a/testing/webcompat/interventions/tests/test_1582582_sling_com.py b/testing/webcompat/interventions/tests/test_1582582_sling_com.py new file mode 100644 index 0000000000..5f19cf9b81 --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1582582_sling_com.py @@ -0,0 +1,24 @@ +import pytest + +URL = "https://watch.sling.com/" +INCOMPATIBLE_CSS = "[class*='unsupported-browser']" +LOADER_CSS = ".loader-container" +VPN_TEXT = "ONLY AVAILABLE INSIDE THE US" + + +@pytest.mark.asyncio +@pytest.mark.with_interventions +async def test_enabled(client): + await client.navigate(URL) + loader, vpn = client.await_first_element_of( + [client.css(LOADER_CSS), client.text(VPN_TEXT)], timeout=20 + ) + assert loader or vpn + assert not client.find_css(INCOMPATIBLE_CSS) + + +@pytest.mark.asyncio +@pytest.mark.without_interventions +async def test_disabled(client): + await client.navigate(URL) + assert client.await_css(INCOMPATIBLE_CSS, timeout=2000) diff --git a/testing/webcompat/interventions/tests/test_1610026_mobilesuica.py b/testing/webcompat/interventions/tests/test_1610026_mobilesuica.py new file mode 100644 index 0000000000..444fe8471f --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1610026_mobilesuica.py @@ -0,0 +1,49 @@ +import pytest + +ADDRESS_CSS = "input[name=MailAddress]" +PASSWORD_CSS = "input[name=Password]" +CLOSE_BUTTON_CSS = "input[name=winclosebutton]" +UNAVAILABLE_TEXT = "時間をお確かめの上、再度実行してください。" +UNSUPPORTED_TEXT = "ご利用のブラウザでは正しく" + + +async def load_site(client): + await client.navigate("https://www.mobilesuica.com/") + + address = client.find_css(ADDRESS_CSS) + password = client.find_css(PASSWORD_CSS) + error1 = client.find_css(CLOSE_BUTTON_CSS) + error2 = client.find_text(UNSUPPORTED_TEXT) + + # The page can be down at certain times, making testing impossible. For instance: + # "モバイルSuicaサービスが可能な時間は4:00~翌日2:00です。 + # 時間をお確かめの上、再度実行してください。" + # "Mobile Suica service is available from 4:00 to 2:00 the next day. + # Please check the time and try again." + site_is_down = client.find_text(UNAVAILABLE_TEXT) + if site_is_down is not None: + pytest.xfail("Site is currently down") + + return address, password, error1 or error2, site_is_down + + +@pytest.mark.asyncio +@pytest.mark.with_interventions +async def test_enabled(client): + address, password, error, site_is_down = await load_site(client) + if site_is_down: + return + assert client.is_displayed(address) + assert client.is_displayed(password) + assert error is None + + +@pytest.mark.asyncio +@pytest.mark.without_interventions +async def test_disabled(client): + address, password, error, site_is_down = await load_site(client) + if site_is_down: + return + assert address is None + assert password is None + assert client.is_displayed(error) diff --git a/testing/webcompat/interventions/tests/test_1610344_directv_com_co.py b/testing/webcompat/interventions/tests/test_1610344_directv_com_co.py new file mode 100644 index 0000000000..96b349d99c --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1610344_directv_com_co.py @@ -0,0 +1,43 @@ +import pytest + +URL = "https://www.directv.com.co/" +IFRAME_CSS = "#main-iframe" +INCOMPATIBLE_CSS = ".browser-compatible.compatible.incompatible" +BLOCKED_TEXT = "blocked by the security rules" +DENIED_TEXT = "not available in your region" + + +async def check_unsupported_visibility(client, should_show): + await client.navigate(URL) + + # their region-block page sometimes wraps the content in an iframe + frame = client.find_css(IFRAME_CSS) + if frame: + client.switch_frame(frame) + + denied, blocked, incompatible = client.await_first_element_of( + [ + client.text(DENIED_TEXT), + client.text(BLOCKED_TEXT), + client.css(INCOMPATIBLE_CSS), + ] + ) + + if denied or blocked: + pytest.skip("Region-locked, cannot test. Try using a VPN set to USA.") + return + + shown = client.is_displayed(incompatible) + assert (should_show and shown) or (not should_show and not shown) + + +@pytest.mark.asyncio +@pytest.mark.with_interventions +async def test_enabled(client): + await check_unsupported_visibility(client, should_show=False) + + +@pytest.mark.asyncio +@pytest.mark.without_interventions +async def test_disabled(client): + await check_unsupported_visibility(client, should_show=True) diff --git a/testing/webcompat/interventions/tests/test_1631811_datastudio.py b/testing/webcompat/interventions/tests/test_1631811_datastudio.py new file mode 100644 index 0000000000..2075ee59eb --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1631811_datastudio.py @@ -0,0 +1,21 @@ +import pytest + +URL = "https://ageor.dipot.com/2020/03/Covid-19-in-Greece.html" +FRAME_CSS = "iframe[src^='https://datastudio.google.com/']" +FRAME_TEXT = "Coranavirus SARS-CoV-2 (Covid-19) in Greece" + + +@pytest.mark.asyncio +@pytest.mark.with_interventions +async def test_enabled(client): + await client.load_page_and_wait_for_iframe(URL, client.css(FRAME_CSS)) + assert client.execute_script("return window.indexedDB === undefined;") + success_text = client.await_text(FRAME_TEXT) + assert client.is_displayed(success_text) + + +@pytest.mark.asyncio +@pytest.mark.without_interventions +async def test_disabled(client): + await client.load_page_and_wait_for_iframe(URL, client.css(FRAME_CSS)) + assert client.execute_script("return window.indexedDB !== undefined;") diff --git a/testing/webcompat/interventions/tests/test_1644830_missingmail_usps.py b/testing/webcompat/interventions/tests/test_1644830_missingmail_usps.py new file mode 100644 index 0000000000..6941c757a9 --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1644830_missingmail_usps.py @@ -0,0 +1,61 @@ +import pytest + +URL = ( + "https://missingmail.usps.com/?_gl=1*veidlp*_gcl_aw*R0NMLjE1OTE3MjUyNTkuRUF" + "JYUlRb2JDaE1Jd3AzaTBhYjE2UUlWa01EQUNoMlBBUVlrRUFBWUFTQUFFZ0lMeFBEX0J3RQ..*" + "_gcl_dc*R0NMLjE1OTE3MjUyNTkuRUFJYUlRb2JDaE1Jd3AzaTBhYjE2UUlWa01EQUNoMlBBUV" + "lrRUFBWUFTQUFFZ0lMeFBEX0J3RQ..#/" +) + +USERNAME_CSS = "#username" +PASSWORD_CSS = "#password" +SIGN_IN_CSS = "#btn-submit" +TERMS_CHECKBOX_CSS = "#tc-checkbox" +TERMS_FAUX_CHECKBOX_CSS = "#tc-checkbox + .mrc-custom-checkbox" + +# The USPS missing mail website takes a very long time to load (multiple +# minutes). We give them a very generous amount of time here, but will +# give up after that and just skip the rest of the test. +TIMEOUT = 900 +TIMEOUT_MESSAGE = "USPS website is too slow, skipping test" + + +async def are_checkboxes_clickable(client, credentials): + await client.navigate(URL) + + username = client.await_css(USERNAME_CSS) + password = client.find_css(PASSWORD_CSS) + sign_in = client.find_css(SIGN_IN_CSS) + assert client.is_displayed(username) + assert client.is_displayed(password) + assert client.is_displayed(sign_in) + + username.send_keys(credentials["username"]) + password.send_keys(credentials["password"]) + sign_in.click() + + tc = client.await_css(TERMS_CHECKBOX_CSS, timeout=TIMEOUT) + if tc is None: + pytest.skip(TIMEOUT_MESSAGE) + return + + assert not tc.selected + + # we need to simulate a real click on the checkbox + tfc = client.find_css(TERMS_FAUX_CHECKBOX_CSS) + await client.dom_ready() + client.execute_script("arguments[0].scrollIntoView(true)", tfc) + client.mouse.click(tfc).perform() + return tc.selected + + +@pytest.mark.asyncio +@pytest.mark.with_interventions +async def test_enabled(client, credentials): + assert await are_checkboxes_clickable(client, credentials) + + +@pytest.mark.asyncio +@pytest.mark.without_interventions +async def test_disabled(client, credentials): + assert not await are_checkboxes_clickable(client, credentials) diff --git a/testing/webcompat/interventions/tests/test_1650317_livescience_com.py b/testing/webcompat/interventions/tests/test_1650317_livescience_com.py new file mode 100644 index 0000000000..648f8bafb2 --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1650317_livescience_com.py @@ -0,0 +1,40 @@ +import pytest + +URL = "https://www.livescience.com/" +TEXT_TO_TEST = ".trending__link" + + +async def is_text_visible(client): + # the page does not properly load, so we just time out + # and wait for the element we're interested in to appear + await client.navigate(URL, timeout=1) + link = client.await_css(TEXT_TO_TEST) + assert client.is_displayed(link) + return client.execute_async_script( + """ + const link = arguments[0]; + const cb = arguments[1]; + const fullHeight = link.scrollHeight; + const parentVisibleHeight = link.parentElement.clientHeight; + link.style.paddingBottom = "0"; + window.requestAnimationFrame(() => { + const bottomPaddingHeight = fullHeight - link.scrollHeight; + cb(fullHeight - parentVisibleHeight <= bottomPaddingHeight); + }); + """, + link, + ) + + +@pytest.mark.skip_platforms("mac") +@pytest.mark.asyncio +@pytest.mark.with_interventions +async def test_enabled(client): + assert await is_text_visible(client) + + +@pytest.mark.skip_platforms("mac") +@pytest.mark.asyncio +@pytest.mark.without_interventions +async def test_disabled(client): + assert not await is_text_visible(client) diff --git a/testing/webcompat/interventions/tests/test_1712833_desuca.py b/testing/webcompat/interventions/tests/test_1712833_desuca.py new file mode 100644 index 0000000000..60796fa54f --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1712833_desuca.py @@ -0,0 +1,18 @@ +import pytest + +URL = "https://buskocchi.desuca.co.jp/smartPhone.html" +SCRIPT = "return document.getElementById('map_canvas')?.clientHeight" + + +@pytest.mark.asyncio +@pytest.mark.with_interventions +async def test_enabled(client): + await client.navigate(URL) + assert client.execute_script(SCRIPT) + + +@pytest.mark.asyncio +@pytest.mark.without_interventions +async def test_disabled(client): + await client.navigate(URL) + assert client.execute_script(SCRIPT) diff --git a/testing/webcompat/interventions/tests/test_1719846_covid_cdc_gov.py b/testing/webcompat/interventions/tests/test_1719846_covid_cdc_gov.py new file mode 100644 index 0000000000..a09c9bc189 --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1719846_covid_cdc_gov.py @@ -0,0 +1,21 @@ +import pytest + +URL = "https://covid.cdc.gov/covid-data-tracker/#pandemic-vulnerability-index" + + +IFRAME_CSS = "#pviIframe" +UNSUPPORTED_TEXT = "not support Firefox" + + +@pytest.mark.asyncio +@pytest.mark.with_interventions +async def test_enabled(client): + await client.navigate(URL) + assert client.await_css(IFRAME_CSS) + + +@pytest.mark.asyncio +@pytest.mark.without_interventions +async def test_disabled(client): + await client.navigate(URL) + assert client.await_text(UNSUPPORTED_TEXT) diff --git a/testing/webcompat/interventions/tests/test_1719859_saxoinvestor.py b/testing/webcompat/interventions/tests/test_1719859_saxoinvestor.py new file mode 100644 index 0000000000..774cc8dbc8 --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1719859_saxoinvestor.py @@ -0,0 +1,28 @@ +import pytest + +URL = ( + "https://www.saxoinvestor.fr/login/?adobe_mc=" + "MCORGID%3D173338B35278510F0A490D4C%2540AdobeOrg%7CTS%3D1621688498" +) + + +@pytest.mark.skip_platforms("linux") +@pytest.mark.asyncio +@pytest.mark.with_interventions +async def test_enabled(client): + await client.navigate(URL) + userid = client.find_css("input#field_userid") + password = client.find_css("input#field_password") + submit = client.find_css("input#button_login") + assert client.is_displayed(userid) + assert client.is_displayed(password) + assert client.is_displayed(submit) + + +@pytest.mark.skip_platforms("linux") +@pytest.mark.asyncio +@pytest.mark.without_interventions +async def test_disabled(client): + await client.navigate(URL) + warning = client.find_css("#browser_support_section") + assert client.is_displayed(warning) diff --git a/testing/webcompat/interventions/tests/test_1741234_alphalabs.py b/testing/webcompat/interventions/tests/test_1741234_alphalabs.py new file mode 100644 index 0000000000..65fd9c06dc --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1741234_alphalabs.py @@ -0,0 +1,35 @@ +import pytest + +URL = "https://patient.alphalabs.ca/Report/CovidReport" + +CONTINUE_CSS = ".btnNormal[type='submit']" +FOOTER_CSS = "footer" + + +async def is_continue_above_footer(client): + await client.navigate(URL) + cont = client.find_css(CONTINUE_CSS) + assert cont + footer = client.find_css(FOOTER_CSS) + assert footer + return client.execute_script( + """ + const cont = arguments[0].getClientRects()[0]; + const footer = arguments[1].getClientRects()[0]; + return cont.bottom < footer.top; + """, + cont, + footer, + ) + + +@pytest.mark.asyncio +@pytest.mark.with_interventions +async def test_enabled(client): + assert await is_continue_above_footer(client) + + +@pytest.mark.asyncio +@pytest.mark.without_interventions +async def test_disabled(client): + assert not await is_continue_above_footer(client) diff --git a/testing/webcompat/interventions/tests/test_1753461_naver.py b/testing/webcompat/interventions/tests/test_1753461_naver.py new file mode 100644 index 0000000000..79cbab5c4b --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1753461_naver.py @@ -0,0 +1,20 @@ +import pytest + +URL = "https://serieson.naver.com/v2/movie/335790?isWebtoonAgreePopUp=true" + +SUPPORTED_CSS = "#playerWrapper" +UNSUPPORTED_CSS = ".end_player_unavailable .download_links" + + +@pytest.mark.asyncio +@pytest.mark.with_interventions +async def test_enabled(client): + await client.navigate(URL) + assert client.await_css(SUPPORTED_CSS) + + +@pytest.mark.asyncio +@pytest.mark.without_interventions +async def test_disabled(client): + await client.navigate(URL) + assert client.await_css(UNSUPPORTED_CSS) diff --git a/testing/webcompat/interventions/tests/test_1774490_rainews_it.py b/testing/webcompat/interventions/tests/test_1774490_rainews_it.py new file mode 100644 index 0000000000..042e8965ae --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1774490_rainews_it.py @@ -0,0 +1,34 @@ +import pytest + +URL = ( + "https://www.rainews.it/photogallery/2022/06/fotorassegna-stampa-le-prime" + "-pagine-dei-quotidiani-di-sabato-04-giugno--cd5414b3-65b9-429b-85d5-e53fadd59f4c.html" +) + +PICTURE_CSS = ".swiper-slide picture" +GALLERY_CSS = ".swiper-wrapper" + + +def get_picture_width(client): + return client.execute_script( + f""" + const p = document.querySelector("{PICTURE_CSS}"); + return window.getComputedStyle(p).width; + """ + ) + + +@pytest.mark.asyncio +@pytest.mark.with_interventions +async def test_enabled(client): + await client.navigate(URL) + client.await_css(GALLERY_CSS) + assert "0px" != get_picture_width(client) + + +@pytest.mark.asyncio +@pytest.mark.without_interventions +async def test_disabled(client): + await client.navigate(URL) + client.await_css(GALLERY_CSS) + assert "0px" == get_picture_width(client) diff --git a/testing/webcompat/interventions/tests/test_1776897_www_edencast_fr.py b/testing/webcompat/interventions/tests/test_1776897_www_edencast_fr.py new file mode 100644 index 0000000000..4823aa0c39 --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1776897_www_edencast_fr.py @@ -0,0 +1,59 @@ +import pytest + +# The page will asyncronously write out an <audio> element on success, but +# will not do anything easily detectable otherwise. +# +# The problem is that the podPressShowHidePlayer function thinks to write +# out a Flash embed unless WebKit is in the UA string, but ends up doing +# nothing at all. However, it calls a different function for html5 vs SWF, +# and we can detect which one it calls to confirm it calls the html5 one. + +URL = "https://www.edencast.fr/zoomcastlost-in-blindness/" + +AUDIO_CSS = "audio#podpresshtml5_1" + +SCRIPT = """ + var done = arguments[0]; + + if (!window?.podPressShowHidePlayer) { + done("none"); + } + + window.podPressenprintHTML5audio = function() { + done("html5"); + }; + + window.podpress_audioplayer_swfobject = { + embedSWF: function() { + done("swf"); + }, + }; + + const d = document.createElement("div"); + d.id = "podPressPlayerSpace_test"; + document.documentElement.appendChild(d); + + const p = document.createElement("div"); + p.id = "podPressPlayerSpace_test_PlayLink"; + document.documentElement.appendChild(p); + + podPressShowHidePlayer("test", "https//x/test.mp3", 100, 100, "force"); + """ + + +@pytest.mark.asyncio +@pytest.mark.with_interventions +async def test_enabled(client): + await client.navigate(URL) + await client.dom_ready() + assert "html5" == client.execute_async_script(SCRIPT) + assert client.find_css(AUDIO_CSS) + + +@pytest.mark.asyncio +@pytest.mark.without_interventions +async def test_disabled(client): + await client.navigate(URL) + await client.dom_ready() + assert "swf" == client.execute_async_script(SCRIPT) + assert not client.find_css(AUDIO_CSS) diff --git a/testing/webcompat/interventions/tests/test_1778168_watch_antennaplus_gr.py b/testing/webcompat/interventions/tests/test_1778168_watch_antennaplus_gr.py new file mode 100644 index 0000000000..d254ff3184 --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1778168_watch_antennaplus_gr.py @@ -0,0 +1,20 @@ +import pytest + +URL = ( + "https://watch.antennaplus.gr/#/shows/agries_melisses/seasons/" + "3/episode/agries_melisses_S03_E137_v1" +) + + +@pytest.mark.asyncio +@pytest.mark.with_interventions +async def test_enabled(client): + await client.navigate(URL) + assert client.await_css(".login-pf-page") + + +@pytest.mark.asyncio +@pytest.mark.without_interventions +async def test_disabled(client): + await client.navigate(URL) + assert client.await_css(".ua-barrier") diff --git a/testing/webcompat/interventions/tests/test_1778239_m_pji_co_kr.py b/testing/webcompat/interventions/tests/test_1778239_m_pji_co_kr.py new file mode 100644 index 0000000000..b7d0043350 --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1778239_m_pji_co_kr.py @@ -0,0 +1,20 @@ +import pytest + +URL = "https://m.pji.co.kr/" +UNSUPPORTED_BANNER = "#chromAlarmView" + + +@pytest.mark.asyncio +@pytest.mark.with_interventions +async def test_enabled(client): + await client.navigate(URL) + unsupported_banner = client.await_css(UNSUPPORTED_BANNER) + assert not client.is_displayed(unsupported_banner) + + +@pytest.mark.asyncio +@pytest.mark.without_interventions +async def test_disabled(client): + await client.navigate(URL) + unsupported_banner = client.await_css(UNSUPPORTED_BANNER) + assert client.is_displayed(unsupported_banner) diff --git a/testing/webcompat/interventions/tests/test_1784199_entrata_platform.py b/testing/webcompat/interventions/tests/test_1784199_entrata_platform.py new file mode 100644 index 0000000000..d10776d5fd --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1784199_entrata_platform.py @@ -0,0 +1,20 @@ +import pytest + +URL = "https://www.liveobserverpark.com/" +UNSUPPORTED_BANNER = ".banner_overlay" + + +@pytest.mark.asyncio +@pytest.mark.with_interventions +async def test_enabled(client): + await client.navigate(URL) + unsupported_banner = client.await_css(UNSUPPORTED_BANNER) + assert not client.is_displayed(unsupported_banner) + + +@pytest.mark.asyncio +@pytest.mark.without_interventions +async def test_disabled(client): + await client.navigate(URL) + unsupported_banner = client.await_css(UNSUPPORTED_BANNER) + assert client.is_displayed(unsupported_banner) diff --git a/testing/webcompat/interventions/tests/test_1786404_business_help_royalmail_com.py b/testing/webcompat/interventions/tests/test_1786404_business_help_royalmail_com.py new file mode 100644 index 0000000000..7500f3509f --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1786404_business_help_royalmail_com.py @@ -0,0 +1,46 @@ +import pytest + +URL = "https://business.help.royalmail.com/app/webforms/stampsenquiries" + +COOKIES_ACCEPT_CSS = "#consent_prompt_submit" +POSTCODE_CSS = "input[name='rn_AddressControl_15textbox']" +OPTION_CSS = "option.addr_pick_line:not(:disabled)" +ADDY1_CSS = "[name='Incident.CustomFields.c.address1_1']" + + +async def getResult(client): + await client.navigate(URL) + client.await_css(COOKIES_ACCEPT_CSS).click() + client.execute_script( + f""" + const proto = EventTarget.prototype; + const def = Object.getOwnPropertyDescriptor(proto, "addEventListener"); + const old = def.value; + def.value = function(type) {{ + if (type === "click" && this?.matches("{OPTION_CSS}")) {{ + window.__expectedListenerAdded = true; + }} + }}; + Object.defineProperty(proto, "addEventListener", def); + """ + ) + + client.await_css(POSTCODE_CSS).send_keys("W1A 1AV") + client.await_css(OPTION_CSS) + return client.execute_script( + """ + return Boolean(window.__expectedListenerAdded); + """ + ) + + +@pytest.mark.asyncio +@pytest.mark.with_interventions +async def test_enabled(client): + assert await getResult(client) + + +@pytest.mark.asyncio +@pytest.mark.without_interventions +async def test_disabled(client): + assert not await getResult(client) diff --git a/testing/webcompat/interventions/tests/test_1800241_mms_telekom_de.py b/testing/webcompat/interventions/tests/test_1800241_mms_telekom_de.py new file mode 100644 index 0000000000..37778ea804 --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1800241_mms_telekom_de.py @@ -0,0 +1,19 @@ +import pytest + +URL = "https://www.mms.telekom.de/OTP/" +LOGIN_CSS = ".LoginbackgroundDiv" + + +@pytest.mark.asyncio +@pytest.mark.with_interventions +async def test_enabled(client): + await client.navigate(URL) + login_element = client.await_css(LOGIN_CSS) + assert client.is_displayed(login_element) + + +@pytest.mark.asyncio +@pytest.mark.without_interventions +async def test_disabled(client): + await client.navigate(URL) + assert not client.find_css(LOGIN_CSS) diff --git a/testing/webcompat/interventions/tests/test_1800936_cov19ent_kdca_go_kr.py b/testing/webcompat/interventions/tests/test_1800936_cov19ent_kdca_go_kr.py new file mode 100644 index 0000000000..e0384a8641 --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1800936_cov19ent_kdca_go_kr.py @@ -0,0 +1,26 @@ +import pytest + +URL = "https://cov19ent.kdca.go.kr/" +HEADER_CSS = "header.mouseOn" + + +async def get_header_position(client): + await client.navigate(URL) + return client.execute_script( + f""" + const r = document.querySelector("{HEADER_CSS}"); + return window.getComputedStyle(r).position; + """ + ) + + +@pytest.mark.asyncio +@pytest.mark.with_interventions +async def test_enabled(client): + assert "absolute" == await get_header_position(client) + + +@pytest.mark.asyncio +@pytest.mark.without_interventions +async def test_disabled(client): + assert "absolute" != await get_header_position(client) diff --git a/testing/webcompat/interventions/tests/test_1803976_youtube_com.py b/testing/webcompat/interventions/tests/test_1803976_youtube_com.py new file mode 100644 index 0000000000..2daa6993d7 --- /dev/null +++ b/testing/webcompat/interventions/tests/test_1803976_youtube_com.py @@ -0,0 +1,60 @@ +import time + +import pytest + +URL = "https://www.youtube.com/" +SEARCH_TERM = "movies" + +SEARCH_FIELD_CSS = "input[type='text'][id*='search']" +SEARCH_BUTTON_CSS = "#search-icon-legacy" +FILTER_BAR_CSS = "#filter-menu" +PERF_NOW_CONSTANT = 11111 + + +def change_performance_now(client): + return client.execute_script( + """ + const PERF_NOW = arguments[0]; + Object.defineProperty(window.performance, "now", { + value: () => PERF_NOW, + }, PERF_NOW_CONSTANT); + """ + ) + + +async def search_for_term(client): + await client.navigate(URL) + search = client.await_css(SEARCH_FIELD_CSS) + button = client.find_css(SEARCH_BUTTON_CSS) + + assert client.is_displayed(search) + assert client.is_displayed(button) + + search.send_keys(SEARCH_TERM) + time.sleep(1) + button.click() + time.sleep(2) + + +@pytest.mark.asyncio +@pytest.mark.with_interventions +async def test_enabled(client): + await search_for_term(client) + filter_bar = client.await_css(FILTER_BAR_CSS) + + client.back() + + assert not client.is_displayed(filter_bar) + + +@pytest.mark.skip(reason="results are intermittent, so skipping this test for now") +@pytest.mark.asyncio +@pytest.mark.without_interventions +async def test_disabled(client): + change_performance_now(client) + await search_for_term(client) + + client.back() + + filter_bar = client.await_css(FILTER_BAR_CSS) + assert client.is_displayed(filter_bar) diff --git a/testing/webcompat/mach_commands.py b/testing/webcompat/mach_commands.py new file mode 100644 index 0000000000..89b0f76f2a --- /dev/null +++ b/testing/webcompat/mach_commands.py @@ -0,0 +1,247 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import argparse +import io +import os +import platform +import sys + +from mach.decorators import Command +from mozbuild.base import MozbuildObject + +here = os.path.abspath(os.path.dirname(__file__)) + + +def get(url): + import requests + + resp = requests.get(url) + resp.raise_for_status() + return resp + + +def untar(fileobj, dest): + import tarfile + + with tarfile.open(fileobj=fileobj, mode="r") as tar_data: + tar_data.extractall(path=dest) + + +def unzip(fileobj, dest): + import zipfile + + with zipfile.ZipFile(fileobj) as zip_data: + zip_data.extractall(path=dest) + + +def create_parser_interventions(): + from mozlog import commandline + + parser = argparse.ArgumentParser() + parser.add_argument("--binary", help="Path to browser binary") + parser.add_argument("--webdriver-binary", help="Path to webdriver binary") + parser.add_argument( + "--webdriver-port", + action="store", + default="4444", + help="Port on which to run WebDriver", + ) + parser.add_argument( + "--webdriver-ws-port", + action="store", + default="9222", + help="Port on which to run WebDriver BiDi websocket", + ) + parser.add_argument("--bug", help="Bug to run tests for") + parser.add_argument( + "--do2fa", + action="store_true", + default=False, + help="Do two-factor auth live in supporting tests", + ) + parser.add_argument( + "--config", help="Path to JSON file containing logins and other settings" + ) + parser.add_argument( + "--debug", action="store_true", default=False, help="Debug failing tests" + ) + parser.add_argument( + "--headless", + action="store_true", + default=False, + help="Run firefox in headless mode", + ) + parser.add_argument( + "--interventions", + action="store", + default="both", + choices=["enabled", "disabled", "both", "none"], + help="Enable webcompat interventions", + ) + parser.add_argument( + "--shims", + action="store", + default="none", + choices=["enabled", "disabled", "both", "none"], + help="Enable SmartBlock shims", + ) + commandline.add_logging_group(parser) + return parser + + +class InterventionTest(MozbuildObject): + def set_default_kwargs(self, logger, kwargs): + if kwargs["binary"] is None: + kwargs["binary"] = self.get_binary_path() + + if kwargs["webdriver_binary"] is None: + webdriver_binary = self.get_binary_path( + "geckodriver", validate_exists=False + ) + + if not os.path.exists(webdriver_binary): + webdriver_binary = self.install_geckodriver( + logger, dest=os.path.dirname(webdriver_binary) + ) + + if not os.path.exists(webdriver_binary): + logger.error("Can't find geckodriver") + sys.exit(1) + kwargs["webdriver_binary"] = webdriver_binary + + def get_capabilities(self, kwargs): + return {"moz:firefoxOptions": {"binary": kwargs["binary"]}} + + def platform_string_geckodriver(self): + uname = platform.uname() + platform_name = {"Linux": "linux", "Windows": "win", "Darwin": "macos"}.get( + uname[0] + ) + + if platform_name in ("linux", "win"): + bits = "64" if uname[4] == "x86_64" else "32" + elif platform_name == "macos": + bits = "" + else: + raise ValueError(f"No precompiled geckodriver for platform {uname}") + + return f"{platform_name}{bits}" + + def install_geckodriver(self, logger, dest): + """Install latest Geckodriver.""" + if dest is None: + dest = os.path.join(self.distdir, "dist", "bin") + + is_windows = platform.uname()[0] == "Windows" + + release = get( + "https://api.github.com/repos/mozilla/geckodriver/releases/latest" + ).json() + ext = "zip" if is_windows else "tar.gz" + platform_name = self.platform_string_geckodriver() + name_suffix = f"-{platform_name}.{ext}" + for item in release["assets"]: + if item["name"].endswith(name_suffix): + url = item["browser_download_url"] + break + else: + raise ValueError(f"Failed to find geckodriver for platform {platform_name}") + + logger.info(f"Installing geckodriver from {url}") + + data = io.BytesIO(get(url).content) + data.seek(0) + decompress = unzip if ext == "zip" else untar + decompress(data, dest=dest) + + exe_ext = ".exe" if is_windows else "" + path = os.path.join(dest, f"geckodriver{exe_ext}") + + return path + + def run(self, **kwargs): + import mozlog + import runner + + mozlog.commandline.setup_logging( + "test-interventions", kwargs, {"mach": sys.stdout} + ) + logger = mozlog.get_default_logger("test-interventions") + status_handler = mozlog.handlers.StatusHandler() + logger.add_handler(status_handler) + + self.set_default_kwargs(logger, kwargs) + + if kwargs["interventions"] != "none": + interventions = ( + ["enabled", "disabled"] + if kwargs["interventions"] == "both" + else [kwargs["interventions"]] + ) + + for interventions_setting in interventions: + runner.run( + logger, + os.path.join(here, "interventions"), + kwargs["binary"], + kwargs["webdriver_binary"], + kwargs["webdriver_port"], + kwargs["webdriver_ws_port"], + bug=kwargs["bug"], + debug=kwargs["debug"], + interventions=interventions_setting, + config=kwargs["config"], + headless=kwargs["headless"], + do2fa=kwargs["do2fa"], + ) + + if kwargs["shims"] != "none": + shims = ( + ["enabled", "disabled"] + if kwargs["shims"] == "both" + else [kwargs["shims"]] + ) + + for shims_setting in shims: + runner.run( + logger, + os.path.join(here, "shims"), + kwargs["binary"], + kwargs["webdriver_binary"], + kwargs["webdriver_port"], + kwargs["webdriver_ws_port"], + bug=kwargs["bug"], + debug=kwargs["debug"], + shims=shims_setting, + config=kwargs["config"], + headless=kwargs["headless"], + do2fa=kwargs["do2fa"], + ) + + summary = status_handler.summarize() + passed = ( + summary.unexpected_statuses == 0 + and summary.log_level_counts.get("ERROR", 0) == 0 + and summary.log_level_counts.get("CRITICAL", 0) == 0 + ) + return passed + + +@Command( + "test-interventions", + category="testing", + description="Test the webcompat interventions", + parser=create_parser_interventions, + virtualenv_name="webcompat", +) +def test_interventions(command_context, **params): + here = os.path.abspath(os.path.dirname(__file__)) + command_context.virtualenv_manager.activate() + command_context.virtualenv_manager.install_pip_requirements( + os.path.join(here, "requirements.txt"), + require_hashes=False, + ) + intervention_test = command_context._spawn(InterventionTest) + return 0 if intervention_test.run(**params) else 1 diff --git a/testing/webcompat/requirements.txt b/testing/webcompat/requirements.txt new file mode 100644 index 0000000000..1e5f90af3c --- /dev/null +++ b/testing/webcompat/requirements.txt @@ -0,0 +1,3 @@ +asyncio==3.4.3 +pytest-asyncio==0.16.0 +urllib3==1.26 diff --git a/testing/webcompat/runner.py b/testing/webcompat/runner.py new file mode 100644 index 0000000000..8d733fb0f8 --- /dev/null +++ b/testing/webcompat/runner.py @@ -0,0 +1,228 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import errno +import os +import shutil +import tempfile + +import pytest + + +def run( + logger, + path, + browser_binary, + webdriver_binary, + webdriver_port, + webdriver_ws_port, + environ=None, + bug=None, + debug=False, + interventions=None, + shims=None, + config=None, + headless=False, + do2fa=False, +): + """""" + old_environ = os.environ.copy() + try: + with TemporaryDirectory() as cache: + if environ: + os.environ.update(environ) + + config_plugin = WDConfig() + result_recorder = ResultRecorder(logger) + + args = [ + "--strict", # turn warnings into errors + "-vv", # show each individual subtest and full failure logs + "--capture", + "no", # enable stdout/stderr from tests + "--basetemp", + cache, # temporary directory + "--showlocals", # display contents of variables in local scope + "-p", + "no:mozlog", # use the WPT result recorder + "--disable-warnings", + "-rfEs", + "-p", + "no:cacheprovider", # disable state preservation across invocations + "-o=console_output_style=classic", # disable test progress bar + "--browser", + "firefox", + "--browser-binary", + browser_binary, + "--webdriver-binary", + webdriver_binary, + "--webdriver-port", + webdriver_port, + "--webdriver-ws-port", + webdriver_ws_port, + ] + + if debug: + args.append("--pdb") + + if headless: + args.append("--headless") + + if bug: + args.append("--bug") + args.append(bug) + + if do2fa: + args.append("--do2fa") + + if config: + args.append("--config") + args.append(config) + + if interventions is not None and shims is not None: + raise ValueError( + "Must provide only one of interventions or shims argument" + ) + elif interventions is None and shims is None: + raise ValueError( + "Must provide either an interventions or shims argument" + ) + + name = "webcompat-interventions" + if interventions == "enabled": + args.extend(["-m", "with_interventions"]) + elif interventions == "disabled": + args.extend(["-m", "without_interventions"]) + elif interventions is not None: + raise ValueError(f"Invalid value for interventions {interventions}") + if shims == "enabled": + args.extend(["-m", "with_shims"]) + name = "smartblock-shims" + elif shims == "disabled": + args.extend(["-m", "without_shims"]) + name = "smartblock-shims" + elif shims is not None: + raise ValueError(f"Invalid value for shims {shims}") + else: + name = "smartblock-shims" + + if bug is not None: + args.extend(["-k", bug]) + + args.append(path) + try: + logger.suite_start([], name=name) + pytest.main(args, plugins=[config_plugin, result_recorder]) + except Exception as e: + logger.critical(str(e)) + finally: + logger.suite_end() + + finally: + os.environ = old_environ + + +class WDConfig: + def pytest_addoption(self, parser): + parser.addoption( + "--browser-binary", action="store", help="Path to browser binary" + ) + parser.addoption( + "--webdriver-binary", action="store", help="Path to webdriver binary" + ) + parser.addoption( + "--webdriver-port", + action="store", + default="4444", + help="Port on which to run WebDriver", + ) + parser.addoption( + "--webdriver-ws-port", + action="store", + default="9222", + help="Port on which to run WebDriver BiDi websocket", + ) + parser.addoption( + "--browser", action="store", choices=["firefox"], help="Name of the browser" + ) + parser.addoption("--bug", action="store", help="Bug number to run tests for") + parser.addoption( + "--do2fa", + action="store_true", + default=False, + help="Do two-factor auth live in supporting tests", + ) + parser.addoption( + "--config", + action="store", + help="Path to JSON file containing logins and other settings", + ) + parser.addoption( + "--headless", action="store_true", help="Run browser in headless mode" + ) + + +class ResultRecorder(object): + def __init__(self, logger): + self.logger = logger + + def pytest_runtest_logreport(self, report): + if report.passed and report.when == "call": + self.record_pass(report) + elif report.failed: + if report.when != "call": + self.record_error(report) + else: + self.record_fail(report) + elif report.skipped: + self.record_skip(report) + + def record_pass(self, report): + self.record(report.nodeid, "PASS") + + def record_fail(self, report): + # pytest outputs the stacktrace followed by an error message prefixed + # with "E ", e.g. + # + # def test_example(): + # > assert "fuu" in "foobar" + # > E AssertionError: assert 'fuu' in 'foobar' + message = "" + for line in report.longreprtext.splitlines(): + if line.startswith("E "): + message = line[1:].strip() + break + + self.record(report.nodeid, "FAIL", message=message, stack=report.longrepr) + + def record_error(self, report): + # error in setup/teardown + if report.when != "call": + message = "%s error" % report.when + self.record(report.nodeid, "ERROR", message, report.longrepr) + + def record_skip(self, report): + self.record(report.nodeid, "SKIP") + + def record(self, test, status, message=None, stack=None): + if stack is not None: + stack = str(stack) + self.logger.test_start(test) + self.logger.test_end( + test=test, status=status, expected="PASS", message=message, stack=stack + ) + + +class TemporaryDirectory(object): + def __enter__(self): + self.path = tempfile.mkdtemp(prefix="pytest-") + return self.path + + def __exit__(self, *args): + try: + shutil.rmtree(self.path) + except OSError as e: + # no such file or directory + if e.errno != errno.ENOENT: + raise diff --git a/testing/webcompat/shims/__init__.py b/testing/webcompat/shims/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/testing/webcompat/shims/__init__.py diff --git a/testing/webcompat/shims/conftest.py b/testing/webcompat/shims/conftest.py new file mode 100644 index 0000000000..0ab18f8104 --- /dev/null +++ b/testing/webcompat/shims/conftest.py @@ -0,0 +1,63 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + +from ..fixtures import * # noqa: F403 + + +def pytest_generate_tests(metafunc): + """Generate tests based on markers.""" + + if "session" not in metafunc.fixturenames: + return + + marks = [mark.name for mark in metafunc.function.pytestmark] + + otherargs = {} + argvalues = [] + ids = [] + + if "skip_platforms" in marks: + for mark in metafunc.function.pytestmark: + if mark.name == "skip_platforms": + otherargs["skip_platforms"] = mark.args + + if "with_private_browsing" in marks: + otherargs["with_private_browsing"] = True + if "with_strict_etp" in marks: + otherargs["with_strict_etp"] = True + if "without_storage_partitioning" in marks: + otherargs["without_storage_partitioning"] = True + if "without_tcp " in marks: + otherargs["without_tcp "] = True + + if "with_shims" in marks: + argvalues.append([dict({"shims": True}, **otherargs)]) + ids.append("with_shims") + + if "without_shims" in marks: + argvalues.append([dict({"shims": False}, **otherargs)]) + ids.append("without_shims") + + metafunc.parametrize(["session"], argvalues, ids=ids, indirect=True) + + +@pytest.fixture(scope="function") # noqa: F405 +async def test_config(request, driver): + params = request.node.callspec.params.get("session") + + use_shims = params.get("shims") + if use_shims is None: + raise ValueError( + "Missing shims marker in %s:%s" + % (request.fspath, request.function.__name__) + ) + + return { + "aps": not params.get("without_storage_partitioning", False), + "use_pbm": params.get("with_private_browsing", False), + "use_shims": use_shims, + "use_strict_etp": params.get("with_strict_etp", False), + "without_tcp": params.get("without_tcp", False), + } diff --git a/testing/webcompat/shims/pytest.ini b/testing/webcompat/shims/pytest.ini new file mode 100644 index 0000000000..20e8b498bf --- /dev/null +++ b/testing/webcompat/shims/pytest.ini @@ -0,0 +1,10 @@ +[pytest] +console_output_style = classic +markers = + skip_platforms: skip tests on specific platforms (mac, linux, windows) + with_shims: enable web-compat shims + without_shims: disable web-compat shims + without_storage_partitioning: disable partitioning of non-cookie third-party web storage + with_private_browsing: run test in a private browsing window + with_strict_etp: enable strict ETP mode + without_tcp: disable Total Cookie Protection diff --git a/testing/webcompat/shims/tests/__init__.py b/testing/webcompat/shims/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/testing/webcompat/shims/tests/__init__.py diff --git a/testing/webcompat/shims/tests/common.py b/testing/webcompat/shims/tests/common.py new file mode 100644 index 0000000000..307e39c74d --- /dev/null +++ b/testing/webcompat/shims/tests/common.py @@ -0,0 +1,41 @@ +GPT_SHIM_MSG = "Google Publisher Tags is being shimmed by Firefox" +GAGTA_SHIM_MSG = "Google Analytics and Tag Manager is being shimmed by Firefox" + + +async def is_gtag_placeholder_displayed(client, url, finder, **kwargs): + await client.navigate(url, **kwargs) + client.execute_async_script( + """ + const done = arguments[0]; + if (window.dataLayer?.push?.toString() === [].push.toString()) { + return done(); + } + setTimeout(() => { + dataLayer.push({ + event: "datalayerReady", + eventTimeout: 1, + eventCallback: done, + }); + }, 100); + """ + ) + return client.is_displayed(client.find_element(finder)) + + +async def clicking_link_navigates(client, url, finder, **kwargs): + await client.navigate(url, **kwargs) + elem = client.await_element(finder) + return client.session.execute_async_script( + """ + const elem = arguments[0], + done = arguments[1]; + window.onbeforeunload = function() { + done(true); + }; + elem.click(); + setTimeout(() => { + done(false); + }, 1000); + """, + args=[elem], + ) diff --git a/testing/webcompat/shims/tests/test_1624914_google_trends.py b/testing/webcompat/shims/tests/test_1624914_google_trends.py new file mode 100644 index 0000000000..dea81e3ea4 --- /dev/null +++ b/testing/webcompat/shims/tests/test_1624914_google_trends.py @@ -0,0 +1,26 @@ +import pytest + +URL = "https://knowyourmeme.com/memes/awesome-face-epic-smiley" +IFRAME = "iframe#trends-widget-1" + + +@pytest.mark.asyncio +@pytest.mark.with_shims +async def test_works_with_shims(client): + await client.load_page_and_wait_for_iframe(URL, client.css(IFRAME)) + assert client.await_css("svg") + + +@pytest.mark.asyncio +@pytest.mark.without_tcp +@pytest.mark.without_shims +async def test_works_without_etp(client): + await client.load_page_and_wait_for_iframe(URL, client.css(IFRAME)) + assert client.await_css("body.neterror") + + +@pytest.mark.asyncio +@pytest.mark.without_shims +async def test_needs_shims(client): + await client.load_page_and_wait_for_iframe(URL, client.css(IFRAME)) + assert client.await_css("body.neterror") diff --git a/testing/webcompat/shims/tests/test_1694168_google_analytics_and_tag_manager.py b/testing/webcompat/shims/tests/test_1694168_google_analytics_and_tag_manager.py new file mode 100644 index 0000000000..a00e617bdb --- /dev/null +++ b/testing/webcompat/shims/tests/test_1694168_google_analytics_and_tag_manager.py @@ -0,0 +1,23 @@ +import pytest + +URL = "https://agspares.co.nz/category/Super-Store-Tractor-Linkage-Pins-Lynch-Pins-R-Clips" +ITEM = ".productsListed.item a[onclick]" + + +from .common import GAGTA_SHIM_MSG, clicking_link_navigates + + +@pytest.mark.asyncio +@pytest.mark.with_strict_etp +@pytest.mark.with_shims +async def test_enabled(client): + assert await clicking_link_navigates( + client, URL, client.css(ITEM), await_console_message=GAGTA_SHIM_MSG + ) + + +@pytest.mark.asyncio +@pytest.mark.with_strict_etp +@pytest.mark.without_shims +async def test_disabled(client): + assert not await clicking_link_navigates(client, URL, client.css(ITEM)) diff --git a/testing/webcompat/shims/tests/test_1762851_google_publisher_tags.py b/testing/webcompat/shims/tests/test_1762851_google_publisher_tags.py new file mode 100644 index 0000000000..3b52ce8480 --- /dev/null +++ b/testing/webcompat/shims/tests/test_1762851_google_publisher_tags.py @@ -0,0 +1,23 @@ +import pytest + +URL = "https://www.carousell.sg/search/ps3/?searchId=DjgOQf" +PLACEHOLDER = "[id*='Desktop_Search_FWB']" + + +from .common import GPT_SHIM_MSG, is_gtag_placeholder_displayed + + +@pytest.mark.asyncio +@pytest.mark.with_strict_etp +@pytest.mark.with_shims +async def test_enabled(client): + assert not await is_gtag_placeholder_displayed( + client, URL, client.css(PLACEHOLDER), await_console_message=GPT_SHIM_MSG + ) + + +@pytest.mark.asyncio +@pytest.mark.with_strict_etp +@pytest.mark.without_shims +async def test_disabled(client): + assert not await is_gtag_placeholder_displayed(client, URL, client.css(PLACEHOLDER)) diff --git a/testing/webcompat/shims/tests/test_1767270_rva311_com_pbm_fix.py b/testing/webcompat/shims/tests/test_1767270_rva311_com_pbm_fix.py new file mode 100644 index 0000000000..bf708af877 --- /dev/null +++ b/testing/webcompat/shims/tests/test_1767270_rva311_com_pbm_fix.py @@ -0,0 +1,21 @@ +import pytest + +URL = "https://www.rva311.com/rvaone" +SHIM_ACTIVE_MSG = "Private Browsing Web APIs is being shimmed by Firefox" +IDB_FAILURE_MSG = "InvalidStateError: A mutation operation was attempted on a database" + + +@pytest.mark.asyncio +@pytest.mark.with_private_browsing +@pytest.mark.with_shims +async def test_with_shim(client): + await client.navigate(URL, await_console_message=SHIM_ACTIVE_MSG) + assert client.await_css("#root nav", is_displayed=True) + + +@pytest.mark.asyncio +@pytest.mark.with_private_browsing +@pytest.mark.without_shims +async def test_without_shim(client): + await client.navigate(URL, await_console_message=IDB_FAILURE_MSG) + assert client.find_css("#root [class*='loading-dot']", is_displayed=True) diff --git a/testing/webcompat/shims/tests/test_1775099_google_publisher_tags.py b/testing/webcompat/shims/tests/test_1775099_google_publisher_tags.py new file mode 100644 index 0000000000..1e4e595561 --- /dev/null +++ b/testing/webcompat/shims/tests/test_1775099_google_publisher_tags.py @@ -0,0 +1,23 @@ +import pytest + +URL = "https://themighty.com/topic/fibromyalgia/difficulties-sitting-chronic-pain-fibromyalgia/" +PLACEHOLDER = ".tm-ads" + + +from .common import GPT_SHIM_MSG, is_gtag_placeholder_displayed + + +@pytest.mark.asyncio +@pytest.mark.with_strict_etp +@pytest.mark.with_shims +async def test_enabled(client): + assert not await is_gtag_placeholder_displayed( + client, URL, client.css(PLACEHOLDER), await_console_message=GPT_SHIM_MSG + ) + + +@pytest.mark.asyncio +@pytest.mark.with_strict_etp +@pytest.mark.without_shims +async def test_disabled(client): + assert await is_gtag_placeholder_displayed(client, URL, client.css(PLACEHOLDER)) |