diff options
Diffstat (limited to 'testing/web-platform/tests/websockets/interfaces')
73 files changed, 1617 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 000000000..acc718516 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/CloseEvent/clean-close.html @@ -0,0 +1,23 @@ +<!doctype html> +<title>WebSockets: wasClean, true</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'); + 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(); + }); +}, null, {timeout:2000}); +</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 000000000..1ed86bdf8 --- /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 000000000..24528a86f --- /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 000000000..faf09783a --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-arraybuffer.html @@ -0,0 +1,25 @@ +<!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.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'); + 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(); + }) +}); +</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 000000000..3af1d93a7 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-blob.html @@ -0,0 +1,26 @@ +<!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.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'); + 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(); + }); +}); +</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 000000000..a6bd53015 --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..feddfb90e --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..68c47e490 --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..0398b0a9c --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-getting.html @@ -0,0 +1,53 @@ +<!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.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<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 000000000..55e9cf9e9 --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..677423736 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-large.html @@ -0,0 +1,27 @@ +<!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.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'); + 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(); + }) +}, null, {timeout:20000}); +</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 000000000..8200b7504 --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..49b1330c9 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-unicode.html @@ -0,0 +1,23 @@ +<!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.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'); + 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(); + }); +}); +</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 000000000..ab6c93b61 --- /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.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+'/'); + 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); +}, undefined, {timeout:9900}); +</script> 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 000000000..2a1104439 --- /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.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+'/sleep_10_v13'); + setTimeout(t.step_func(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.step_func(assert_unreached); +}, undefined, {timeout:12000}); +</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 000000000..d64ac694f --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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) { + setTimeout(f, 500); + return; + } + assert_equals(i, 1); + t.done() + }); + setTimeout(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 000000000..d66495a69 --- /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.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+'/'); + 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); + } + setTimeout(t.step_func(function() { + assert_equals(i, 1); + t.done(); + }), 50); + }); + ws.close(); + assert_equals(ws.readyState, ws.CLOSING); +}, undefined, {timeout:9900}); +</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 000000000..a3d29d0c9 --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..c752c4224 --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..efc249aab --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..7280e09b4 --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..cdb06e5eb --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..a5b7649df --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..b3c2e932e --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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(new 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 000000000..702193456 --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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(new 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 000000000..4af7636bf --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/001.html @@ -0,0 +1,17 @@ +<!doctype html> +<title>WebSockets: getting on*</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 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 000000000..279e0c580 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/002.html @@ -0,0 +1,19 @@ +<!doctype html> +<title>WebSockets: setting on*</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 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 000000000..a9b76d84f --- /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.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+'/'); + 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); +}, null, {timeout:2000}); +</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 000000000..0c384a6cf --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..f7ccf1030 --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..4305097d1 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/007.html @@ -0,0 +1,21 @@ +<!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.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+'/'); + 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); +}, null, {timeout:2000}); +</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 000000000..dd06f0d18 --- /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.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+'/'); + 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 000000000..dc25884ce --- /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.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+'/'); + 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); +}, null, {timeout:2000}); +</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 000000000..f4a4850d6 --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..918becc10 --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..633f02c4a --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..465505128 --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..9250fb267 --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..8852e6415 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/015.html @@ -0,0 +1,33 @@ +<!doctype html> +<title>WebSockets: instanceof on events</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_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 + ws.send('\\x81\\x04test\\x83\\x03LOL'); + }); + 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 000000000..0e88c7903 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/016.html @@ -0,0 +1,37 @@ +<!doctype html> +<title>WebSockets: addEventListener</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'); + 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 000000000..b2ed59367 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/017.html @@ -0,0 +1,53 @@ +<!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.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_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 + ws.send('\\x81\\x04test\\x83\\x03LOL'); + 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 000000000..a3ef0f500 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/events/018.html @@ -0,0 +1,49 @@ +<!doctype html> +<title>WebSockets: toString(), bubbles, cancelable</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 ws = null; +setup(function() { + ws = new WebSocket(SCHEME_DOMAIN_PORT+'/echo_raw'); +}); + +async_test(function(t) { + ws.addEventListener('open', t.step_func_done(function(e) { + // first a text frame, then a frame with reserved opcode 3 + // which should fail the connection + ws.send('\\x81\\x04test\\x83\\x03LOL'); + 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); +}, "open event"); + +async_test(function(t) { + ws.addEventListener('message', t.step_func_done(function(e) { + 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); +}, "message event"); + +async_test(function(t) { + ws.addEventListener('error', t.step_func_done(function(e) { + 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); +}, "error event"); + +async_test(function(t) { + ws.addEventListener('close', t.step_func_done(function(e) { + 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); +}, "close event"); +</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 000000000..f975a8098 --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..54d96fe63 --- /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.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('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 000000000..f5003868e --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..ba27228ec --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..aa5d9fdf1 --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..9e97416f3 --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..93d72b64b --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..fbe326a10 --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..3ca870529 --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..e0be938ab --- /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.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'); + 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 000000000..12a4cd087 --- /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.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'); + 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 000000000..c83ead4e7 --- /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.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'); + 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 000000000..3a22420ad --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + assert_throws(new 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 000000000..f5c7e4feb --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..08aadbf46 --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + assert_throws("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 000000000..af906b553 --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + assert_throws("INVALID_STATE_ERR", function(){ws.send('a\uDC00x')}); +}, "lone low surrogate"); + +test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + assert_throws("INVALID_STATE_ERR", function(){ws.send('a\uD800x')}); +}, "lone high surrogate"); + +test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/'); + assert_throws("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 000000000..69e727d11 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/005.html @@ -0,0 +1,18 @@ +<!doctype html> +<title>WebSockets: send() 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> +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 000000000..ce871a106 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/006.html @@ -0,0 +1,25 @@ +<!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.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'); + 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.step_func(function() {assert_unreached()}); + setTimeout(function() {t.done();}, 50); + }); + ws.close(); + }) + }); +</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 000000000..73dd08930 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/007.html @@ -0,0 +1,26 @@ +<!doctype html> +<title>WebSockets: close() followed by send()</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'); + 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.step_func(function() {assert_unreached()}); + setTimeout(function() {t.done()}, 50); + }); + ws.onerror = ws.onmessage = t.step_func(function() {assert_unreached()}); +}); +</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 000000000..c5fc34bd8 --- /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.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'); + 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.step_func(function() {assert_unreached()}); + setTimeout(function() {t.done()}, 50); + }) + ws.onerror = t.step_func(function() {assert_unreached()}); +}); +</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 000000000..8f9417e77 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/009.html @@ -0,0 +1,26 @@ +<!doctype html> +<title>WebSockets: send('')</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+'/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.step_func(function() {assert_unreached()}); + setTimeout(function() {t.done()}, 50); + }); + ws.onerror = t.step_func(function() {assert_unreached()}); +}); +</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 000000000..f6680c66f --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/010.html @@ -0,0 +1,41 @@ +<!doctype html> +<title>WebSockets: sending non-strings</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(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 000000000..c00fa7f33 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/011.html @@ -0,0 +1,27 @@ +<!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.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'); + 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.step_func(function() {assert_unreached()}); + setTimeout(function() {t.done()}, 50); + }) + ws.close(); + }) + ws.onclose = ws.onerror = t.step_func(function() {assert_unreached()}); +}); +</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 000000000..af5b935c6 --- /dev/null +++ b/testing/web-platform/tests/websockets/interfaces/WebSocket/send/012.html @@ -0,0 +1,27 @@ +<!doctype html> +<title>WebSockets: sending null</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'); + 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.step_func(function() {assert_unreached()}); + setTimeout(function() {t.done()}, 50); + }) + ws.close(); + }); + ws.onclose = ws.onerror = t.step_func(function() {assert_unreached()}); +}); +</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 000000000..3d1e5e5b8 --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..aa1166402 --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..8cc0b7919 --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..908e2cd9e --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..f3d89cf2e --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..124bdbc19 --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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 000000000..ad7db147f --- /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.js?pipe=sub></script> +<meta name="variant" content=""> +<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> |