summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-imageSmoothingEnabled-repaint.js
blob: f8c0833120475c61c85721162c1d17d19607cce9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// This is a regression test for bug https://bugs.webkit.org/show_bug.cgi?id=89018

description("Tests that disabling the imageSmoothingEnabled attribute still works after multiple repaints");
var dstCanvas = document.getElementById("destination");
var dstCtx = dstCanvas.getContext('2d');
var srcCanvas = document.getElementById("source");
var srcCtx = srcCanvas.getContext('2d');


var srcCanvas, srcCtx, dstCanvas, dstCtx;

function draw()
{
    srcCtx.clearRect(0, 0, 300, 300);
    dstCtx.clearRect(0, 0, 300, 300);
    srcCtx.fillStyle = "rgb(255, 0, 0)";
    srcCtx.fillRect(0, 0, 1, 1);
    srcCtx.fillStyle = "rgb(0, 255, 0)";
    srcCtx.fillRect(1, 0, 1, 1);
    dstCtx.webkitImageSmoothingEnabled = false;
    dstCtx.drawImage(srcCanvas, 0, 0, 2, 1, 0, 0, 300, 300);
}

function testResult() {
    debug("Test that the image is not filtered");
	left_of_center_pixel = dstCtx.getImageData(149, 150, 1, 1);
	shouldBe("left_of_center_pixel.data[0]", "255");
	shouldBe("left_of_center_pixel.data[1]", "0");
	shouldBe("left_of_center_pixel.data[2]", "0");
	right_of_center_pixel = dstCtx.getImageData(150, 150, 1, 1);
	shouldBe("right_of_center_pixel.data[0]", "0");
	shouldBe("right_of_center_pixel.data[1]", "255");
	shouldBe("right_of_center_pixel.data[2]", "0");
    finishJSTest();
}

// Bug 89018 requires 2 draw iteration in order to manifest itself.
var drawIterations = 2;

// Unrolled repaint loop for running the test in DumpRenderTree
function TestControllerPaint() {
    while (drawIterations > 0) {
        draw();
        layoutTestController.display();
        drawIterations = drawIterations - 1;
    }
    draw();
    testResult();
}

// Repaint loop for running the test in the browser
function BrowserPaint(){
    draw();
	if (drawIterations > 0) {
		drawIterations = drawIterations - 1;
		window.webkitRequestAnimationFrame(BrowserPaint);
    } else {
	    testResult();
	}
}

function onLoadHandler()
{
    if (window.layoutTestController) {
        TestControllerPaint();
    } else {
        BrowserPaint();
    }
}

window.jsTestIsAsync = true;
window.onload = onLoadHandler;