summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/workers/constructors/SharedWorker
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/tests/workers/constructors/SharedWorker
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/workers/constructors/SharedWorker')
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/13
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/1.headers1
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/Infinity3
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/Infinity-arguments.html13
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/Infinity.headers1
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/NaN3
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/NaN-arguments.html13
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/NaN.headers1
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/SharedWorker-constructor.html28
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/URLMismatchError.htm31
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/connect-event.html14
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/connect-event.js3
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/dummy-name.html10
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/dummy-shared-worker.html10
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/dummy-shared-worker.js0
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/empty-name.html10
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/empty.js0
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/global-members.html12
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/global-members.js9
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/interface-objects.html20
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/interface-objects.js13
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/name.html12
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/name.js3
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/no-arguments-ctor.html13
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/null3
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/null-arguments.html13
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/null.headers1
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/number-arguments.html13
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/port-onmessage.html12
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/port-onmessage.js3
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/port-properties.html19
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/port-readonly.html14
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/same-origin.html62
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/setting-port-members.html53
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/shared-worker.js6
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/undefined3
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/undefined-arguments.html13
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/undefined.headers1
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/unexpected-global-properties.html12
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/unexpected-global-properties.js9
-rw-r--r--testing/web-platform/tests/workers/constructors/SharedWorker/unresolvable-url.html12
41 files changed, 475 insertions, 0 deletions
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/1 b/testing/web-platform/tests/workers/constructors/SharedWorker/1
new file mode 100644
index 0000000000..831434e639
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/1
@@ -0,0 +1,3 @@
+onconnect = e => {
+ e.ports[0].postMessage(['1', self.name]);
+};
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/1.headers b/testing/web-platform/tests/workers/constructors/SharedWorker/1.headers
new file mode 100644
index 0000000000..e7ec0d6699
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/1.headers
@@ -0,0 +1 @@
+Content-Type: text/javascript
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/Infinity b/testing/web-platform/tests/workers/constructors/SharedWorker/Infinity
new file mode 100644
index 0000000000..d4c921c565
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/Infinity
@@ -0,0 +1,3 @@
+onconnect = e => {
+ e.ports[0].postMessage(['Infinity', self.name]);
+};
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/Infinity-arguments.html b/testing/web-platform/tests/workers/constructors/SharedWorker/Infinity-arguments.html
new file mode 100644
index 0000000000..b38e55dc6b
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/Infinity-arguments.html
@@ -0,0 +1,13 @@
+<!doctype html>
+<title>Infinity as arguments</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+async_test(t => {
+ const worker = new SharedWorker(Infinity, Infinity);
+ worker.port.onmessage = t.step_func_done(e => {
+ assert_equals(e.data[0], 'Infinity', 'first arg (script name)');
+ assert_equals(e.data[1], 'Infinity', 'second arg (worker name)');
+ });
+}, 'Test constructing a shared worker with Infinity');
+</script>
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/Infinity.headers b/testing/web-platform/tests/workers/constructors/SharedWorker/Infinity.headers
new file mode 100644
index 0000000000..6805c323df
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/Infinity.headers
@@ -0,0 +1 @@
+Content-Type: text/javascript; charset=utf-8
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/NaN b/testing/web-platform/tests/workers/constructors/SharedWorker/NaN
new file mode 100644
index 0000000000..1d06329788
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/NaN
@@ -0,0 +1,3 @@
+onconnect = e => {
+ e.ports[0].postMessage(['NaN', self.name]);
+};
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/NaN-arguments.html b/testing/web-platform/tests/workers/constructors/SharedWorker/NaN-arguments.html
new file mode 100644
index 0000000000..8a4578a965
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/NaN-arguments.html
@@ -0,0 +1,13 @@
+<!doctype html>
+<title>NaN as arguments</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+async_test(t => {
+ const worker = new SharedWorker(NaN, NaN);
+ worker.port.onmessage = t.step_func_done(e => {
+ assert_equals(e.data[0], 'NaN', 'first arg (script name)');
+ assert_equals(e.data[1], 'NaN', 'second arg (worker name)');
+ });
+}, 'Test constructing a shared worker with NaN');
+</script>
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/NaN.headers b/testing/web-platform/tests/workers/constructors/SharedWorker/NaN.headers
new file mode 100644
index 0000000000..6805c323df
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/NaN.headers
@@ -0,0 +1 @@
+Content-Type: text/javascript; charset=utf-8
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/SharedWorker-constructor.html b/testing/web-platform/tests/workers/constructors/SharedWorker/SharedWorker-constructor.html
new file mode 100644
index 0000000000..7909eb5369
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/SharedWorker-constructor.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<title>Test SharedWorker constructor functionality.</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+test(() => {
+ assert_throws_js(Error,
+ function() {
+ new SharedWorker({toString:function(){throw new Error()}})},
+ 'toString exception should be propagated');
+}, 'Test toString propagation exception.');
+
+test(() => {
+ assert_throws_js(TypeError,
+ function() { new SharedWorker(); },
+ 'invoking SharedWorker constructor without arguments should result ' +
+ 'in an exception.')
+}, 'Test Sharedworker creation with no arguments');
+
+
+test(() => {
+ assert_throws_dom("SyntaxError",
+ function() { var Sharedworker = new SharedWorker('http://invalid:123$'); },
+ 'Invoking SharedWorker constructor with invalid script URL should ' +
+ 'result in an exception.');
+}, 'Test invalid script URL.');
+
+</script>
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/URLMismatchError.htm b/testing/web-platform/tests/workers/constructors/SharedWorker/URLMismatchError.htm
new file mode 100644
index 0000000000..683d201ad3
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/URLMismatchError.htm
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Web Workers: SharedWorker - same name, different URL</title>
+<link rel="author" title="Intel" href="http://www.intel.com">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+setup({ single_test: true });
+
+let counter = 0
+const maybeDone = () => {
+ if(counter) {
+ done()
+ }
+ counter++
+}
+
+const worker = new SharedWorker('shared-worker.js', 'name');
+worker.port.postMessage("trigger a response")
+worker.port.onmessage = e => {
+ assert_equals(e.data, "ping")
+ maybeDone()
+}
+
+// This used to throw "URLMismatchError", but the standard changed
+const worker2 = new SharedWorker('1', 'name');
+worker2.port.onmessage = e => {
+ assert_array_equals(e.data, ["1", "name"])
+ maybeDone()
+}
+</script>
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/connect-event.html b/testing/web-platform/tests/workers/constructors/SharedWorker/connect-event.html
new file mode 100644
index 0000000000..0ab41d25c9
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/connect-event.html
@@ -0,0 +1,14 @@
+<!doctype html>
+<title>connect event</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+async_test(t => {
+ const worker = new SharedWorker('connect-event.js');
+ worker.port.onmessage = t.step_func_done(e => {
+ assert_true(e.data[0], "e.data === ''");
+ assert_true(e.data[1], "e instanceof MessageEvent");
+ assert_true(e.data[2], "e.ports.length == 1");
+ });
+}, 'Test connect event for a shared worker');
+</script>
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/connect-event.js b/testing/web-platform/tests/workers/constructors/SharedWorker/connect-event.js
new file mode 100644
index 0000000000..2cf26a723e
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/connect-event.js
@@ -0,0 +1,3 @@
+onconnect = e => {
+ e.ports[0].postMessage([e.data === '', e instanceof MessageEvent, e.ports.length == 1]);
+};
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/dummy-name.html b/testing/web-platform/tests/workers/constructors/SharedWorker/dummy-name.html
new file mode 100644
index 0000000000..25277042e2
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/dummy-name.html
@@ -0,0 +1,10 @@
+<!doctype html>
+<title>creating a dummy shared worker with name "foo"</title>
+<link rel=help href="http://www.whatwg.org/html/#dom-sharedworker">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+test(() => {
+ const worker = new SharedWorker('empty.js', 'foo');
+});
+</script>
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/dummy-shared-worker.html b/testing/web-platform/tests/workers/constructors/SharedWorker/dummy-shared-worker.html
new file mode 100644
index 0000000000..59a449ad7d
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/dummy-shared-worker.html
@@ -0,0 +1,10 @@
+<!doctype html>
+<title>creating a dummy shared worker</title>
+<link rel=help href="http://www.whatwg.org/html/#dom-sharedworker">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+test(() => {
+ const worker = new SharedWorker('dummy-shared-worker.js');
+});
+</script>
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/dummy-shared-worker.js b/testing/web-platform/tests/workers/constructors/SharedWorker/dummy-shared-worker.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/dummy-shared-worker.js
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/empty-name.html b/testing/web-platform/tests/workers/constructors/SharedWorker/empty-name.html
new file mode 100644
index 0000000000..94771d27c9
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/empty-name.html
@@ -0,0 +1,10 @@
+<!doctype html>
+<title>creating a dummy shared worker with explicit name ""</title>
+<link rel=help href="http://www.whatwg.org/html/#dom-sharedworker">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+test(() => {
+ const worker = new SharedWorker('empty.js', '');
+});
+</script>
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/empty.js b/testing/web-platform/tests/workers/constructors/SharedWorker/empty.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/empty.js
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/global-members.html b/testing/web-platform/tests/workers/constructors/SharedWorker/global-members.html
new file mode 100644
index 0000000000..2da4fc1cee
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/global-members.html
@@ -0,0 +1,12 @@
+<!doctype html>
+<title>members of SharedWorkerGlobalScope</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+async_test(t => {
+ const worker = new SharedWorker('global-members.js');
+ worker.port.onmessage = t.step_func_done(e => {
+ assert_equals(e.data, '');
+ });
+}, 'Test if global members exist in a shared worker');
+</script>
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/global-members.js b/testing/web-platform/tests/workers/constructors/SharedWorker/global-members.js
new file mode 100644
index 0000000000..453da6aae5
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/global-members.js
@@ -0,0 +1,9 @@
+const expected = 'self location close onerror importScripts navigator addEventListener removeEventListener dispatchEvent name onconnect setTimeout clearTimeout setInterval clearInterval'.split(' ');
+let log = '';
+for (let i = 0; i < expected.length; ++i) {
+ if (!(expected[i] in self))
+ log += expected[i] + ' did not exist\n';
+}
+onconnect = e => {
+ e.ports[0].postMessage(log);
+};
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/interface-objects.html b/testing/web-platform/tests/workers/constructors/SharedWorker/interface-objects.html
new file mode 100644
index 0000000000..a8f6998168
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/interface-objects.html
@@ -0,0 +1,20 @@
+<!doctype html>
+<title>expected interface objects/constructors</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+async_test(t => {
+ const expected = 'XMLHttpRequest WebSocket EventSource MessageChannel Worker'.split(' ');
+ const supported = [];
+ for (let i = 0; i < expected.length; ++i) {
+ if (expected[i] in window)
+ supported.push(expected[i]);
+ }
+ const worker = new SharedWorker('interface-objects.js');
+ worker.port.start();
+ worker.port.postMessage(supported);
+ worker.port.onmessage = t.step_func_done(e => {
+ assert_equals(e.data, 'These were missing: ');
+ });
+}, 'Test if interface objects exist in a shared worker');
+</script>
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/interface-objects.js b/testing/web-platform/tests/workers/constructors/SharedWorker/interface-objects.js
new file mode 100644
index 0000000000..2a7aaee687
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/interface-objects.js
@@ -0,0 +1,13 @@
+let prt;
+const handleCall = e => {
+ const log = [];
+ for (let i = 0; i < e.data.length; ++i) {
+ if (!(e.data[i] in self))
+ log.push(e.data[i]);
+ }
+ prt.postMessage('These were missing: '+log.join(', '));
+};
+onconnect = e => {
+ prt = e.ports[0];
+ prt.onmessage = handleCall;
+};
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/name.html b/testing/web-platform/tests/workers/constructors/SharedWorker/name.html
new file mode 100644
index 0000000000..4531cb1b80
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/name.html
@@ -0,0 +1,12 @@
+<!doctype html>
+<title>self.name</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+async_test(t => {
+ const worker = new SharedWorker('name.js', 'hello');
+ worker.port.onmessage = t.step_func_done(e => {
+ assert_equals(e.data, 'hello');
+ });
+}, 'Test self.name in a shared worker');
+</script>
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/name.js b/testing/web-platform/tests/workers/constructors/SharedWorker/name.js
new file mode 100644
index 0000000000..2bc2a4b18b
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/name.js
@@ -0,0 +1,3 @@
+onconnect = e => {
+ e.ports[0].postMessage(self.name);
+};
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/no-arguments-ctor.html b/testing/web-platform/tests/workers/constructors/SharedWorker/no-arguments-ctor.html
new file mode 100644
index 0000000000..5a1231d7b5
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/no-arguments-ctor.html
@@ -0,0 +1,13 @@
+<!doctype html>
+<title>no arguments</title>
+<link rel=help href="http://www.whatwg.org/html/#sharedworker">
+<link rel=help href="http://dev.w3.org/2006/webapi/WebIDL/#es-interface-call">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+test(() => {
+ assert_throws_js(TypeError, () => {
+ const worker = new SharedWorker();
+ });
+});
+</script>
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/null b/testing/web-platform/tests/workers/constructors/SharedWorker/null
new file mode 100644
index 0000000000..16f02d5131
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/null
@@ -0,0 +1,3 @@
+onconnect = e => {
+ e.ports[0].postMessage(['null', self.name]);
+};
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/null-arguments.html b/testing/web-platform/tests/workers/constructors/SharedWorker/null-arguments.html
new file mode 100644
index 0000000000..dd5e5773ed
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/null-arguments.html
@@ -0,0 +1,13 @@
+<!doctype html>
+<title>null as arguments</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+async_test(t => {
+ const worker = new SharedWorker(null, null);
+ worker.port.onmessage = t.step_func_done(e => {
+ assert_equals(e.data[0], 'null', 'first arg (script name)');
+ assert_equals(e.data[1], '', 'second arg (worker name)');
+ });
+}, 'Test constructing a shared worker with null');
+</script>
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/null.headers b/testing/web-platform/tests/workers/constructors/SharedWorker/null.headers
new file mode 100644
index 0000000000..e7ec0d6699
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/null.headers
@@ -0,0 +1 @@
+Content-Type: text/javascript
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/number-arguments.html b/testing/web-platform/tests/workers/constructors/SharedWorker/number-arguments.html
new file mode 100644
index 0000000000..8f90baa898
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/number-arguments.html
@@ -0,0 +1,13 @@
+<!doctype html>
+<title>1 as arguments</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+async_test(t => {
+ const worker = new SharedWorker(1, 1);
+ worker.port.onmessage = t.step_func_done(e => {
+ assert_equals(e.data[0], '1', 'first arg (script name)');
+ assert_equals(e.data[1], '1', 'second arg (worker name)');
+ });
+}, 'Test constructing a shared worker with 1');
+</script>
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/port-onmessage.html b/testing/web-platform/tests/workers/constructors/SharedWorker/port-onmessage.html
new file mode 100644
index 0000000000..706420c5e4
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/port-onmessage.html
@@ -0,0 +1,12 @@
+<!doctype html>
+<title>worker.port.onmessage</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+async_test(t => {
+ const worker = new SharedWorker('port-onmessage.js', '');
+ worker.port.onmessage = t.step_func_done(e => {
+ assert_true(e.data);
+ });
+}, 'Test SharedWorker.port.onmessage');
+</script>
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/port-onmessage.js b/testing/web-platform/tests/workers/constructors/SharedWorker/port-onmessage.js
new file mode 100644
index 0000000000..64ef84df15
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/port-onmessage.js
@@ -0,0 +1,3 @@
+onconnect = e => {
+ e.ports[0].postMessage(true);
+};
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/port-properties.html b/testing/web-platform/tests/workers/constructors/SharedWorker/port-properties.html
new file mode 100644
index 0000000000..e2a1d5b2a8
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/port-properties.html
@@ -0,0 +1,19 @@
+<!doctype html>
+<title>worker.port</title>
+<link rel=help href="http://www.whatwg.org/html/#sharedworker">
+<link rel=help href="http://www.whatwg.org/html/#messageport">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+test(() => {
+ const worker = new SharedWorker('empty.js', '');
+ assert_true('port' in worker, "port");
+ assert_true('postMessage' in worker.port, "postMessage");
+ assert_true('start' in worker.port, "start");
+ assert_true('close' in worker.port, "close");
+ assert_true('onmessage' in worker.port, "onmessage");
+ assert_true('addEventListener' in worker.port, "addEventListener");
+ assert_true('removeEventListener' in worker.port, "removeEventListener");
+ assert_true('dispatchEvent' in worker.port, "dispatchEvent");
+});
+</script>
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/port-readonly.html b/testing/web-platform/tests/workers/constructors/SharedWorker/port-readonly.html
new file mode 100644
index 0000000000..cfb5f3afa5
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/port-readonly.html
@@ -0,0 +1,14 @@
+<!doctype html>
+<title>setting worker.port</title>
+<link rel=help href="http://www.whatwg.org/html/#sharedworker">
+<link rel=help href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-attribute-setter">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+test(() => {
+ const worker = new SharedWorker('empty.js', '');
+ const x = worker.port;
+ worker.port = 1;
+ assert_equals(worker.port, x);
+});
+</script>
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/same-origin.html b/testing/web-platform/tests/workers/constructors/SharedWorker/same-origin.html
new file mode 100644
index 0000000000..0bfc503d06
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/same-origin.html
@@ -0,0 +1,62 @@
+<!doctype html>
+<title>same-origin checks</title>
+<meta name="timeout" content="long">
+<link rel=help href="https://html.spec.whatwg.org/multipage/workers.html#dom-sharedworker">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+// Needed to prevent a race condition if a worker throws an exception that may or may
+// not propogate to the window before the tests finish
+setup({allow_uncaught_exception: true});
+
+testSharedWorkerHelper = (t, script) => {
+ try {
+ const worker = new SharedWorker(script, '');
+ worker.onerror = t.step_func_done(e => {
+ assert_true(e instanceof Event);
+ });
+ } catch (e) {
+ assert_throws_dom("SecurityError", () => {throw e}, "DOMExceptions thrown on cross-origin SharedWorker construction must be SecurityErrors");
+ t.done();
+ }
+}
+
+test(() => {
+ assert_throws_dom("SecurityError", () => { new SharedWorker('unsupported:', ''); });
+}, "unsupported_scheme");
+
+async_test(t => {
+ const worker = new SharedWorker('data:,onconnect = e => { e.ports[0].postMessage(1); }', '');
+ worker.port.onmessage = t.step_func_done(e => {
+ assert_equals(e.data, 1);
+ });
+}, "data_url");
+
+async_test(t => {
+ testSharedWorkerHelper(t, 'javascript:""');
+}, "javascript_url");
+
+async_test(t => {
+ testSharedWorkerHelper(t, 'about:blank');
+}, "about_blank");
+
+async_test(t => {
+ testSharedWorkerHelper(t, 'http://www.opera.com/');
+}, "opera_com");
+
+async_test(t => {
+ testSharedWorkerHelper(t, location.protocol+'//'+location.hostname+':81/');
+}, "port_81");
+
+async_test(t => {
+ testSharedWorkerHelper(t, 'https://'+location.hostname+':80/');
+}, "https_port_80");
+
+async_test(t => {
+ testSharedWorkerHelper(t, 'https://'+location.hostname+':8000/');
+}, "https_port_8000");
+
+async_test(t => {
+ testSharedWorkerHelper(t, 'http://'+location.hostname+':8012/');
+}, "http_port_8012");
+</script>
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/setting-port-members.html b/testing/web-platform/tests/workers/constructors/SharedWorker/setting-port-members.html
new file mode 100644
index 0000000000..0c53474ff0
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/setting-port-members.html
@@ -0,0 +1,53 @@
+<!doctype html>
+<title>setting members of worker.port</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+setup(() => {
+ window.worker = new SharedWorker('#', '');
+});
+test(() => {
+ worker.port.postMessage = 1;
+ assert_equals(worker.port.postMessage, 1);
+}, 'postMessage');
+test(() => {
+ worker.port.start = 1;
+ assert_equals(worker.port.start, 1);
+}, 'start');
+test(() => {
+ worker.port.close = 1;
+ assert_equals(worker.port.close, 1);
+}, 'close');
+test(() => {
+ const f = () => {};
+ worker.port.onmessage = f;
+ assert_equals(worker.port.onmessage, f, '() => {}');
+ worker.port.onmessage = 1;
+ assert_equals(worker.port.onmessage, null, '1');
+ worker.port.onmessage = f;
+ worker.port.onmessage = ';';
+ assert_equals(worker.port.onmessage, null, '";"');
+ worker.port.onmessage = f;
+ const handler = {handleEvent:() => {}};
+ worker.port.onmessage = handler;
+ assert_equals(worker.port.onmessage, handler, '{handleEvent:() => {}}');
+ worker.port.onmessage = f;
+ worker.port.onmessage = null;
+ assert_equals(worker.port.onmessage, null, 'null');
+ worker.port.onmessage = f;
+ worker.port.onmessage = undefined;
+ assert_equals(worker.port.onmessage, null, 'undefined');
+}, 'onmessage');
+test(() => {
+ worker.port.addEventListener = 1;
+ assert_equals(worker.port.addEventListener, 1);
+}, 'addEventListener');
+test(() => {
+ worker.port.removeEventListener = 1;
+ assert_equals(worker.port.removeEventListener, 1);
+}, 'removeEventListener');
+test(() => {
+ worker.port.despatchEvent = 1;
+ assert_equals(worker.port.despatchEvent, 1);
+}, 'despatchEvent');
+</script>
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/shared-worker.js b/testing/web-platform/tests/workers/constructors/SharedWorker/shared-worker.js
new file mode 100644
index 0000000000..b6d18855da
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/shared-worker.js
@@ -0,0 +1,6 @@
+onconnect = e => {
+ const port = e.ports[0];
+ port.onmessage = e => {
+ port.postMessage('ping');
+ }
+}
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/undefined b/testing/web-platform/tests/workers/constructors/SharedWorker/undefined
new file mode 100644
index 0000000000..b8462f1911
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/undefined
@@ -0,0 +1,3 @@
+onconnect = e => {
+ e.ports[0].postMessage(['undefined', self.name]);
+};
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/undefined-arguments.html b/testing/web-platform/tests/workers/constructors/SharedWorker/undefined-arguments.html
new file mode 100644
index 0000000000..cd4c86e84a
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/undefined-arguments.html
@@ -0,0 +1,13 @@
+<!doctype html>
+<title>undefined as arguments</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+async_test(t => {
+ const worker = new SharedWorker(undefined, undefined);
+ worker.port.onmessage = t.step_func_done(e => {
+ assert_equals(e.data[0], 'undefined', 'first arg (script name)');
+ assert_equals(e.data[1], '', 'second arg (worker name)');
+ });
+}, 'Test constructing a shared worker with undefined');
+</script>
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/undefined.headers b/testing/web-platform/tests/workers/constructors/SharedWorker/undefined.headers
new file mode 100644
index 0000000000..e7ec0d6699
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/undefined.headers
@@ -0,0 +1 @@
+Content-Type: text/javascript
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/unexpected-global-properties.html b/testing/web-platform/tests/workers/constructors/SharedWorker/unexpected-global-properties.html
new file mode 100644
index 0000000000..522d31ff56
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/unexpected-global-properties.html
@@ -0,0 +1,12 @@
+<!doctype html>
+<title>unexpected members/interface objects/constructors</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+async_test(t => {
+ const worker = new SharedWorker('unexpected-global-properties.js');
+ worker.port.onmessage = t.step_func_done(e => {
+ assert_equals(e.data, '');
+ });
+}, 'Test unexpected properties are not in global scope');
+</script>
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/unexpected-global-properties.js b/testing/web-platform/tests/workers/constructors/SharedWorker/unexpected-global-properties.js
new file mode 100644
index 0000000000..0af8935821
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/unexpected-global-properties.js
@@ -0,0 +1,9 @@
+const unexpected = 'open print stop getComputedStyle getSelection releaseEvents captureEvents alert confirm prompt addEventStream removeEventStream back forward attachEvent detachEvent navigate DOMParser XMLSerializer XPathEvaluator XSLTProcessor opera Image Option frames Audio SVGUnitTypes SVGZoomAndPan java netscape sun Packages ByteArray closed defaultStatus document event frameElement history innerHeight innerWidth opener outerHeight outerWidth pageXOffset pageYOffset parent screen screenLeft screenTop screenX screenY status top window length'.split(' '); // iterated window in opera and removed expected ones
+let log = '';
+for (let i = 0; i < unexpected.length; ++i) {
+ if (unexpected[i] in self)
+ log += unexpected[i] + ' ';
+}
+onconnect = e => {
+ e.ports[0].postMessage(log);
+};
diff --git a/testing/web-platform/tests/workers/constructors/SharedWorker/unresolvable-url.html b/testing/web-platform/tests/workers/constructors/SharedWorker/unresolvable-url.html
new file mode 100644
index 0000000000..c68968d77d
--- /dev/null
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/unresolvable-url.html
@@ -0,0 +1,12 @@
+<!doctype html>
+<title>resolving broken url</title>
+<link rel=help href="http://www.whatwg.org/html/#dom-sharedworker">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+test(() => {
+ assert_throws_dom("SyntaxError", () => {
+ const worker = new SharedWorker('http://foo bar');
+ });
+});
+</script>