Skip to content

Commit 60d0620

Browse files
committed
tests: Add avm2/edittext_autosize_lazy_bounds_events test
This test verifies lazy autozise bounds behavior in relation to various events.
1 parent 126062a commit 60d0620

File tree

4 files changed

+209
-0
lines changed

4 files changed

+209
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
package {
2+
import flash.display.Sprite;
3+
import flash.display.DisplayObject;
4+
import flash.text.TextField;
5+
import flash.text.TextFormat;
6+
import flash.events.Event;
7+
import flash.utils.setTimeout;
8+
9+
public class Test extends Sprite {
10+
private var desc: String = null;
11+
private var cb: Function = null;
12+
private var currentFrame: int = 0;
13+
14+
public function Test() {
15+
stage.scaleMode = "noScale";
16+
17+
testRender();
18+
testEvents();
19+
20+
trace("Tests finished");
21+
}
22+
23+
private function testRender() {
24+
testBoundsUpdate("none", function(text:TextField, cb:Function) {
25+
cb();
26+
});
27+
28+
// NOTE: setTimeout with 0 time produces nondeterministic
29+
// results, make sure its > than frame time
30+
31+
testBoundsUpdate("set timeout", function(text:TextField, cb:Function) {
32+
setTimeout(cb, 100);
33+
});
34+
testBoundsUpdate("add child + set timeout", function(text:TextField, cb:Function) {
35+
addChild(text);
36+
setTimeout(cb, 100);
37+
});
38+
39+
var that = this;
40+
setTimeout(function():void {
41+
that.cb();
42+
}, 100);
43+
testBoundsUpdate("add child + set timeout before construction", function(text:TextField, cb:Function) {
44+
addChild(text);
45+
that.cb = cb;
46+
});
47+
48+
testBoundsUpdate("enter frame", function(text:TextField, cb:Function) {
49+
runEventOnce(cb, "enterFrame");
50+
});
51+
testBoundsUpdate("frame constructed", function(text:TextField, cb:Function) {
52+
runEventOnce(cb, "frameConstructed");
53+
});
54+
testBoundsUpdate("exit frame", function(text:TextField, cb:Function) {
55+
runEventOnce(cb, "exitFrame");
56+
});
57+
58+
testBoundsUpdate("add child", function(text:TextField, cb:Function) {
59+
addChild(text);
60+
cb();
61+
});
62+
testBoundsUpdate("add child + enter frame", function(text:TextField, cb:Function) {
63+
addChild(text);
64+
runEventOnce(cb, "enterFrame");
65+
});
66+
testBoundsUpdate("add child + frame constructed", function(text:TextField, cb:Function) {
67+
addChild(text);
68+
runEventOnce(cb, "frameConstructed");
69+
});
70+
testBoundsUpdate("add child + exit frame", function(text:TextField, cb:Function) {
71+
addChild(text);
72+
runEventOnce(cb, "exitFrame");
73+
});
74+
75+
testBoundsUpdate("invisible + add child + enter frame", function(text:TextField, cb:Function) {
76+
text.visible = "false";
77+
addChild(text);
78+
cb();
79+
});
80+
testBoundsUpdate("add child + invisible + enter frame", function(text:TextField, cb:Function) {
81+
addChild(text);
82+
text.visible = "false";
83+
cb();
84+
});
85+
testBoundsUpdate("add child + remove child + enter frame", function(text:TextField, cb:Function) {
86+
addChild(text);
87+
removeChild(text);
88+
runEventOnce(cb);
89+
});
90+
}
91+
92+
private function testEvents() {
93+
var test = this;
94+
var events = ["enterFrame", "frameConstructed", "exitFrame"];
95+
96+
for each (var fromEventName in events) {
97+
runEventOnce(function(): void {
98+
var fromFrame = test.currentFrame;
99+
for each (var toEventName in events) {
100+
testBoundsUpdate("event " + fromEventName + " -> " + toEventName, function(text:TextField, cb:Function) {
101+
addChild(text);
102+
runEventOnce(function():void {
103+
var toFrame = test.currentFrame;
104+
trace("// " + "event " + fromEventName + " -> " + toEventName);
105+
trace("// " + fromFrame + " -> " + toFrame);
106+
cb();
107+
}, toEventName);
108+
});
109+
}
110+
}, fromEventName);
111+
}
112+
}
113+
114+
private function runEventOnce(fun: Function, eventName: String = Event.ENTER_FRAME, target: DisplayObject = null):void {
115+
if (target == null) {
116+
target = stage;
117+
}
118+
function handler(event:Event):void {
119+
target.removeEventListener(eventName, handler);
120+
fun();
121+
}
122+
123+
target.addEventListener(eventName, handler);
124+
}
125+
126+
private function testBoundsUpdate(desc: String, fun: Function, before: Function = null):void {
127+
this.desc = desc;
128+
var text = new TextField();
129+
text.width = 100;
130+
text.height = 20;
131+
if (before != null) {
132+
before(text);
133+
}
134+
135+
text.autoSize = "center";
136+
fun(text, function():void {
137+
text.wordWrap = true;
138+
trace("Testing: " + desc);
139+
trace(" " + text.x + "," + text.y + "," + text.width + "," + text.height);
140+
});
141+
}
142+
}
143+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
Testing: none
2+
0,0,100,4
3+
Testing: add child
4+
0,0,100,4
5+
Testing: invisible + add child + enter frame
6+
0,0,100,4
7+
Testing: add child + invisible + enter frame
8+
0,0,100,4
9+
Tests finished
10+
Testing: frame constructed
11+
0,0,100,4
12+
Testing: add child + frame constructed
13+
0,0,100,4
14+
Testing: exit frame
15+
0,0,100,4
16+
Testing: add child + exit frame
17+
0,0,100,4
18+
// event exitFrame -> exitFrame
19+
// 0 -> 0
20+
Testing: event exitFrame -> exitFrame
21+
0,0,100,4
22+
Testing: enter frame
23+
0,0,100,4
24+
Testing: add child + enter frame
25+
48,0,4,4
26+
Testing: add child + remove child + enter frame
27+
0,0,100,4
28+
// event exitFrame -> exitFrame
29+
// 0 -> 0
30+
Testing: event exitFrame -> enterFrame
31+
48,0,4,4
32+
// event exitFrame -> exitFrame
33+
// 0 -> 0
34+
Testing: event exitFrame -> enterFrame
35+
48,0,4,4
36+
// event exitFrame -> exitFrame
37+
// 0 -> 0
38+
Testing: event exitFrame -> frameConstructed
39+
48,0,4,4
40+
// event exitFrame -> exitFrame
41+
// 0 -> 0
42+
Testing: event exitFrame -> frameConstructed
43+
48,0,4,4
44+
// event exitFrame -> exitFrame
45+
// 0 -> 0
46+
Testing: event exitFrame -> frameConstructed
47+
0,0,100,4
48+
// event exitFrame -> exitFrame
49+
// 0 -> 0
50+
Testing: event exitFrame -> exitFrame
51+
48,0,4,4
52+
// event exitFrame -> exitFrame
53+
// 0 -> 0
54+
Testing: event exitFrame -> exitFrame
55+
0,0,100,4
56+
// event exitFrame -> exitFrame
57+
// 0 -> 0
58+
Testing: event exitFrame -> enterFrame
59+
48,0,4,4
60+
Testing: set timeout
61+
0,0,100,4
62+
Testing: add child + set timeout
63+
48,0,4,4
64+
Testing: add child + set timeout before construction
65+
48,0,4,4
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
num_ticks = 4

0 commit comments

Comments
 (0)