From 60d0620c1120a0973c619a3b4fa5780a0777bd69 Mon Sep 17 00:00:00 2001 From: Kamil Jarosz Date: Thu, 5 Dec 2024 21:24:05 +0100 Subject: [PATCH] tests: Add avm2/edittext_autosize_lazy_bounds_events test This test verifies lazy autozise bounds behavior in relation to various events. --- .../Test.as | 143 ++++++++++++++++++ .../output.txt | 65 ++++++++ .../test.swf | Bin 0 -> 2608 bytes .../test.toml | 1 + 4 files changed, 209 insertions(+) create mode 100644 tests/tests/swfs/avm2/edittext_autosize_lazy_bounds_events/Test.as create mode 100644 tests/tests/swfs/avm2/edittext_autosize_lazy_bounds_events/output.txt create mode 100644 tests/tests/swfs/avm2/edittext_autosize_lazy_bounds_events/test.swf create mode 100644 tests/tests/swfs/avm2/edittext_autosize_lazy_bounds_events/test.toml diff --git a/tests/tests/swfs/avm2/edittext_autosize_lazy_bounds_events/Test.as b/tests/tests/swfs/avm2/edittext_autosize_lazy_bounds_events/Test.as new file mode 100644 index 0000000000000..ac05ed2acfafd --- /dev/null +++ b/tests/tests/swfs/avm2/edittext_autosize_lazy_bounds_events/Test.as @@ -0,0 +1,143 @@ +package { +import flash.display.Sprite; +import flash.display.DisplayObject; +import flash.text.TextField; +import flash.text.TextFormat; +import flash.events.Event; +import flash.utils.setTimeout; + +public class Test extends Sprite { + private var desc: String = null; + private var cb: Function = null; + private var currentFrame: int = 0; + + public function Test() { + stage.scaleMode = "noScale"; + + testRender(); + testEvents(); + + trace("Tests finished"); + } + + private function testRender() { + testBoundsUpdate("none", function(text:TextField, cb:Function) { + cb(); + }); + + // NOTE: setTimeout with 0 time produces nondeterministic + // results, make sure its > than frame time + + testBoundsUpdate("set timeout", function(text:TextField, cb:Function) { + setTimeout(cb, 100); + }); + testBoundsUpdate("add child + set timeout", function(text:TextField, cb:Function) { + addChild(text); + setTimeout(cb, 100); + }); + + var that = this; + setTimeout(function():void { + that.cb(); + }, 100); + testBoundsUpdate("add child + set timeout before construction", function(text:TextField, cb:Function) { + addChild(text); + that.cb = cb; + }); + + testBoundsUpdate("enter frame", function(text:TextField, cb:Function) { + runEventOnce(cb, "enterFrame"); + }); + testBoundsUpdate("frame constructed", function(text:TextField, cb:Function) { + runEventOnce(cb, "frameConstructed"); + }); + testBoundsUpdate("exit frame", function(text:TextField, cb:Function) { + runEventOnce(cb, "exitFrame"); + }); + + testBoundsUpdate("add child", function(text:TextField, cb:Function) { + addChild(text); + cb(); + }); + testBoundsUpdate("add child + enter frame", function(text:TextField, cb:Function) { + addChild(text); + runEventOnce(cb, "enterFrame"); + }); + testBoundsUpdate("add child + frame constructed", function(text:TextField, cb:Function) { + addChild(text); + runEventOnce(cb, "frameConstructed"); + }); + testBoundsUpdate("add child + exit frame", function(text:TextField, cb:Function) { + addChild(text); + runEventOnce(cb, "exitFrame"); + }); + + testBoundsUpdate("invisible + add child + enter frame", function(text:TextField, cb:Function) { + text.visible = "false"; + addChild(text); + cb(); + }); + testBoundsUpdate("add child + invisible + enter frame", function(text:TextField, cb:Function) { + addChild(text); + text.visible = "false"; + cb(); + }); + testBoundsUpdate("add child + remove child + enter frame", function(text:TextField, cb:Function) { + addChild(text); + removeChild(text); + runEventOnce(cb); + }); + } + + private function testEvents() { + var test = this; + var events = ["enterFrame", "frameConstructed", "exitFrame"]; + + for each (var fromEventName in events) { + runEventOnce(function(): void { + var fromFrame = test.currentFrame; + for each (var toEventName in events) { + testBoundsUpdate("event " + fromEventName + " -> " + toEventName, function(text:TextField, cb:Function) { + addChild(text); + runEventOnce(function():void { + var toFrame = test.currentFrame; + trace("// " + "event " + fromEventName + " -> " + toEventName); + trace("// " + fromFrame + " -> " + toFrame); + cb(); + }, toEventName); + }); + } + }, fromEventName); + } + } + + private function runEventOnce(fun: Function, eventName: String = Event.ENTER_FRAME, target: DisplayObject = null):void { + if (target == null) { + target = stage; + } + function handler(event:Event):void { + target.removeEventListener(eventName, handler); + fun(); + } + + target.addEventListener(eventName, handler); + } + + private function testBoundsUpdate(desc: String, fun: Function, before: Function = null):void { + this.desc = desc; + var text = new TextField(); + text.width = 100; + text.height = 20; + if (before != null) { + before(text); + } + + text.autoSize = "center"; + fun(text, function():void { + text.wordWrap = true; + trace("Testing: " + desc); + trace(" " + text.x + "," + text.y + "," + text.width + "," + text.height); + }); + } +} +} diff --git a/tests/tests/swfs/avm2/edittext_autosize_lazy_bounds_events/output.txt b/tests/tests/swfs/avm2/edittext_autosize_lazy_bounds_events/output.txt new file mode 100644 index 0000000000000..fba1989b549dd --- /dev/null +++ b/tests/tests/swfs/avm2/edittext_autosize_lazy_bounds_events/output.txt @@ -0,0 +1,65 @@ +Testing: none + 0,0,100,4 +Testing: add child + 0,0,100,4 +Testing: invisible + add child + enter frame + 0,0,100,4 +Testing: add child + invisible + enter frame + 0,0,100,4 +Tests finished +Testing: frame constructed + 0,0,100,4 +Testing: add child + frame constructed + 0,0,100,4 +Testing: exit frame + 0,0,100,4 +Testing: add child + exit frame + 0,0,100,4 +// event exitFrame -> exitFrame +// 0 -> 0 +Testing: event exitFrame -> exitFrame + 0,0,100,4 +Testing: enter frame + 0,0,100,4 +Testing: add child + enter frame + 48,0,4,4 +Testing: add child + remove child + enter frame + 0,0,100,4 +// event exitFrame -> exitFrame +// 0 -> 0 +Testing: event exitFrame -> enterFrame + 48,0,4,4 +// event exitFrame -> exitFrame +// 0 -> 0 +Testing: event exitFrame -> enterFrame + 48,0,4,4 +// event exitFrame -> exitFrame +// 0 -> 0 +Testing: event exitFrame -> frameConstructed + 48,0,4,4 +// event exitFrame -> exitFrame +// 0 -> 0 +Testing: event exitFrame -> frameConstructed + 48,0,4,4 +// event exitFrame -> exitFrame +// 0 -> 0 +Testing: event exitFrame -> frameConstructed + 0,0,100,4 +// event exitFrame -> exitFrame +// 0 -> 0 +Testing: event exitFrame -> exitFrame + 48,0,4,4 +// event exitFrame -> exitFrame +// 0 -> 0 +Testing: event exitFrame -> exitFrame + 0,0,100,4 +// event exitFrame -> exitFrame +// 0 -> 0 +Testing: event exitFrame -> enterFrame + 48,0,4,4 +Testing: set timeout + 0,0,100,4 +Testing: add child + set timeout + 48,0,4,4 +Testing: add child + set timeout before construction + 48,0,4,4 diff --git a/tests/tests/swfs/avm2/edittext_autosize_lazy_bounds_events/test.swf b/tests/tests/swfs/avm2/edittext_autosize_lazy_bounds_events/test.swf new file mode 100644 index 0000000000000000000000000000000000000000..4d18765db54527ac0220db4be3c381aa439ef3fe GIT binary patch literal 2608 zcmV-03eWXJS5qlp5dZ*q0hO1{Qya+@z`N%|Er}5b1LDh=!Dx+v0SO6XgKbvWSlDZ? z?KRlm-FTKAG(Bk6(ny&Z0Zvk0homaWCOPGlL#jCCnm-|@9CAs?-rDRTw_LI}Px22q zuUj7oyS7qs)r|V}`@Pq%-+SF-4v_Rugu4HT&=5xJy+a70FZ=$55xU}<*2;tRyn0YB zIo=9LSEq`;UtLM1_V@Sa_p|dAcQ>`Lyu6%BXHuEW91wHfGsia$<{WQwYLz=!r(VIe ztG-=vROZmwsnqrCCVP5-n55_fiY<3*g8stXLJdZ1}52wOXnDdI2!qa_YkIq>o!z*4%9fQoqxBU`bU8@>}B31JxdZ4Zyn{&89FxEVdbG5lk z3oPahZq4K37M&cktJZc(wpXNXYn{!CICXbXG9)rxR;8Me{{7<76#!O0v zvs*KE=_+-$A8vA=?J2$k!>6n3w4h$l)J!_F*a(+RUP-accT}P|1I1lM-SOJ+-FtKQ z*ETmF-+Qo*>OIf_C;qL+zZ0*Z>%yBiZ$6ERpbEhw#h?B)3tfWHpZ+HN{&z6?OLU8R zKKgV2f4UK38ZO4sJQ6@~B`(HNP{GTW*?8XYWY32U5vQ_QFiJGyvG<1+lSX~eKcJ3D zT|T_A$C^R*U86v|nXRWe@a{o}657DDUljK@0x%3Y-z!q3-xe=$7MC*r9Ll(FQnr zQh&n9>4uK-%&hPPF}>kKue;J-#WoeU=J5G@PJu=tfz-{rMw!Mf_J$xl->nsVNFhD2 zeXf!%qvTPtXM6TeiFUcPT-l>MEy{64l4;4QI5f^?uCX5X9#)~xX%}Qx^&6=jgmk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KS*0t$esEMWP+Dwi#g=}4$&4ru7QeD$>k*2Ux*XDB3rm$Mq z=5t+5;aXiw<&>t7uWRXCtSQ{CYYVyVrf|QmWpX`D;bC3N=HgA^(+z~9?7z*YL_twL zc#SWhU5I#B@3nfZQ-|LKML1%YwB;kc&+0qUE+6UrR{s${ayHZG1J(eWe%YA&LQmXD zz+rd_dF&GmmUc1?m^2F2x4OXq4uCWKhIP!{0)%Ls2t!NPi)T{;m&MLxi0TFsdsz@eEQme?e+ng_MWe~r_&VAH+kJi58rDaw5q;De&7Xz~`|OcFb>Q; z7M8hfHfFkF>`}eDq#>bgn&`YVg0ou*G2sw)h8j zVxPD7_yh4dFUPxE+(OS`pBP?Ggy+GRbqE|A=YtoJ2R-yb2pyKC;HMyzq@-z_3l1B@ zeq$>585@dfAN;8r{G5+XhONQH@e59Ax-lL6k`1BPL6aL=;}^wmAxdcy;R!UxdUytj z@PQme5<(*aeD{{?>;nMpsi&=UT3@gh()zeHp4Kx~Caq_!Y+6rQDgOExjq!iQd9Wa` S_efv+Z{8gIz58Da$o~1x{r(F8 literal 0 HcmV?d00001 diff --git a/tests/tests/swfs/avm2/edittext_autosize_lazy_bounds_events/test.toml b/tests/tests/swfs/avm2/edittext_autosize_lazy_bounds_events/test.toml new file mode 100644 index 0000000000000..7cfc6eecb6364 --- /dev/null +++ b/tests/tests/swfs/avm2/edittext_autosize_lazy_bounds_events/test.toml @@ -0,0 +1 @@ +num_ticks = 4