mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-26 19:32:06 -05:00
LibWeb: Add a test for mouse{over,out,enter,leave} events
This commit is contained in:
parent
4ae2eaead1
commit
0652d159cf
5 changed files with 83 additions and 0 deletions
13
Tests/LibWeb/Text/expected/UIEvents/mouse-events.txt
Normal file
13
Tests/LibWeb/Text/expected/UIEvents/mouse-events.txt
Normal file
|
@ -0,0 +1,13 @@
|
|||
> move pointer over #inner
|
||||
mouseover target.id=(inner) currentTarget.id=(inner)
|
||||
mouseover target.id=(inner) currentTarget.id=(outer)
|
||||
mouseenter target.id=(inner) currentTarget.id=(inner)
|
||||
mouseenter target.id=(outer) currentTarget.id=(outer)
|
||||
> move pointer over #outer
|
||||
mouseout target.id=(inner) currentTarget.id=(inner)
|
||||
mouseout target.id=(inner) currentTarget.id=(outer)
|
||||
mouseleave target.id=(inner) currentTarget.id=(inner)
|
||||
mouseover target.id=(outer) currentTarget.id=(outer)
|
||||
> click document.body
|
||||
mouseout target.id=(outer) currentTarget.id=(outer)
|
||||
mouseleave target.id=(outer) currentTarget.id=(outer)
|
62
Tests/LibWeb/Text/input/UIEvents/mouse-events.html
Normal file
62
Tests/LibWeb/Text/input/UIEvents/mouse-events.html
Normal file
|
@ -0,0 +1,62 @@
|
|||
<!DOCTYPE html>
|
||||
<style>
|
||||
body {
|
||||
margin: 0px;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
#outer {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
background-color: yellowgreen;
|
||||
}
|
||||
|
||||
#inner {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
background-color: magenta;
|
||||
}
|
||||
</style>
|
||||
<div id="outer"><div id="inner"></div></div>
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
function handleMouseOver(e) {
|
||||
println(`mouseover target.id=(${e.target.id}) currentTarget.id=(${e.currentTarget.id})`);
|
||||
}
|
||||
function handleMouseOut(e) {
|
||||
println(`mouseout target.id=(${e.target.id}) currentTarget.id=(${e.currentTarget.id})`);
|
||||
}
|
||||
function handleMouseEnter(e) {
|
||||
println(`mouseenter target.id=(${e.target.id}) currentTarget.id=(${e.currentTarget.id})`);
|
||||
}
|
||||
function handleMouseLeave(e) {
|
||||
println(`mouseleave target.id=(${e.target.id}) currentTarget.id=(${e.currentTarget.id})`);
|
||||
}
|
||||
|
||||
outer.onmouseover = handleMouseOver;
|
||||
outer.onmouseout = handleMouseOut;
|
||||
outer.onmouseenter = handleMouseEnter;
|
||||
outer.onmouseleave = handleMouseLeave;
|
||||
|
||||
inner.onmouseover = handleMouseOver;
|
||||
inner.onmouseout = handleMouseOut;
|
||||
inner.onmouseenter = handleMouseEnter;
|
||||
inner.onmouseleave = handleMouseLeave;
|
||||
|
||||
const clickOnBody = () => {
|
||||
return new Promise(resolve => {
|
||||
document.body.onclick = () => { resolve(); };
|
||||
internals.click(1, 1);
|
||||
});
|
||||
}
|
||||
|
||||
asyncTest(async done => {
|
||||
println("> move pointer over #inner");
|
||||
internals.movePointerTo(10, 10);
|
||||
println("> move pointer over #outer");
|
||||
internals.movePointerTo(60, 60);
|
||||
println("> click document.body");
|
||||
await clickOnBody();
|
||||
done();
|
||||
});
|
||||
</script>
|
|
@ -83,6 +83,12 @@ void Internals::click(double x, double y)
|
|||
page.handle_mouseup({ x, y }, { x, y }, 1, 0, 0);
|
||||
}
|
||||
|
||||
void Internals::move_pointer_to(double x, double y)
|
||||
{
|
||||
auto& page = global_object().browsing_context()->page();
|
||||
page.handle_mousemove({ x, y }, { x, y }, 0, 0);
|
||||
}
|
||||
|
||||
void Internals::wheel(double x, double y, double delta_x, double delta_y)
|
||||
{
|
||||
auto& page = global_object().browsing_context()->page();
|
||||
|
|
|
@ -26,6 +26,7 @@ public:
|
|||
void commit_text();
|
||||
|
||||
void click(double x, double y);
|
||||
void move_pointer_to(double x, double y);
|
||||
void wheel(double x, double y, double delta_x, double delta_y);
|
||||
|
||||
WebIDL::ExceptionOr<bool> dispatch_user_activated_event(DOM::EventTarget&, DOM::Event& event);
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
undefined commitText();
|
||||
|
||||
undefined click(double x, double y);
|
||||
undefined movePointerTo(double x, double y);
|
||||
undefined wheel(double x, double y, double deltaX, double deltaY);
|
||||
|
||||
boolean dispatchUserActivatedEvent(EventTarget target, Event event);
|
||||
|
|
Loading…
Add table
Reference in a new issue