summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/websockets/constructor
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/websockets/constructor')
-rw-r--r--testing/web-platform/tests/websockets/constructor/001.html14
-rw-r--r--testing/web-platform/tests/websockets/constructor/004.html36
-rw-r--r--testing/web-platform/tests/websockets/constructor/005.html14
-rw-r--r--testing/web-platform/tests/websockets/constructor/006.html29
-rw-r--r--testing/web-platform/tests/websockets/constructor/007.html17
-rw-r--r--testing/web-platform/tests/websockets/constructor/008.html15
-rw-r--r--testing/web-platform/tests/websockets/constructor/009.html24
-rw-r--r--testing/web-platform/tests/websockets/constructor/010.html22
-rw-r--r--testing/web-platform/tests/websockets/constructor/011.html28
-rw-r--r--testing/web-platform/tests/websockets/constructor/012.html20
-rw-r--r--testing/web-platform/tests/websockets/constructor/013.html42
-rw-r--r--testing/web-platform/tests/websockets/constructor/014.html39
-rw-r--r--testing/web-platform/tests/websockets/constructor/016.html20
-rw-r--r--testing/web-platform/tests/websockets/constructor/017.html19
-rw-r--r--testing/web-platform/tests/websockets/constructor/018.html20
-rw-r--r--testing/web-platform/tests/websockets/constructor/019.html21
-rw-r--r--testing/web-platform/tests/websockets/constructor/020.html21
-rw-r--r--testing/web-platform/tests/websockets/constructor/021.html12
-rw-r--r--testing/web-platform/tests/websockets/constructor/022.html23
19 files changed, 436 insertions, 0 deletions
diff --git a/testing/web-platform/tests/websockets/constructor/001.html b/testing/web-platform/tests/websockets/constructor/001.html
new file mode 100644
index 0000000000..0c39a0ee71
--- /dev/null
+++ b/testing/web-platform/tests/websockets/constructor/001.html
@@ -0,0 +1,14 @@
+<!doctype html>
+<title>WebSockets: new WebSocket() with no args</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script src=../constants.sub.js></script>
+<meta name="variant" content="">
+<meta name="variant" content="?wss">
+<meta name="variant" content="?wpt_flags=h2">
+<div id=log></div>
+<script>
+test(function() {
+ assert_throws_js(TypeError, function(){new WebSocket()});
+});
+</script>
diff --git a/testing/web-platform/tests/websockets/constructor/004.html b/testing/web-platform/tests/websockets/constructor/004.html
new file mode 100644
index 0000000000..e599bf224a
--- /dev/null
+++ b/testing/web-platform/tests/websockets/constructor/004.html
@@ -0,0 +1,36 @@
+<!doctype html>
+<title>WebSockets: new WebSocket(url, invalid protocol)</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script src=../constants.sub.js></script>
+<meta name="variant" content="">
+<meta name="variant" content="?wss">
+<meta name="variant" content="?wpt_flags=h2">
+<div id=log></div>
+<script>
+// empty string
+test(function() {
+ assert_throws_dom("SyntaxError", function() {
+ new WebSocket(SCHEME_DOMAIN_PORT + '/empty-message', "")
+ })
+});
+
+// chars below U+0020 except U+0000; U+0000 is tested in a separate test
+for (var i = 1; i < 0x20; ++i) {
+ test(function() {
+ assert_throws_dom("SyntaxError", function() {
+ new WebSocket(SCHEME_DOMAIN_PORT + '/empty-message',
+ "a"+String.fromCharCode(i)+"b")
+ }, 'char code '+i);
+ })
+}
+// some chars above U+007E
+for (var i = 0x7F; i < 0x100; ++i) {
+ test(function() {
+ assert_throws_dom("SyntaxError", function() {
+ new WebSocket(SCHEME_DOMAIN_PORT + '/empty-message',
+ "a"+String.fromCharCode(i)+"b")
+ }, 'char code '+i);
+ })
+}
+</script>
diff --git a/testing/web-platform/tests/websockets/constructor/005.html b/testing/web-platform/tests/websockets/constructor/005.html
new file mode 100644
index 0000000000..377d9c4217
--- /dev/null
+++ b/testing/web-platform/tests/websockets/constructor/005.html
@@ -0,0 +1,14 @@
+<!doctype html>
+<title>WebSockets: return value</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script src=../constants.sub.js></script>
+<meta name="variant" content="">
+<meta name="variant" content="?wss">
+<meta name="variant" content="?wpt_flags=h2">
+<div id=log></div>
+<script>
+test(function() {
+ assert_true(new WebSocket(SCHEME_DOMAIN_PORT + '/empty-message') instanceof WebSocket);
+});
+</script>
diff --git a/testing/web-platform/tests/websockets/constructor/006.html b/testing/web-platform/tests/websockets/constructor/006.html
new file mode 100644
index 0000000000..65178e0016
--- /dev/null
+++ b/testing/web-platform/tests/websockets/constructor/006.html
@@ -0,0 +1,29 @@
+<!doctype html>
+<title>WebSockets: converting first arguments</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script src=../constants.sub.js></script>
+<meta name="variant" content="">
+<meta name="variant" content="?wss">
+<meta name="variant" content="?wpt_flags=h2">
+<div id=log></div>
+<script>
+async_test(function(t) {
+ var a = document.createElement('a');
+ a.href = SCHEME_DOMAIN_PORT+'/echo';
+ var ws = new WebSocket(a); // should stringify arguments; <a> stringifies to its .href
+ assert_equals(ws.url, a.href);
+ ws.onopen = t.step_func(function(e) {
+ ws.send('test');
+ });
+ ws.onmessage = t.step_func(function(e) {
+ assert_equals(e.data, 'test');
+ ws.onclose = t.step_func(function(e) {
+ ws.onclose = t.unreached_func();
+ t.step_timeout(() => t.done(), 50);
+ });
+ ws.close();
+ });
+ ws.onerror = ws.onclose = t.unreached_func();
+});
+</script>
diff --git a/testing/web-platform/tests/websockets/constructor/007.html b/testing/web-platform/tests/websockets/constructor/007.html
new file mode 100644
index 0000000000..647f4202a1
--- /dev/null
+++ b/testing/web-platform/tests/websockets/constructor/007.html
@@ -0,0 +1,17 @@
+<!doctype html>
+<title>WebSockets: new WebSocket(url, null char)</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script src=../constants.sub.js></script>
+<meta name="variant" content="">
+<meta name="variant" content="?wss">
+<meta name="variant" content="?wpt_flags=h2">
+<div id=log></div>
+<script>
+test(function() {
+ assert_throws_dom("SyntaxError", function() {
+ new WebSocket(SCHEME_DOMAIN_PORT + '/empty-message',
+ 'a' + String.fromCharCode(0) + 'b')
+ })
+});
+</script>
diff --git a/testing/web-platform/tests/websockets/constructor/008.html b/testing/web-platform/tests/websockets/constructor/008.html
new file mode 100644
index 0000000000..de7fb457ba
--- /dev/null
+++ b/testing/web-platform/tests/websockets/constructor/008.html
@@ -0,0 +1,15 @@
+<!doctype html>
+<title>WebSockets: new WebSocket(url with not blocked port)</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script src=../constants.sub.js></script>
+<meta name="variant" content="">
+<meta name="variant" content="?wss">
+<div id=log></div>
+<script>
+//Pass condition is to not throw
+test(function(){new WebSocket('ws://example.invalid:80/')});
+test(function(){new WebSocket('ws://example.invalid:443/')});
+test(function(){new WebSocket('wss://example.invalid:80/')});
+test(function(){new WebSocket('wss://example.invalid:443/')});
+</script>
diff --git a/testing/web-platform/tests/websockets/constructor/009.html b/testing/web-platform/tests/websockets/constructor/009.html
new file mode 100644
index 0000000000..4e69a839eb
--- /dev/null
+++ b/testing/web-platform/tests/websockets/constructor/009.html
@@ -0,0 +1,24 @@
+<!doctype html>
+<title>WebSockets: protocol</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script src=../constants.sub.js></script>
+<meta name="variant" content="">
+<meta name="variant" content="?wss">
+<meta name="variant" content="?wpt_flags=h2">
+<div id=log></div>
+<script>
+async_test(function(t) {
+ var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/protocol', 'foobar');
+
+ ws.onmessage = t.step_func(function(e) {
+ assert_equals(ws.protocol, 'foobar');
+ ws.onclose = t.step_func(function(e) {
+ ws.onclose = t.unreached_func();
+ t.step_timeout(() => t.done(), 50);
+ })
+ ws.close();
+ })
+ ws.onerror = t.unreached_func();
+});
+</script>
diff --git a/testing/web-platform/tests/websockets/constructor/010.html b/testing/web-platform/tests/websockets/constructor/010.html
new file mode 100644
index 0000000000..0adf2b13f9
--- /dev/null
+++ b/testing/web-platform/tests/websockets/constructor/010.html
@@ -0,0 +1,22 @@
+<!doctype html>
+<title>WebSockets: protocol in response but no requested protocol</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script src=../constants.sub.js></script>
+<meta name="variant" content="">
+<meta name="variant" content="?wss">
+<meta name="variant" content="?wpt_flags=h2">
+<div id=log></div>
+<script>
+async_test(function(t) {
+ var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/handshake_protocol');
+ ws.onopen = ws.onmessage = ws.onclose = t.step_func(e => assert_unreached(e.type));
+ ws.onerror = t.step_func(function(e) {
+ ws.onclose = t.step_func(function(e) {
+ assert_false(e.wasClean, 'e.wasClean should be false');
+ assert_equals(e.code, 1006, 'e.code should be 1006');
+ t.done();
+ });
+ })
+});
+</script>
diff --git a/testing/web-platform/tests/websockets/constructor/011.html b/testing/web-platform/tests/websockets/constructor/011.html
new file mode 100644
index 0000000000..9b7f114dc0
--- /dev/null
+++ b/testing/web-platform/tests/websockets/constructor/011.html
@@ -0,0 +1,28 @@
+<!doctype html>
+<title>WebSockets: protocol mismatch</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script src=../constants.sub.js></script>
+<meta name="variant" content="">
+<meta name="variant" content="?wss">
+<meta name="variant" content="?wpt_flags=h2">
+<div id=log></div>
+<script>
+async_test(function(t) {
+ // Sub-protocol matching is case-sensitive.
+ var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/handshake_protocol', 'FOOBAR');
+ var gotOpen = false;
+ var gotError = false;
+ ws.onopen = t.step_func(function(e) {
+ gotOpen = true;
+ });
+ ws.onerror = t.step_func(function(e) {
+ gotError = true;
+ });
+ ws.onclose = t.step_func(function(e) {
+ assert_false(gotOpen, 'got open');
+ assert_true(gotError, 'got error');
+ t.done();
+ });
+});
+</script>
diff --git a/testing/web-platform/tests/websockets/constructor/012.html b/testing/web-platform/tests/websockets/constructor/012.html
new file mode 100644
index 0000000000..3472361672
--- /dev/null
+++ b/testing/web-platform/tests/websockets/constructor/012.html
@@ -0,0 +1,20 @@
+<!doctype html>
+<title>WebSockets: no protocol in response</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script src=../constants.sub.js></script>
+<meta name="variant" content="">
+<meta name="variant" content="?wss">
+<meta name="variant" content="?wpt_flags=h2">
+<div id=log></div>
+<script>
+async_test(function(t) {
+ var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/handshake_no_protocol', 'foobar');
+ ws.onclose = t.step_func(function(e) {
+ ws.onclose = t.unreached_func();
+ t.step_timeout(() => t.done(), 50);
+ })
+ ws.onmessage = t.unreached_func();
+});
+</script>
+
diff --git a/testing/web-platform/tests/websockets/constructor/013.html b/testing/web-platform/tests/websockets/constructor/013.html
new file mode 100644
index 0000000000..53b0400a2d
--- /dev/null
+++ b/testing/web-platform/tests/websockets/constructor/013.html
@@ -0,0 +1,42 @@
+<!doctype html>
+<title>WebSockets: multiple WebSocket objects</title>
+<meta name=timeout content=long>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script src=../constants.sub.js></script>
+<meta name="variant" content="">
+<meta name="variant" content="?wss">
+<meta name="variant" content="?wpt_flags=h2">
+<div id=log></div>
+<script>
+async_test(function(t) {
+ // test that the events are fired as they should when opening 25 websockets and
+ // sending a message on each and then closing when getting the message back
+ var ws = [];
+ var events = 0;
+ for (var i = 0; i < 25; ++i) {
+ ws[i] = new WebSocket(SCHEME_DOMAIN_PORT+'/echo');
+ ws[i].id = i;
+ ws[i].onopen = t.step_func(function(e) {
+ events++;
+ this.send(this.id);
+ this.onopen = t.step_func(function() {assert_unreached()});
+ }, ws[i]);
+ ws[i].onmessage = t.step_func(function(e) {
+ events++;
+ assert_equals(e.data, ''+this.id);
+ this.close();
+ this.onmessage = t.step_func(function() {assert_unreached()});
+ }, ws[i]);
+ ws[i].onclose = t.step_func(function(e) {
+ events++;
+ if (events == 75) {
+ t.done();
+ }
+ this.onclose = t.step_func(function() {assert_unreached()});
+ }, ws[i]);
+ ws[i].onerror = t.step_func(function() {assert_unreached()});
+ }
+});
+</script>
+
diff --git a/testing/web-platform/tests/websockets/constructor/014.html b/testing/web-platform/tests/websockets/constructor/014.html
new file mode 100644
index 0000000000..f3f38ad278
--- /dev/null
+++ b/testing/web-platform/tests/websockets/constructor/014.html
@@ -0,0 +1,39 @@
+<!doctype html>
+<title>WebSockets: serialize establish a connection</title>
+<meta name="timeout" content="long">
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script src=../constants.sub.js></script>
+<meta name="variant" content="">
+<meta name="variant" content="?wss">
+<div id=log></div>
+<script>
+
+async_test(function(t) {
+ var ws = [];
+ var events = 0;
+ var prevDate;
+ var date;
+ for (var i = 0; i < 2; ++i) {
+ ws[i] = new WebSocket(SCHEME_DOMAIN_PORT+'/handshake_sleep_2');
+ ws[i].id = i;
+ ws[i].onopen = t.step_func(function(e) {
+ events++;
+ date = new Date();
+ if (prevDate) {
+ assert_greater_than(date - prevDate, 1000);
+ }
+ prevDate = date;
+ this.onopen = t.step_func(function() {assert_unreached()});
+ }.bind(ws[i]))
+ ws[i].onclose = t.step_func(function() {
+ events++;
+ if (events == 4) {
+ t.done();
+ }
+ this.onclose = t.step_func(function() {assert_unreached()});
+ }.bind(ws[i]));
+ ws[i].onerror = ws[i].onmessage = t.step_func(function() {assert_unreached()});
+ }
+});
+</script>
diff --git a/testing/web-platform/tests/websockets/constructor/016.html b/testing/web-platform/tests/websockets/constructor/016.html
new file mode 100644
index 0000000000..7a5c9a9e07
--- /dev/null
+++ b/testing/web-platform/tests/websockets/constructor/016.html
@@ -0,0 +1,20 @@
+<!doctype html>
+<meta charset=windows-1252>
+<title>WebSockets: non-ascii URL in query, document encoding windows-1252</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script src=../constants.sub.js></script>
+<meta name="variant" content="">
+<meta name="variant" content="?wss">
+<meta name="variant" content="?wpt_flags=h2">
+<div id=log></div>
+<script>
+async_test(function(t) {
+ var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/echo-query_v13?едц');
+ ws.onclose = t.step_func(function() {assert_unreached()});
+ ws.onmessage = t.step_func(function(e) {
+ assert_equals(e.data, '%C3%A5%C3%A4%C3%B6');
+ t.done();
+ });
+});
+</script>
diff --git a/testing/web-platform/tests/websockets/constructor/017.html b/testing/web-platform/tests/websockets/constructor/017.html
new file mode 100644
index 0000000000..5087290f3c
--- /dev/null
+++ b/testing/web-platform/tests/websockets/constructor/017.html
@@ -0,0 +1,19 @@
+<!doctype html>
+<title>WebSockets: too few slashes after ws: and wss:</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script src=../constants.sub.js></script>
+<meta name="variant" content="">
+<meta name="variant" content="?wss">
+<meta name="variant" content="?wpt_flags=h2">
+<div id=log></div>
+<script>
+var tests = [
+ [__SCHEME + ':', __PORT],
+ [__SCHEME + ':/', __PORT],
+];
+//Pass condition is to not throw
+for (var i = 0; i < tests.length; ++i) {
+ test(function(){new WebSocket(tests[i][0] + location.hostname + ':' + tests[i][1] + '/echo')}, tests[i][0]);
+}
+</script>
diff --git a/testing/web-platform/tests/websockets/constructor/018.html b/testing/web-platform/tests/websockets/constructor/018.html
new file mode 100644
index 0000000000..f4d6ab30d9
--- /dev/null
+++ b/testing/web-platform/tests/websockets/constructor/018.html
@@ -0,0 +1,20 @@
+<!doctype html>
+<title>WebSockets: NULL char in url</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script src=../constants.sub.js></script>
+<meta name="variant" content="">
+<meta name="variant" content="?wss">
+<meta name="variant" content="?wpt_flags=h2">
+<div id=log></div>
+<script>
+async_test(function(t) {
+ var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/echo-query?x\u0000y\u0000');
+ ws.onmessage = t.step_func(function(e) {
+ assert_equals(e.data, 'x%00y');
+ ws.close();
+ t.done();
+ })
+ ws.onclose = ws.onerror = t.step_func(function(e) {assert_unreached(e.type)});
+});
+</script>
diff --git a/testing/web-platform/tests/websockets/constructor/019.html b/testing/web-platform/tests/websockets/constructor/019.html
new file mode 100644
index 0000000000..a0ec6c3ad7
--- /dev/null
+++ b/testing/web-platform/tests/websockets/constructor/019.html
@@ -0,0 +1,21 @@
+<!doctype html>
+<title>WebSockets: uppercase 'WS:'</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script src=../constants.sub.js></script>
+<meta name="variant" content="">
+<meta name="variant" content="?wss">
+<meta name="variant" content="?wpt_flags=h2">
+<div id=log></div>
+<script>
+async_test(function(t) {
+ var scheme = SCHEME_DOMAIN_PORT.split('://')[0];
+ var domain = SCHEME_DOMAIN_PORT.split('://')[1];
+ var ws = new WebSocket(scheme.toUpperCase()+'://'+domain+'/echo');
+ ws.onopen = t.step_func(function(e) {
+ ws.close();
+ t.done();
+ })
+ ws.onclose = ws.onerror = ws.onmessage = t.step_func(function() {assert_unreached()});
+});
+</script>
diff --git a/testing/web-platform/tests/websockets/constructor/020.html b/testing/web-platform/tests/websockets/constructor/020.html
new file mode 100644
index 0000000000..f050a1b8fa
--- /dev/null
+++ b/testing/web-platform/tests/websockets/constructor/020.html
@@ -0,0 +1,21 @@
+<!doctype html>
+<title>WebSockets: uppercase host</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script src=../constants.sub.js></script>
+<meta name="variant" content="">
+<meta name="variant" content="?wss">
+<meta name="variant" content="?wpt_flags=h2">
+<div id=log></div>
+<script>
+async_test(function(t) {
+ var scheme = SCHEME_DOMAIN_PORT.split('://')[0];
+ var domain = SCHEME_DOMAIN_PORT.split('://')[1];
+ var ws = new WebSocket(scheme+'://'+domain.toUpperCase()+'/echo');
+ ws.onopen = t.step_func(function(e) {
+ ws.close();
+ t.done();
+ });
+ ws.onclose = ws.onerror = ws.onmessage = t.step_func(function() {assert_unreached()});
+});
+</script>
diff --git a/testing/web-platform/tests/websockets/constructor/021.html b/testing/web-platform/tests/websockets/constructor/021.html
new file mode 100644
index 0000000000..039d74b043
--- /dev/null
+++ b/testing/web-platform/tests/websockets/constructor/021.html
@@ -0,0 +1,12 @@
+<!doctype html>
+<title>WebSockets: Same sub protocol twice</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script src=../constants.sub.js></script>
+<meta name="variant" content="">
+<meta name="variant" content="?wss">
+<meta name="variant" content="?wpt_flags=h2">
+<div id=log></div>
+<script>
+test(function() {assert_throws_dom("SyntaxError", function(){new WebSocket("ws://certo2.oslo.osa/protocol_array",["foobar, foobar"])})});
+</script>
diff --git a/testing/web-platform/tests/websockets/constructor/022.html b/testing/web-platform/tests/websockets/constructor/022.html
new file mode 100644
index 0000000000..a55d8f349d
--- /dev/null
+++ b/testing/web-platform/tests/websockets/constructor/022.html
@@ -0,0 +1,23 @@
+<!doctype html>
+<title>WebSockets: protocol array</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script src=../constants.sub.js></script>
+<meta name="variant" content="">
+<meta name="variant" content="?wss">
+<meta name="variant" content="?wpt_flags=h2">
+<div id=log></div>
+<script>
+async_test(function(t) {
+ var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/protocol_array',['foobar','foobar2']);
+ ws.onmessage = t.step_func(function(e) {
+ assert_equals(ws.protocol, 'foobar');
+ ws.onclose = t.step_func(function(e) {
+ ws.onclose = t.unreached_func();
+ t.step_timeout(() => t.done(), 50);
+ });
+ ws.close();
+ });
+ ws.onerror = t.unreached_func();
+});
+</script>