Commit a68aaed6 authored by Jérome Perrin's avatar Jérome Perrin

ui_test_core: fix verifyImageMatchSnapshot with multiple images

The counter was not managed properly, it was never increased, so when
there was more than one assertion, they were all using the same
reference image.

Implement also the TODO that prevented to re-run a test.
parent 7d3c55e2
...@@ -132,15 +132,17 @@ Selenium.prototype.assertElementPositionRangeTop = function(locator, range){ ...@@ -132,15 +132,17 @@ Selenium.prototype.assertElementPositionRangeTop = function(locator, range){
}; };
// a memo test pathname => image counter // a memo test pathname => image counter
// TODO: reset this on testSuite.reset(), because we cannot re-run a test. var imageMatchReference = new Map();
imageMatchReference = new Map(); // reset this when starting a new test.
var HtmlTestRunnerControlPanel_reset = window['HtmlTestRunnerControlPanel'].prototype.reset;
window['HtmlTestRunnerControlPanel'].prototype.reset = function() {
imageMatchReference.clear();
return HtmlTestRunnerControlPanel_reset.call(this);
}
function getReferenceImageCounter(testPathName) { function getReferenceImageCounter(testPathName) {
var counter = imageMatchReference.get(testPathName); var counter = imageMatchReference.get(testPathName) || 0;
if (counter !== undefined) { counter = counter + 1;
return counter;
}
counter = imageMatchReference.size + 1;
imageMatchReference.set(testPathName, counter); imageMatchReference.set(testPathName, counter);
return counter; return counter;
} }
...@@ -180,7 +182,6 @@ function generateElement(tagName, childList, attributeDict, textContent) { ...@@ -180,7 +182,6 @@ function generateElement(tagName, childList, attributeDict, textContent) {
* *
* @param {string} referenceImageURL relative URL of the reference image * @param {string} referenceImageURL relative URL of the reference image
* @param {string} newImageData the new image data, base64 encoded * @param {string} newImageData the new image data, base64 encoded
* @param {Map<string,any>?} attributeDict attributes
* @return {Promise<string>} the base64 encoded html form * @return {Promise<string>} the base64 encoded html form
*/ */
function generateUpdateForm(referenceImageURL, newImageData) { function generateUpdateForm(referenceImageURL, newImageData) {
...@@ -316,6 +317,7 @@ Selenium.prototype.doVerifyImageMatchSnapshot = ( ...@@ -316,6 +317,7 @@ Selenium.prototype.doVerifyImageMatchSnapshot = (
}, },
e => { e => {
// fetching reference was not found, return empty image instead, it will be different // fetching reference was not found, return empty image instead, it will be different
// (unless the tolerance is too high)
return document.createElement('canvas').toDataURL(); return document.createElement('canvas').toDataURL();
} }
) )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment