Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web: Fix enter key + add input tests #14005

Merged
merged 4 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
40 changes: 32 additions & 8 deletions web/packages/selfhosted/test/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const path = require("path");
const { expect } = require("chai");
torokati44 marked this conversation as resolved.
Show resolved Hide resolved

async function isRuffleLoaded(browser) {
return await browser.execute(
Expand Down Expand Up @@ -75,16 +76,34 @@ async function playAndMonitor(browser, player, expectedOutput) {
expectedOutput = "Hello from Flash!\n";
}

const actualOutput = await getTraceOutput(browser, player);
expect(actualOutput).to.eql(expectedOutput);
}

async function getTraceOutput(browser, player) {
// Await any trace output
await browser.waitUntil(
async () =>
(await browser.execute(
(player) => player.__ruffle_log__,
player,
)) === expectedOutput,
async () => {
return (
(await browser.execute(
(player) => player.__ruffle_log__,
player,
)) !== ""
);
},
{
timeoutMsg: "Expected Ruffle to trace a message",
},
);

// Get the output, and replace it with an empty string for any future test
const output = await browser.execute((player) => {
const log = player.__ruffle_log__;
player.__ruffle_log__ = "";
return log;
}, player);

return output;
}

async function injectRuffleAndWait(browser) {
Expand Down Expand Up @@ -120,9 +139,13 @@ function jsApiBefore(swf) {
});

if (swf) {
await browser.execute((player) => {
player.load("/test_assets/example.swf");
}, player);
await browser.execute(
async (player, swf) => {
await player.load(swf);
},
player,
swf,
);
await playAndMonitor(browser, player);
}
});
Expand All @@ -137,4 +160,5 @@ module.exports = {
openTest,
setupErrorHandler,
jsApiBefore,
getTraceOutput,
};
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