diff options
Diffstat (limited to 'testing/web-platform/tests/workers/semantics/multiple-workers')
12 files changed, 303 insertions, 0 deletions
diff --git a/testing/web-platform/tests/workers/semantics/multiple-workers/001.html b/testing/web-platform/tests/workers/semantics/multiple-workers/001.html new file mode 100644 index 000000000..82ddcc3c1 --- /dev/null +++ b/testing/web-platform/tests/workers/semantics/multiple-workers/001.html @@ -0,0 +1,41 @@ +<!-- +if ('onmessage' in self) { // dedicated worker + onmessage = function(e) { + postMessage(e.data); + } +} else { // shared worker + onconnect = function(e) { + e.ports[0].onmessage = function(e) { + this.postMessage(e.data); + } + } +} +/* +--> +<!doctype html> +<title>dedicated and shared worker in same page</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script> +async_test(function() { + var worker = new Worker('#'); + worker.onmessage = this.step_func(function(e) { + assert_equals(e.data, 'dedicated'); + this.done(); + }); + worker.postMessage('dedicated'); +}, 'dedicated'); +async_test(function() { + var shared = new SharedWorker('#', ''); + shared.port.onmessage = this.step_func(function(e) { + assert_equals(e.data, 'shared'); + this.done(); + }); + shared.port.postMessage('shared'); +}, 'shared'); +</script> +<!-- +*/ +//--> + diff --git a/testing/web-platform/tests/workers/semantics/multiple-workers/002.html b/testing/web-platform/tests/workers/semantics/multiple-workers/002.html new file mode 100644 index 000000000..9ab1f54f4 --- /dev/null +++ b/testing/web-platform/tests/workers/semantics/multiple-workers/002.html @@ -0,0 +1,28 @@ +<!-- +postMessage(1); +/* +--> +<!doctype html> +<title>creating 3 sibling dedicated workers</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script> +async_test(function(t) { + var w1 = new Worker('#'); + var w2 = new Worker('#'); + var w3 = new Worker('#'); + var got = [false, false, false]; + var check_done = t.step_func(function() { + if (got.every(function(x) {return x})) { + t.done(); + } + }); + w1.onmessage = t.step_func(function(e) {got[0] = true; check_done()}); + w2.onmessage = t.step_func(function(e) {got[1] = true; check_done()}); + w3.onmessage = t.step_func(function(e) {got[2] = true; check_done()}); +}); +</script> +<!-- +*/ +//--> diff --git a/testing/web-platform/tests/workers/semantics/multiple-workers/003.html b/testing/web-platform/tests/workers/semantics/multiple-workers/003.html new file mode 100644 index 000000000..85c688bc0 --- /dev/null +++ b/testing/web-platform/tests/workers/semantics/multiple-workers/003.html @@ -0,0 +1,34 @@ +<!-- +if (location.hash == '#1') { + var w2 = new Worker('#2'); + w2.onmessage = function(e) { + postMessage('1'+e.data); + } +} else if (location.hash == '#2') { + var w3 = new Worker('#3'); + w3.onmessage = function(e) { + postMessage('2'+e.data); + } +} else { + postMessage('3'); +} + +/* +--> +<!doctype html> +<title>creating 3 nested dedicated workers</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script> +async_test(function() { + var w1 = new Worker('#1'); + w1.onmessage = this.step_func(function(e) { + assert_equals(e.data, '123'); + this.done(); + }); +}); +</script> +<!-- +*/ +//--> diff --git a/testing/web-platform/tests/workers/semantics/multiple-workers/004-1.html b/testing/web-platform/tests/workers/semantics/multiple-workers/004-1.html new file mode 100644 index 000000000..eac038c5b --- /dev/null +++ b/testing/web-platform/tests/workers/semantics/multiple-workers/004-1.html @@ -0,0 +1,7 @@ +<!doctype html> +<title></title> +<script> +window.onload = function() { + var w=new SharedWorker('004-2.js', 'x'); +}; +</script> diff --git a/testing/web-platform/tests/workers/semantics/multiple-workers/004-2.js b/testing/web-platform/tests/workers/semantics/multiple-workers/004-2.js new file mode 100644 index 000000000..e59cd6927 --- /dev/null +++ b/testing/web-platform/tests/workers/semantics/multiple-workers/004-2.js @@ -0,0 +1,6 @@ +var port; +onconnect = function(e) { + if (!port) + port = e.ports[0]; + port.postMessage(1); +}
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/semantics/multiple-workers/004.html b/testing/web-platform/tests/workers/semantics/multiple-workers/004.html new file mode 100644 index 000000000..c47337008 --- /dev/null +++ b/testing/web-platform/tests/workers/semantics/multiple-workers/004.html @@ -0,0 +1,34 @@ +<!doctype html> +<title>shared worker with multiple documents</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script> +var i = 0; +var load_count = 0; + +var w1 = new SharedWorker('004-2.js', 'x'); +w1.port.onmessage = function(e) { + i++; + check_result(); +}; + + +function iframe_loaded() { + load_count++; + check_result(); +} + +function check_result() { + //timeout to allow for extra, unexpected, messages to arrive + if (i == 3 && load_count == 2) { + setTimeout(function() { + assert_equals(load_count, 2); + assert_equals(i, 3); + done(); + }, 500); + } +} +</script> +<iframe src=004-1.html onload="iframe_loaded()"></iframe> +<iframe src=004-1.html onload="iframe_loaded()"></iframe> diff --git a/testing/web-platform/tests/workers/semantics/multiple-workers/005.html b/testing/web-platform/tests/workers/semantics/multiple-workers/005.html new file mode 100644 index 000000000..289c25ec6 --- /dev/null +++ b/testing/web-platform/tests/workers/semantics/multiple-workers/005.html @@ -0,0 +1,37 @@ +<!-- +if (location.hash == '#1') { + var w2 = new SharedWorker('#2'); + w2.port.onmessage = function(e) { + postMessage('1'+e.data); + } +} else if (location.hash == '#2') { + onconnect = function(e) { + var port = e.ports[0]; + var w3 = new Worker('#3'); + w3.onmessage = function(e) { + port.postMessage('2'+e.data); + } + } +} else { + postMessage('3'); +} + +/* +--> +<!doctype html> +<title>dedicated worker in shared worker in dedicated worker</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script> +async_test(function() { + var w1 = new Worker('#1'); + w1.onmessage = this.step_func(function(e) { + assert_equals(e.data, '123'); + this.done(); + }); +}); +</script> +<!-- +*/ +//--> diff --git a/testing/web-platform/tests/workers/semantics/multiple-workers/006-1.js b/testing/web-platform/tests/workers/semantics/multiple-workers/006-1.js new file mode 100644 index 000000000..6c1ed9323 --- /dev/null +++ b/testing/web-platform/tests/workers/semantics/multiple-workers/006-1.js @@ -0,0 +1,3 @@ + onconnect = function(e) { + e.ports[0].postMessage('3'); + }
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/semantics/multiple-workers/006.html b/testing/web-platform/tests/workers/semantics/multiple-workers/006.html new file mode 100644 index 000000000..ef2124256 --- /dev/null +++ b/testing/web-platform/tests/workers/semantics/multiple-workers/006.html @@ -0,0 +1,35 @@ +<!-- +if (location.hash == '#1') { + onconnect = function(e) { + var port = e.ports[0]; + var w2 = new Worker('#2'); + w2.onmessage = function(e) { + port.postMessage('1'+e.data); + } + } +} else if (location.hash == '#2') { + var w3 = new SharedWorker('006-1.js'); + w3.port.onmessage = function(e) { + postMessage('2'+e.data); + } +} + +/* +--> +<!doctype html> +<title>shared worker in dedicated worker in shared worker</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script> +async_test(function() { + var w1 = new SharedWorker('#1'); + w1.port.onmessage = this.step_func(function(e) { + assert_equals(e.data, '123'); + this.done(); + }); +}); +</script> +<!-- +*/ +//--> diff --git a/testing/web-platform/tests/workers/semantics/multiple-workers/007.html b/testing/web-platform/tests/workers/semantics/multiple-workers/007.html new file mode 100644 index 000000000..e99345073 --- /dev/null +++ b/testing/web-platform/tests/workers/semantics/multiple-workers/007.html @@ -0,0 +1,39 @@ +<!-- +if (location.hash == '#1') { + onconnect = function(e) { + var port = e.ports[0]; + var w2 = new Worker('#2'); + w2.onmessage = function(e) { + port.postMessage('1'+e.data); + } + } +} else if (location.hash == '#2') { + var w3 = new SharedWorker('#3'); + w3.port.onmessage = function(e) { + postMessage('2'+e.data); + } +} else { + onconnect = function(e) { + e.ports[0].postMessage('3'); + } +} + +/* +--> +<!doctype html> +<title>shared worker in dedicated worker in shared worker</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script> +async_test(function() { + var w1 = new SharedWorker('#1'); + w1.port.onmessage = this.step_func(function(e) { + assert_equals(e.data, '123'); + this.done(); + }); +}); +</script> +<!-- +*/ +//--> diff --git a/testing/web-platform/tests/workers/semantics/multiple-workers/008-1.html b/testing/web-platform/tests/workers/semantics/multiple-workers/008-1.html new file mode 100644 index 000000000..82a8a3835 --- /dev/null +++ b/testing/web-platform/tests/workers/semantics/multiple-workers/008-1.html @@ -0,0 +1,8 @@ +<!doctype html> +<title>008-1</title> +<script> +var w1 = new SharedWorker('008.html#'); +w1.port.onmessage = function(e) { + e.ports[0].postMessage(2); +} +</script>
\ No newline at end of file diff --git a/testing/web-platform/tests/workers/semantics/multiple-workers/008.html b/testing/web-platform/tests/workers/semantics/multiple-workers/008.html new file mode 100644 index 000000000..fbb41e0d0 --- /dev/null +++ b/testing/web-platform/tests/workers/semantics/multiple-workers/008.html @@ -0,0 +1,31 @@ +<!-- +var channel = new MessageChannel(); +var i = 0; +onconnect = function(e) { + i++; + e.ports[0].postMessage(1, [channel['port' + i]]); +} + +/* +--> +<!doctype html> +<title>messagechannel in shared worker</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<iframe src=008-1.html></iframe> +<script> +var t = async_test(); +onload = t.step_func(function() { + var w1 = new SharedWorker('#'); + w1.port.onmessage = this.step_func(function(e) { + e.ports[0].onmessage = this.step_func(function(e) { + assert_equals(e.data, 2); + this.done(); + }); + }); +}); +</script> +<!-- +*/ +//--> |