diff options
Diffstat (limited to 'testing/web-platform/tests/websockets/constructor')
20 files changed, 442 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 000000000..2a868bfa0 --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/001.html @@ -0,0 +1,13 @@ +<!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.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function() { + assert_throws(new TypeError(), function(){new WebSocket()}); +}); +</script> diff --git a/testing/web-platform/tests/websockets/constructor/002.html b/testing/web-platform/tests/websockets/constructor/002.html new file mode 100644 index 000000000..94015979b --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/002.html @@ -0,0 +1,20 @@ +<!doctype html> +<title>WebSockets: new WebSocket(invalid url)</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function() {assert_throws("SyntaxError", function(){new WebSocket("/test")})}); +test(function() {assert_throws("SyntaxError", function(){new WebSocket("ws://foo bar.com/")})}); +test(function() {assert_throws("SyntaxError", function(){new WebSocket("wss://foo bar.com/")})}); +test(function() {assert_throws("SyntaxError", function(){new WebSocket("http://"+location.host+"/")})}); +test(function() {assert_throws("SyntaxError", function(){new WebSocket("mailto:example@example.org")})}); +test(function() {assert_throws("SyntaxError", function(){new WebSocket("about:blank")})}); +test(function() {assert_throws("SyntaxError", function(){new WebSocket(SCHEME_DOMAIN_PORT+"/#")})}); +test(function() {assert_throws("SyntaxError", function(){new WebSocket(SCHEME_DOMAIN_PORT+"/#test")})}); +test(function() {assert_throws("SyntaxError", function(){new WebSocket("?test")})}); +test(function() {assert_throws("SyntaxError", function(){new WebSocket("#test")})}); +</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 000000000..f35802154 --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/004.html @@ -0,0 +1,35 @@ +<!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.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +// empty string +test(function() { + assert_throws("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("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("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 000000000..63e61ddb0 --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/005.html @@ -0,0 +1,13 @@ +<!doctype html> +<title>WebSockets: return value</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<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 000000000..a9d01bbf3 --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/006.html @@ -0,0 +1,28 @@ +<!doctype html> +<title>WebSockets: converting first arguments</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<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.step_func(function() {assert_unreached()}); + setTimeout(t.step_func(function() {t.done()}), 50); + }); + ws.close(); + }); + ws.onerror = ws.onclose = t.step_func(function() {assert_unreached()}); +}); +</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 000000000..6f141a541 --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/007.html @@ -0,0 +1,16 @@ +<!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.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function() { + assert_throws("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 000000000..f425ff058 --- /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.js?pipe=sub></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 000000000..56eb912c8 --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/009.html @@ -0,0 +1,23 @@ +<!doctype html> +<title>WebSockets: protocol</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<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.step_func(function() {assert_unreached()}); + setTimeout(t.step_func(function() {t.done()}), 50); + }) + ws.close(); + }) + ws.onerror = t.step_func(function() {assert_unreached()}); +}); +</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 000000000..da2a9bf59 --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/handshake_protocol'); + ws.onerror = ws.onmessage = ws.onclose = t.step_func(function(e) {assert_unreached(e.type)}); + ws.onopen = t.step_func(function(e) { + ws.onclose = t.step_func(function(e) { + ws.onclose = t.step_func(function(e) {assert_unreached(e.type)}); + setTimeout(t.step_func(function() {t.done();}), 50); + }) + ws.close(); + }) +}); +</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 000000000..e8d0b3aaf --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/011.html @@ -0,0 +1,27 @@ +<!doctype html> +<title>WebSockets: protocol mismatch</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(t) { + 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_true(gotOpen, 'got open'); + assert_true(gotError, 'got error'); + ws.onclose = t.step_func(function() {assert_unreached()}); + setTimeout(t.step_func(function() {t.done();}), 50); + }) +}); +</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 000000000..29ac6d53f --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/012.html @@ -0,0 +1,19 @@ +<!doctype html> +<title>WebSockets: no protocol in response</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<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.step_func(function() {assert_unreached()}); + setTimeout(t.step_func(function() {t.done();}), 50) + }) + ws.onmessage = t.step_func(function() {assert_unreached()}); +}); +</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 000000000..fe777af19 --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/013.html @@ -0,0 +1,41 @@ +<!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.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<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()}); + } +}, null, {timeout:25000}); +</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 000000000..579a5d3ed --- /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.js?pipe=sub></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 < 4; ++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 == 8) { + 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 000000000..a1bf28167 --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/016.html @@ -0,0 +1,19 @@ +<!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.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<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 000000000..8a7960d88 --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/017.html @@ -0,0 +1,20 @@ +<!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.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +var tests = [ + ['ws:', PORT], + ['ws:/', PORT], + ['wss:', PORT_SSL], + ['wss:/', PORT_SSL] +]; +//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 000000000..d96d4be6b --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/018.html @@ -0,0 +1,19 @@ +<!doctype html> +<title>WebSockets: NULL char in url</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<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 000000000..b56745aa2 --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/019.html @@ -0,0 +1,20 @@ +<!doctype html> +<title>WebSockets: uppercase 'WS:'</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<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 000000000..55ca9934b --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/020.html @@ -0,0 +1,20 @@ +<!doctype html> +<title>WebSockets: uppercase host</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<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 000000000..80156540f --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/021.html @@ -0,0 +1,11 @@ +<!doctype html> +<title>WebSockets: Same sub protocol twice</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function() {assert_throws("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 000000000..136a40d10 --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/022.html @@ -0,0 +1,22 @@ +<!doctype html> +<title>WebSockets: protocol array</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<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.step_func(function() {assert_unreached()}); + setTimeout(t.step_func(function() {t.done();}), 50) + }); + ws.close(); + }); + ws.onerror = t.step_func(function() {assert_unreached()}); +}); +</script> |