Beging implementing reftests

This commit is contained in:
MoyuScript
2017-08-09 00:50:31 +08:00
parent 8fde015829
commit b4dfb4404f
163 changed files with 15221 additions and 14371 deletions

View File

@ -1,15 +1,30 @@
var h2cSelector, h2cOptions;
var CI = window.location.search.indexOf('selenium') !== -1;
var AUTORUN = window.location.search.indexOf('run=false') === -1;
var REFTEST = window.location.search.indexOf('reftest') !== -1;
(function(document, window) {
function appendScript(src) {
document.write('<script type="text/javascript" src="' + src + '.js?' + Math.random() + '"></script>');
document.write(
'<script type="text/javascript" src="' + src + '.js?' + Math.random() + '"></script>'
);
}
['/tests/assets/jquery-1.6.2', '/dist/html2canvas'].forEach(appendScript);
(typeof Promise === 'undefined' ? ['/node_modules/promise-polyfill/promise.min'] : [])
.concat([
'/node_modules/jquery/dist/jquery.min',
'/dist/html2canvas',
'/dist/RefTestRenderer'
])
.forEach(appendScript);
window.onload = function() {
(function( $ ){
var targets = REFTEST
? [new html2canvas.CanvasRenderer(), new RefTestRenderer()]
: new html2canvas.CanvasRenderer();
(function($) {
$.fn.html2canvas = function(options) {
if (options && options.profile && window.console && window.console.profile && window.location.search !== "?selenium2") {
if (options && options.profile && window.console && window.console.profile && !CI) {
window.console.profile();
}
var date = new Date(),
@ -19,79 +34,100 @@ var h2cSelector, h2cOptions;
options = options || {};
var promise = html2canvas(this[0], options);
promise['catch'](function(err) {
console.log("html2canvas threw an error", err);
console.log('html2canvas threw an error', err);
});
promise.then(function(canvas) {
promise.then(function(output) {
var canvas = Array.isArray(targets) ? output[0] : output;
if (Array.isArray(targets)) {
console.log(output[1]);
}
var $canvas = $(canvas),
finishTime = new Date();
if (options && options.profile && window.console && window.console.profileEnd) {
window.console.profileEnd();
}
$canvas.addClass("html2canvas")
$canvas
.addClass('html2canvas')
.css({
position: 'absolute',
left: 0,
top: 0
}).appendTo(document.body);
if (window.location.search !== "?selenium") {
})
.appendTo(document.body);
if (!CI) {
$canvas.siblings().toggle();
$(window).click(function(){
$(window).click(function() {
var scrollTop = $(window).scrollTop();
$canvas.toggle().siblings().toggle();
$(document.documentElement).css('background', $canvas.is(':visible') ? "none" : "");
$(document.body).css('background', $canvas.is(':visible') ? "none" : "");
throwMessage("Canvas Render " + ($canvas.is(':visible') ? "visible" : "hidden"));
$(document.documentElement).css(
'background',
$canvas.is(':visible') ? 'none' : ''
);
$(document.body).css(
'background',
$canvas.is(':visible') ? 'none' : ''
);
throwMessage(
'Canvas Render ' + ($canvas.is(':visible') ? 'visible' : 'hidden')
);
$(window).scrollTop(scrollTop);
});
$(document.documentElement).css('background', $canvas.is(':visible') ? "none" : "");
$(document.body).css('background', $canvas.is(':visible') ? "none" : "");
throwMessage('Screenshot created in '+ ((finishTime.getTime()-timer)) + " ms<br />",4000);
$(document.documentElement).css(
'background',
$canvas.is(':visible') ? 'none' : ''
);
$(document.body).css('background', $canvas.is(':visible') ? 'none' : '');
throwMessage(
'Screenshot created in ' + (finishTime.getTime() - timer) + ' ms<br />',
4000
);
} else {
$canvas.css('display', 'none');
}
// test if canvas is read-able
try {
$canvas[0].toDataURL();
} catch(e) {
if ($canvas[0].nodeName.toLowerCase() === "canvas") {
} catch (e) {
if ($canvas[0].nodeName.toLowerCase() === 'canvas') {
// TODO, maybe add a bit less offensive way to present this, but still something that can easily be noticed
window.alert("Canvas is tainted, unable to read data");
window.alert('Canvas is tainted, unable to read data');
}
}
});
function throwMessage(msg,duration){
function throwMessage(msg, duration) {
window.clearTimeout(timeoutTimer);
timeoutTimer = window.setTimeout(function(){
$message.fadeOut(function(){
timeoutTimer = window.setTimeout(function() {
$message.fadeOut(function() {
$message.remove();
$message = null;
});
},duration || 2000);
if ($message)
$message.remove();
$message = $('<div />').html(msg).css({
margin:0,
padding:10,
background: "#000",
opacity:0.7,
position:"fixed",
top:10,
right:10,
fontFamily: 'Tahoma',
color:'#fff',
fontSize:12,
borderRadius:12,
width:'auto',
height:'auto',
textAlign:'center',
textDecoration:'none',
display:'none'
}).appendTo(document.body).fadeIn();
console.log(msg);
}, duration || 2000);
if ($message) $message.remove();
$message = $('<div />')
.html(msg)
.css({
margin: 0,
padding: 10,
background: '#000',
opacity: 0.7,
position: 'fixed',
top: 10,
right: 10,
fontFamily: 'Tahoma',
color: '#fff',
fontSize: 12,
borderRadius: 12,
width: 'auto',
height: 'auto',
textAlign: 'center',
textDecoration: 'none',
display: 'none'
})
.appendTo(document.body)
.fadeIn();
}
};
})(jQuery);
@ -103,17 +139,24 @@ var h2cSelector, h2cOptions;
}
window.run = function() {
$(h2cSelector).html2canvas($.extend({
logging: true,
profile: true,
proxy: "http://localhost:8082",
useCORS: false,
removeContainer: false
}, h2cOptions));
$(h2cSelector).html2canvas(
$.extend(
{
logging: true,
profile: true,
proxy: 'http://localhost:8082',
useCORS: false,
removeContainer: false,
target: targets
},
h2cOptions,
REFTEST ? {windowWidth: 800, windowHeight: 600} : {}
)
);
};
if (typeof(dontRun) === "undefined") {
if (typeof dontRun === 'undefined' && AUTORUN) {
setTimeout(window.run, 100);
}
};
}(document, window));
})(document, window);