| <!DOCTYPE> |
| <script src="../../resources/testharness.js"></script> |
| <script src="../../resources/testharnessreport.js"></script> |
| <script id="myWorker" type="text/worker"> |
| self.onmessage = function(e) { |
| var offscreenCanvas = new OffscreenCanvas(50, 50); |
| var offscreen2d = offscreenCanvas.getContext("2d"); |
| try { |
| offscreen2d.commit(); |
| self.postMessage("NoError"); |
| } catch (ex) { |
| self.postMessage(ex.name); |
| } |
| }; |
| </script> |
| <script> |
| function makeWorker(script) { |
| var blob = new Blob([script]); |
| return new Worker(URL.createObjectURL(blob)); |
| } |
| |
| |
| test(function() { |
| var offscreenCanvas = new OffscreenCanvas(50, 50); |
| var offscreen2d = offscreenCanvas.getContext("2d"); |
| assert_throws("InvalidStateError", function () { |
| offscreen2d.commit(); |
| }); |
| }, "Calling OffscreenCanvas.commit() on main without transferControlToOffscreen throws exception."); |
| |
| async_test(function() { |
| var worker = makeWorker(document.getElementById("myWorker").textContent); |
| worker.onmessage = this.step_func(function (e) { |
| assert_equals(e.data, "InvalidStateError", "Expected exception on worker but receives " + e.data); |
| this.done(); |
| }); |
| worker.postMessage(""); |
| }, "Calling OffscreenCanvas.commit() on worker without transferControlToOffscreen throws exception."); |
| |
| |
| |
| </script> |