Skip to content

Commit

Permalink
Bug 1828953 - add automated tests for the webcompat v114 and v115 int…
Browse files Browse the repository at this point in the history
…erventions, remove some obsolete ones; r=denschub DONTBUILD

Differential Revision: https://phabricator.services.mozilla.com/D177325
  • Loading branch information
wisniewskit committed Jun 9, 2023
1 parent d5393fa commit 8abc619
Show file tree
Hide file tree
Showing 36 changed files with 708 additions and 159 deletions.
30 changes: 24 additions & 6 deletions testing/webcompat/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async def navigate(self, url, timeout=None, await_console_message=None):
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)
console_message = self.monitor_for_console_message(await_console_message)
await self.session.bidi_session.session.subscribe(events=["log.entryAdded"])
try:
self.session.url = url
Expand All @@ -123,6 +123,12 @@ async def navigate(self, url, timeout=None, await_console_message=None):
if timeout is not None:
self.session.timeouts.page_load = old_timeout

async def promise_console_message(self, message, timeout=20):
promise = self.monitor_for_console_message(message, timeout)
await self.session.bidi_session.session.subscribe(events=["log.entryAdded"])
await promise
await self.session.bidi_session.session.unsubscribe(events=["log.entryAdded"])

def back(self):
self.session.back()

Expand Down Expand Up @@ -164,7 +170,7 @@ async def on_event(method, data):
)
return asyncio.wait_for(future, timeout=timeout)

def promise_console_message(self, msg):
def monitor_for_console_message(self, msg, timeout=20):
def check_messages(method, data):
if "text" in data:
if msg in data["text"]:
Expand All @@ -173,7 +179,9 @@ def check_messages(method, data):
if msg in data["args"][0]["value"]:
return True

return self.promise_bidi_event("log.entryAdded", check_messages)
return self.promise_bidi_event(
"log.entryAdded", check_messages, timeout=timeout
)

def execute_script(self, script, *args):
return self.session.execute_script(script, args=args)
Expand All @@ -186,6 +194,13 @@ def clear_all_cookies(self):
"DELETE", "session/%s/cookie" % self.session.session_id
)

def send_element_command(self, element, method, uri, body=None):
url = "element/%s/%s" % (element.id, uri)
return self.session.send_session_command(method, url, body)

def get_element_attribute(self, element, name):
return self.send_element_command(element, "GET", "attribute/%s" % name)

def _do_is_displayed_check(self, ele, is_displayed):
if ele is None:
return None
Expand Down Expand Up @@ -357,19 +372,22 @@ def test_for_fastclick(self, element):
self.execute_script(
"""
const sel = arguments[0];
sel.fastclicked = false;
window.fastclicked = false;
const evt = sel.nodeName === "SELECT" ? "mousedown" : "click";
document.addEventListener(evt, e => {
if (e.target === sel && !e.isTrusted) {
sel.fastclicked = true;
window.fastclicked = true;
}
}, true);
""",
element,
)
self.scroll_into_view(element)
# tap a few times in case the site's other code interferes
self.touch.click(element=element).perform()
self.touch.click(element=element).perform()
self.touch.click(element=element).perform()
return self.execute_script("return arguments[0].fastclicked", element)
return self.execute_script("return window.fastclicked")

def is_displayed(self, element):
if element is None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import time

import pytest
from webdriver.error import NoSuchElementException

Expand All @@ -14,6 +16,7 @@ async def check_choose_dealer_works(client):
cookies = client.css(COOKIES_CSS)
client.await_element(cookies).click()
client.await_element_hidden(cookies)
time.sleep(0.5)

