Skip to content
Open
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
23 changes: 23 additions & 0 deletions test/browser/test_glfw_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,27 @@ static void on_error(int error, const char *msg) {
}
#endif

void test_text_input() {
EM_ASM({
// Create an input element, add it to the DOM, and focus on it.
input = document.createElement("input");
document.body.appendChild(input);

// When sent to an input element, backspace and tab are treated like any
// other key. TODO: this is not yet functional, see
// https://github.com/emscripten-core/emscripten/pull/22879
// After that lands, the two "!" here can be removed.
assert( simulateKeyEvent("keydown", 65, 65, 'A', input));
assert(!simulateKeyEvent("keydown", 8, 8, "Backspace", input));
assert(!simulateKeyEvent("keydown", 9, 9, "Tab", input));

// When sent anywhere else, backspace and tab are preventDefaulted.
assert( simulateKeyEvent("keydown", 65, 65, 'A'));
assert(!simulateKeyEvent("keydown", 8, 8, "Backspace"));
assert(!simulateKeyEvent("keydown", 9, 9, "Tab"));
});
}

int main() {
unsigned int success = (1 << (sizeof(g_tests) / sizeof(test_t))) - 1; // (2^count)-1;

Expand Down Expand Up @@ -235,6 +256,8 @@ int main() {
}
}

test_text_input();

glfwTerminate();

printf("%d == %d = %d", g_state, success, g_state == success);
Expand Down
23 changes: 23 additions & 0 deletions test/browser/test_sdl_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,33 @@ void one() {
#endif
}

void test_text_input() {
EM_ASM({
// Create an input element, add it to the DOM, and focus on it.
input = document.createElement("input");
document.body.appendChild(input);

// When sent to an input element, backspace and tab are treated like any
// other key. TODO: this is not yet functional, see
// https://github.com/emscripten-core/emscripten/pull/22879
// After that lands, the two "!" here can be removed.
assert( simulateKeyEvent("keydown", 65, 65, 'A', input));
assert(!simulateKeyEvent("keydown", 8, 8, "Backspace", input));
assert(!simulateKeyEvent("keydown", 9, 9, "Tab", input));

// When sent anywhere else, backspace and tab are preventDefaulted.
assert( simulateKeyEvent("keydown", 65, 65, 'A'));
assert(!simulateKeyEvent("keydown", 8, 8, "Backspace"));
assert(!simulateKeyEvent("keydown", 9, 9, "Tab"));
});
}

int main(int argc, char **argv) {
SDL_Init(SDL_INIT_VIDEO);
SDL_Surface *screen = SDL_SetVideoMode(600, 450, 32, SDL_HWSURFACE);

test_text_input();

#ifdef TEST_EMSCRIPTEN_SDL_SETEVENTHANDLER
emscripten_SDL_SetEventHandler(EventHandler, 0);
#endif
Expand Down
Loading