diff options
Diffstat (limited to 'testing/web-platform/tests/workers/support/WorkerGlobalScope-close.js')
-rw-r--r-- | testing/web-platform/tests/workers/support/WorkerGlobalScope-close.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/testing/web-platform/tests/workers/support/WorkerGlobalScope-close.js b/testing/web-platform/tests/workers/support/WorkerGlobalScope-close.js new file mode 100644 index 0000000000..e2b1c0a2fd --- /dev/null +++ b/testing/web-platform/tests/workers/support/WorkerGlobalScope-close.js @@ -0,0 +1,43 @@ +// Check to see if the worker handles pending events. Messages after close() will not be sent to the parent page, so we use exceptions instead to report failures after close(). +onmessage = function(evt) +{ + if (evt.data == "closeWithPendingEvents") { + // Set a timer to generate an event - minimum timeout is 1ms. + setTimeout(function() { + postMessage("pending event processed"); + throw "should not be executed"; + }, 1); + var start = new Date().getTime(); + // Loop for 10 ms so the timer is ready to fire + while (new Date().getTime() - start < 100) + ; + // Now close - timer should not fire + close(); + } else if (evt.data == "typeofClose") { + postMessage("typeof close: " + (typeof close)); + } else if (evt.data == "close") { + close(); + postMessage("Should be delivered"); + } else if (evt.data == "ping") { + postMessage("pong"); + } else if (evt.data == "throw") { + throw "should never be executed"; + } else if (evt.data == "closeWithError") { + close(); + nonExistentFunction(); // Undefined function - throws exception + } else if (evt.data == "close_post_loop") { + close(); + postMessage("closed"); + while(true) {} // Should loop forever. + } else if (evt.data == "take_port") { + messagePort = evt.ports[0]; + messagePort.onmessage = function(event) { + close(); + postMessage("echo_" + event.data); + } + } else if (evt.data == "start_port") { + messagePort.start(); + } else { + postMessage("FAIL: Unknown message type: " + evt.data); + } +} |