Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!-- |
michael@0 | 2 | Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 4 | --> |
michael@0 | 5 | <!DOCTYPE HTML> |
michael@0 | 6 | <html> |
michael@0 | 7 | <!-- |
michael@0 | 8 | Tests of DOM Worker terminate feature |
michael@0 | 9 | --> |
michael@0 | 10 | <head> |
michael@0 | 11 | <title>Test for DOM Worker Navigator</title> |
michael@0 | 12 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 13 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 14 | </head> |
michael@0 | 15 | <body> |
michael@0 | 16 | <p id="display"></p> |
michael@0 | 17 | <div id="content" style="display: none"> |
michael@0 | 18 | |
michael@0 | 19 | </div> |
michael@0 | 20 | <pre id="test"> |
michael@0 | 21 | <script class="testbody" language="javascript"> |
michael@0 | 22 | |
michael@0 | 23 | |
michael@0 | 24 | var messageCount = 0; |
michael@0 | 25 | var intervalCount = 0; |
michael@0 | 26 | |
michael@0 | 27 | var interval; |
michael@0 | 28 | |
michael@0 | 29 | var worker; |
michael@0 | 30 | |
michael@0 | 31 | function messageListener(event) { |
michael@0 | 32 | is(event.data, "Still alive!", "Correct message!"); |
michael@0 | 33 | if (messageCount++ == 20) { |
michael@0 | 34 | ok(worker.onmessage === messageListener, |
michael@0 | 35 | "Correct listener before terminate"); |
michael@0 | 36 | |
michael@0 | 37 | worker.terminate(); |
michael@0 | 38 | |
michael@0 | 39 | var exception = false; |
michael@0 | 40 | try { |
michael@0 | 41 | worker.addEventListener("message", messageListener, false); |
michael@0 | 42 | } |
michael@0 | 43 | catch (e) { |
michael@0 | 44 | exception = true; |
michael@0 | 45 | } |
michael@0 | 46 | is(exception, false, "addEventListener didn't throw after terminate"); |
michael@0 | 47 | |
michael@0 | 48 | exception = false; |
michael@0 | 49 | try { |
michael@0 | 50 | worker.removeEventListener("message", messageListener, false); |
michael@0 | 51 | } |
michael@0 | 52 | catch (e) { |
michael@0 | 53 | exception = true; |
michael@0 | 54 | } |
michael@0 | 55 | is(exception, false, "removeEventListener didn't throw after terminate"); |
michael@0 | 56 | |
michael@0 | 57 | exception = false; |
michael@0 | 58 | try { |
michael@0 | 59 | worker.postMessage("foo"); |
michael@0 | 60 | } |
michael@0 | 61 | catch (e) { |
michael@0 | 62 | exception = true; |
michael@0 | 63 | } |
michael@0 | 64 | is(exception, false, "postMessage didn't throw after terminate"); |
michael@0 | 65 | |
michael@0 | 66 | exception = false; |
michael@0 | 67 | try { |
michael@0 | 68 | worker.terminate(); |
michael@0 | 69 | } |
michael@0 | 70 | catch (e) { |
michael@0 | 71 | exception = true; |
michael@0 | 72 | } |
michael@0 | 73 | is(exception, false, "terminate didn't throw after terminate"); |
michael@0 | 74 | |
michael@0 | 75 | ok(worker.onmessage === messageListener, |
michael@0 | 76 | "Correct listener after terminate"); |
michael@0 | 77 | |
michael@0 | 78 | worker.onmessage = function(event) { } |
michael@0 | 79 | |
michael@0 | 80 | interval = setInterval(testCount, 1000); |
michael@0 | 81 | } |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | function testCount() { |
michael@0 | 85 | is(messageCount, 21, "Received another message after terminated!"); |
michael@0 | 86 | if (intervalCount++ == 5) { |
michael@0 | 87 | clearInterval(interval); |
michael@0 | 88 | SimpleTest.finish(); |
michael@0 | 89 | } |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | worker = new Worker("terminate_worker.js"); |
michael@0 | 93 | worker.onmessage = messageListener; |
michael@0 | 94 | |
michael@0 | 95 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 96 | |
michael@0 | 97 | </script> |
michael@0 | 98 | </pre> |
michael@0 | 99 | </body> |
michael@0 | 100 | </html> |