diff options
Diffstat (limited to 'testing/webcompat/shims')
10 files changed, 230 insertions, 0 deletions
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)) |