Skip to content

Commit

Permalink
tests: Add avm2/focusrect_focuslost
Browse files Browse the repository at this point in the history
This test verifies the behavior of focus-related events when
the window focus is lost.
  • Loading branch information
kjarosh committed Jul 13, 2024
1 parent 30169d9 commit be14f68
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 0 deletions.
64 changes: 64 additions & 0 deletions tests/tests/swfs/avm2/focusrect_focuslost/Test.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package {

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="50", height="50", backgroundColor="#000000")]
public class Test extends MovieClip {
private var clip:Sprite;

public function Test() {
super();

this.clip = new Sprite();
this.clip.x = 15;
this.clip.y = 15;
this.clip.graphics.beginFill(0xFF00FF);
this.clip.graphics.drawRect(0, 0, 20, 20);
this.clip.name = "clip";
this.clip.tabEnabled = true;
this.clip.tabIndex = 1;

this.stage.addChild(this.clip);

stage.addEventListener("keyDown", function(evt:KeyboardEvent):void {
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);
}
}

for each (var obj: InteractiveObject in [
clip, 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));
}
}
}
}
7 changes: 7 additions & 0 deletions tests/tests/swfs/avm2/focusrect_focuslost/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{ "type": "KeyDown", "key_code": 9 },
{ "type": "KeyDown", "key_code": 9 },
{ "type": "FocusLost" },
{ "type": "FocusGained" },
{ "type": "Wait" }
]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions tests/tests/swfs/avm2/focusrect_focuslost/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Tab pressed
null, null: [FocusEvent type="keyFocusChange" bubbles=true cancelable=true eventPhase=2 relatedObject=[object Sprite] shiftKey=false keyCode=9]
clip, clip: [FocusEvent type="focusIn" bubbles=true cancelable=false eventPhase=2 relatedObject=null shiftKey=false keyCode=0]
null, clip: [FocusEvent type="focusIn" bubbles=true cancelable=false eventPhase=3 relatedObject=null shiftKey=false keyCode=0]
Tab pressed
clip, clip: [FocusEvent type="keyFocusChange" bubbles=true cancelable=true eventPhase=2 relatedObject=[object Sprite] shiftKey=false keyCode=9]
null, clip: [FocusEvent type="keyFocusChange" bubbles=true cancelable=true eventPhase=3 relatedObject=[object Sprite] shiftKey=false keyCode=9]
clip, clip: [FocusEvent type="focusOut" bubbles=true cancelable=false eventPhase=2 relatedObject=null shiftKey=false keyCode=0]
null, clip: [FocusEvent type="focusOut" bubbles=true cancelable=false eventPhase=3 relatedObject=null shiftKey=false keyCode=0]
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/tests/swfs/avm2/focusrect_focuslost/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
num_ticks = 1

image_comparisons."output".trigger = 1

[player_options]
with_renderer = { optional = true, sample_count = 1 }

0 comments on commit be14f68

Please sign in to comment.