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 Oct 2, 2024
1 parent 649e86a commit c4bdcb1
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 @@ -2207,7 +2207,6 @@ def run_browser(self, html_file, expected=None, message=None, timeout=None, extr
def make_reftest(self, expected):
# 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.copy(expected, 'expected.png')
create_file('reftest.js', '''
function doReftest() {
Expand Down Expand Up @@ -2256,30 +2255,16 @@ def make_reftest(self, expected):
}
// 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 @@ -2314,7 +2299,7 @@ def make_reftest(self, expected):
}
setupRefTest();
''' % (reporting, EMTEST_REBASELINE))
''' % EMTEST_REBASELINE)

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 @@ -856,9 +856,11 @@ def test_sdl_canvas(self, args):

def post_manual_reftest(self):
assert os.path.exists('reftest.js')
shutil.copy(test_file('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 c4bdcb1

Please sign in to comment.