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.
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);
19 // This test is compatible with shared-worker-simple.html layout test.
20 runTests = function (url) {
22 var greeting = "hello";
24 ws = new WebSocket(url);
25 ws.onopen = function() {
28 ws.onmessage = function(e) {
29 // Receive echoed "hello".
30 if (e.data != greeting) {
31 postMessage("FAIL: received data is wrong: " + e.data);
36 ws.onclose = function(e) {
38 postMessage("FAIL: close is not clean");
44 postMessage("FAIL: worker: Unexpected exception: " + e);