Picture analyzer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
71 KiB

var expect = chai.expect;
var people_src =
'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAcEBAQFBAcFBQcKBwUHCgwJBwcJDA0LCwwLCw0RDQ0NDQ0NEQ0PEBEQDw0UFBYWFBQeHR0dHiIiIiIiIiIiIiL/2wBDAQgHBw0MDRgQEBgaFREVGiAgICAgICAgICAgICAhICAgICAgISEhICAgISEhISEhISEiIiIiIiIiIiIiIiIiIiL/wAARCAH0AfQDAREAAhEBAxEB/8QAHAABAAEFAQEAAAAAAAAAAAAAAAECBQYHCAQD/8QAXRAAAQMDAQQCCgkOCgkDBQAAAAECAwQFEQYHEiExE0EIFBUiMlFhcYGRI0JSU3KSobHBFhckMzZDVGJzgpPC0dI0VWNkdKKjsrPiGCUmZZSkw+PwN4PhNUR10/H/xAAaAQEBAAMBAQAAAAAAAAAAAAAAAQIEBQMG/8QAOREBAAECBAMFBgUEAgIDAAAAAAECAwQFERITITEVMkFRoSIzYWJx4RYjUoGxFJHB8ELRNHIGNYL/2gAMAwEAAhEDEQA/AOkQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
function request_success() {
return new Promise(function(resolve, reject) {
resemble('../demoassets/People.jpg')
.compareTo('../demoassets/People2.jpg')
.onComplete(function(data) {
console.info('Reached oncomplete for request_success');
expect(data.diffBounds).to.have.all.keys(
'bottom',
'left',
'top',
'right'
);
expect(data.diffBounds.bottom).to.equal(431);
expect(data.diffBounds.left).to.equal(22);
expect(data.diffBounds.right).to.equal(450);
expect(data.diffBounds.top).to.equal(58);
expect(data.dimensionDifference.height).to.equal(0);
expect(data.dimensionDifference.width).to.equal(0);
expect(data.isSameDimensions).to.be.true;
expect(data.misMatchPercentage).to.equal('8.63');
resolve();
});
});
}
function base64_string() {
return new Promise(function(resolve, reject) {
resemble(people_src).compareTo(people2_src).onComplete(function(data) {
console.info('Reached oncomplete for base64_string');
expect(data.diffBounds.bottom).to.equal(431);
expect(data.diffBounds.left).to.equal(22);
expect(data.diffBounds.right).to.equal(450);
expect(data.diffBounds.top).to.equal(58);
expect(data.dimensionDifference.height).to.equal(0);
expect(data.dimensionDifference.width).to.equal(0);
expect(data.isSameDimensions).to.be.true;
expect(data.misMatchPercentage).to.equal('8.63');
resolve();
});
});
}
function request_404() {
return new Promise(function(resolve, reject) {
resemble('../demoassets/People.jpg')
.compareTo('../demoassets/404-image.jpg')
.onComplete(function(data) {
console.info('Reached oncomplete for request_404');
console.log(data);
expect(data).to.deep.equal({ error: 'Image load error.' });
resolve();
});
});
}
function request_cors() {
return new Promise(function(resolve, reject) {
resemble('../demoassets/People.jpg')
.compareTo(
'https://www.google.ca/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'
)
.onComplete(function(data) {
console.info('Reached oncomplete for request_cors');
expect(data).to.deep.equal({ error: 'Image load error.' });
resolve();
});
});
}
request_success()
.then(function() {
console.info('Test 1 complete.');
})
.then(request_404)
.then(function() {
console.info('Test 2 complete.');
})
.then(request_success)
.then(function() {
console.info('Test 3 complete.');
})
.then(request_404)
.then(function() {
console.info('Test 4 complete.');
})
.then(base64_string)
.then(function() {
console.info('Test 5 complete.');
})
// Not going to bother fixing this test
// .then(request_cors)
// .then(function() {
// console.info('Test 6 complete.');
// })
.then(function() {
console.info('All tests completed.');
});