| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 if (!self.postMessage) { | |
| 6 // This is a shared worker - mimic dedicated worker APIs | |
| 7 onconnect = function(event) { | |
| 8 event.ports[0].onmessage = function(e) { | |
| 9 self.postMessage = function (msg) { | |
| 10 event.ports[0].postMessage(msg); | |
| 11 }; | |
| 12 runTests(e.data); | |
| 13 }; | |
| 14 }; | |
| 15 } else { | |
| 16 runTests(event.data); | |
| 17 } | |
| 18 | |
| 19 // This test is compatible with shared-worker-simple.html layout test. | |
| 20 runTests = function (url) { | |
| 21 var ws; | |
| 22 var greeting = "hello"; | |
| 23 try { | |
| 24 ws = new WebSocket(url); | |
| 25 ws.onopen = function() { | |
| 26 ws.send(greeting); | |
| 27 }; | |
| 28 ws.onmessage = function(e) { | |
| 29 // Receive echoed "hello". | |
| 30 if (e.data != greeting) { | |
| 31 postMessage("FAIL: received data is wrong: " + e.data); | |
| 32 } else { | |
| 33 ws.close(); | |
| 34 } | |
| 35 }; | |
| 36 ws.onclose = function(e) { | |
| 37 if (!e.wasClean) { | |
| 38 postMessage("FAIL: close is not clean"); | |
| 39 } else { | |
| 40 postMessage("DONE"); | |
| 41 } | |
| 42 }; | |
| 43 } catch (e) { | |
| 44 postMessage("FAIL: worker: Unexpected exception: " + e); | |
| 45 } | |
| 46 }; | |
| OLD | NEW |