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