diff options
author | toyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-17 08:35:00 +0000 |
---|---|---|
committer | toyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-17 08:35:00 +0000 |
commit | ca6966bf908defc280bef151c6964a4fc1429708 (patch) | |
tree | f2424ffe6815884676cdb426dac4de295ff26bd9 /net | |
parent | 3f58551be28a5a2084503112251bcfafb7fcbdd9 (diff) | |
download | chromium_src-ca6966bf908defc280bef151c6964a4fc1429708.zip chromium_src-ca6966bf908defc280bef151c6964a4fc1429708.tar.gz chromium_src-ca6966bf908defc280bef151c6964a4fc1429708.tar.bz2 |
Replace WorkerWebSocketHttpLayoutTest with WorkerTest.WebSocketSharedWorker.
WorkerWebSocketHttpLayoutTest was disable.
Actually, shared-worker-simple.html is the only test which is useful to run now.
Also, providing fixed port for WebSocket test server is not so easy.
So, I decided to remove existing WorkerWebSocketHttpLayoutTest, then introduce
WorkerTest.WebSocketSharedWorker as a compatible test with shared-worker-simple.html.
BUG=155014, 137639
TEST=content_browsertests --gtest_filter='WorkerTest.WebSocketSharedWorker'
Review URL: https://chromiumcodereview.appspot.com/11028111
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162326 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/data/websocket/websocket_shared_worker.html | 31 | ||||
-rw-r--r-- | net/data/websocket/websocket_worker_simple.js | 46 |
2 files changed, 77 insertions, 0 deletions
diff --git a/net/data/websocket/websocket_shared_worker.html b/net/data/websocket/websocket_shared_worker.html new file mode 100644 index 0000000..ed990e2 --- /dev/null +++ b/net/data/websocket/websocket_shared_worker.html @@ -0,0 +1,31 @@ +<html> +<body> +<div id=result></div> +<script> +function log(message) +{ + document.getElementById("result").innerHTML += message + "<br>"; +} +var worker = new SharedWorker("websocket_worker_simple.js"); +var href = window.location.href; +var hostBegin = href.indexOf("/") + 2; +var hostEnd = href.lastIndexOf(":"); +var host = href.slice(hostBegin, hostEnd); +var portBegin = hostEnd + 1; +var portEnd = href.lastIndexOf("/"); +var port = href.slice(portBegin, portEnd); +var url = "ws://" + host + ":" + port + "/echo"; +worker.port.onmessage = function (evt) { + log(evt.data); + if (evt.data == "DONE") { + document.title = "OK"; + } else { + document.title = "FAIL"; + } +}; +worker.port.postMessage(url); + +</script> +</body> +</html> + diff --git a/net/data/websocket/websocket_worker_simple.js b/net/data/websocket/websocket_worker_simple.js new file mode 100644 index 0000000..37e3be8 --- /dev/null +++ b/net/data/websocket/websocket_worker_simple.js @@ -0,0 +1,46 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +if (!self.postMessage) { + // This is a shared worker - mimic dedicated worker APIs + onconnect = function(event) { + event.ports[0].onmessage = function(e) { + self.postMessage = function (msg) { + event.ports[0].postMessage(msg); + }; + runTests(e.data); + }; + }; +} else { + runTests(event.data); +} + +// This test is compatible with shared-worker-simple.html layout test. +runTests = function (url) { + var ws; + var greeting = "hello"; + try { + ws = new WebSocket(url); + ws.onopen = function() { + ws.send(greeting); + }; + ws.onmessage = function(e) { + // Receive echoed "hello". + if (e.data != greeting) { + postMessage("FAIL: received data is wrong: " + e.data); + } else { + ws.close(); + } + }; + ws.onclose = function(e) { + if (!e.wasClean) { + postMessage("FAIL: close is not clean"); + } else { + postMessage("DONE"); + } + }; + } catch (e) { + postMessage("FAIL: worker: Unexpected exception: " + e); + } +}; |