1 <!DOCTYPE HTML
><meta charset=utf-
8>
2 <title>Canvas test: ImageData
</title>
3 <script type=
"text/javascript" src=
"/resources/testharness.js"></script>
4 <script type=
"text/javascript" src=
"/resources/testharnessreport.js"></script>
10 assert_throws(new TypeError(), function(){ new ImageData(); });
11 assert_throws(new TypeError(), function(){ new ImageData(1); });
12 assert_throws(new TypeError(), function(){ new ImageData(new Uint8ClampedArray([1,2,3,4])); });
13 assert_throws("IndexSizeError", function(){ new ImageData(0,0); });
14 assert_throws("IndexSizeError", function(){ new ImageData(0,1); });
15 assert_throws("IndexSizeError", function(){ new ImageData(1,0); });
19 assert_throws("IndexSizeError", function(){ new ImageData(2,0); });
22 assert_throws("IndexSizeError", function(){ new ImageData(32768,32768); });
23 assert_throws("IndexSizeError", function(){ new ImageData(32768,32769); });
24 assert_throws("IndexSizeError", function(){ new ImageData(32769,32768); });
25 assert_throws("IndexSizeError", function(){ new ImageData(2,536870912); });
26 assert_throws("IndexSizeError", function(){ new ImageData(2,536870913); });
27 assert_throws("IndexSizeError", function(){ new ImageData(536870912,2); });
28 assert_throws("IndexSizeError", function(){ new ImageData(536870913,2); });
29 assert_throws("InvalidStateError", function(){ new ImageData(new Uint8ClampedArray([]),0); });
30 assert_throws("InvalidStateError", function(){ new ImageData(new Uint8ClampedArray([]),0,0); });
31 assert_throws("InvalidStateError", function(){ new ImageData(new Uint8ClampedArray([]),1); });
32 assert_throws("InvalidStateError", function(){ new ImageData(new Uint8ClampedArray([1]),1); });
33 assert_throws("InvalidStateError", function(){ new ImageData(new Uint8ClampedArray([1,2]),1); });
34 assert_throws("InvalidStateError", function(){ new ImageData(new Uint8ClampedArray([1,2,3]),1); });
35 assert_throws("InvalidStateError", function(){ new ImageData(new Uint8ClampedArray([1,2,3,4,5]),1); });
36 assert_throws("IndexSizeError", function(){ new ImageData(new Uint8ClampedArray([1,2,3,4]),0); });
37 new ImageData(new Uint8ClampedArray([1,2,3,4]),1);
38 assert_throws("IndexSizeError", function(){ new ImageData(new Uint8ClampedArray([1,2,3,4]),2); });
39 assert_throws("IndexSizeError", function(){ new ImageData(new Uint8ClampedArray([1,2,3,4,5,6,7,8]),0); });
40 new ImageData(new Uint8ClampedArray([1,2,3,4,5,6,7,8]),1);
41 new ImageData(new Uint8ClampedArray([1,2,3,4,5,6,7,8]),2);
42 assert_throws("IndexSizeError", function(){ new ImageData(new Uint8ClampedArray([1,2,3,4,5,6,7,8]),3); });
43 assert_throws("InvalidStateError", function(){ new ImageData(new Uint8ClampedArray([]),1,1); });
44 assert_throws("InvalidStateError", function(){ new ImageData(new Uint8ClampedArray([1]),1,1); });
45 assert_throws("InvalidStateError", function(){ new ImageData(new Uint8ClampedArray([1,2]),1,1); });
46 assert_throws("InvalidStateError", function(){ new ImageData(new Uint8ClampedArray([1,2,3]),1,1); });
47 assert_throws("InvalidStateError", function(){ new ImageData(new Uint8ClampedArray([1,2,3,4,5]),1,1); });
48 assert_throws("IndexSizeError", function(){ new ImageData(new Uint8ClampedArray([1,2,3,4]),0,0); });
49 assert_throws("IndexSizeError", function(){ new ImageData(new Uint8ClampedArray([1,2,3,4]),0,1); });
50 assert_throws("IndexSizeError", function(){ new ImageData(new Uint8ClampedArray([1,2,3,4]),0,2); });
51 assert_throws("IndexSizeError", function(){ new ImageData(new Uint8ClampedArray([1,2,3,4]),1,0); });
52 new ImageData(new Uint8ClampedArray([1,2,3,4]),1,1);
53 assert_throws("IndexSizeError", function(){ new ImageData(new Uint8ClampedArray([1,2,3,4]),1,2); });
54 assert_throws("IndexSizeError", function(){ new ImageData(new Uint8ClampedArray([1,2,3,4]),2,0); });
55 assert_throws("IndexSizeError", function(){ new ImageData(new Uint8ClampedArray([1,2,3,4]),2,1); });
56 assert_throws("IndexSizeError", function(){ new ImageData(new Uint8ClampedArray([1,2,3,4]),2,2); });
57 assert_throws("IndexSizeError", function(){ new ImageData(new Uint8ClampedArray([1,2,3,4,5,6,7,8]),1,1); });
58 new ImageData(new Uint8ClampedArray([1,2,3,4,5,6,7,8]),1,2);
59 assert_throws("IndexSizeError", function(){ new ImageData(new Uint8ClampedArray([1,2,3,4,5,6,7,8]),1,3); });
60 assert_throws("IndexSizeError", function(){ new ImageData(new Uint8ClampedArray([1,2,3,4,5,6,7,8]),2,0); });
61 new ImageData(new Uint8ClampedArray([1,2,3,4,5,6,7,8]),2,1);
62 assert_throws("IndexSizeError", function(){ new ImageData(new Uint8ClampedArray([1,2,3,4,5,6,7,8]),2,2); });
63 assert_throws("IndexSizeError", function(){ new ImageData(new Uint8ClampedArray([1,2,3,4,5,6,7,8]),2,536870912); });
64 assert_throws("IndexSizeError", function(){ new ImageData(new Uint8ClampedArray([1,2,3,4,5,6,7,8]),2,536870913); });
65 assert_throws("IndexSizeError", function(){ new ImageData(new Uint8ClampedArray([1,2,3,4,5,6,7,8]),536870912,2); });
66 assert_throws("IndexSizeError", function(){ new ImageData(new Uint8ClampedArray([1,2,3,4,5,6,7,8]),536870913,2); });
67 }, "Test constructor arguments");
70 var data
= new Uint8ClampedArray([1,2,3,4,5,6,7,8]);
71 var imgData
= new ImageData(data
,1);
72 assert_equals(imgData
.width
, 1);
73 assert_equals(imgData
.height
, 2);
74 assert_array_equals(imgData
.data
, [1,2,3,4,5,6,7,8]);
75 data
.set([8,7,6,5,4,3,2,1]);
76 assert_array_equals(imgData
.data
, [8,7,6,5,4,3,2,1]);
77 }, "The data argument is not copied");