summaryrefslogtreecommitdiffstats
path: root/testing/webcompat/shims/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /testing/webcompat/shims/tests
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/webcompat/shims/tests')
-rw-r--r--testing/webcompat/shims/tests/__init__.py0
-rw-r--r--testing/webcompat/shims/tests/common.py84
-rw-r--r--testing/webcompat/shims/tests/test_1624914_google_trends.py29
-rw-r--r--testing/webcompat/shims/tests/test_1694168_google_analytics_and_tag_manager.py23
-rw-r--r--testing/webcompat/shims/tests/test_1701685_advertising_com.py22
-rw-r--r--testing/webcompat/shims/tests/test_1717806_adsafeprotected.py37
-rw-r--r--testing/webcompat/shims/tests/test_1717806_stickyadstv.py22
-rw-r--r--testing/webcompat/shims/tests/test_1762851_google_publisher_tags.py23
-rw-r--r--testing/webcompat/shims/tests/test_1767270_rva311_com_pbm_fix.py26
-rw-r--r--testing/webcompat/shims/tests/test_1775099_google_publisher_tags.py23
10 files changed, 289 insertions, 0 deletions
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..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("<html>"))
+ 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))