Bug 1947402 - [wdspec] Add wdspec test for performActions hiding iframe with display none r=webdriver-reviewers,whimboo

Depends on D247042

Differential Revision: https://phabricator.services.mozilla.com/D238910
This commit is contained in:
Julian Descottes
2025-05-06 07:52:06 +00:00
committed by jdescottes@mozilla.com
parent 7f22fdbbec
commit 6db653dc92
2 changed files with 117 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
import pytest
from webdriver.bidi.modules.input import Actions, get_element_origin
pytestmark = pytest.mark.asyncio
async def test_click_in_display_none_frame(
bidi_session, top_context, get_element, inline
):
frame_url = inline(
"""
<button>click to hide</button>
<script type="text/javascript">
const btn = document.querySelector('button');
btn.addEventListener('click', ev => {
window.parent.postMessage("test");
});
</script>
"""
)
url = inline(
f"""
<div id="content">
<iframe src='{frame_url}'></iframe>
</div>
<script>
window.addEventListener("message", ev => {{
document.querySelector("iframe").style.display = "none";
}}, false);
</script>
"""
)
await bidi_session.browsing_context.navigate(
context=top_context["context"],
url=url,
wait="complete",
)
all_contexts = await bidi_session.browsing_context.get_tree(
root=top_context["context"]
)
frame_context = all_contexts[0]["children"][0]
button = await get_element("button", context=frame_context)
actions = Actions()
(
actions.add_pointer()
.pointer_move(x=0, y=0, origin=get_element_origin(button))
.pointer_down(button=0)
.pointer_up(button=0)
.pause(100)
)
# Firefox bug:
# - the click will hide the iframe via display none
# - the last bit of performActions tries to wait for animationFrame in the
# iframe browsing context, but since it's hidden there won't be any and
# we never resolve
# Note that the pause(100) is not strictly necessary to reproduce the issue
# but it makes it fail consistently. Otherwise it's very much intermittent.
await bidi_session.input.perform_actions(
actions=actions, context=frame_context["context"]
)

View File

@@ -0,0 +1,51 @@
import pytest
pytestmark = pytest.mark.asyncio
async def test_click_in_display_none_frame(session, inline):
frame_url = inline(
"""
<button>click to hide</button>
<script type="text/javascript">
const btn = document.querySelector('button');
btn.addEventListener('click', ev => {
window.parent.postMessage("test");
});
</script>
"""
)
url = inline(
f"""
<div id="content">
<iframe src='{frame_url}'></iframe>
</div>
<script>
window.addEventListener("message", ev => {{
document.querySelector("iframe").style.display = "none";
}}, false);
</script>
"""
)
session.url = url
frame = session.find.css("iframe", all=False)
session.switch_frame(frame)
button = session.find.css("button", all=False)
mouse_chain = session.actions.sequence(
"pointer", "pointer_id", {"pointerType": "mouse"}
)
# Firefox bug:
# - the click will hide the iframe via display none
# - the last bit of performActions tries to wait for animationFrame in the
# iframe browsing context, but since it's hidden there won't be any and
# we never resolve
# Note that the pause(100) is not strictly necessary to reproduce the issue
# but it makes it fail consistently. Otherwise it's very much intermittent.
mouse_chain.pointer_move(0, 0, origin=button).pointer_down().pointer_up().pause(
100
).perform()