Skip to content

Commit d89f1dd

Browse files
committed
Add test for findCanvasEventTarget's various cases
1 parent b3b5ca6 commit d89f1dd

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

src/library_html5.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ var LibraryHTML5 = {
363363
// If not found, if one is querying by using DOM tag name selector 'canvas', grab the first
364364
// OffscreenCanvas that we can find.
365365
|| (target == 'canvas' && Object.values(GL.offscreenCanvases)[0])
366-
// If that is not found either, query via the regular DOM selector.
366+
// If that is not found either, query via the regular findEventTarget mechanism.
367367
|| findEventTarget(target);
368368
},
369369
#else
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2024 The Emscripten Authors. All rights reserved.
2+
// Emscripten is available under two separate licenses, the MIT license and the
3+
// University of Illinois/NCSA Open Source License. Both these licenses can be
4+
// found in the LICENSE file.
5+
6+
#include <GLES2/gl2.h>
7+
#include <GLES2/gl2ext.h>
8+
#include <assert.h>
9+
10+
#include <emscripten/emscripten.h>
11+
#include <emscripten/html5.h>
12+
13+
const char *TARGETS[]={"!foovas", "#canvas", "canvas"};
14+
const char *target = TARGETS[WHICH_TARGET];
15+
16+
int main()
17+
{
18+
EM_ASM({
19+
specialHTMLTargets["!foovas"] = Module.canvas;
20+
});
21+
int w=0, h=0;
22+
EMSCRIPTEN_RESULT res = emscripten_get_canvas_element_size(target, &w, &h);
23+
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
24+
EmscriptenWebGLContextAttributes attrs;
25+
emscripten_webgl_init_context_attributes(&attrs);
26+
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context(target, &attrs);
27+
assert(context > 0);
28+
res = emscripten_webgl_make_context_current(context);
29+
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
30+
assert(emscripten_webgl_get_current_context() == context);
31+
res = emscripten_get_canvas_element_size(target, &w, &h);
32+
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
33+
res = emscripten_webgl_destroy_context(context);
34+
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
35+
return 0;
36+
}

test/test_browser.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2618,6 +2618,18 @@ def test_html5_webgl_create_context2(self):
26182618
def test_html5_special_event_targets(self):
26192619
self.btest_exit('html5_special_event_targets.cpp', args=['-lGL'])
26202620

2621+
@parameterized({
2622+
'': ([],),
2623+
'offscreen_no_pthread': (['-sOFFSCREENCANVAS_SUPPORT'],),
2624+
'offscreen_pthread': (['-sOFFSCREENCANVAS_SUPPORT', '-sPROXY_TO_PTHREAD', '-pthread'],),
2625+
})
2626+
@requires_graphics_hardware
2627+
# Verify bug https://github.com/emscripten-core/emscripten/issues/22942: findCanvasEventTarget doesn't use specialHTMLTargets
2628+
def test_html5_special_canvas_event_targets(self, args):
2629+
self.btest_exit('html5_special_canvas_event_targets.cpp', args=args + ['-lGL', '-sDISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1', '-DWHICH_TARGET=0'])
2630+
self.btest_exit('html5_special_canvas_event_targets.cpp', args=args + ['-lGL', '-sDISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1', '-DWHICH_TARGET=1'])
2631+
self.btest_exit('html5_special_canvas_event_targets.cpp', args=args + ['-lGL', '-sDISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1', '-DWHICH_TARGET=2'])
2632+
26212633
@requires_graphics_hardware
26222634
def test_html5_webgl_destroy_context(self):
26232635
for opts in ([], ['-O2', '-g1'], ['-sFULL_ES2']):

0 commit comments

Comments
 (0)