test_offscreencanvas_neuter.html (2494B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>OffscreenCanvas: Test neutering</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <link rel="stylesheet" href="/tests/SimpleTest/test.css"> 7 </head> 8 <body> 9 <canvas id="c" width="64" height="64"></canvas> 10 <script> 11 12 SimpleTest.waitForExplicitFinish(); 13 14 function runTest() { 15 16 var htmlCanvas = document.getElementById("c"); 17 var worker = new Worker("offscreencanvas_neuter.js"); 18 19 ok(htmlCanvas, "Should have HTML canvas element"); 20 ok(worker, "Web worker successfully created"); 21 22 ok(htmlCanvas.transferControlToOffscreen, "HTMLCanvasElement has transferControlToOffscreen function"); 23 24 var offscreenCanvas = htmlCanvas.transferControlToOffscreen(); 25 ok(offscreenCanvas, "Expected transferControlToOffscreen to succeed"); 26 27 /* check html canvas is neuterd */ 28 is(htmlCanvas.width, 64, "HTML canvas has correct width"); 29 SimpleTest.doesThrow( 30 function() { htmlCanvas.width = 128; }, 31 "Can't change html canvas' width after transferControlToOffscreen"); 32 33 SimpleTest.doesThrow( 34 function() { htmlCanvas.height = 128; }, 35 "Can't change html canvas' height after transferControlToOffscreen"); 36 37 ok(!htmlCanvas.getContext("2d"), "Can't getContext after transferControlToOffscreen"); 38 ok(!htmlCanvas.getContext("webgl"), "Can't getContext after transferControlToOffscreen"); 39 ok(!htmlCanvas.getContext("webgl2"), "Can't getContext after transferControlToOffscreen"); 40 41 worker.postMessage(offscreenCanvas, [offscreenCanvas]); 42 43 /* check parent offscreencanvas is neutered after being transfered */ 44 SimpleTest.doesThrow( 45 function() { offscreenCanvas.width = 128; }, 46 "Can't change transfered worker canvas width"); 47 48 SimpleTest.doesThrow( 49 function() { offscreenCanvas.height = 128; }, 50 "Can't change transfered worker canvas height"); 51 52 SimpleTest.doesThrow( 53 function() { offscreenCanvas.getContext("2d") }, 54 "Can't getContext on transfered worker canvas"); 55 56 SimpleTest.doesThrow( 57 function() { offscreenCanvas.getContext("webgl") }, 58 "Can't getContext on transfered worker canvas"); 59 60 SimpleTest.doesThrow( 61 function() { offscreenCanvas.getContext("webgl2") }, 62 "Can't getContext on transfered worker canvas"); 63 64 // Transfer a neutered offscreencanvas should be ok. 65 worker.postMessage(offscreenCanvas, [offscreenCanvas]); 66 67 worker.terminate(); 68 SimpleTest.finish(); 69 } 70 71 SpecialPowers.pushPrefEnv({'set': [ 72 ['webgl.force-enabled', true], 73 ]}, runTest); 74 75 </script> 76 </body> 77 </html>