offscreencanvas.constructor.html (1918B)
1 <!DOCTYPE html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <script src="/html/canvas/resources/canvas-tests.js"></script> 5 <link rel="help" href="https://html.spec.whatwg.org/#dom-offscreencanvas"> 6 <script> 7 8 test(function() { 9 assert_throws_js( 10 TypeError, 11 () => OffscreenCanvas(100, 50), 12 "Calling OffscreenCanvas constructor without 'new' must throw" 13 ); 14 }, "OffscreenCanvas constructor called as normal function"); 15 16 test(function() { 17 var offscreenCanvas = new OffscreenCanvas(100, 50); 18 assert_equals(offscreenCanvas.width, 100); 19 assert_equals(offscreenCanvas.height, 50); 20 21 offscreenCanvas.width = 50; 22 offscreenCanvas.height = 100; 23 assert_equals(offscreenCanvas.width, 50); 24 assert_equals(offscreenCanvas.height, 100); 25 }, "Test that calling OffscreenCanvas's constructor generates correct width and height."); 26 27 test(function() { 28 var offscreenCanvas1 = new OffscreenCanvas(1, 1); 29 30 offscreenCanvas1.width = null; 31 offscreenCanvas1.height = null; 32 assert_equals(offscreenCanvas1.width, 0); 33 assert_equals(offscreenCanvas1.height, 0); 34 35 assert_throws_js(TypeError, function() { new OffscreenCanvas(-1, -1); }); 36 37 var offscreenCanvas2 = new OffscreenCanvas(null, null); 38 assert_equals(offscreenCanvas2.width, 0); 39 assert_equals(offscreenCanvas2.height, 0); 40 41 assert_throws_js(TypeError, function() { offscreenCanvas2.width = -1; }); 42 assert_throws_js(TypeError, function() { offscreenCanvas2.height = -1; }); 43 44 var obj = {Name: "John Doe", Age: 30}; 45 assert_throws_js(TypeError, function() { offscreenCanvas2.width = obj; }); 46 assert_throws_js(TypeError, function() { offscreenCanvas2.height = obj; }); 47 assert_throws_js(TypeError, function() { new OffscreenCanvas(obj, obj); }); 48 }, "Test that OffscreenCanvas constructor handles invalid arguments correctly"); 49 50 </script>