diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/websockets/interfaces | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/websockets/interfaces')
74 files changed, 1681 insertions, 0 deletions
diff --git a/testing/web-platform/tests/websockets/interfaces/CloseEvent/clean-close.html b/testing/web-platform/tests/websockets/interfaces/CloseEvent/clean-close.html new file mode 100644 index 0000000000..8614028fd0 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/CloseEvent/clean-close.html @@ -0,0 +1,24 @@ +<!doctype html> +<title>WebSockets: wasClean, true</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../constants.sub.js></script> +<meta name="variant" content="?default"> +<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'); + ws.onopen = t.step_func(function(e) { + ws.send('Test'); + }); + ws.onmessage = t.step_func(function(e) { + ws.close(); + }); + ws.onclose = t.step_func(function(e) { + assert_equals(e.wasClean,true); + t.done(); + }); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/CloseEvent/constructor.html b/testing/web-platform/tests/websockets/interfaces/CloseEvent/constructor.html new file mode 100644 index 0000000000..1ed86bdf8f --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/CloseEvent/constructor.html @@ -0,0 +1,35 @@ +<!doctype html> +<meta charset=utf-8> +<title>CloseEvent: constructor</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<div id=log></div> +<script> +test(function() { + var event = new CloseEvent("foo"); + assert_true(event instanceof CloseEvent, "should be a CloseEvent"); + assert_equals(event.type, "foo"); + assert_false(event.bubbles, "bubbles"); + assert_false(event.cancelable, "cancelable"); + assert_false(event.wasClean, "wasClean"); + assert_equals(event.code, 0); + assert_equals(event.reason, ""); +}, "new CloseEvent() without dictionary"); + +test(function() { + var event = new CloseEvent("foo", { + bubbles: true, + cancelable: true, + wasClean: true, + code: 7, + reason: "x", + }); + assert_true(event instanceof CloseEvent, "should be a CloseEvent"); + assert_equals(event.type, "foo"); + assert_true(event.bubbles, "bubbles"); + assert_true(event.cancelable, "cancelable"); + assert_true(event.wasClean, "wasClean"); + assert_equals(event.code, 7); + assert_equals(event.reason, "x"); +}, "new CloseEvent() with dictionary"); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/CloseEvent/historical.html b/testing/web-platform/tests/websockets/interfaces/CloseEvent/historical.html new file mode 100644 index 0000000000..24528a86fb --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/CloseEvent/historical.html @@ -0,0 +1,12 @@ +<!doctype html> +<meta charset=utf-8> +<title>CloseEvent: historical initialization</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<div id=log></div> +<script> +test(function() { + assert_false("initCloseEvent" in CloseEvent.prototype); + assert_false("initCloseEvent" in new CloseEvent('close')); +}, "initCloseEvent"); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-arraybuffer.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-arraybuffer.html new file mode 100644 index 0000000000..5d2bfd076c --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-arraybuffer.html @@ -0,0 +1,27 @@ +<!doctype html> +<meta charset=utf-8> +<title>WebSockets: bufferedAmount for ArrayBuffer</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<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'); + var datasize = 10; + ws.onopen = t.step_func(function(e) { + ws.binaryType = "arraybuffer"; + var data = new ArrayBuffer(datasize); + ws.send(data); + assert_equals(ws.bufferedAmount, data.byteLength); + }) + ws.onmessage = t.step_func(function(e) { + assert_equals(e.data.byteLength, datasize); + t.done(); + }) + ws.onclose = t.unreached_func('close event should not fire'); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-blob.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-blob.html new file mode 100644 index 0000000000..d0028dae0f --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-blob.html @@ -0,0 +1,28 @@ +<!doctype html> +<meta charset=utf-8> +<title>WebSockets: bufferedAmount for blob</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<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'); + var datasize = 10; + ws.onopen = t.step_func(function(e) { + ws.binaryType = "blob"; + var data = new ArrayBuffer(datasize); + ws.send(data); + assert_equals(ws.bufferedAmount, data.byteLength); + }); + ws.onmessage = t.step_func(function(e) { + assert_true(e.data instanceof Blob); + assert_equals(e.data.size, datasize); + t.done(); + }); + ws.onclose = t.unreached_func('close event should not fire'); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-defineProperty-getter.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-defineProperty-getter.html new file mode 100644 index 0000000000..ea6e70cfcf --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-defineProperty-getter.html @@ -0,0 +1,18 @@ +<!doctype html> +<meta charset=utf-8> +<title>WebSockets: defineProperty getter for bufferedAmount</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function(){ + Object.defineProperty(WebSocket.prototype, 'bufferedAmount', { + get: function() { return 'foo'; } + }); + var ws = new WebSocket('ws://example.invalid/'); + assert_equals(ws.bufferedAmount, 'foo'); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-defineProperty-setter.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-defineProperty-setter.html new file mode 100644 index 0000000000..8f0fa5c806 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-defineProperty-setter.html @@ -0,0 +1,20 @@ +<!doctype html> +<meta charset=utf-8> +<title>WebSockets: defineProperty setter for bufferedAmount</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function() { + window.setter_ran = false; + Object.defineProperty(WebSocket.prototype, 'bufferedAmount', { + set: function(v) { window[v] = true; } + }); + var ws = new WebSocket('ws://example.invalid/'); + ws.bufferedAmount = 'setter_ran'; + assert_true(setter_ran); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-deleting.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-deleting.html new file mode 100644 index 0000000000..1d99636bf0 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-deleting.html @@ -0,0 +1,23 @@ +<!doctype html> +<meta charset=utf-8> +<title>WebSockets: delete bufferedAmount</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function(){ + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/echo'); + assert_equals(ws.bufferedAmount, 0, 'after creation'); + ws.close(); + delete ws.bufferedAmount; + assert_equals(ws.bufferedAmount, 0, + 'after attempt to delete ws.bufferedAmount'); + delete WebSocket.prototype.bufferedAmount; + assert_equals(ws.bufferedAmount, undefined, + 'after attempt to delete WebSocket.prototype.bufferedAmount'); +}); +</script> + diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-getting.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-getting.html new file mode 100644 index 0000000000..92bcea6082 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-getting.html @@ -0,0 +1,54 @@ +<!doctype html> +<meta charset=utf-8> +<title>WebSockets: bufferedAmount after send()ing</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<meta name="variant" content="?wpt_flags=h2"> +<div id=log></div> +<script> +async_test(function(t){ + // bufferedAmount should increase sync in the send() method and decrease between + // events in the event loop (so never while script is running). + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/echo'); + ws.onopen = t.step_func(function(e) { + ws.send('x'); + assert_equals(ws.bufferedAmount, 1, 'bufferedAmount after sent "x"'); + ws.send('\u00E5'); + assert_equals(ws.bufferedAmount, 1+2, 'bufferedAmount after sent "x", "\u00E5"'); + ws.send('\u5336'); + assert_equals(ws.bufferedAmount, 1+2+3, 'bufferedAmount after sent "x", "\u00E5", "\u5336"'); + ws.send('\uD801\uDC7E'); + assert_equals(ws.bufferedAmount, 1+2+3+4, 'bufferedAmount after sent "x", "\u00E5", "\u5336", "\uD801\uDC7E"'); + }) + var i = 0; + ws.onmessage = t.step_func(function(e) { + i++; + switch(i) { + case 1: + assert_equals(e.data, 'x'); + assert_true(ws.bufferedAmount < 2+3+4 + 1, 'bufferedAmount after received "x"'); + break; + case 2: + assert_equals(e.data, '\u00E5'); + assert_true(ws.bufferedAmount < 3+4 + 1, 'bufferedAmount after received "x", "\u00E5"'); + break; + case 3: + assert_equals(e.data, '\u5336'); + assert_true(ws.bufferedAmount < 4 + 1, 'bufferedAmount after received "x", "\u00E5", "\u5336"'); + break; + case 4: + assert_equals(e.data, '\uD801\uDC7E'); + assert_equals(ws.bufferedAmount, 0, 'bufferedAmount after received "x", "\u00E5", "\u5336", "\uD801\uDC7E"'); + t.done(); + break; + default: + assert_unreached(i); + } + }) + ws.onerror = ws.onclose = t.step_func(function() {assert_unreached()}); +}); +</script> + diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-initial.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-initial.html new file mode 100644 index 0000000000..be37b6dea0 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-initial.html @@ -0,0 +1,15 @@ +<!doctype html> +<meta charset=utf-8> +<title>WebSockets: getting bufferedAmount</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function(){ + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + assert_equals(ws.bufferedAmount, 0); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-large.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-large.html new file mode 100644 index 0000000000..18c5482535 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-large.html @@ -0,0 +1,29 @@ +<!doctype html> +<meta charset=utf-8> +<title>WebSockets: bufferedAmount for 65K data</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="?default"> +<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'); + var data = ""; + ws.onopen = t.step_func(function(e) { + for (var i = 0; i < 65000; i++) { + data = data + "x"; + } + ws.send(data); + assert_equals(data.length, ws.bufferedAmount); + }); + ws.onmessage = t.step_func(function(e) { + assert_equals(e.data, data); + t.done(); + }) + ws.onclose = t.unreached_func('close event should not fire'); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-readonly.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-readonly.html new file mode 100644 index 0000000000..152da696e1 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-readonly.html @@ -0,0 +1,16 @@ +<!doctype html> +<meta charset=utf-8> +<title>WebSockets: setting bufferedAmount</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function(){ + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + ws.bufferedAmount = 5; + assert_equals(ws.bufferedAmount, 0); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-unicode.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-unicode.html new file mode 100644 index 0000000000..ab01f3c790 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-unicode.html @@ -0,0 +1,25 @@ +<!doctype html> +<meta charset=utf-8> +<title>WebSockets: bufferedAmount for unicode data</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<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'); + var data = "¥¥¥¥¥¥"; + ws.onopen = t.step_func(function(e) { + ws.send(data); + assert_equals(data.length * 2, ws.bufferedAmount); + }); + ws.onmessage = t.step_func(function(e) { + assert_equals(e.data, data); + t.done(); + }); + ws.onclose = t.unreached_func('close event should not fire'); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/close/close-basic.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/close/close-basic.html new file mode 100644 index 0000000000..b646ca4167 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/close/close-basic.html @@ -0,0 +1,26 @@ +<!doctype html> +<title>WebSockets: close()</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + ws.onclose = t.step_func(function(e) { + assert_equals(e instanceof CloseEvent, true, 'e instanceof CloseEvent'); + assert_equals(e.wasClean, false, 'e.wasClean'); + e.wasClean = true; + assert_equals(e.wasClean, false, 'e.wasClean = true'); + delete e.wasClean; + assert_equals(e.wasClean, false, 'delete e.wasClean'); + delete CloseEvent.prototype.wasClean; + assert_equals(e.wasClean, undefined, 'delete CloseEvent.prototype.wasClean'); + t.done(); + }); + ws.close(); + assert_equals(ws.readyState, ws.CLOSING); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/close/close-connecting-async.any.js b/testing/web-platform/tests/websockets/interfaces/WebSocket/close/close-connecting-async.any.js new file mode 100644 index 0000000000..88005520b0 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/close/close-connecting-async.any.js @@ -0,0 +1,31 @@ +// META: script=../../../constants.sub.js +// META: variant=?default +// META: variant=?wpt_flags=h2 +// META: variant=?wss + +async_test(t => { + const ws = new WebSocket(SCHEME_DOMAIN_PORT + '/handshake_sleep_2'); + let closeMethodReturned = false; + let errorEventSeen = false; + let closeEventSeen = false; + ws.onerror = t.step_func(() => { + assert_true(closeMethodReturned, 'ws.close() should have returned'); + assert_false(errorEventSeen, 'error event should only fire once'); + errorEventSeen = true; + assert_false(closeEventSeen, 'error event should come before close event'); + }); + ws.onclose = t.step_func_done(() => { + assert_true(closeMethodReturned, 'ws.close() should have returned'); + assert_true(errorEventSeen, 'error event should have fired'); + assert_false(closeEventSeen, 'close event should only fire once'); + closeEventSeen = true; + assert_equals(ws.readyState, WebSocket.CLOSED, + 'readyState should be CLOSED'); + }); + assert_equals(ws.readyState, WebSocket.CONNECTING, + 'readyState should be CONNECTING'); + ws.close(); + closeMethodReturned = true; + assert_equals(ws.readyState, WebSocket.CLOSING, + 'readyState should be CLOSING'); +}, 'close event should be fired asynchronously when WebSocket is connecting'); diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/close/close-connecting.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/close/close-connecting.html new file mode 100644 index 0000000000..de038ca09f --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/close/close-connecting.html @@ -0,0 +1,25 @@ +<!doctype html> +<title>WebSockets: close() when connecting</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="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/sleep_10_v13'); + t.step_timeout(function() { + assert_equals(ws.readyState, ws.CONNECTING); + ws.close(); + assert_equals(ws.readyState, ws.CLOSING); + ws.onclose = t.step_func(function(e) { + assert_equals(ws.readyState, ws.CLOSED); + assert_equals(e.wasClean, false); + t.done(); + }); + }, 1000); + ws.onopen = ws.onclose = t.unreached_func(); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/close/close-multiple.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/close/close-multiple.html new file mode 100644 index 0000000000..e440d80179 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/close/close-multiple.html @@ -0,0 +1,29 @@ +<!doctype html> +<title>WebSockets: close() several times</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +var i = 0; +async_test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + ws.onclose = t.step_func(function(e) { + i++; + }); + ws.close(); + ws.close(); + ws.close(); + var f = t.step_func(function() { + if (i < 1) { + t.step_timeout(f, 500); + return; + } + assert_equals(i, 1); + t.done() + }); + t.step_timeout(f, 500); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/close/close-nested.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/close/close-nested.html new file mode 100644 index 0000000000..74b8fa0c48 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/close/close-nested.html @@ -0,0 +1,28 @@ +<!doctype html> +<title>WebSockets: close() in close event handler</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + var i = 0; + ws.onclose = t.step_func(function(e) { + i++; + if (i == 1) { + assert_equals(ws.readyState, ws.CLOSED); + ws.close(); + assert_equals(ws.readyState, ws.CLOSED); + } + t.step_timeout(function() { + assert_equals(i, 1); + t.done(); + }, 50); + }); + ws.close(); + assert_equals(ws.readyState, ws.CLOSING); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/close/close-replace.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/close/close-replace.html new file mode 100644 index 0000000000..e9d2364794 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/close/close-replace.html @@ -0,0 +1,15 @@ +<!doctype html> +<title>WebSockets: replacing close</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function() { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + ws.close = 5; + assert_equals(ws.close, 5); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/close/close-return.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/close/close-return.html new file mode 100644 index 0000000000..e74c9b076d --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/close/close-return.html @@ -0,0 +1,14 @@ +<!doctype html> +<title>WebSockets: close() 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="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function() { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + assert_equals(ws.close(), undefined); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/constants/001.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/constants/001.html new file mode 100644 index 0000000000..7d79bf5d7b --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/constants/001.html @@ -0,0 +1,17 @@ +<!doctype html> +<title>WebSockets: getting constants on constructor</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +var constants = ['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED']; +for (var i = 0; i < constants.length; ++i) { + test(function(){ + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + assert_equals(WebSocket[constants[i]], i, 'WebSocket.'+constants[i]); + }, "Constants on constructors " + constants[i]); +}; +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/constants/002.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/constants/002.html new file mode 100644 index 0000000000..6810bc6c29 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/constants/002.html @@ -0,0 +1,24 @@ +<!doctype html> +<title>WebSockets: setting constants</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +// this test is testing WebIDL stuff +var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); +var constants = ['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED']; +for (var i = 0; i < constants.length; ++i) { + test(function() { + WebSocket[constants[i]] = 5; // should be ignored, has { ReadOnly } + WebSocket.prototype[constants[i]] = 5; // should be ignored, has { ReadOnly } + ws[constants[i]] = 5; // should be ignored, { ReadOnly } is inherited from prototype + assert_equals(WebSocket[constants[i]], i, 'WebSocket.'+constants[i]); + assert_equals(WebSocket.prototype[constants[i]], i, 'WebSocket.prototype.'+constants[i]); + assert_equals(ws[constants[i]], i, 'ws.'+constants[i]); + }, "Readonly constants " + constants[i]); +}; +</script> + diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/constants/003.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/constants/003.html new file mode 100644 index 0000000000..4a86af8b1c --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/constants/003.html @@ -0,0 +1,22 @@ +<!doctype html> +<title>WebSockets: deleting constants</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +var constants = ['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED']; +for (var i = 0; i < constants.length; ++i) { + test(function(){ + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + delete WebSocket[constants[i]]; // should be ignored, has { DontDelete } + delete WebSocket.prototype[constants[i]]; // should be ignored, has { DontDelete } + delete ws[constants[i]]; // should be ignored, there is no such property on the object + assert_equals(WebSocket[constants[i]], i, 'WebSocket.'+constants[i]); + assert_equals(WebSocket.prototype[constants[i]], i, 'WebSocket.prototype.'+constants[i]); + assert_equals(ws[constants[i]], i, 'ws.'+constants[i]); + }) +}; +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/constants/004.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/constants/004.html new file mode 100644 index 0000000000..2ca3830b72 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/constants/004.html @@ -0,0 +1,21 @@ +<!doctype html> +<title>WebSockets: getting constants on prototype and object</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +var constants = ['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED']; +for (var i = 0; i < constants.length; ++i) { + test(function() { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + assert_equals(WebSocket.prototype[constants[i]], i); + }, 'WebSocket.prototype.'+constants[i]); + test(function() { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + assert_equals(ws[constants[i]], i); + }, 'ws.'+constants[i]); +}; +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/constants/005.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/constants/005.html new file mode 100644 index 0000000000..26d5b24d2c --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/constants/005.html @@ -0,0 +1,20 @@ +<!doctype html> +<title>WebSockets: defineProperty getter for constants</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +var constants = ['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED']; +for (var i = 0; i < constants.length; ++i) { + test(function() { + assert_throws_js(TypeError, function() { + Object.defineProperty(WebSocket.prototype, constants[i], { + get: function() { return 'foo'; } + }); + }); + }, "defineProperty getter " + constants[i]); +}; +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/constants/006.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/constants/006.html new file mode 100644 index 0000000000..78126c86f5 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/constants/006.html @@ -0,0 +1,20 @@ +<!doctype html> +<title>WebSockets: defineProperty setter for constants</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +var constants = ['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED']; +for (var i = 0; i < constants.length; ++i) { + test(function() { + assert_throws_js(TypeError, function(){ + Object.defineProperty(WebSocket.prototype, constants[i], { + set: function() { return 'foo'; } + }); + }); + }, "defineProperty setter " + constants[i]) +}; +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/events/001.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/001.html new file mode 100644 index 0000000000..88dcf9e424 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/001.html @@ -0,0 +1,18 @@ +<!doctype html> +<title>WebSockets: getting on*</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<meta name="variant" content="?wpt_flags=h2"> +<div id=log></div> +<script> +var events = ['open', 'message', 'error', 'close']; +for (var i = 0; i < events.length; ++i) { + test(function(){ + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + assert_equals(ws['on'+events[i]], null, 'on'+events[i]); + }); +}; +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/events/002.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/002.html new file mode 100644 index 0000000000..481730800c --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/002.html @@ -0,0 +1,20 @@ +<!doctype html> +<title>WebSockets: setting on*</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<meta name="variant" content="?wpt_flags=h2"> +<div id=log></div> +<script> +var events = ['open', 'message', 'error', 'close']; +for (var i = 0; i < events.length; ++i) { + test(function(){ + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + var foo = function () {}; + ws['on'+events[i]] = foo; + assert_equals(ws['on'+events[i]], foo); + }); +} +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/events/003.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/003.html new file mode 100644 index 0000000000..a5373ecded --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/003.html @@ -0,0 +1,21 @@ +<!doctype html> +<title>WebSockets: listening for events with onopen</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + var foo = t.step_func(function (e) { + if (e.detail == 5) + t.done(); + }) + ws.onopen = foo; + var ev = document.createEvent('UIEvents'); + ev.initUIEvent('open', false, false, window, 5); + ws.dispatchEvent(ev); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/events/004.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/004.html new file mode 100644 index 0000000000..9c5144cefa --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/004.html @@ -0,0 +1,16 @@ +<!doctype html> +<title>WebSockets: members of EventTarget</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function(){ + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + assert_equals(typeof ws.addEventListener, 'function'); + assert_equals(typeof ws.removeEventListener, 'function'); + assert_equals(typeof ws.dispatchEvent, 'function'); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/events/006.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/006.html new file mode 100644 index 0000000000..de2f55694d --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/006.html @@ -0,0 +1,17 @@ +<!doctype html> +<title>WebSockets: 'on*' in ws</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function(){ + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + assert_equals('onopen' in ws, true, 'onopen'); + assert_equals('onmessage' in ws, true, 'onmessage'); + assert_equals('onerror' in ws, true, 'onerror'); + assert_equals('onclose' in ws, true, 'onclose'); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/events/007.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/007.html new file mode 100644 index 0000000000..0fe7241ecf --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/007.html @@ -0,0 +1,22 @@ +<!doctype html> +<title>WebSockets: listening for events with onmessage</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<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+'/'); + var foo = t.step_func(function (e) { + if (e.detail == 5) + t.done(); + }) + ws.onmessage = foo; + var ev = document.createEvent('UIEvents'); + ev.initUIEvent('message', false, false, window, 5); + ws.dispatchEvent(ev); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/events/008.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/008.html new file mode 100644 index 0000000000..066eb0922e --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/008.html @@ -0,0 +1,24 @@ +<!doctype html> +<title>WebSockets: listening for events with onerror</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + var run = false; + var foo = t.step_func(function (e) { + run = true; + assert_equals(e.detail, 5) + }); + ws.onerror = foo; + var ev = document.createEvent('UIEvents'); + ev.initUIEvent('error', false, false, window, 5); + ws.dispatchEvent(ev); + assert_true(run); + t.done(); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/events/009.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/009.html new file mode 100644 index 0000000000..b9e56e2fbd --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/009.html @@ -0,0 +1,21 @@ +<!doctype html> +<title>WebSockets: listening for events with onclose</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + var foo = t.step_func(function (e) { + if (e.detail == 5) + t.done(); + }); + ws.onclose = foo; + var ev = document.createEvent('UIEvents'); + ev.initUIEvent('close', false, false, window, 5); + ws.dispatchEvent(ev); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/events/010.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/010.html new file mode 100644 index 0000000000..360e7d9bd2 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/010.html @@ -0,0 +1,21 @@ +<!doctype html> +<title>WebSockets: setting event handlers to undefined</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +var events = ['onclose', 'onopen', 'onerror', 'onmessage']; +for (var i = 0; i < events.length; ++i) { + test(function(){ + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/empty-message'); + var foo = function() {} + ws[events[i]] = foo; + assert_equals(ws[events[i]], foo, events[i]); + ws[events[i]] = undefined; + assert_equals(ws[events[i]], null, events[i]); + }); +} +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/events/011.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/011.html new file mode 100644 index 0000000000..f64857579e --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/011.html @@ -0,0 +1,18 @@ +<!doctype html> +<title>WebSockets: setting event handlers to 1</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +var events = ['onclose', 'onopen', 'onerror', 'onmessage']; +for (var i = 0; i < events.length; ++i) { + test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/empty-message'); + ws[events[i]] = 1; + assert_equals(ws[events[i]], null); + }, events[i]); +}; +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/events/012.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/012.html new file mode 100644 index 0000000000..bdd63e3f69 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/012.html @@ -0,0 +1,18 @@ +<!doctype html> +<title>WebSockets: setting event handlers to ";"</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +var events = ['onclose', 'onopen', 'onerror', 'onmessage']; +for (var i = 0; i < events.length; ++i) { + test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/empty-message'); + ws[events[i]] = ";"; + assert_equals(ws[events[i]], null); + }, events[i]); +}; +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/events/013.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/013.html new file mode 100644 index 0000000000..9e251c6217 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/013.html @@ -0,0 +1,20 @@ +<!doctype html> +<title>WebSockets: setting event handlers to {handleEvent:function(){}}</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +var events = ['onclose', 'onopen', 'onerror', 'onmessage']; +for (var i = 0; i < events.length; ++i) { + test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/empty-message'); + var obj = {handleEvent:this.unreached_func("handleEvent was called")}; + ws[events[i]] = obj; + assert_equals(ws[events[i]], obj); + ws.dispatchEvent(new Event(events[i].substr(2))); + }, events[i]); +}; +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/events/014.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/014.html new file mode 100644 index 0000000000..9fcd8b3f6a --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/014.html @@ -0,0 +1,21 @@ +<!doctype html> +<title>WebSockets: setting event handlers to null</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +var events = ['onclose', 'onopen', 'onerror', 'onmessage']; +for (var i = 0; i < events.length; ++i) { + test(function() { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/empty-message'); + var foo = function() {} + ws[events[i]] = foo; + assert_equals(ws[events[i]], foo, events[i]); + ws[events[i]] = null; + assert_equals(ws[events[i]], null, events[i]); + }, "Setting event handlers to null " + events[i]); +}; +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/events/015.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/015.html new file mode 100644 index 0000000000..5089c0fb67 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/015.html @@ -0,0 +1,36 @@ +<!doctype html> +<title>WebSockets: instanceof on events</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<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_raw'); + ws.onopen = t.step_func(function(e) { + assert_true(e instanceof Event); + // first a text frame, then a frame with reserved opcode 3 + // which should fail the connection + + // send '\\x81\\x04test\\x83\\x03LOL' in bytes + ws.send(new Uint8Array([129, 4, 116, 101, 115, 116, 131, 3, 76, 79, 76])); + }); + ws.onmessage = t.step_func(function(e) { + assert_true(e instanceof Event); + assert_true(e instanceof MessageEvent); + assert_equals(ws.readyState, ws.OPEN); + }) + ws.onerror = t.step_func(function(e) { + assert_true(e instanceof Event); + assert_equals(ws.readyState, ws.CLOSED); + }) + ws.onclose = t.step_func(function(e) { + assert_true(e instanceof Event); + assert_true(e instanceof CloseEvent); + t.done(); + }) +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/events/016.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/016.html new file mode 100644 index 0000000000..8b5aaf9f42 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/016.html @@ -0,0 +1,39 @@ +<!doctype html> +<title>WebSockets: addEventListener</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="?default"> +<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'); + var count = 0; + var checkCount = t.step_func(function (c, e) { + count++; + assert_equals(count, c); + }); + // no spec requires this order for event listeners but the web does + ws.addEventListener('open', t.step_func(function(e) { + checkCount(1, e); + ws.send('Goodbye'); + }), false); + ws.onopen = t.step_func(function(e) {checkCount(2, e) }); + ws.addEventListener('open', t.step_func(function(e) {checkCount(3, e); }), false); + + ws.addEventListener('message', t.step_func(function(e) {checkCount(4, e); }), false); + ws.onmessage = t.step_func(function(e) {checkCount(5, e) }); + ws.addEventListener('message', t.step_func(function(e) {checkCount(6, e); }), false); + + ws.addEventListener('close', t.step_func(function(e) {checkCount(7, e); }), false); + ws.onclose = t.step_func(function(e) {checkCount(8, e) }); + ws.addEventListener('close', t.step_func(function(e) { + checkCount(9, e); + t.done(); + }), false); + +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/events/017.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/017.html new file mode 100644 index 0000000000..a9f06eaf7d --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/017.html @@ -0,0 +1,56 @@ +<!doctype html> +<title>WebSockets: this, e.target, e.currentTarget, e.eventPhase</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<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_raw'); + ws.addEventListener('open', function(e) { + var this_val = this; + t.step(function() { + // first a text frame, then a frame with reserved opcode 3 + // which should fail the connection + + // send '\\x81\\x04test\\x83\\x03LOL' in bytes + ws.send(new Uint8Array([129, 4, 116, 101, 115, 116, 131, 3, 76, 79, 76])); + assert_equals(this_val, ws); + assert_equals(e.target, ws); + assert_equals(e.currentTarget, ws); + assert_equals(e.eventPhase, 2); + }); + }, false); + ws.addEventListener('message', function(e) { + var this_val = this; + t.step(function() { + assert_equals(this_val, ws); + assert_equals(e.target, ws); + assert_equals(e.currentTarget, ws); + assert_equals(e.eventPhase, 2); + }); + }, false); + ws.addEventListener('error', function(e) { + var this_val = this; + t.step(function() { + assert_equals(this_val, ws); + assert_equals(e.target, ws); + assert_equals(e.currentTarget, ws); + assert_equals(e.eventPhase, 2); + }); + }, false); + ws.addEventListener('close', function(e) { + var this_val = this; + t.step(function() { + assert_equals(this_val, ws); + assert_equals(e.target, ws); + assert_equals(e.currentTarget, ws); + assert_equals(e.eventPhase, 2); + t.done(); + }); + }, false); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/events/018.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/018.html new file mode 100644 index 0000000000..a340c69f45 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/018.html @@ -0,0 +1,52 @@ +<!doctype html> +<title>WebSockets: toString(), bubbles, cancelable</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<meta name="variant" content="?wpt_flags=h2"> +<div id=log></div> +<script> +var ws = null; +setup(function() { + ws = new WebSocket(SCHEME_DOMAIN_PORT+'/echo_raw'); +}); + +async_test(function(t) { + let openFired = false; + let messageFired = false; + let errorFired = false; + ws.addEventListener('open', t.step_func(function(e) { + openFired = true; + // first a text frame, then a frame with reserved opcode 3 + // which should fail the connection + + // send '\\x81\\x04test\\x83\\x03LOL' in bytes + ws.send(new Uint8Array([129, 4, 116, 101, 115, 116, 131, 3, 76, 79, 76])); + assert_equals(e.toString(), '[object Event]', "open e.toString()"); + assert_equals(e.bubbles, false, 'open e.bubbles'); + assert_equals(e.cancelable, false, 'open e.cancelable'); + }), false); + ws.addEventListener('message', t.step_func(function(e) { + messageFired = true; + assert_equals(e.toString(), '[object MessageEvent]', "message e.toString()"); + assert_equals(e.bubbles, false, 'message e.bubbles'); + assert_equals(e.cancelable, false, 'message e.cancelable'); + }), false); + ws.addEventListener('error', t.step_func(function(e) { + errorFired = true; + assert_equals(e.toString(), '[object Event]', "error e.toString()"); + assert_equals(e.bubbles, false, 'error e.bubbles'); + assert_equals(e.cancelable, false, 'error e.cancelable'); + }), false); + ws.addEventListener('close', t.step_func_done(function(e) { + assert_true(openFired, 'open event should fire'); + assert_true(messageFired, 'message event should fire'); + assert_true(errorFired, 'error event should fire'); + assert_equals(e.toString(), '[object CloseEvent]', "close e.toString()"); + assert_equals(e.bubbles, false, 'close e.bubbles'); + assert_equals(e.cancelable, false, 'close e.cancelable'); + }), false); +}, "open, message, error and close events"); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/events/019.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/019.html new file mode 100644 index 0000000000..deb079f81a --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/019.html @@ -0,0 +1,31 @@ +<!doctype html> +<title>WebSockets: removeEventListener</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +var events = ['open', 'message', 'error', 'close']; +for (var i = 0; i < events.length; ++i) { + test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/echo'); + ws.close(); + var got = []; + var event; + function addThis(e) { + got.push(e.type); + } + ws.addEventListener(events[i], addThis, false); + ws.removeEventListener(events[i], addThis, false); + event = document.createEvent('Event'); + event.initEvent(events[i], false, false); + ws.dispatchEvent(event); + assert_equals(got.length, 0); + if (got.length) { + debug('Got: '+got); + } + }) +}; +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/events/020.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/020.html new file mode 100644 index 0000000000..f43b0af93f --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/020.html @@ -0,0 +1,17 @@ +<!doctype html> +<title>WebSockets: error events</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(t) { + var ws = new WebSocket('ws://example.invalid/'); + ws.onerror = t.step_func(function(e) { + assert_true(e instanceof Event); + t.done(); + }) +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/extensions/001.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/extensions/001.html new file mode 100644 index 0000000000..bd26483a79 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/extensions/001.html @@ -0,0 +1,14 @@ +<!doctype html> +<title>WebSockets: getting extensions in connecting</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function(t) { + // The extensions attribute must initially return the empty string + assert_equals((new WebSocket(SCHEME_DOMAIN_PORT+'/empty-message')).extensions, ''); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/protocol/protocol-initial.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/protocol/protocol-initial.html new file mode 100644 index 0000000000..2e7bf66557 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/protocol/protocol-initial.html @@ -0,0 +1,14 @@ +<!doctype html> +<title>WebSockets: getting protocol in connecting</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function(t) { + // The protocol attribute must initially return the empty string + assert_equals((new WebSocket(SCHEME_DOMAIN_PORT + '/empty-message')).protocol, ''); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/readyState/001.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/readyState/001.html new file mode 100644 index 0000000000..15b73fdb7c --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/readyState/001.html @@ -0,0 +1,13 @@ +<!doctype html> +<title>WebSockets: getting readyState in connecting</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function(t) { + assert_equals((new WebSocket(SCHEME_DOMAIN_PORT+'/')).readyState, WebSocket.CONNECTING); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/readyState/002.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/readyState/002.html new file mode 100644 index 0000000000..239e5d7cf8 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/readyState/002.html @@ -0,0 +1,15 @@ +<!doctype html> +<title>WebSockets: setting readyState</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + ws.readyState = 5; + assert_equals(ws.readyState, ws.CONNECTING); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/readyState/003.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/readyState/003.html new file mode 100644 index 0000000000..65d86c437f --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/readyState/003.html @@ -0,0 +1,18 @@ +<!doctype html> +<title>WebSockets: delete readyState</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + ws.close(); + delete ws.readyState; + assert_equals(ws.readyState, ws.CLOSING, 'delete ws.readyState'); + delete WebSocket.prototype.readyState; + assert_equals(ws.readyState, undefined, 'delete WebSocket.prototype.readyState'); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/readyState/004.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/readyState/004.html new file mode 100644 index 0000000000..0645816a6c --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/readyState/004.html @@ -0,0 +1,17 @@ +<!doctype html> +<title>WebSockets: defineProperty getter for readyState</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function() { + Object.defineProperty(WebSocket.prototype, 'readyState', { + get: function() { return 'foo'; } + }); + var ws = new WebSocket('ws://example.invalid/'); + assert_equals(ws.readyState, 'foo'); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/readyState/005.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/readyState/005.html new file mode 100644 index 0000000000..bee179ffcb --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/readyState/005.html @@ -0,0 +1,19 @@ +<!doctype html> +<title>WebSockets: defineProperty setter for readyState</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function(){ + window.setter_ran = false; + Object.defineProperty(WebSocket.prototype, 'readyState', { + set: function(v) { window[v] = true; } + }); + var ws = new WebSocket('ws://example.invalid/'); + ws.readyState = 'setter_ran'; + assert_true(setter_ran); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/readyState/006.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/readyState/006.html new file mode 100644 index 0000000000..4290c00836 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/readyState/006.html @@ -0,0 +1,19 @@ +<!doctype html> +<title>WebSockets: getting readyState in open</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/echo'); + ws.onopen = t.step_func(function(e) { + assert_equals(ws.readyState, ws.OPEN); + ws.close(); + t.done(); + }); + ws.onerror = ws.onmessage = ws.onclose = t.step_func(function() {assert_unreached()}); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/readyState/007.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/readyState/007.html new file mode 100644 index 0000000000..69b5d9c9a9 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/readyState/007.html @@ -0,0 +1,19 @@ +<!doctype html> +<title>WebSockets: getting readyState in closing</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/echo'); + ws.onopen = t.step_func(function(e) { + ws.close(); + assert_equals(ws.readyState, ws.CLOSING); + t.done(); + }); + ws.onerror = ws.onmessage = ws.onclose = t.step_func(function() {assert_unreached()}); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/readyState/008.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/readyState/008.html new file mode 100644 index 0000000000..d085a7f4e3 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/readyState/008.html @@ -0,0 +1,21 @@ +<!doctype html> +<title>WebSockets: getting readyState in closed</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/echo'); + ws.onopen = t.step_func(function(e) { + ws.onclose = t.step_func(function(e) { + assert_equals(ws.readyState, ws.CLOSED); + t.done(); + }) + ws.close(); + }); + ws.onerror = ws.onmessage = ws.onclose = t.step_func(function() {assert_unreached()}); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/send/001.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/001.html new file mode 100644 index 0000000000..8abc655f5d --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/001.html @@ -0,0 +1,15 @@ +<!doctype html> +<title>WebSockets: send() 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="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + assert_throws_js(TypeError, function(){ws.send()}); +}); +</script> + diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/send/002.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/002.html new file mode 100644 index 0000000000..a51c67762c --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/002.html @@ -0,0 +1,15 @@ +<!doctype html> +<title>WebSockets: replacing send</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function() { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + ws.send = 5; + assert_equals(ws.send, 5); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/send/003.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/003.html new file mode 100644 index 0000000000..069f24cde5 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/003.html @@ -0,0 +1,15 @@ +<!doctype html> +<title>WebSockets: send() when readyState is CONNECTING</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + assert_throws_dom("INVALID_STATE_ERR", function(){ws.send('a')}); +}); +</script> + diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/send/004.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/004.html new file mode 100644 index 0000000000..7125d1922a --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/004.html @@ -0,0 +1,25 @@ +<!doctype html> +<title>WebSockets: send() with unpaired surrogate when readyState is CONNECTING</title> + +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + assert_throws_dom("INVALID_STATE_ERR", function(){ws.send('a\uDC00x')}); +}, "lone low surrogate"); + +test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + assert_throws_dom("INVALID_STATE_ERR", function(){ws.send('a\uD800x')}); +}, "lone high surrogate"); + +test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + assert_throws_dom("INVALID_STATE_ERR", function(){ws.send('a\uDC00\uD800x')}); +}, "surrogates in wrong order"); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/send/005.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/005.html new file mode 100644 index 0000000000..5da4600771 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/005.html @@ -0,0 +1,19 @@ +<!doctype html> +<title>WebSockets: send() return value</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="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(t){ + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/echo'); + ws.onopen = t.step_func(function(e) { + assert_equals(ws.send('test'), undefined); + t.done(); + }); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/send/006.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/006.html new file mode 100644 index 0000000000..4095c0ba6b --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/006.html @@ -0,0 +1,28 @@ +<!doctype html> +<title>WebSockets: send() with unpaired surrogate when readyState is OPEN</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<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'); + ws.onopen = t.step_func(function(e) { + // lone low surrogate, lone high surrogate + surrogates in wrong order. + ws.send('a\uDC00xb\uD800xc\uDC00\uD800x'); + }) + ws.onmessage = t.step_func(function(e) { + assert_equals(e.data, 'a\uFFFDxb\uFFFDxc\uFFFD\uFFFDx'); + ws.onclose = t.step_func(function(e) { + ws.onclose = t.unreached_func(); + t.step_timeout(() => t.done(), 50); + }); + ws.close(); + }) + // This will be overridden if the message event fires. + ws.onclose = t.unreached_func('close event should not fire before message event'); + }); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/send/007.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/007.html new file mode 100644 index 0000000000..6a5614257a --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/007.html @@ -0,0 +1,27 @@ +<!doctype html> +<title>WebSockets: close() followed by send()</title> + +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<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'); + ws.onopen = t.step_func(function(e) { + // test that nothing strange happens if we send something after close() + ws.close(); + var sent = ws.send('test'); + assert_equals(sent, undefined); + }); + ws.onclose = t.step_func(function(e) { + ws.onclose = t.unreached_func(); + t.step_timeout(() => t.done(), 50); + }); + ws.onerror = ws.onmessage = t.unreached_func(); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/send/008.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/008.html new file mode 100644 index 0000000000..709c066ade --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/008.html @@ -0,0 +1,25 @@ +<!doctype html> +<title>WebSockets: send() in onclose</title> + +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/echo'); + ws.onopen = t.step_func(function(e) { + ws.send('Goodbye'); + }) + ws.onclose = t.step_func(function(e) { + // test that nothing strange happens when send()ing in closed state + var sent = ws.send('test'); + assert_equals(sent, undefined); + ws.onclose = t.unreached_func(); + t.step_timeout(() => t.done(), 50); + }) + ws.onerror = t.unreached_func(); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/send/009.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/009.html new file mode 100644 index 0000000000..57da896ea6 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/009.html @@ -0,0 +1,27 @@ +<!doctype html> +<title>WebSockets: send('')</title> + +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<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+'/empty-message'); + ws.onopen = t.step_func(function(e) { + ws.send(''); + }) + ws.onmessage = t.step_func(function(e) { + assert_equals(e.data, 'pass'); + ws.close(); + }); + ws.onclose = t.step_func(function(e) { + ws.onclose = t.unreached_func(); + t.step_timeout(() => t.done(), 50); + }); + ws.onerror = t.unreached_func(); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/send/010.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/010.html new file mode 100644 index 0000000000..4a008b610c --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/010.html @@ -0,0 +1,42 @@ +<!doctype html> +<title>WebSockets: sending non-strings</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="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(outer) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/echo'); + var stuffToSend = [null, undefined, 1, window, document.body, {}, [], ws, function(){}, new Error()] + var tests = []; + + for (var i=0; i<stuffToSend.length; i++) { + tests.push(async_test(document.title + " (" + stuffToSend[i] + ")")); + } + + i = 0; + function sendNext() { + if (i === stuffToSend.length) { + outer.done() + ws.close(); + } else { + var t = tests[i]; + ws.onmessage = t.step_func(function(e) { + assert_equals(e.data, String(stuffToSend[i])); + i++; + sendNext(); + t.done(); + }); + ws.onclose = ws.onerror = t.step_func(function() {assert_unreached()}); + ws.send(stuffToSend[i]); + } + } + ws.onopen = outer.step_func(function(e) { + sendNext(); + }); +}, "Constructor succeeds"); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/send/011.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/011.html new file mode 100644 index 0000000000..5f63c4471c --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/011.html @@ -0,0 +1,28 @@ +<!doctype html> +<title>WebSockets: sending non-ascii, combining chars and non-BMP</title> + +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<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'); + ws.onopen = t.step_func(function(e) { + ws.send('\u00E5 a\u030A \uD801\uDC7E'); + }); + ws.onmessage = t.step_func(function(e) { + assert_equals(e.data, '\u00E5 a\u030A \uD801\uDC7E'); + ws.onclose = t.step_func(function(e) { + ws.onclose = t.unreached_func(); + t.step_timeout(() => t.done(), 50); + }) + ws.close(); + }) + ws.onclose = ws.onerror = t.unreached_func(); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/send/012.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/012.html new file mode 100644 index 0000000000..9876c7bdd3 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/012.html @@ -0,0 +1,28 @@ +<!doctype html> +<title>WebSockets: sending null</title> + +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<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'); + ws.onopen = t.step_func(function(e) { + ws.send(null); + }); + ws.onmessage = t.step_func(function(e) { + assert_equals(e.data, 'null'); + ws.onclose = t.step_func(function(e) { + ws.onclose = t.unreached_func(); + t.step_timeout(() => t.done(), 50); + }) + ws.close(); + }); + ws.onclose = ws.onerror = t.unreached_func(); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/url/001.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/url/001.html new file mode 100644 index 0000000000..6c7306d038 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/url/001.html @@ -0,0 +1,13 @@ +<!doctype html> +<title>WebSockets: getting url</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function() { + assert_equals((new WebSocket(SCHEME_DOMAIN_PORT)).url, SCHEME_DOMAIN_PORT+'/'); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/url/002.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/url/002.html new file mode 100644 index 0000000000..e1cc6d0c01 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/url/002.html @@ -0,0 +1,15 @@ +<!doctype html> +<title>WebSockets: setting url</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function() { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + ws.url = SCHEME_DOMAIN_PORT+'/test'; + assert_equals(ws.url, SCHEME_DOMAIN_PORT+'/'); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/url/003.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/url/003.html new file mode 100644 index 0000000000..aaae33a4cc --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/url/003.html @@ -0,0 +1,17 @@ +<!doctype html> +<title>WebSockets: deleting url</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function() { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + delete ws.url; + assert_equals(ws.url, SCHEME_DOMAIN_PORT+'/', 'delete ws.url'); + delete WebSocket.prototype.url; + assert_equals(ws.url, undefined, 'delete WebSocket.prototype.url'); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/url/004.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/url/004.html new file mode 100644 index 0000000000..7db5e1e425 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/url/004.html @@ -0,0 +1,17 @@ +<!doctype html> +<title>WebSockets: 'URL'</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function() { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + assert_equals(ws.URL, undefined); + assert_equals('URL' in ws, false); + assert_equals(WebSocket.prototype.URL, undefined); + assert_equals('URL' in WebSocket.prototype, false); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/url/005.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/url/005.html new file mode 100644 index 0000000000..00a5d90024 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/url/005.html @@ -0,0 +1,17 @@ +<!doctype html> +<title>WebSockets: defineProperty getter for url</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function() { + Object.defineProperty(WebSocket.prototype, 'url', { + get: function() { return 'foo'; } + }); + var ws = new WebSocket('ws://example.invalid/'); + assert_equals(ws.url, 'foo'); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/url/006.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/url/006.html new file mode 100644 index 0000000000..6e83770405 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/url/006.html @@ -0,0 +1,19 @@ +<!doctype html> +<title>WebSockets: defineProperty setter for url</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function() { + window.setter_ran = false; + Object.defineProperty(WebSocket.prototype, 'url', { + set: function(v) { window[v] = true; } + }); + var ws = new WebSocket('ws://example.invalid/'); + ws.url = 'setter_ran'; + assert_true(setter_ran); +}); +</script> diff --git a/testing/web-platform/tests/websockets/interfaces/WebSocket/url/resolve.html b/testing/web-platform/tests/websockets/interfaces/WebSocket/url/resolve.html new file mode 100644 index 0000000000..2452073827 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/url/resolve.html @@ -0,0 +1,14 @@ +<!doctype html> +<title>WebSocket#url: resolving</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../../../constants.sub.js></script> +<meta name="variant" content="?default"> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function() { + var ws = new WebSocket(SCHEME_DOMAIN_PORT + '/echo?foo%20bar baz'); + assert_equals(ws.url, SCHEME_DOMAIN_PORT + '/echo?foo%20bar%20baz'); +}); +</script> |