OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <title>Tests that the 2D and webgl context of OffscreenCanvas can be constructed
on a worker thread.</title> |
3 <script src="../../resources/js-test.js"></script> | 3 <script src="../../resources/testharness.js"></script> |
4 <body> | 4 <script src="../../resources/testharnessreport.js"></script> |
5 <script id="myWorker" type="text/worker"> | 5 <script> |
6 self.onmessage = function(e) { | 6 fetch_tests_from_worker(new Worker("OffscreenCanvas-getContext-in-worker.js")); |
7 var aCanvas = new OffscreenCanvas(50, 50); | |
8 var bCanvas = new OffscreenCanvas(50, 50); | |
9 try { | |
10 var ctx1 = aCanvas.getContext('2d'); | |
11 var ctx2 = bCanvas.getContext('webgl'); | |
12 if (!(ctx1 instanceof OffscreenCanvasRenderingContext2D)) { | |
13 self.postMessage("aCanvas.getContext('2d') returns " + ctx1); | |
14 } else if (!(ctx2 instanceof WebGLRenderingContext)) { | |
15 self.postMessage("bCanvas.getContext('webgl') returns " + ctx2); | |
16 } else { | |
17 self.postMessage("success"); | |
18 } | |
19 } catch (e) { | |
20 self.postMessage(e); | |
21 } | |
22 }; | |
23 </script> | 7 </script> |
24 | |
25 <script> | |
26 jsTestIsAsync = true; | |
27 description("Tests that the 2D and webgl context of OffscreenCanvas can be const
ructed on a worker thread."); | |
28 | |
29 function makeWorker(script) { | |
30 var blob = new Blob([script]); | |
31 return new Worker(URL.createObjectURL(blob)); | |
32 } | |
33 | |
34 function handleMessageFromWorker(msg) | |
35 { | |
36 if (msg.data == "success") { | |
37 testPassed("getContext('2d') and getContext('webgl') works on a worker t
hread"); | |
38 } else { | |
39 testFailed(msg.data); | |
40 } | |
41 finishJSTest(); | |
42 } | |
43 | |
44 var worker = makeWorker(document.getElementById('myWorker').textContent); | |
45 worker.addEventListener('message', handleMessageFromWorker); | |
46 worker.postMessage(""); | |
47 </script> | |
48 | |
49 </body> | |
50 </html> | |
OLD | NEW |