Skip to content

Commit

Permalink
[test] Cleanup make_reftest part 2. NFC
Browse files Browse the repository at this point in the history
Avoid including/inlining browser_reporting.js in the middle of
reftest.js.
  • Loading branch information
sbc100 committed Sep 25, 2024
1 parent a0fc53c commit f657328
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
21 changes: 3 additions & 18 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2191,7 +2191,6 @@ def run_browser(self, html_file, expected=None, message=None, timeout=None, extr
def make_reftest(self, expected, manually_trigger=False):
# make sure the pngs used here have no color correction, using e.g.
# pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB infile outfile
reporting = read_file(test_file('browser_reporting.js'))
shutil.copyfile(expected, 'expected.png')
create_file('reftest.js', '''
function doReftest() {
Expand Down Expand Up @@ -2239,30 +2238,16 @@ def make_reftest(self, expected, manually_trigger=False):
}
// floor, to allow some margin of error for antialiasing
var wrong = Math.floor(total / (img.width*img.height*3));
function reportResult(result) {
// If the main JS file is in a worker, or modularize, then we need to supply our own
// reporting logic.
if (typeof reportResultToServer === 'undefined') {
(() => {
%s
reportResultToServer(result);
})();
} else {
reportResultToServer(result);
}
}
var rebaseline = %s;
if (wrong || rebaseline) {
// Generate a png of the actual rendered image and send it back
// to the server.
Module.canvas.toBlob((blob) => {
sendFileToServer('actual.png', blob);
reportResult(wrong);
reportResultToServer(wrong);
})
} else {
reportResult(wrong);
reportResultToServer(wrong);
}
};
actualImage.src = actualUrl;
Expand Down Expand Up @@ -2311,7 +2296,7 @@ def make_reftest(self, expected, manually_trigger=False):
}
setupRefTest();
''' % (reporting, EMTEST_REBASELINE, int(manually_trigger)))
''' % (EMTEST_REBASELINE, int(manually_trigger)))

def compile_btest(self, filename, args, reporting=Reporting.FULL):
# Inject support code for reporting results. This adds an include a header so testcases can
Expand Down
4 changes: 3 additions & 1 deletion test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,9 +852,11 @@ def test_sdl_canvas(self, args):

def post_manual_reftest(self):
assert os.path.exists('reftest.js')
shutil.copyfile(test_file('browser_reporting.js'), 'browser_reporting.js')
html = read_file('test.html')
html = html.replace('</body>', '''
<script src="reftest.js"/>
<script src="browser_reporting.js"></script>
<script src="reftest.js"></script>
<script>
var windowClose = window.close;
window.close = () => {
Expand Down

0 comments on commit f657328

Please sign in to comment.