Skip to content

Commit

Permalink
web: Add mouse_wheel_avm2 integration test
Browse files Browse the repository at this point in the history
This test verifies how scrolling works in AVM2 and whether
the page is scrolled when it should be or not.
  • Loading branch information
kjarosh committed Dec 20, 2024
1 parent 7769572 commit 8daa672
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package {
import flash.display.*;
import flash.text.*;
import flash.events.*;

[SWF(width="800", height="400")]
public class Test extends MovieClip {
private var text: TextField;

public function Test() {
var a = newSprite()
a.x = 0;
a.y = 0;
a.width = 200;
a.height = 400;
a.addEventListener(MouseEvent.MOUSE_WHEEL, consumeWheel1);
addChild(a);

var b = newSprite()
b.x = 400;
b.y = 0;
b.width = 200;
b.height = 400;
b.addEventListener(MouseEvent.MOUSE_WHEEL, consumeWheel2);
addChild(b);

var c = new TextField();
c.mouseWheelEnabled = true;
c.border = true;
c.x = 200;
c.y = 0;
c.width = 200;
c.height = 400;
c.multiline = true;
for (var i = 0; i < 100; ++ i) {
c.text += "line\n";
}
addChild(c);
text = c;

trace("Loaded!");
}

function consumeWheel1(event: MouseEvent) {
trace("Wheel consumed 1, vscroll: " + text.scrollV);
}

function consumeWheel2(event: MouseEvent) {
trace("Wheel consumed 2, vscroll: " + text.scrollV);
event.preventDefault();
}

function handleScroll(event: Event) {
trace("Scrolled");
}

private function newSprite(): Sprite {
var s:Sprite = new Sprite();
s.graphics.beginFill(0xFF00FF);
s.graphics.drawRect(0, 0, 200, 400);
s.graphics.endFill();
return s;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<html>

<head>
<title>mouse_wheel</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<body>
<div>
<object type="application/x-shockwave-flash" data="test.swf" width="800" height="400" id="objectElement"></object>
</div>
</body>

</html>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import {
getTraceOutput,
hideHardwareAccelerationModal,
injectRuffleAndWait,
openTest,
playAndMonitor,
} from "../../utils.js";
import { expect, use } from "chai";
import chaiHtml from "chai-html";

use(chaiHtml);

async function scroll(
browser: WebdriverIO.Browser,
player: ChainablePromiseElement,
x: number,
y: number,
lines: number) {
const canvas = await player.shadow$("canvas");

return await browser.execute((element, x, y, lines) => {
const el = element as unknown as HTMLElement;
el.dispatchEvent(new PointerEvent("pointermove", {
clientX: x,
clientY: y,
}));
return el.dispatchEvent(new WheelEvent("wheel", {
deltaY: lines,
deltaMode: WheelEvent.DOM_DELTA_LINE,
cancelable: true,
}));
}, canvas, x, y, lines);
}

describe("Mouse Wheel AVM2", () => {
it("load the test", async () => {
await openTest(browser, "integration_tests/mouse_wheel");
await injectRuffleAndWait(browser);
const player = await browser.$("<ruffle-object>");
await playAndMonitor(browser, player, "Loaded!\n");
await hideHardwareAccelerationModal(browser, player);
});

it("scroll the first clip", async () => {
const player = await browser.$("#objectElement");

expect(await scroll(browser, player, 100, 100, 1)).to.equal(false);

expect(await getTraceOutput(browser, player)).to.equal(
"Wheel consumed 1, vscroll: 1\n",
);
});

it("scroll the text field", async () => {
const player = await browser.$("#objectElement");

expect(await scroll(browser, player, 300, 100, 1)).to.equal(false);
});

it("scroll the second clip", async () => {
const player = await browser.$("#objectElement");

expect(await scroll(browser, player, 500, 100, 1)).to.equal(false);

expect(await getTraceOutput(browser, player)).to.equal(
"Wheel consumed 2, vscroll: 2\n",
);
});

it("scroll non-interactive content", async () => {
const player = await browser.$("#objectElement");

expect(await scroll(browser, player, 700, 100, 1)).to.equal(true);
});
});

0 comments on commit 8daa672

Please sign in to comment.