Update web-platform-tests to revision dc5cbf088edcdb266541d4e5a76149a2c6e716a0

This commit is contained in:
Ms2ger 2016-09-09 09:40:35 +02:00
parent 1d40075f03
commit 079092dfea
2381 changed files with 90360 additions and 17722 deletions

View file

@ -1,45 +1,119 @@
<!DOCTYPE html>
<html>
<head>
<title>CanvasRenderingContext2D imageSmoothingEnabled test</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="author" title="ShinHyunjin" href="mailto:jini7927@gmail.com">
<link rel="help" href="http://www.w3.org/html/wg/drafts/2dcontext/html5_canvas/#image-smoothing">
</head>
<body>
<div id="log"></div>
<canvas id="test_canvas_1"></canvas>
<canvas id="test_canvas_2"></canvas>
<canvas id="test_canvas_3"></canvas>
<meta charset="utf-8">
<title>CanvasRenderingContext2D imageSmoothingEnabled test</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="https://html.spec.whatwg.org/multipage/scripting.html#image-smoothing">
<script>
function createTestImage() {
var image = document.createElement('canvas');
var imgctx = image.getContext('2d');
imgctx.fillStyle = "#F00";
imgctx.fillRect(0, 0, 2, 2);
imgctx.fillStyle = "#0F0";
imgctx.fillRect(0, 0, 1, 1);
return image;
}
<script>
(function() {
test(function() {
var canvas = document.getElementById('test_canvas_1');
var ctx = canvas.getContext('2d');
test(function() {
var ctx = document.createElement('canvas').getContext('2d');
assert_true(ctx.imageSmoothingEnabled);
}, "When the canvas context is created, imageSmoothingEnabled must be set to true.");
assert_true(ctx.imageSmoothingEnabled);
}, "When the CanvasRenderingContext2D object is created, the attribute must be set to true.");
test(function() {
var ctx = document.createElement('canvas').getContext('2d');
ctx.imageSmoothingEnabled = false;
assert_false(ctx.imageSmoothingEnabled);
}, "On getting imageSmoothingEnabled, the user agent must return the last value it was set to.");
test(function() {
var canvas = document.getElementById('test_canvas_2');
var ctx = canvas.getContext('2d');
test(function() {
var ctx = document.createElement('canvas').getContext('2d');
var image = createTestImage();
ctx.scale(10, 10);
ctx.drawImage(image, 0, 0);
var pixels = ctx.getImageData(9, 9, 1, 1).data;
assert_not_equals(pixels[0], 0);
assert_not_equals(pixels[1], 255);
}, "Test that image smoothing is actually on by default and just the attribute value.");
ctx.imageSmoothingEnabled = false;
assert_false(ctx.imageSmoothingEnabled);
}, "On getting the imageSmoothingEnabled attribute, the user agent must return the last value it was set to.");
test(function() {
var ctx = document.createElement('canvas').getContext('2d');
ctx.imageSmoothingEnabled = true;
var image = createTestImage();
ctx.scale(10, 10);
ctx.drawImage(image, 0, 0);
var pixels = ctx.getImageData(9, 9, 1, 1).data;
assert_not_equals(pixels[0], 0);
assert_not_equals(pixels[1], 255);
}, "Test that image smoothing works when imageSmoothingEnabled is set to true");
test(function() {
var canvas = document.getElementById('test_canvas_3');
var ctx = canvas.getContext('2d');
test(function() {
var ctx = document.createElement('canvas').getContext('2d');
var image = createTestImage();
ctx.imageSmoothingEnabled = false;
ctx.scale(10, 10);
ctx.drawImage(image, 0, 0);
var pixels = ctx.getImageData(9, 9, 1, 1).data;
assert_array_equals(pixels, [0, 255, 0, 255]);
}, "Test that imageSmoothingEnabled = false (nearest-neighbor interpolation) works with drawImage().");
ctx.imageSmoothingEnabled = false;
assert_equals(ctx.imageSmoothingEnabled, false);
}, "On setting the imageSmoothingEnabled attribute, it must be set to the new value.");
})();
test(function() {
var ctx = document.createElement('canvas').getContext('2d');
var image = createTestImage();
ctx.imageSmoothingEnabled = false;
ctx.scale(10, 10);
ctx.fillStyle = ctx.createPattern(image, 'repeat');
ctx.fillRect(0, 0, 10, 10);
var pixels = ctx.getImageData(9, 9, 1, 1).data;
assert_array_equals(pixels, [0, 255, 0, 255]);
}, "Test that imageSmoothingEnabled = false (nearest-neighbor interpolation) works with fillRect and createPattern().");
test(function() {
var ctx = document.createElement('canvas').getContext('2d');
var image = createTestImage();
ctx.imageSmoothingEnabled = false;
ctx.fillStyle = ctx.createPattern(image, 'repeat');
ctx.scale(10, 10);
ctx.rect(0, 0, 10, 10);
ctx.fill();
var pixels = ctx.getImageData(9, 9, 1, 1).data;
assert_array_equals(pixels, [0, 255, 0, 255]);
}, "Test that imageSmoothingEnabled = false (nearest-neighbor interpolation) works with fill() and createPattern().");
</script>
</body>
</html>
test(function() {
var ctx = document.createElement('canvas').getContext('2d');
var image = createTestImage();
ctx.strokeStyle = ctx.createPattern(image, 'repeat');
ctx.lineWidth = 5;
ctx.imageSmoothingEnabled = false;
ctx.scale(10, 10);
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(10, 10);
ctx.stroke();
var pixels = ctx.getImageData(9, 9, 1, 1).data;
assert_array_equals(pixels, [0, 255, 0, 255]);
}, "Test that imageSmoothingEnabled = false (nearest-neighbor interpolation) works with stroke() and createPattern().");
test(function() {
var repaints = 5;
var ctx = document.createElement('canvas').getContext('2d');
function draw() {
ctx.clearRect(0, 0, 10, 10);
ctx.setTransform(1, 0, 0, 1, 0, 0);
var image = createTestImage();
ctx.imageSmoothingEnabled = false;
ctx.scale(10, 10);
ctx.drawImage(image, 0, 0);
var pixels = ctx.getImageData(9, 9, 1, 1).data;
assert_array_equals(pixels, [0, 255, 0, 255]);
}
while (repaints > 0) {
draw();
repaints = repaints - 1;
}
}, "Test that imageSmoothingEnabled = false (nearest-neighbor interpolation) still works after repaints.");
</script>