Skip to content

Commit 873dc2e

Browse files
authored
Move browser source map test to interactive tests. (#25216)
This test tries to manually launch a browser for verification. This causes issues when trying to launch a browser from headless mode over ssh. The test also doesn't launch the correct file URL in windowed mode, so I'm guessing this hasn't been checked for a very long time.
1 parent 80ca182 commit 873dc2e

File tree

2 files changed

+33
-39
lines changed

2 files changed

+33
-39
lines changed

test/test_browser.py

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import subprocess
1212
import time
1313
import unittest
14-
import webbrowser
1514
import zlib
1615
from functools import wraps
1716
from http.server import BaseHTTPRequestHandler, HTTPServer
@@ -280,44 +279,6 @@ def test_sdl1(self):
280279
def test_sdl1_es6(self):
281280
self.reftest('hello_world_sdl.c', 'htmltest.png', cflags=['-sUSE_SDL', '-lGL', '-sEXPORT_ES6'])
282281

283-
# Deliberately named as test_zzz_* to make this test the last one
284-
# as this test may take the focus away from the main test window
285-
# by opening a new window and possibly not closing it.
286-
def test_zzz_html_source_map(self):
287-
# browsers will try to 'guess' the corresponding original line if a
288-
# generated line is unmapped, so if we want to make sure that our
289-
# numbering is correct, we need to provide a couple of 'possible wrong
290-
# answers'. thus, we add some printf calls so that the cpp file gets
291-
# multiple mapped lines. in other words, if the program consists of a
292-
# single 'throw' statement, browsers may just map any thrown exception to
293-
# that line, because it will be the only mapped line.
294-
create_file('src.cpp', r'''
295-
#include <cstdio>
296-
297-
int main() {
298-
printf("Starting test\n");
299-
try {
300-
throw 42; // line 8
301-
} catch (int e) { }
302-
printf("done\n");
303-
return 0;
304-
}
305-
''')
306-
# use relative paths when calling emcc, because file:// URIs can only load
307-
# sourceContent when the maps are relative paths
308-
self.compile_btest('src.cpp', ['-o', 'src.html', '-gsource-map'])
309-
self.assertExists('src.html')
310-
self.assertExists('src.wasm.map')
311-
if not has_browser():
312-
self.skipTest('need a browser')
313-
webbrowser.open_new('file://src.html')
314-
print('''
315-
If manually bisecting:
316-
Check that you see src.cpp among the page sources.
317-
Even better, add a breakpoint, e.g. on the printf, then reload, then step
318-
through and see the print (best to run with --save-dir for the reload).
319-
''')
320-
321282
def test_emscripten_log(self):
322283
self.btest_exit('test_emscripten_log.cpp', cflags=['-Wno-deprecated-pragma', '-gsource-map'])
323284

test/test_interactive.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,39 @@ def test_audio_worklet_memory_growth(self):
350350
shutil.copy(test_file('webaudio/audio_files/emscripten-bass.mp3'), 'audio_files/')
351351
self.btest_exit('webaudio/audioworklet_memory_growth.c', cflags=['-sAUDIO_WORKLET', '-sWASM_WORKERS', '-sALLOW_MEMORY_GROWTH'])
352352

353+
def test_html_source_map(self):
354+
# browsers will try to 'guess' the corresponding original line if a
355+
# generated line is unmapped, so if we want to make sure that our
356+
# numbering is correct, we need to provide a couple of 'possible wrong
357+
# answers'. thus, we add some printf calls so that the cpp file gets
358+
# multiple mapped lines. in other words, if the program consists of a
359+
# single 'throw' statement, browsers may just map any thrown exception to
360+
# that line, because it will be the only mapped line.
361+
create_file('src.cpp', r'''
362+
#include <cstdio>
363+
364+
int main() {
365+
printf("Starting test\n");
366+
try {
367+
throw 42; // line 8
368+
} catch (int e) { }
369+
printf("done\n");
370+
return 0;
371+
}
372+
''')
373+
# use relative paths when calling emcc, because file:// URIs can only load
374+
# sourceContent when the maps are relative paths
375+
self.compile_btest('src.cpp', ['-o', 'src.html', '-gsource-map'])
376+
self.assertExists('src.html')
377+
self.assertExists('src.wasm.map')
378+
print('''
379+
If manually bisecting:
380+
Open the file with ./emrun out/test/src.html
381+
Check that you see src.cpp among the page sources.
382+
Even better, add a breakpoint, e.g. on the printf, then reload, then step
383+
through and see the print (best to run with --save-dir for the reload).
384+
''')
385+
353386

354387
class interactive64(interactive):
355388
def setUp(self):

0 commit comments

Comments
 (0)