-
-
Notifications
You must be signed in to change notification settings - Fork 836
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add avm2/edittext_autosize_lazy_bounds_events test
This test verifies lazy autozise bounds behavior in relation to various events.
- Loading branch information
Showing
4 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
143 changes: 143 additions & 0 deletions
143
tests/tests/swfs/avm2/edittext_autosize_lazy_bounds_events/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,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); | ||
}); | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
tests/tests/swfs/avm2/edittext_autosize_lazy_bounds_events/output.txt
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 @@ | ||
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 |
Binary file not shown.
1 change: 1 addition & 0 deletions
1
tests/tests/swfs/avm2/edittext_autosize_lazy_bounds_events/test.toml
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 @@ | ||
num_ticks = 4 |