imagedata.html (1749B)
1 <!doctype html> 2 <meta charset="utf-8"> 3 <title>ImageData Tests</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script> 7 test(function() { 8 assert_throws_dom("IndexSizeError", function() { 9 new ImageData(0, 1); 10 }); 11 }, "ImageData(w, h), width cannot be 0"); 12 13 test(function() { 14 assert_throws_dom("IndexSizeError", function() { 15 new ImageData(1, 0); 16 }); 17 }, "ImageData(w, h), height cannot be 0"); 18 19 test(function() { 20 var imageData = new ImageData(2, 3); 21 assert_equals(imageData.width, 2); 22 assert_equals(imageData.height, 3); 23 assert_equals(imageData.data.length, 24); 24 assert_true(imageData.data instanceof Uint8ClampedArray); 25 }, "ImageData(w, h), exposed attributes check"); 26 27 test(function() { 28 assert_throws_dom("InvalidStateError", function() { 29 new ImageData(new Uint8ClampedArray(3), 1); 30 }); 31 }, "ImageData(buffer, w), the buffer size must be a multiple of 4"); 32 33 test(function() { 34 assert_throws_dom("IndexSizeError", function() { 35 new ImageData(new Uint8ClampedArray(16), 3); 36 }); 37 }, "ImageData(buffer, w), buffer size must be a multiple of the image width"); 38 39 test(function() { 40 assert_throws_dom("IndexSizeError", function() { 41 new ImageData(new Uint8ClampedArray(16), 4, 3); 42 }); 43 }, "ImageData(buffer, w, h), buffer.length == 4 * w * h must be true"); 44 45 test(function() { 46 var imageData = new ImageData(new Uint8ClampedArray(24), 2); 47 assert_equals(imageData.width, 2); 48 assert_equals(imageData.height, 3); 49 assert_equals(imageData.data.length, 24); 50 assert_true(imageData.data instanceof Uint8ClampedArray); 51 }, "ImageData(buffer, w, opt h), exposed attributes check"); 52 </script>