Skip to content

Commit

Permalink
Add test for findCanvasEventTarget's various cases
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeOsborn committed Nov 21, 2024
1 parent b3b5ca6 commit d89f1dd
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/library_html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ var LibraryHTML5 = {
// If not found, if one is querying by using DOM tag name selector 'canvas', grab the first
// OffscreenCanvas that we can find.
|| (target == 'canvas' && Object.values(GL.offscreenCanvases)[0])
// If that is not found either, query via the regular DOM selector.
// If that is not found either, query via the regular findEventTarget mechanism.
|| findEventTarget(target);
},
#else
Expand Down
36 changes: 36 additions & 0 deletions test/browser/html5_special_canvas_event_targets.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2024 The Emscripten Authors. All rights reserved.
// Emscripten is available under two separate licenses, the MIT license and the
// University of Illinois/NCSA Open Source License. Both these licenses can be
// found in the LICENSE file.

#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <assert.h>

#include <emscripten/emscripten.h>
#include <emscripten/html5.h>

const char *TARGETS[]={"!foovas", "#canvas", "canvas"};
const char *target = TARGETS[WHICH_TARGET];

int main()
{
EM_ASM({
specialHTMLTargets["!foovas"] = Module.canvas;
});
int w=0, h=0;
EMSCRIPTEN_RESULT res = emscripten_get_canvas_element_size(target, &w, &h);
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
EmscriptenWebGLContextAttributes attrs;
emscripten_webgl_init_context_attributes(&attrs);
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context(target, &attrs);
assert(context > 0);
res = emscripten_webgl_make_context_current(context);
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
assert(emscripten_webgl_get_current_context() == context);
res = emscripten_get_canvas_element_size(target, &w, &h);
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
res = emscripten_webgl_destroy_context(context);
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
return 0;
}
12 changes: 12 additions & 0 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2618,6 +2618,18 @@ def test_html5_webgl_create_context2(self):
def test_html5_special_event_targets(self):
self.btest_exit('html5_special_event_targets.cpp', args=['-lGL'])

@parameterized({
'': ([],),
'offscreen_no_pthread': (['-sOFFSCREENCANVAS_SUPPORT'],),
'offscreen_pthread': (['-sOFFSCREENCANVAS_SUPPORT', '-sPROXY_TO_PTHREAD', '-pthread'],),
})
@requires_graphics_hardware
# Verify bug https://github.com/emscripten-core/emscripten/issues/22942: findCanvasEventTarget doesn't use specialHTMLTargets
def test_html5_special_canvas_event_targets(self, args):
self.btest_exit('html5_special_canvas_event_targets.cpp', args=args + ['-lGL', '-sDISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1', '-DWHICH_TARGET=0'])
self.btest_exit('html5_special_canvas_event_targets.cpp', args=args + ['-lGL', '-sDISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1', '-DWHICH_TARGET=1'])
self.btest_exit('html5_special_canvas_event_targets.cpp', args=args + ['-lGL', '-sDISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1', '-DWHICH_TARGET=2'])

@requires_graphics_hardware
def test_html5_webgl_destroy_context(self):
for opts in ([], ['-O2', '-g1'], ['-sFULL_ES2']):
Expand Down

0 comments on commit d89f1dd

Please sign in to comment.