Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / net / data / websocket / websocket_worker_simple.js
blob37e3be8b80d59db2bd9e80db88437c5cc72e1849
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);
12 runTests(e.data);
15 } else {
16 runTests(event.data);
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);
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();
36 ws.onclose = function(e) {
37 if (!e.wasClean) {
38 postMessage("FAIL: close is not clean");
39 } else {
40 postMessage("DONE");
43 } catch (e) {
44 postMessage("FAIL: worker: Unexpected exception: " + e);