Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2191,18 +2191,16 @@ 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
basename = os.path.basename(expected)
if os.path.abspath(os.path.dirname(expected)) != self.get_dir():
shutil.copyfile(expected, self.in_dir(basename))
reporting = read_file(test_file('browser_reporting.js'))
shutil.copyfile(expected, 'expected.png')
create_file('reftest.js', '''
function doReftest() {
if (doReftest.done) return;
doReftest.done = true;
var img = new Image();
img.onload = function() {
assert(img.width == Module.canvas.width, 'Invalid width: ' + Module.canvas.width + ', should be ' + img.width);
assert(img.height == Module.canvas.height, 'Invalid height: ' + Module.canvas.height + ', should be ' + img.height);
img.onload = () => {
assert(img.width == Module.canvas.width, `Invalid width: ${Module.canvas.width}, should be ${img.width}`);
assert(img.height == Module.canvas.height, `Invalid height: ${Module.canvas.height}, should be ${img.height}`);

var canvas = document.createElement('canvas');
canvas.width = img.width;
Expand All @@ -2213,7 +2211,7 @@ def make_reftest(self, expected, manually_trigger=False):

var actualUrl = Module.canvas.toDataURL();
var actualImage = new Image();
actualImage.onload = function() {
actualImage.onload = () => {
/*
document.body.appendChild(img); // for comparisons
var div = document.createElement('div');
Expand Down Expand Up @@ -2242,7 +2240,7 @@ def make_reftest(self, expected, manually_trigger=False):
var wrong = Math.floor(total / (img.width*img.height*3)); // floor, to allow some margin of error for antialiasing
// If the main JS file is in a worker, or modularize, then we need to supply our own reporting logic.
if (typeof reportResultToServer === 'undefined') {
(function() {
(() => {
%s
reportResultToServer(wrong);
})();
Expand All @@ -2252,7 +2250,7 @@ def make_reftest(self, expected, manually_trigger=False):
};
actualImage.src = actualUrl;
}
img.src = '%s';
img.src = 'expected.png';
};

/** @suppress {uselessCode} */
Expand All @@ -2267,16 +2265,16 @@ def make_reftest(self, expected, manually_trigger=False):
// trigger reftest from RAF as well, needed for workers where there is no pre|postRun on the main thread
var realRAF = window.requestAnimationFrame;
/** @suppress{checkTypes} */
window.requestAnimationFrame = function(func) {
return realRAF(function() {
window.requestAnimationFrame = (func) => {
return realRAF(() => {
func();
realRAF(doReftest);
});
};

// trigger reftest from canvas render too, for workers not doing GL
var realWOM = worker.onmessage;
worker.onmessage = function(event) {
worker.onmessage = (event) => {
realWOM(event);
if (event.data.target === 'canvas' && event.data.op === 'render') {
realRAF(doReftest);
Expand All @@ -2290,14 +2288,12 @@ def make_reftest(self, expected, manually_trigger=False):
// The user will call it.
// Add an event loop iteration to ensure rendering, so users don't need to bother.
var realDoReftest = doReftest;
doReftest = function() {
setTimeout(realDoReftest, 1);
};
doReftest = () => setTimeout(realDoReftest, 1);
}
}

setupRefTest();
''' % (reporting, basename, int(manually_trigger)))
''' % (reporting, 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
Loading