OLD | NEW |
| (Empty) |
1 <pre id="console"></pre> | |
2 <script> | |
3 testRunner.dumpAsText(); | |
4 | |
5 function log(message) | |
6 { | |
7 document.getElementById("console").appendChild(document.createTextNode(m
essage + "\n")); | |
8 } | |
9 | |
10 function formatColor(r, g, b, a) | |
11 { | |
12 return "[" + r + ", " + g + ", " + b + ", " + a + "]"; | |
13 } | |
14 | |
15 function assertBlack(imageData, i) | |
16 { | |
17 var r = imageData.data[i * 4]; | |
18 var g = imageData.data[i * 4 + 1]; | |
19 var b = imageData.data[i * 4 + 2]; | |
20 var a = imageData.data[i * 4 + 3]; | |
21 if (r == 0 && g == 0 && b == 0 && a == 255) | |
22 log("PASS: Pixel " + i + " is black."); | |
23 else | |
24 log("FAIL: Pixel " + i + " is not black: " + formatColor(r, g, b, a)
+ "."); | |
25 } | |
26 | |
27 function assertGreen(imageData, i) | |
28 { | |
29 var r = imageData.data[i * 4]; | |
30 var g = imageData.data[i * 4 + 1]; | |
31 var b = imageData.data[i * 4 + 2]; | |
32 var a = imageData.data[i * 4 + 3]; | |
33 if (r == 0 && g == 255 && b == 0 && a == 255) | |
34 log("PASS: Pixel " + i + " is green."); | |
35 else | |
36 log("FAIL: Pixel " + i + " is not green: " + formatColor(r, g, b, a)
+ "."); | |
37 } | |
38 | |
39 function assertBlue(imageData, i) | |
40 { | |
41 var r = imageData.data[i * 4]; | |
42 var g = imageData.data[i * 4 + 1]; | |
43 var b = imageData.data[i * 4 + 2]; | |
44 var a = imageData.data[i * 4 + 3]; | |
45 if (r == 0 && g == 0 && b == 255 && a == 255) | |
46 log("PASS: Pixel " + i + " is blue."); | |
47 else | |
48 log("FAIL: Pixel " + i + " is not blue: " + formatColor(r, g, b, a)
+ "."); | |
49 } | |
50 | |
51 if (!window.testRunner) | |
52 log("This test requires WebKitTestRunner or DumpRenderTree."); | |
53 | |
54 testRunner.waitUntilDone(); | |
55 testRunner.setBackingScaleFactor(2, function() { | |
56 var canvas = document.createElement("canvas"); | |
57 canvas.width = 8; | |
58 canvas.height = 8; | |
59 | |
60 var context = canvas.getContext("2d"); | |
61 | |
62 if (context.webkitBackingStorePixelRatio === 2) { | |
63 | |
64 context.fillStyle = "#0f0"; | |
65 context.fillRect(0, 0, 4, 8); | |
66 context.fillStyle = "#00f"; | |
67 context.fillRect(4, 0, 4, 8); | |
68 | |
69 log("Testing getImageDataHD"); | |
70 | |
71 var imageData = context.webkitGetImageDataHD(7, 0, 2, 1); | |
72 assertGreen(imageData, 0); | |
73 assertBlue(imageData, 1); | |
74 | |
75 log("\nTesting putImageDataHD"); | |
76 | |
77 context.fillStyle = "#000"; | |
78 context.fillRect(0, 0, 8, 8); | |
79 | |
80 imageData = context.createImageData(8, 8); | |
81 for (var i = 0; i < 128; i += 4) { | |
82 imageData.data[i] = 0; | |
83 imageData.data[i + 1] = 255; | |
84 imageData.data[i + 2] = 0; | |
85 imageData.data[i + 3] = 255; | |
86 } | |
87 for (var i = 128; i < 256; i += 4) { | |
88 imageData.data[i] = 0; | |
89 imageData.data[i + 1] = 0; | |
90 imageData.data[i + 2] = 255; | |
91 imageData.data[i + 3] = 255; | |
92 } | |
93 | |
94 context.webkitPutImageDataHD(imageData, 2, 2); | |
95 | |
96 imageData = context.getImageData(2, 0, 1, 1); | |
97 assertBlack(imageData, 0); | |
98 | |
99 imageData = context.getImageData(2, 1, 1, 1); | |
100 assertGreen(imageData, 0); | |
101 | |
102 imageData = context.getImageData(2, 2, 1, 1); | |
103 assertGreen(imageData, 0); | |
104 | |
105 imageData = context.getImageData(2, 3, 1, 1); | |
106 assertBlue(imageData, 0); | |
107 | |
108 imageData = context.getImageData(2, 4, 1, 1); | |
109 assertBlue(imageData, 0); | |
110 | |
111 imageData = context.getImageData(2, 5, 1, 1); | |
112 assertBlack(imageData, 0); | |
113 } else | |
114 log("High-DPI canvas is not enabled."); | |
115 | |
116 testRunner.notifyDone(); | |
117 }); | |
118 </script> | |
OLD | NEW |