-
-
Notifications
You must be signed in to change notification settings - Fork 830
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
web: Add mouse_wheel_avm2 integration test
This test verifies how scrolling works in AVM2 and whether the page is scrolled when it should be or not.
- Loading branch information
Showing
4 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
web/packages/selfhosted/test/integration_tests/mouse_wheel_avm2/Test.as
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
web/packages/selfhosted/test/integration_tests/mouse_wheel_avm2/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+1.51 KB
web/packages/selfhosted/test/integration_tests/mouse_wheel_avm2/test.swf
Binary file not shown.
86 changes: 86 additions & 0 deletions
86
web/packages/selfhosted/test/integration_tests/mouse_wheel_avm2/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
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); | ||
}); | ||
}); |