Skip to content

Commit 004d96c

Browse files
authored
Update test_html5_fullscreen. NFC (#23797)
1 parent 63df1a1 commit 004d96c

File tree

1 file changed

+27
-32
lines changed

1 file changed

+27
-32
lines changed

test/test_html5_fullscreen.c

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,14 @@
55
* found in the LICENSE file.
66
*/
77

8+
#include <assert.h>
89
#include <stdio.h>
910
#include <emscripten.h>
1011
#include <string.h>
1112
#include <emscripten/html5.h>
1213
#include <GLES2/gl2.h>
1314
#include <math.h>
1415

15-
void report_result(int result) {
16-
if (result == 0) {
17-
printf("Test successful!\n");
18-
} else {
19-
printf("Test failed!\n");
20-
}
21-
#ifdef REPORT_RESULT
22-
REPORT_RESULT(result);
23-
#endif
24-
}
25-
2616
static inline const char *emscripten_event_type_to_string(int eventType) {
2717
const char *events[] = { "(invalid)", "(none)", "keypress", "keydown", "keyup", "click", "mousedown", "mouseup", "dblclick", "mousemove", "wheel", "resize",
2818
"scroll", "blur", "focus", "focusin", "focusout", "deviceorientation", "devicemotion", "orientationchange", "fullscreenchange", "pointerlockchange",
@@ -47,12 +37,14 @@ const char *emscripten_result_to_string(EMSCRIPTEN_RESULT result) {
4737
return "Unknown EMSCRIPTEN_RESULT!";
4838
}
4939

50-
#define TEST_RESULT(x) if (ret != EMSCRIPTEN_RESULT_SUCCESS) printf("%s returned %s.\n", #x, emscripten_result_to_string(ret));
40+
#define TEST_RESULT(x) if (ret != EMSCRIPTEN_RESULT_SUCCESS) { \
41+
printf("%s returned %s.\n", #x, emscripten_result_to_string(ret)); \
42+
assert(false && #x); \
43+
}
5144

5245
// The event handler functions can return 1 to suppress the event and disable the default action. That calls event.preventDefault();
5346
// Returning 0 signals that the event was not consumed by the code, and will allow the event to pass on and bubble up normally.
54-
bool key_callback(int eventType, const EmscriptenKeyboardEvent *e, void *userData)
55-
{
47+
bool key_callback(int eventType, const EmscriptenKeyboardEvent *e, void *userData) {
5648
if (eventType == EMSCRIPTEN_EVENT_KEYPRESS && (!strcmp(e->key, "f") || e->which == 102)) {
5749
EmscriptenFullscreenChangeEvent fsce;
5850
EMSCRIPTEN_RESULT ret = emscripten_get_fullscreen_status(&fsce);
@@ -71,8 +63,7 @@ bool key_callback(int eventType, const EmscriptenKeyboardEvent *e, void *userDat
7163
fprintf(stderr, "Fullscreen exit did not work!\n");
7264
}
7365
}
74-
}
75-
else if (eventType == EMSCRIPTEN_EVENT_KEYPRESS && (!strcmp(e->key, "Esc") || !strcmp(e->key, "Escape") || e->which == 27)) {
66+
} else if (eventType == EMSCRIPTEN_EVENT_KEYPRESS && (!strcmp(e->key, "Esc") || !strcmp(e->key, "Escape") || e->which == 27)) {
7667
emscripten_exit_soft_fullscreen();
7768
}
7869
return 0;
@@ -81,20 +72,24 @@ bool key_callback(int eventType, const EmscriptenKeyboardEvent *e, void *userDat
8172
int callCount = 0;
8273

8374
bool fullscreenchange_callback(int eventType, const EmscriptenFullscreenChangeEvent *e, void *userData) {
84-
printf("%s, isFullscreen: %d, fullscreenEnabled: %d, fs element nodeName: \"%s\", fs element id: \"%s\". New size: %dx%d pixels. Screen size: %dx%d pixels.\n",
85-
emscripten_event_type_to_string(eventType), e->isFullscreen, e->fullscreenEnabled, e->nodeName, e->id, e->elementWidth, e->elementHeight, e->screenWidth, e->screenHeight);
75+
printf("%s, isFullscreen: %d, fullscreenEnabled: %d, fs element nodeName: "
76+
"'%s', fs element id: '%s'. New size: %dx%d pixels. Screen size: "
77+
"%dx%d pixels.\n",
78+
emscripten_event_type_to_string(eventType),
79+
e->isFullscreen,
80+
e->fullscreenEnabled,
81+
e->nodeName,
82+
e->id,
83+
e->elementWidth,
84+
e->elementHeight,
85+
e->screenWidth,
86+
e->screenHeight);
8687

8788
++callCount;
8889
if (callCount == 1) { // Transitioned to fullscreen.
89-
if (!e->isFullscreen) {
90-
report_result(1);
91-
}
90+
assert(e->isFullscreen);
9291
} else if (callCount == 2) { // Transitioned to windowed, we must be back to the default pixel size 300x150.
93-
if (e->isFullscreen || e->elementWidth != 300 || e->elementHeight != 150) {
94-
report_result(1);
95-
} else {
96-
report_result(0);
97-
}
92+
assert(!e->isFullscreen);
9893
}
9994
return 0;
10095
}
@@ -122,7 +117,7 @@ bool on_canvassize_changed(int eventType, const void *reserved, void *userData)
122117
int w, h;
123118
emscripten_get_canvas_element_size("#canvas", &w, &h);
124119
double cssW, cssH;
125-
emscripten_get_element_css_size(0, &cssW, &cssH);
120+
emscripten_get_element_css_size("#canvas", &cssW, &cssH);
126121
printf("Canvas resized: WebGL RTT size: %dx%d, canvas CSS size: %02gx%02g\n", w, h, cssW, cssH);
127122
return 0;
128123
}
@@ -134,7 +129,7 @@ void requestFullscreen(int scaleMode, int canvasResolutionScaleMode, int filteri
134129
s.canvasResolutionScaleMode = canvasResolutionScaleMode;
135130
s.filteringMode = filteringMode;
136131
s.canvasResizedCallback = on_canvassize_changed;
137-
EMSCRIPTEN_RESULT ret = emscripten_request_fullscreen_strategy(0, 1, &s);
132+
EMSCRIPTEN_RESULT ret = emscripten_request_fullscreen_strategy("#canvas", 1, &s);
138133
TEST_RESULT(requestFullscreen);
139134
}
140135

@@ -145,12 +140,13 @@ void enterSoftFullscreen(int scaleMode, int canvasResolutionScaleMode, int filte
145140
s.canvasResolutionScaleMode = canvasResolutionScaleMode;
146141
s.filteringMode = filteringMode;
147142
s.canvasResizedCallback = on_canvassize_changed;
148-
EMSCRIPTEN_RESULT ret = emscripten_enter_soft_fullscreen(0, &s);
143+
EMSCRIPTEN_RESULT ret = emscripten_enter_soft_fullscreen("#canvas", &s);
149144
TEST_RESULT(enterSoftFullscreen);
150145
}
151146

152-
int on_button_click(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) {
153-
switch((long)userData) {
147+
bool on_button_click(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) {
148+
printf("on_button_click: %ld\n", (long)userData);
149+
switch ((long)userData) {
154150
case 0: requestFullscreen(EMSCRIPTEN_FULLSCREEN_SCALE_DEFAULT, EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_NONE, EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT); break;
155151
case 1: requestFullscreen(EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH, EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_STDDEF, EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT); break;
156152
case 2: requestFullscreen(EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH, EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_HIDEF, EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT); break;
@@ -247,7 +243,6 @@ int main() {
247243
emscripten_set_click_callback("#b16", (void*)16, 1, on_button_click);
248244

249245
printf("To finish this test, press f to enter fullscreen mode, and then exit it.\n");
250-
printf("On IE, press a mouse key over the canvas after pressing f to activate the fullscreen request event.\n");
251246

252247
emscripten_set_main_loop(draw, 0, 0);
253248
return 0;

0 commit comments

Comments
 (0)