From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- testing/webcompat/shims/__init__.py | 0 testing/webcompat/shims/conftest.py | 68 ++++++++++++++++++ testing/webcompat/shims/pytest.ini | 11 +++ testing/webcompat/shims/tests/__init__.py | 0 testing/webcompat/shims/tests/common.py | 84 ++++++++++++++++++++++ .../shims/tests/test_1624914_google_trends.py | 29 ++++++++ ...est_1694168_google_analytics_and_tag_manager.py | 23 ++++++ .../shims/tests/test_1701685_advertising_com.py | 22 ++++++ .../shims/tests/test_1717806_adsafeprotected.py | 37 ++++++++++ .../shims/tests/test_1717806_stickyadstv.py | 22 ++++++ .../tests/test_1762851_google_publisher_tags.py | 23 ++++++ .../shims/tests/test_1767270_rva311_com_pbm_fix.py | 26 +++++++ .../tests/test_1775099_google_publisher_tags.py | 23 ++++++ 13 files changed, 368 insertions(+) create mode 100644 testing/webcompat/shims/__init__.py create mode 100644 testing/webcompat/shims/conftest.py create mode 100644 testing/webcompat/shims/pytest.ini create mode 100644 testing/webcompat/shims/tests/__init__.py create mode 100644 testing/webcompat/shims/tests/common.py create mode 100644 testing/webcompat/shims/tests/test_1624914_google_trends.py create mode 100644 testing/webcompat/shims/tests/test_1694168_google_analytics_and_tag_manager.py create mode 100644 testing/webcompat/shims/tests/test_1701685_advertising_com.py create mode 100644 testing/webcompat/shims/tests/test_1717806_adsafeprotected.py create mode 100644 testing/webcompat/shims/tests/test_1717806_stickyadstv.py create mode 100644 testing/webcompat/shims/tests/test_1762851_google_publisher_tags.py create mode 100644 testing/webcompat/shims/tests/test_1767270_rva311_com_pbm_fix.py create mode 100644 testing/webcompat/shims/tests/test_1775099_google_publisher_tags.py (limited to 'testing/webcompat/shims') diff --git a/testing/webcompat/shims/__init__.py b/testing/webcompat/shims/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/testing/webcompat/shims/conftest.py b/testing/webcompat/shims/conftest.py new file mode 100644 index 0000000000..30807a1188 --- /dev/null +++ b/testing/webcompat/shims/conftest.py @@ -0,0 +1,68 @@ +# 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 "only_platforms" in marks: + for mark in metafunc.function.pytestmark: + if mark.name == "only_platforms": + otherargs["only_platforms"] = mark.args + + 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..6f1f05efd9 --- /dev/null +++ b/testing/webcompat/shims/pytest.ini @@ -0,0 +1,11 @@ +[pytest] +console_output_style = classic +markers = + only_platforms: only run tests on specific platforms (mac, linux, windows, android) + skip_platforms: skip tests on specific platforms (mac, linux, windows, android) + 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 diff --git a/testing/webcompat/shims/tests/common.py b/testing/webcompat/shims/tests/common.py new file mode 100644 index 0000000000..9a822e9e83 --- /dev/null +++ b/testing/webcompat/shims/tests/common.py @@ -0,0 +1,84 @@ +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], + ) + + +async def verify_redirectors(client, urls, expected="REDIRECTED"): + await client.navigate(client.inline("")) + for url, type in urls.items(): + assert expected == client.execute_async_script( + """ + const [url, type, resolve] = arguments; + fetch(url).then(async response => { + if (!response.ok) { + return resolve("FAILED"); + } + + try { + if (type === "image") { + const blob = await response.blob(); + const url = URL.createObjectURL(blob); + const img = new Image(1, 1); + await new Promise((res, rej) => { + img.onerror = rej; + img.onload = res; + img.src = url; + }); + } else if (type === "js") { + const text = await response.text(); + if (!text.includes("This script is intentionally empty")) { + throw ""; + } + } else { + return resolve("UNKNOWN TYPE"); + } + } catch(_) { + return resolve("TYPE MISMATCH"); + } + + resolve(response.redirected ? "REDIRECTED" : "LOADED"); + }).catch(_ => { + resolve("BLOCKED"); + }); + """, + url, + type, + ) 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..1a11713cdc --- /dev/null +++ b/testing/webcompat/shims/tests/test_1624914_google_trends.py @@ -0,0 +1,29 @@ +import pytest + +URL = "https://knowyourmeme.com/memes/awesome-face-epic-smiley" +IFRAME = "iframe#trends-widget-1" + + +@pytest.mark.skip_platforms("android") +@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.skip_platforms("android") +@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.skip_platforms("android") +@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_1701685_advertising_com.py b/testing/webcompat/shims/tests/test_1701685_advertising_com.py new file mode 100644 index 0000000000..b89cf51135 --- /dev/null +++ b/testing/webcompat/shims/tests/test_1701685_advertising_com.py @@ -0,0 +1,22 @@ +import pytest + +from .common import verify_redirectors + +URLS = { + "https://ads.advertising.com/x.js?1": "js", + "https://ads.advertising.com/x?1": "image", +} + + +@pytest.mark.asyncio +@pytest.mark.with_strict_etp +@pytest.mark.with_shims +async def test_works_with_shims(client): + await verify_redirectors(client, URLS, "REDIRECTED") + + +@pytest.mark.asyncio +@pytest.mark.with_strict_etp +@pytest.mark.without_shims +async def test_works_without_etp(client): + await verify_redirectors(client, URLS, "BLOCKED") diff --git a/testing/webcompat/shims/tests/test_1717806_adsafeprotected.py b/testing/webcompat/shims/tests/test_1717806_adsafeprotected.py new file mode 100644 index 0000000000..e7a530e141 --- /dev/null +++ b/testing/webcompat/shims/tests/test_1717806_adsafeprotected.py @@ -0,0 +1,37 @@ +import pytest + +from .common import verify_redirectors + +URLS = { + "https://x.adsafeprotected.com/x.gif?1": "image", + "https://x.adsafeprotected.com/x.png?1": "image", + "https://x.adsafeprotected.com/x/x": "image", + "https://x.adsafeprotected.com/img": "image", + "https://x.adsafeprotected.com/x.js?1": "js", + "https://x.adsafeprotected.com/x/adj?1": "js", + "https://x.adsafeprotected.com/x/imp/1": "js", + "https://x.adsafeprotected.com/x/Serving/1": "js", + "https://x.adsafeprotected.com/x/unit/1": "js", + "https://x.adsafeprotected.com/jload": "js", + "https://x.adsafeprotected.com/jload?1": "js", + "https://x.adsafeprotected.com/jsvid": "js", + "https://x.adsafeprotected.com/jsvid?1": "js", + "https://x.adsafeprotected.com/mon?1": "js", + "https://x.adsafeprotected.com/tpl": "js", + "https://x.adsafeprotected.com/tpl?1": "js", + "https://x.adsafeprotected.com/services/pub?1": "js", +} + + +@pytest.mark.asyncio +@pytest.mark.with_strict_etp +@pytest.mark.with_shims +async def test_works_with_shims(client): + await verify_redirectors(client, URLS, "REDIRECTED") + + +@pytest.mark.asyncio +@pytest.mark.with_strict_etp +@pytest.mark.without_shims +async def test_works_without_etp(client): + await verify_redirectors(client, URLS, "BLOCKED") diff --git a/testing/webcompat/shims/tests/test_1717806_stickyadstv.py b/testing/webcompat/shims/tests/test_1717806_stickyadstv.py new file mode 100644 index 0000000000..74a895aa51 --- /dev/null +++ b/testing/webcompat/shims/tests/test_1717806_stickyadstv.py @@ -0,0 +1,22 @@ +import pytest + +from .common import verify_redirectors + +URLS = { + "https://ads.stickyadstv.com/auto-user-sync?1": "image", + "https://ads.stickyadstv.com/user-matching?1": "image", +} + + +@pytest.mark.asyncio +@pytest.mark.with_strict_etp +@pytest.mark.with_shims +async def test_works_with_shims(client): + await verify_redirectors(client, URLS, "REDIRECTED") + + +@pytest.mark.asyncio +@pytest.mark.with_strict_etp +@pytest.mark.without_shims +async def test_works_without_etp(client): + await verify_redirectors(client, URLS, "BLOCKED") 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..2e30bae2cb --- /dev/null +++ b/testing/webcompat/shims/tests/test_1767270_rva311_com_pbm_fix.py @@ -0,0 +1,26 @@ +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, platform): + msg = None if platform == "android" else SHIM_ACTIVE_MSG + await client.navigate(URL, await_console_message=msg) + desktop, mobile = client.await_first_element_of( + [client.css("#root nav"), client.css("#mobilePageTitle")], is_displayed=True + ) + assert desktop or mobile + + +@pytest.mark.asyncio +@pytest.mark.with_private_browsing +@pytest.mark.without_shims +async def test_without_shim(client, platform): + msg = None if platform == "android" else IDB_FAILURE_MSG + await client.navigate(URL, await_console_message=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)) -- cgit v1.2.3