Skip to content

Commit

Permalink
web: Fix enter key's keyCode, + test
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinnerbone authored and torokati44 committed Nov 13, 2023
1 parent 1bb96d8 commit b1cbdc4
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions web/packages/selfhosted/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"ruffle-core": "^0.1.0"
},
"devDependencies": {
"webdriverio": "^8.20.4",
"@wdio/cli": "^8.20.5",
"json5": "^2.2.3",
"webpack": "^5.89.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package {
import flash.display.MovieClip;
import flash.events.KeyboardEvent;

public class Test extends MovieClip {
public function Test() {
text.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
text.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);

// Magic phrase is expected by "playAndMonitor", tells the test that it's ready
trace("Hello from Flash!");
}

function onKeyDown(event: KeyboardEvent) {
trace("onKeyDown");
trace("event.charCode = " + event.charCode);
trace("event.keyCode = " + event.keyCode);
trace("");
}

function onKeyUp(event: KeyboardEvent) {
trace("onKeyUp");
trace("event.charCode = " + event.charCode);
trace("event.keyCode = " + event.keyCode);
trace("");
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const { jsApiBefore, getTraceOutput } = require("../../utils");
const { use, expect } = require("chai");
const chaiHtml = require("chai-html");
const { Key } = require("webdriverio");

use(chaiHtml);

describe("Key up and down events work", () => {
jsApiBefore("/test/integration_tests/keyboard_input/test.swf");

it("'a' key is recognised", async () => {
const player = await browser.$("<ruffle-player>");
await player.click();

await browser.keys("a");
const actualOutput = await getTraceOutput(browser, player);
expect(actualOutput).to.eql(
`onKeyDown
event.charCode = 97
event.keyCode = 65
onKeyUp
event.charCode = 97
event.keyCode = 65
`,
);
});

it("enter key is recognised", async () => {
const player = await browser.$("<ruffle-player>");
await player.click();

await browser.keys([Key.Enter]);
const actualOutput = await getTraceOutput(browser, player);
expect(actualOutput).to.eql(
`onKeyDown
event.charCode = 13
event.keyCode = 13
onKeyUp
event.charCode = 13
event.keyCode = 13
`,
);
});
});
Binary file not shown.
1 change: 1 addition & 0 deletions web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,7 @@ fn web_key_to_codepoint(key: &str) -> Option<char> {
match key {
"Backspace" => Some(8 as char),
"Delete" => Some(127 as char),
"Enter" => Some(13 as char),
_ => None,
}
}
Expand Down

0 comments on commit b1cbdc4

Please sign in to comment.