down, dealer = client.await_first_element_of(
[
Expand Down
62 changes: 0 additions & 62 deletions testing/webcompat/interventions/tests/test_1803976_youtube_com.py

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
async def is_fastclick_active(client):
await client.navigate(URL)
menu = client.await_css(MENU_CSS)
menu.click()
client.soft_click(menu)
return client.test_for_fastclick(client.await_css(SELECT_CSS))


Expand Down
22 changes: 22 additions & 0 deletions testing/webcompat/interventions/tests/test_1829126_otsuka_co_jp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest

URL = "https://www.otsuka.co.jp/fib/"
SPLASH_CSS = ".splash"
ERROR_MSG = "__im_uid_11310 is not defined"


@pytest.mark.only_platforms("android")
@pytest.mark.asyncio
@pytest.mark.with_interventions
async def test_enabled(client):
await client.navigate(URL)
assert client.await_css(SPLASH_CSS)
client.await_element_hidden(client.css(SPLASH_CSS), timeout=10)


@pytest.mark.only_platforms("android")
@pytest.mark.asyncio
@pytest.mark.without_interventions
async def test_disabled(client):
await client.navigate(URL, await_console_message=ERROR_MSG)
assert client.find_css(SPLASH_CSS, is_displayed=False)
18 changes: 18 additions & 0 deletions testing/webcompat/interventions/tests/test_1829944_411_ca.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pytest

URL = "https://411.ca"
UNSUPPORTED_CSS = "ngb-alert.header-outdated-alert"


@pytest.mark.asyncio
@pytest.mark.with_interventions
async def test_enabled(client):
await client.navigate(URL)
assert not client.find_css(UNSUPPORTED_CSS)


@pytest.mark.asyncio
@pytest.mark.without_interventions
async def test_disabled(client):
await client.navigate(URL)
assert client.find_css(UNSUPPORTED_CSS)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

URL = "https://gofreeconcepts.de/collections/shamma-sandals/products/shamma-sandals-warriors-maximus-mit-lederfussbett"
SELECT_CSS = "#productSelect"
URL = "https://www.discountcoffee.co.uk/collections/wholesale-coffee-beans"
SELECT_CSS = "#collection-filter-type select"


async def is_fastclick_active(client):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import pytest

URL = "https://www.eventer.co.il"
EVENT_CSS = "a.slide-a-tag[href*='/event']"
ELEM_CSS = ".mobileStripButton:not(.ng-hide)"


async def is_too_tall(client):
await client.navigate(URL)
event = client.await_css(EVENT_CSS)
await client.navigate(URL + client.get_element_attribute(event, "href"))
elem = client.await_css(ELEM_CSS)
return client.execute_script(
"""
return window.innerHeight == arguments[0].getBoundingClientRect().height;
""",
elem,
)


@pytest.mark.only_platforms("android")
@pytest.mark.asyncio
@pytest.mark.with_interventions
async def test_enabled(client):
assert not await is_too_tall(client)


@pytest.mark.only_platforms("android")
@pytest.mark.asyncio
@pytest.mark.without_interventions
async def test_disabled(client):
assert await is_too_tall(client)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pytest

URL = "https://casinoextreme.eu/games"
RUN_CSS = "a.playgame-demo[onclick^='playGame']"
IFRAME_CSS = "#gameplay > iframe"
GOOD_MSG = "GameViewModel"
BAD_MSG = "UnsupportedDevice"


@pytest.mark.only_platforms("android")
@pytest.mark.asyncio
@pytest.mark.with_interventions
async def test_enabled(client):
await client.navigate(URL)
client.soft_click(client.await_css(RUN_CSS))
client.switch_to_frame(client.await_css(IFRAME_CSS))
await client.promise_console_message(GOOD_MSG)


@pytest.mark.only_platforms("android")
@pytest.mark.asyncio
@pytest.mark.without_interventions
async def test_disabled(client):
await client.navigate(URL)
client.soft_click(client.await_css(RUN_CSS))
client.switch_to_frame(client.await_css(IFRAME_CSS))
await client.promise_console_message(BAD_MSG)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pytest

URL = "https://www.cryptoloko.com/webplay/?play=sweet-16-blast"
IFRAME_CSS = "#gameiframe"
GOOD_MSG = "GameViewModel"
BAD_MSG = "UnsupportedDevice"


@pytest.mark.only_platforms("android")
@pytest.mark.asyncio
@pytest.mark.with_interventions
async def test_enabled(client):
await client.navigate(URL)
client.switch_to_frame(client.await_css(IFRAME_CSS))
await client.promise_console_message(GOOD_MSG)


@pytest.mark.only_platforms("android")
@pytest.mark.asyncio
@pytest.mark.without_interventions
async def test_disabled(client):
await client.navigate(URL)
client.switch_to_frame(client.await_css(IFRAME_CSS))
await client.promise_console_message(BAD_MSG)
Loading

0 comments on commit 8abc619

Please sign in to comment.