diff options
author | atwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-10 00:09:01 +0000 |
---|---|---|
committer | atwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-10 00:09:01 +0000 |
commit | ae7593642c76769c2eb4c56428b861d1327f7a87 (patch) | |
tree | 2b188c5001b934bcf00c0a9134b0f767bb5db01d /chrome/test/data/workers | |
parent | 0f780b3f165fca6bb30742f790c76f9ccaa9720b (diff) | |
download | chromium_src-ae7593642c76769c2eb4c56428b861d1327f7a87.zip chromium_src-ae7593642c76769c2eb4c56428b861d1327f7a87.tar.gz chromium_src-ae7593642c76769c2eb4c56428b861d1327f7a87.tar.bz2 |
Changed CreateWorker to coalesce any matching queued shared workers when a
shared worker is started.
Added tests for worker close and queued shared worker cases.
BUG=29998
TEST=new UI tests added.
Review URL: http://codereview.chromium.org/580007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38549 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/data/workers')
-rw-r--r-- | chrome/test/data/workers/many_shared_workers.html | 38 | ||||
-rw-r--r-- | chrome/test/data/workers/queued_shared_worker_shutdown.html | 48 | ||||
-rw-r--r-- | chrome/test/data/workers/shutdown_shared_worker.html | 18 | ||||
-rw-r--r-- | chrome/test/data/workers/single_shared_worker.html | 17 | ||||
-rw-r--r-- | chrome/test/data/workers/worker_close.html | 31 | ||||
-rw-r--r-- | chrome/test/data/workers/worker_common.js | 15 |
6 files changed, 164 insertions, 3 deletions
diff --git a/chrome/test/data/workers/many_shared_workers.html b/chrome/test/data/workers/many_shared_workers.html new file mode 100644 index 0000000..2958e85 --- /dev/null +++ b/chrome/test/data/workers/many_shared_workers.html @@ -0,0 +1,38 @@ +<html> +<body> +<div id=result></div> +<script> +function log(message) +{ + document.getElementById("result").innerHTML += message + "<br>"; +} + +var url = document.location.toString(); +var num_workers = parseInt(url.substr(url.search("count=") + 6)); + +if (!num_workers) { + log("No count= parameter provided - test aborted"); +} + +for (var i = 0; i < num_workers ; ++i) { + createWorker(i); +} + +var workers_created = 0; +function createWorker(i) { + var worker = new SharedWorker("worker_common.js?id=" + i); + worker.port.postMessage("eval num_clients"); + worker.port.onmessage = function(event) { + workers_created++; + log("worker " + i + " started - num_clients = " + event.data); + if (workers_created == num_workers) { + // created the last worker + log("SUCCESS: all workers created"); + document.cookie = "status=OK"; + } + } +} +</script> + +</body> +</html> diff --git a/chrome/test/data/workers/queued_shared_worker_shutdown.html b/chrome/test/data/workers/queued_shared_worker_shutdown.html new file mode 100644 index 0000000..3a6163f --- /dev/null +++ b/chrome/test/data/workers/queued_shared_worker_shutdown.html @@ -0,0 +1,48 @@ +<html> +<body> +<div id=result></div> +<script> +function log(message) +{ + document.getElementById("result").innerHTML += message + "<br>"; +} + +var url = document.location.toString(); +var num_workers = parseInt(url.substr(url.search("count=") + 6)); + +if (!num_workers) { + log("No count= parameter provided - test aborted"); +} else { + for (var i = 0; i < num_workers ; ++i) { + createWorker(i); + } + + // Create two extra workers - these should both be queued, and launched as a + // single instance when we shutdown a worker. + createWorker(num_workers); + createWorker(num_workers); +} + +var workers_created = 0; +function createWorker(i) { + var worker = new SharedWorker("worker_common.js?id=" + i); + worker.port.postMessage("ping"); + worker.port.onmessage = function() { + workers_created++; + log("worker " + i + " started"); + if (workers_created == num_workers) { + // We've created all of our workers. Let's shut down the most recent one + // and see if we startup the queued worker. + log("Shutting down worker " + i); + worker.port.postMessage("close"); + } else if (workers_created == (num_workers+2)) { + // created the last worker + log("SUCCESS: queued worker created"); + document.cookie = "status=OK"; + } + } +} +</script> + +</body> +</html> diff --git a/chrome/test/data/workers/shutdown_shared_worker.html b/chrome/test/data/workers/shutdown_shared_worker.html new file mode 100644 index 0000000..7fd2015 --- /dev/null +++ b/chrome/test/data/workers/shutdown_shared_worker.html @@ -0,0 +1,18 @@ +<html> +<body> +<div id=result></div> +<script> +function log(message) +{ + document.getElementById("result").innerHTML += message + "<br>"; +} + +var url = document.location.toString(); +var id = parseInt(url.substr(url.search("id=") + 3)); +log("Shutting down worker #" + id); +var worker = new SharedWorker("worker_common.js?id=" + id); +worker.port.postMessage("close"); +</script> + +</body> +</html> diff --git a/chrome/test/data/workers/single_shared_worker.html b/chrome/test/data/workers/single_shared_worker.html new file mode 100644 index 0000000..bf72cf7 --- /dev/null +++ b/chrome/test/data/workers/single_shared_worker.html @@ -0,0 +1,17 @@ +<html> +<body> +<div id=result></div> +<script> +function log(message) +{ + document.getElementById("result").innerHTML += message + "<br>"; +} + +var url = document.location.toString(); +var id = parseInt(url.substr(url.search("id=") + 3)); +log("Creating worker #" + id); +var worker = new SharedWorker("worker_common.js?id=" + id); +</script> + +</body> +</html> diff --git a/chrome/test/data/workers/worker_close.html b/chrome/test/data/workers/worker_close.html new file mode 100644 index 0000000..5726873 --- /dev/null +++ b/chrome/test/data/workers/worker_close.html @@ -0,0 +1,31 @@ +<html> +<body> +<div id=result></div> +<script> +function log(message) +{ + document.getElementById("result").innerHTML += message + "<br>"; +} + +var worker = new Worker("worker_common.js"); +worker.postMessage("ping"); +worker.onmessage = workerStarted; + +var sharedWorker; +function workerStarted(event) { + log ("worker created"); + worker.postMessage("close"); + sharedWorker = new SharedWorker("worker_common.js"); + sharedWorker.port.postMessage("ping"); + sharedWorker.port.onmessage = sharedWorkerStarted; +} + +function sharedWorkerStarted(event) { + log ("shared worker created"); + sharedWorker.port.postMessage("close"); + document.cookie = "status=OK"; +} +</script> + +</body> +</html> diff --git a/chrome/test/data/workers/worker_common.js b/chrome/test/data/workers/worker_common.js index 664da58..675de0d 100644 --- a/chrome/test/data/workers/worker_common.js +++ b/chrome/test/data/workers/worker_common.js @@ -1,19 +1,28 @@ +// Track the number of clients for this worker - tests can use this to ensure +// that shared workers are actually shared, not distinct. +var num_clients = 0; + if (!self.postMessage) { // This is a shared worker - mimic dedicated worker APIs onconnect = function(event) { + num_clients++; event.ports[0].onmessage = function(e) { + self.postMessage = function(msg) { + event.ports[0].postMessage(msg); + }; self.onmessage(e); }; - self.postMessage = function(msg, ports) { - event.ports[0].postMessage(msg, ports); - }; }; +} else { + num_clients++; } onmessage = function(evt) { if (evt.data == "ping") postMessage("pong"); else if (evt.data == "auth") importScripts("/auth-basic"); + else if (evt.data == "close") + close(); else if (/eval.+/.test(evt.data)) { try { postMessage(eval(evt.data.substr(5))); |