From 8daa6728bb1b19130f35059da49a94de74d9500d Mon Sep 17 00:00:00 2001 From: Kamil Jarosz Date: Fri, 20 Dec 2024 23:57:40 +0100 Subject: [PATCH] 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. --- .../mouse_wheel_avm2/Test.as | 65 +++++++++++++++ .../mouse_wheel_avm2/index.html | 15 ++++ .../mouse_wheel_avm2/test.swf | Bin 0 -> 1542 bytes .../mouse_wheel_avm2/test.ts | 75 ++++++++++++++++++ 4 files changed, 155 insertions(+) create mode 100644 web/packages/selfhosted/test/integration_tests/mouse_wheel_avm2/Test.as create mode 100644 web/packages/selfhosted/test/integration_tests/mouse_wheel_avm2/index.html create mode 100644 web/packages/selfhosted/test/integration_tests/mouse_wheel_avm2/test.swf create mode 100644 web/packages/selfhosted/test/integration_tests/mouse_wheel_avm2/test.ts diff --git a/web/packages/selfhosted/test/integration_tests/mouse_wheel_avm2/Test.as b/web/packages/selfhosted/test/integration_tests/mouse_wheel_avm2/Test.as new file mode 100644 index 0000000000000..d83fe9b62b4df --- /dev/null +++ b/web/packages/selfhosted/test/integration_tests/mouse_wheel_avm2/Test.as @@ -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; + } + } +} diff --git a/web/packages/selfhosted/test/integration_tests/mouse_wheel_avm2/index.html b/web/packages/selfhosted/test/integration_tests/mouse_wheel_avm2/index.html new file mode 100644 index 0000000000000..256bb4f118252 --- /dev/null +++ b/web/packages/selfhosted/test/integration_tests/mouse_wheel_avm2/index.html @@ -0,0 +1,15 @@ + + + + + mouse_wheel + + + + +
+ +
+ + + diff --git a/web/packages/selfhosted/test/integration_tests/mouse_wheel_avm2/test.swf b/web/packages/selfhosted/test/integration_tests/mouse_wheel_avm2/test.swf new file mode 100644 index 0000000000000000000000000000000000000000..8b1e37ef6c4e0c6ce51070275bd4d68955a6cc4b GIT binary patch literal 1542 zcmV+h2Ko6zS5qlP2><|i0fkjvZ`;TfogpcXDEUK*ZP}K;WLt^rttC;E<6SF`HmYT9 zk|s?N?KVXL!Jx>Y#V$<>BxN~IP4f#{^sz7bCw(f=zR5PW`v;1}zM1=8z`Yzgw$(gT zz>H?@J?G4snXAz$B142GKOi)RQ6oK%5cv6(N%xQh#Uy?)0s zy)Jb>uG4Z1f1tXspwqW?=9Cd{fgw$Esp>obm-G=9QY_Uz>Z?bzM(x9IT1@jM#CD+i zwAP?nPLa2uDch0XFuGR?kN(b8Tu0z`YiJ_Xpa0dX!msPC)|*$a8)!HQB{1@7q<-Z0 z&^~u{b@jUh4=E9vkoxwY6(|#gu0G8C@D~{UJ@Ga5eDt^J?;#&%*ffQTh`ajZe+WV^ z1Qr=D!7V;|6po9khgICc8a5@H4q83e^eH}NLXgW>wpXt&L)D!QEo#njsotuT6j|OW zb^4~|oAx-n`=V}oJxhI?h-N-L^~a(iJqasmb_7*@>71B!-!gmCqw&Z=el*yKq+fM@ zPc?tvfeJTm>aL7}p4mQiRn0d~Xarms&5wvIM!CpZ^&oT@=2agm)x~dP15@|AVwajn zT|e>C>3fu6k}qF<(>geO^Yq~0#kl6!UjLZB=~8NyQ>v~r$P3f+DY%P6V83fx`Up;u zzJ`Non$*(M$Du4^AJ}TgqPo~|T%EeoaUYJ=f-MT+DaOK4BId*1D0$(iI@MP}#q&#H z7h_vkU^2ODM|!Tjl{6n zrrcF+-J($}#*PAeVsxGHBUkNpP0f=!^vJZEre(!-R~@{D>m=0H!$5|KK>eM-52kuk zi?fG^N6w+|9O~3CZ8Lm#4!hLq@jb`m%e!TvT&`>jWo1VhyK6uwZ!0@O`JtjnH2NMWQuDWl9t{-*l))|)2(g)H;ivb^}wqy|sQCr*`0g)eXKq+>Xi$Z)e< zJee8GjAth1a297Lv#D%4doMeco#s-QOzNm!b}QU*)2n8fD@ zKTm|Lw15e}NQ5OqmZcRe<*>Ahr8P|O8sYPV-z5ANiOWP(2wx%mHsK!}N{vHc;ks$Z#nB1>UVfdjxF{S`FHl zO)fM0)zfEq_c_ddi5Hh73E^1!2^s^XcpY&VC+mpE+(I1*n8$S#!vefaB3^7@#KTSr z!dOc1L-{KR^RYzouiQ_3kQmC)o}o)XCogdfPhDb>TeyThuLsFt6QlRv1!HGyZ?))P^$@uf_#5vOP?42qgz)K>hp< zN;zvzqs^cKV1Wbh9DpB2;D^BufQwA*bI8YHkbeUC-7sH9)u7tWJkOwaneT!}XU1#+ zH|N0J9t`s+kKiC+)6IEdGk6T4W)_yIojrxWET{(Q%b^TPgrfGcu`IV&j1{?^Gjei! s)mW9=YsQ+~&KMcFy<{x0?zdgJE_2~_5P0Vv4D?gdr|r~m)} literal 0 HcmV?d00001 diff --git a/web/packages/selfhosted/test/integration_tests/mouse_wheel_avm2/test.ts b/web/packages/selfhosted/test/integration_tests/mouse_wheel_avm2/test.ts new file mode 100644 index 0000000000000..18c760bfab064 --- /dev/null +++ b/web/packages/selfhosted/test/integration_tests/mouse_wheel_avm2/test.ts @@ -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.$(""); + 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); + }); +});