diff options
author | Jukka Jylänki <jujjyl@gmail.com> | 2014-03-14 11:26:19 +0200 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2014-03-14 11:26:19 +0200 |
commit | a564e870359a576ad42531bb39a279db12bd5b2b (patch) | |
tree | 45625d0e9e6727dbe759101a45258e0bf59c6f10 | |
parent | fb0b19e4c5dbf53f61ddfd02ce480ac97aee20d8 (diff) |
Add an automated version of the html5 mouse test in browser test suite.
-rw-r--r-- | tests/test_browser.py | 5 | ||||
-rw-r--r-- | tests/test_html5_mouse.c | 42 |
2 files changed, 37 insertions, 10 deletions
diff --git a/tests/test_browser.py b/tests/test_browser.py index d5949709..f0343669 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -1790,6 +1790,11 @@ Module["preRun"].push(function () { print opts self.btest(path_from_root('tests', 'test_html5.c'), args=opts, expected='0') + def test_html5_mouse(self): + for opts in [[], ['-O2', '-g1', '--closure', '1']]: + print opts + self.btest(path_from_root('tests', 'test_html5_mouse.c'), args=opts + ['-DAUTOMATE_SUCCESS=1'], expected='0') + def test_codemods(self): for opt_level in [0, 2]: print 'opt level', opt_level diff --git a/tests/test_html5_mouse.c b/tests/test_html5_mouse.c index f0596718..e73211c4 100644 --- a/tests/test_html5_mouse.c +++ b/tests/test_html5_mouse.c @@ -62,17 +62,22 @@ void instruction() EM_BOOL mouse_callback(int eventType, const EmscriptenMouseEvent *e, void *userData) { - /* printf("%s, screen: (%ld,%ld), client: (%ld,%ld),%s%s%s%s button: %hu, buttons: %hu, movement: (%ld,%ld), canvas: (%ld,%ld)\n", emscripten_event_type_to_string(eventType), e->screenX, e->screenY, e->clientX, e->clientY, e->ctrlKey ? " CTRL" : "", e->shiftKey ? " SHIFT" : "", e->altKey ? " ALT" : "", e->metaKey ? " META" : "", e->button, e->buttons, e->movementX, e->movementY, e->canvasX, e->canvasY); -*/ - if (eventType == EMSCRIPTEN_EVENT_CLICK) gotClick = 1; - if (eventType == EMSCRIPTEN_EVENT_MOUSEDOWN) gotMouseDown = 1; - if (eventType == EMSCRIPTEN_EVENT_MOUSEUP) gotMouseUp = 1; - if (eventType == EMSCRIPTEN_EVENT_DBLCLICK) gotDblClick = 1; - if (eventType == EMSCRIPTEN_EVENT_MOUSEMOVE && (e->movementX != 0 || e->movementY != 0)) gotMouseMove = 1; + + if (e->screenX != 0 && e->screenY != 0 && e->clientX != 0 && e->clientY != 0 && e->canvasX != 0 && e->canvasY != 0) + { + if (e->buttons != 0) + { + if (eventType == EMSCRIPTEN_EVENT_CLICK) gotClick = 1; + if (eventType == EMSCRIPTEN_EVENT_MOUSEDOWN) gotMouseDown = 1; + if (eventType == EMSCRIPTEN_EVENT_DBLCLICK) gotDblClick = 1; + } + if (eventType == EMSCRIPTEN_EVENT_MOUSEUP) gotMouseUp = 1; + if (eventType == EMSCRIPTEN_EVENT_MOUSEMOVE && (e->movementX != 0 || e->movementY != 0)) gotMouseMove = 1; + } instruction(); return 0; @@ -80,14 +85,13 @@ EM_BOOL mouse_callback(int eventType, const EmscriptenMouseEvent *e, void *userD EM_BOOL wheel_callback(int eventType, const EmscriptenWheelEvent *e, void *userData) { - /* printf("%s, screen: (%ld,%ld), client: (%ld,%ld),%s%s%s%s button: %hu, buttons: %hu, canvas: (%ld,%ld), delta:(%g,%g,%g), deltaMode:%lu\n", emscripten_event_type_to_string(eventType), e->mouse.screenX, e->mouse.screenY, e->mouse.clientX, e->mouse.clientY, e->mouse.ctrlKey ? " CTRL" : "", e->mouse.shiftKey ? " SHIFT" : "", e->mouse.altKey ? " ALT" : "", e->mouse.metaKey ? " META" : "", e->mouse.button, e->mouse.buttons, e->mouse.canvasX, e->mouse.canvasY, (float)e->deltaX, (float)e->deltaY, (float)e->deltaZ, e->deltaMode); -*/ - if (e->deltaY != 0.f) + + if (e->deltaY > 0.f || e->deltaY < 0.f) gotWheel = 1; instruction(); @@ -110,6 +114,24 @@ int main() ret = emscripten_set_wheel_callback(0, 0, 1, wheel_callback); TEST_RESULT(emscripten_set_wheel_callback); +#ifdef AUTOMATE_SUCCESS + EM_ASM( + function sendEvent(type, data) { + var event = document.createEvent('Event'); + event.initEvent(type, true, true); + for(var d in data) event[d] = data[d]; + window.dispatchEvent(event); + } + sendEvent('click', { screenX: 1, screenY: 1, clientX: 1, clientY: 1, button: 0, buttons: 1 }); + sendEvent('mousedown', { screenX: 1, screenY: 1, clientX: 1, clientY: 1, button: 0, buttons: 1 }); + sendEvent('mouseup', { screenX: 1, screenY: 1, clientX: 1, clientY: 1, button: 0, buttons: 0 }); + sendEvent('dblclick', { screenX: 1, screenY: 1, clientX: 1, clientY: 1, button: 0, buttons: 1 }); + sendEvent('mousemove', { screenX: 1, screenY: 1, clientX: 1, clientY: 1, button: 0, buttons: 0, movementX: 1, movementY: 1 }); + sendEvent('wheel', { screenX: 1, screenY: 1, clientX: 1, clientY: 1, button: 0, buttons: 0, deltaX: 1, deltaY: 1, deltaZ: 1, deltaMode: 1 }); + sendEvent('mousewheel', { screenX: 1, screenY: 1, clientX: 1, clientY: 1, button: 0, buttons: 0, wheelDeltaX: 1, wheelDeltaY: 1 }); + ); +#endif + /* For the events to function, one must either call emscripten_set_main_loop or enable Module.noExitRuntime by some other means. Otherwise the application will exit after leaving main(), and the atexit handlers will clean up all event hooks (by design). */ EM_ASM(Module['noExitRuntime'] = true); |