-
-
Notifications
You must be signed in to change notification settings - Fork 828
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/focus_events_mixed_key_mouse test
This test verifies the behavior of focus-related events when changing focus using keyboard and mouse interchangeably.
- Loading branch information
Showing
6 changed files
with
277 additions
and
0 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
tests/tests/swfs/avm2/focus_events_mixed_key_mouse/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,98 @@ | ||
package { | ||
|
||
import flash.display.DisplayObject; | ||
import flash.display.InteractiveObject; | ||
import flash.display.MovieClip; | ||
import flash.display.Sprite; | ||
import flash.events.Event; | ||
import flash.events.KeyboardEvent; | ||
import flash.events.MouseEvent; | ||
|
||
[SWF(width="300", height="200")] | ||
public class Test extends MovieClip { | ||
private var sprite1: Sprite; | ||
private var sprite2: Sprite; | ||
private var sprite3: Sprite; | ||
|
||
private var logDirty: Boolean = true; | ||
|
||
public function Test() { | ||
super(); | ||
|
||
sprite1 = newSprite(0xFF0000); | ||
sprite1.name = "sprite1"; | ||
sprite1.x = 0; | ||
sprite1.y = 100; | ||
sprite1.tabEnabled = true; | ||
sprite1.tabIndex = 1; | ||
sprite2 = newSprite(0x00FF00); | ||
sprite2.name = "sprite2"; | ||
sprite2.x = 100; | ||
sprite2.y = 100; | ||
sprite2.tabEnabled = true; | ||
sprite2.tabIndex = 2; | ||
sprite3 = newSprite(0x0000FF); | ||
sprite3.name = "sprite3"; | ||
sprite3.x = 200; | ||
sprite3.y = 100; | ||
sprite3.tabEnabled = true; | ||
|
||
stage.addChild(sprite1); | ||
stage.addChild(sprite2); | ||
stage.addChild(sprite3); | ||
|
||
stage.addEventListener("keyDown", function(evt:KeyboardEvent):void { | ||
if (evt.keyCode == 27 && logDirty) { | ||
logDirty = false; | ||
trace("Escape pressed"); | ||
} | ||
if (evt.keyCode == 9) { | ||
trace("Tab pressed"); | ||
} | ||
}); | ||
|
||
function eventListener(obj: InteractiveObject): Function { | ||
return function(evt: Event): void { | ||
var str; | ||
if (evt is MouseEvent) { | ||
str = evt.formatToString( | ||
"MouseEvent", "type", "cancelable", "eventPhase", | ||
"relatedObject", "ctrlKey", "altKey", "shiftKey"); | ||
} else { | ||
str = evt.toString(); | ||
} | ||
trace(" " + obj.name + ", " + evt.target.name + ": " + str + ", focus: " + objectToString(stage.focus)); | ||
logDirty = true; | ||
} | ||
} | ||
|
||
for each (var obj: InteractiveObject in [ | ||
sprite1, sprite2, sprite3, | ||
stage | ||
]) { | ||
obj.addEventListener("focusIn", eventListener(obj)); | ||
obj.addEventListener("focusOut", eventListener(obj)); | ||
obj.addEventListener("mouseDown", eventListener(obj)); | ||
obj.addEventListener("mouseUp", eventListener(obj)); | ||
obj.addEventListener("click", eventListener(obj)); | ||
obj.addEventListener("mouseFocusChange", eventListener(obj)); | ||
obj.addEventListener("keyFocusChange", eventListener(obj)); | ||
obj.addEventListener("rollOut", eventListener(obj)); | ||
obj.addEventListener("rollOver", eventListener(obj)); | ||
obj.addEventListener("mouseOver", eventListener(obj)); | ||
} | ||
} | ||
|
||
private function objectToString(obj: DisplayObject): String { | ||
return "" + obj + ((obj != null) ? " (" + obj.name + ")" : ""); | ||
} | ||
|
||
private function newSprite(color: int): Sprite { | ||
var s:Sprite = new Sprite(); | ||
s.graphics.beginFill(color); | ||
s.graphics.drawRect(0, 0, 100, 100); | ||
s.graphics.endFill(); | ||
return s; | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
tests/tests/swfs/avm2/focus_events_mixed_key_mouse/input.json
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,42 @@ | ||
[ | ||
{ "type": "KeyDown", "key_code": 9 }, | ||
{ "type": "KeyUp", "key_code": 9 }, | ||
{ "type": "KeyDown", "key_code": 9 }, | ||
{ "type": "KeyUp", "key_code": 9 }, | ||
{ "type": "KeyDown", "key_code": 27 }, | ||
{ "type": "KeyUp", "key_code": 27 }, | ||
{ "type": "MouseMove", "pos": [1, 101] }, | ||
{ "type": "MouseDown", "pos": [1, 101], "btn": "Left" }, | ||
{ "type": "MouseUp", "pos": [1, 101], "btn": "Left" }, | ||
{ "type": "KeyDown", "key_code": 9 }, | ||
{ "type": "KeyUp", "key_code": 9 }, | ||
{ "type": "KeyDown", "key_code": 27 }, | ||
{ "type": "KeyUp", "key_code": 27 }, | ||
{ "type": "MouseMove", "pos": [101, 101] }, | ||
{ "type": "MouseDown", "pos": [101, 101], "btn": "Left" }, | ||
{ "type": "MouseUp", "pos": [101, 101], "btn": "Left" }, | ||
{ "type": "KeyDown", "key_code": 9 }, | ||
{ "type": "KeyUp", "key_code": 9 }, | ||
{ "type": "KeyDown", "key_code": 27 }, | ||
{ "type": "KeyUp", "key_code": 27 }, | ||
{ "type": "KeyDown", "key_code": 9 }, | ||
{ "type": "KeyUp", "key_code": 9 }, | ||
{ "type": "MouseMove", "pos": [101, 101] }, | ||
{ "type": "MouseDown", "pos": [101, 101], "btn": "Left" }, | ||
{ "type": "MouseUp", "pos": [101, 101], "btn": "Left" }, | ||
{ "type": "KeyDown", "key_code": 27 }, | ||
{ "type": "KeyUp", "key_code": 27 }, | ||
{ "type": "MouseMove", "pos": [201, 101] }, | ||
{ "type": "MouseDown", "pos": [201, 101], "btn": "Left" }, | ||
{ "type": "MouseUp", "pos": [201, 101], "btn": "Left" }, | ||
{ "type": "KeyDown", "key_code": 9 }, | ||
{ "type": "KeyUp", "key_code": 9 }, | ||
{ "type": "KeyDown", "key_code": 27 }, | ||
{ "type": "KeyUp", "key_code": 27 }, | ||
{ "type": "MouseMove", "pos": [1, 1] }, | ||
{ "type": "MouseDown", "pos": [1, 1], "btn": "Left" }, | ||
{ "type": "MouseUp", "pos": [1, 1], "btn": "Left" }, | ||
{ "type": "KeyDown", "key_code": 27 }, | ||
{ "type": "KeyUp", "key_code": 27 }, | ||
{ "type": "FocusLost" } | ||
] |
36 changes: 36 additions & 0 deletions
36
tests/tests/swfs/avm2/focus_events_mixed_key_mouse/input.json.py
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,36 @@ | ||
#!/usr/bin/env python3 | ||
|
||
coord_map = { | ||
'void': [1, 1], | ||
'sprite1': [1, 101], | ||
'sprite2': [101, 101], | ||
'sprite3': [201, 101], | ||
} | ||
|
||
click_seq = [ | ||
'tab', 'tab', 'esc', | ||
'sprite1', 'tab', 'esc', | ||
'sprite2', 'tab', 'esc', | ||
'tab', 'sprite2', 'esc', | ||
'sprite3', 'tab', 'esc', | ||
'void', 'esc', | ||
] | ||
|
||
print('[') | ||
|
||
for obj in click_seq: | ||
if obj == 'esc': | ||
print(f' {{ "type": "KeyDown", "key_code": 27 }},') | ||
print(f' {{ "type": "KeyUp", "key_code": 27 }},') | ||
continue | ||
if obj == 'tab': | ||
print(f' {{ "type": "KeyDown", "key_code": 9 }},') | ||
print(f' {{ "type": "KeyUp", "key_code": 9 }},') | ||
continue | ||
pos = coord_map[obj] | ||
print(f' {{ "type": "MouseMove", "pos": {pos} }},') | ||
print(f' {{ "type": "MouseDown", "pos": {pos}, "btn": "Left" }},') | ||
print(f' {{ "type": "MouseUp", "pos": {pos}, "btn": "Left" }},') | ||
|
||
print(f' {{ "type": "FocusLost" }}') | ||
print(']') |
Oops, something went wrong.