OLD | NEW |
1 // This is a regression test for bug https://bugs.webkit.org/show_bug.cgi?id=890
18 | 1 // This is a regression test for bug https://bugs.webkit.org/show_bug.cgi?id=890
18 |
2 | 2 |
3 description("Tests that disabling the imageSmoothingEnabled attribute still work
s after multiple repaints"); | 3 description("Tests that disabling the imageSmoothingEnabled attribute still work
s after multiple repaints"); |
4 var dstCanvas = document.getElementById("destination"); | 4 var dstCanvas = document.getElementById("destination"); |
5 var dstCtx = dstCanvas.getContext('2d'); | 5 var dstCtx = dstCanvas.getContext('2d'); |
6 var srcCanvas = document.getElementById("source"); | 6 var srcCanvas = document.getElementById("source"); |
7 var srcCtx = srcCanvas.getContext('2d'); | 7 var srcCtx = srcCanvas.getContext('2d'); |
8 | 8 |
9 | 9 |
10 var srcCanvas, srcCtx, dstCanvas, dstCtx; | 10 var srcCanvas, srcCtx, dstCanvas, dstCtx; |
11 | 11 |
12 function draw() | 12 function draw() |
13 { | 13 { |
14 srcCtx.clearRect(0, 0, 300, 300); | 14 srcCtx.clearRect(0, 0, 300, 300); |
15 dstCtx.clearRect(0, 0, 300, 300); | 15 dstCtx.clearRect(0, 0, 300, 300); |
16 srcCtx.fillStyle = "rgb(255, 0, 0)"; | 16 srcCtx.fillStyle = "rgb(255, 0, 0)"; |
17 srcCtx.fillRect(0, 0, 1, 1); | 17 srcCtx.fillRect(0, 0, 1, 1); |
18 srcCtx.fillStyle = "rgb(0, 255, 0)"; | 18 srcCtx.fillStyle = "rgb(0, 255, 0)"; |
19 srcCtx.fillRect(1, 0, 1, 1); | 19 srcCtx.fillRect(1, 0, 1, 1); |
20 dstCtx.imageSmoothingEnabled = false; | 20 dstCtx.imageSmoothingEnabled = false; |
21 dstCtx.drawImage(srcCanvas, 0, 0, 2, 1, 0, 0, 300, 300); | 21 dstCtx.drawImage(srcCanvas, 0, 0, 2, 1, 0, 0, 300, 300); |
22 } | 22 } |
23 | 23 |
24 function testResult() { | 24 function testResult() { |
25 debug("Test that the image is not filtered"); | 25 debug("Test that the image is not filtered"); |
26 » left_of_center_pixel = dstCtx.getImageData(149, 150, 1, 1); | 26 left_of_center_pixel = dstCtx.getImageData(149, 150, 1, 1); |
27 » shouldBe("left_of_center_pixel.data[0]", "255"); | 27 shouldBe("left_of_center_pixel.data[0]", "255"); |
28 » shouldBe("left_of_center_pixel.data[1]", "0"); | 28 shouldBe("left_of_center_pixel.data[1]", "0"); |
29 » shouldBe("left_of_center_pixel.data[2]", "0"); | 29 shouldBe("left_of_center_pixel.data[2]", "0"); |
30 » right_of_center_pixel = dstCtx.getImageData(150, 150, 1, 1); | 30 right_of_center_pixel = dstCtx.getImageData(150, 150, 1, 1); |
31 » shouldBe("right_of_center_pixel.data[0]", "0"); | 31 shouldBe("right_of_center_pixel.data[0]", "0"); |
32 » shouldBe("right_of_center_pixel.data[1]", "255"); | 32 shouldBe("right_of_center_pixel.data[1]", "255"); |
33 » shouldBe("right_of_center_pixel.data[2]", "0"); | 33 shouldBe("right_of_center_pixel.data[2]", "0"); |
34 finishJSTest(); | 34 finishJSTest(); |
35 } | 35 } |
36 | 36 |
37 // Bug 89018 requires 2 draw iteration in order to manifest itself. | 37 // Bug 89018 requires 2 draw iteration in order to manifest itself. |
38 var drawIterations = 2; | 38 var drawIterations = 2; |
39 | 39 |
40 // Unrolled repaint loop for running the test in DumpRenderTree | |
41 function TestControllerPaint() { | |
42 while (drawIterations > 0) { | |
43 draw(); | |
44 testRunner.display(); | |
45 drawIterations = drawIterations - 1; | |
46 } | |
47 draw(); | |
48 testResult(); | |
49 } | |
50 | |
51 // Repaint loop for running the test in the browser | |
52 function BrowserPaint(){ | 40 function BrowserPaint(){ |
53 draw(); | 41 draw(); |
54 » if (drawIterations > 0) { | 42 if (drawIterations > 0) { |
55 » » drawIterations = drawIterations - 1; | 43 drawIterations = drawIterations - 1; |
56 » » window.requestAnimationFrame(BrowserPaint); | 44 window.requestAnimationFrame(BrowserPaint); |
57 } else { | 45 } else { |
58 » testResult(); | 46 testResult(); |
59 » } | 47 } |
60 } | 48 } |
61 | 49 |
62 function onLoadHandler() | 50 function onLoadHandler() |
63 { | 51 { |
64 if (window.testRunner) { | 52 BrowserPaint(); |
65 TestControllerPaint(); | |
66 } else { | |
67 BrowserPaint(); | |
68 } | |
69 } | 53 } |
70 | 54 |
71 window.jsTestIsAsync = true; | 55 window.jsTestIsAsync = true; |
72 window.onload = onLoadHandler; | 56 window.onload = onLoadHandler; |
73 | 57 |
OLD | NEW |