OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <script src="../../resources/js-test.js"></script> |
| 4 <body> |
| 5 <script id="myWorker" type="text/worker"> |
| 6 self.onmessage = function(e) { |
| 7 var aCanvas = new OffScreenCanvas(50, 50); |
| 8 self.postMessage({version:'first', width:aCanvas.width, height:aCanvas.height}
); |
| 9 |
| 10 aCanvas.width = 100; |
| 11 aCanvas.height = 100; |
| 12 self.postMessage({version:'second', width:aCanvas.width, height:aCanvas.height
}); |
| 13 }; |
| 14 </script> |
| 15 |
| 16 <script> |
| 17 jsTestIsAsync = true; |
| 18 description("Tests that the OffScreenCanvas can be constructed on a worker threa
d."); |
| 19 |
| 20 var width; |
| 21 var height; |
| 22 |
| 23 function makeWorker(script) { |
| 24 var blob = new Blob([script]); |
| 25 return new Worker(URL.createObjectURL(blob)); |
| 26 } |
| 27 |
| 28 function handleMessageFromWorker(msg) { |
| 29 width = msg.data.width; |
| 30 height = msg.data.height; |
| 31 switch (msg.data.version) { |
| 32 case 'first': |
| 33 shouldBe('width', '50'); |
| 34 shouldBe('height', '50'); |
| 35 break; |
| 36 case 'second': |
| 37 shouldBe('width', '100'); |
| 38 shouldBe('height', '100'); |
| 39 finishJSTest(); |
| 40 break; |
| 41 default: |
| 42 testFailed("Unexpected failure"); |
| 43 break; |
| 44 } |
| 45 } |
| 46 |
| 47 var worker = makeWorker(document.getElementById('myWorker').textContent); |
| 48 worker.addEventListener('message', handleMessageFromWorker); |
| 49 worker.postMessage(""); |
| 50 </script> |
| 51 |
| 52 </body> |
| 53 </html> |
OLD | NEW |