diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /testing/web-platform/tests/websockets | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/web-platform/tests/websockets')
237 files changed, 6260 insertions, 0 deletions
diff --git a/testing/web-platform/tests/websockets/Close-0.htm b/testing/web-platform/tests/websockets/Close-0.htm new file mode 100644 index 000000000..4dd88f6c7 --- /dev/null +++ b/testing/web-platform/tests/websockets/Close-0.htm @@ -0,0 +1,25 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close WebSocket - Code is 0</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var test = async_test("W3C WebSocket API - Create WebSocket - Close the Connection - close(0) - INVALID_ACCESS_ERR is thrown"); + + var wsocket = CreateWebSocket(false, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', test.step_func(function (evt) { + assert_throws("INVALID_ACCESS_ERR", function () { wsocket.close(0, "Close not in range 3000-4999") }); + test.done(); + }), true); + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Close-1000-reason.htm b/testing/web-platform/tests/websockets/Close-1000-reason.htm new file mode 100644 index 000000000..8424d7882 --- /dev/null +++ b/testing/web-platform/tests/websockets/Close-1000-reason.htm @@ -0,0 +1,35 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close WebSocket - Code is 1000 and reason</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Create WebSocket - Close the Connection - Connection should be opened"); + var testClose = async_test("W3C WebSocket API - Create WebSocket - Close the Connection - close(1000, reason) - readyState should be in CLOSED state and wasClean is TRUE - Connection should be closed"); + + var wsocket = CreateWebSocket(false, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.close(1000, "Clean Close"); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be opened"); + assert_equals(wsocket.readyState, 3, "readyState should be 3(CLOSED)"); + assert_equals(evt.wasClean, true, "wasClean should be TRUE"); + testClose.done(); + }), true); + + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Close-1000.htm b/testing/web-platform/tests/websockets/Close-1000.htm new file mode 100644 index 000000000..1622109d8 --- /dev/null +++ b/testing/web-platform/tests/websockets/Close-1000.htm @@ -0,0 +1,35 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close WebSocket - Code is 1000</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Create WebSocket - Connection should be opened"); + var testClose = async_test("W3C WebSocket API - Create WebSocket - Close the Connection - close(1000) - readyState should be in CLOSED state and wasClean is TRUE - Connection should be closed"); + + var wsocket = CreateWebSocket(false, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.close(1000); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be opened"); + assert_equals(wsocket.readyState, 3, "readyState should be 3(CLOSED)"); + assert_equals(evt.wasClean, true, "wasClean should be TRUE"); + testClose.done(); + }), true); + + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Close-NaN.htm b/testing/web-platform/tests/websockets/Close-NaN.htm new file mode 100644 index 000000000..8fd221929 --- /dev/null +++ b/testing/web-platform/tests/websockets/Close-NaN.htm @@ -0,0 +1,25 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close WebSocket - Code is NaN</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var test = async_test("W3C WebSocket API - Create WebSocket - Close the Connection - close(NaN) - INVALID_ACCESS_ERR is thrown"); + + var wsocket = CreateWebSocket(false, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', test.step_func(function (evt) { + assert_throws("INVALID_ACCESS_ERR", function () { wsocket.close(NaN) }); + test.done(); + }), true); + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Close-Reason-124Bytes.htm b/testing/web-platform/tests/websockets/Close-Reason-124Bytes.htm new file mode 100644 index 000000000..82a661e24 --- /dev/null +++ b/testing/web-platform/tests/websockets/Close-Reason-124Bytes.htm @@ -0,0 +1,27 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close WebSocket - Reason is more than 123 bytes long</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var test = async_test("W3C WebSocket API - Create WebSocket - Close the Connection - close(code, 'reason more than 123 bytes') - SYNTAX_ERR is thrown"); + + var wsocket = CreateWebSocket(false, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', test.step_func(function (evt) { + var reason = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123"; + assert_equals(reason.length, 124); + assert_throws("SYNTAX_ERR", function () { wsocket.close(1000, reason) }); + test.done(); + }), true); + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Close-clamp.htm b/testing/web-platform/tests/websockets/Close-clamp.htm new file mode 100644 index 000000000..6660e813e --- /dev/null +++ b/testing/web-platform/tests/websockets/Close-clamp.htm @@ -0,0 +1,14 @@ +<!DOCTYPE html> +<title>WebSocket#close(2**16+1000)</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="websocket.sub.js"></script> +<div id="log"></div> +<script> +test(function() { + var ws = CreateWebSocket(false, false, false); + assert_throws("InvalidAccessError", function () { + ws.close(0x10000 + 1000); + }); +}); +</script> diff --git a/testing/web-platform/tests/websockets/Close-null.htm b/testing/web-platform/tests/websockets/Close-null.htm new file mode 100644 index 000000000..dcd477313 --- /dev/null +++ b/testing/web-platform/tests/websockets/Close-null.htm @@ -0,0 +1,25 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close WebSocket - Code is null</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var test = async_test("W3C WebSocket API - Create WebSocket - Close the Connection - close(null) - INVALID_ACCESS_ERR is thrown"); + + var wsocket = CreateWebSocket(false, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', test.step_func(function (evt) { + assert_throws("INVALID_ACCESS_ERR", function () { wsocket.close(null) }); + test.done(); + }), true); + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Close-reason-unpaired-surrogates.htm b/testing/web-platform/tests/websockets/Close-reason-unpaired-surrogates.htm new file mode 100644 index 000000000..9ad8d618c --- /dev/null +++ b/testing/web-platform/tests/websockets/Close-reason-unpaired-surrogates.htm @@ -0,0 +1,36 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close WebSocket - Reason with unpaired surrogates</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Create WebSocket - Close the Connection - close(reason with unpaired surrogates) - connection should get opened"); + var testClose = async_test("W3C WebSocket API - Create WebSocket - Close the Connection - close(reason with unpaired surrogates) - connection should get closed"); + + var wsocket = CreateWebSocket(false, false, false); + var isOpenCalled = false; + var replacementChar = "\uFFFD"; + var reason = "\uD807"; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.close(1000, reason); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be opened"); + assert_equals(evt.reason, replacementChar, "reason replaced with replacement character"); + testClose.done(); + }), true); + + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Close-string.htm b/testing/web-platform/tests/websockets/Close-string.htm new file mode 100644 index 000000000..d394d5cca --- /dev/null +++ b/testing/web-platform/tests/websockets/Close-string.htm @@ -0,0 +1,25 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close WebSocket - Code is String</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var test = async_test("W3C WebSocket API - Create WebSocket - Close the Connection - close(String) - INVALID_ACCESS_ERR is thrown"); + + var wsocket = CreateWebSocket(false, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', test.step_func(function (evt) { + assert_throws("INVALID_ACCESS_ERR", function () { wsocket.close('string') }); + test.done(); + }), true); + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Close-undefined.htm b/testing/web-platform/tests/websockets/Close-undefined.htm new file mode 100644 index 000000000..d6c89afbf --- /dev/null +++ b/testing/web-platform/tests/websockets/Close-undefined.htm @@ -0,0 +1,25 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close WebSocket - Code is undefined</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var test = async_test(); + + var wsocket = CreateWebSocket(false, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', test.step_func(function (evt) { + wsocket.close(undefined); + test.done(); + }), true); + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Create-Secure-blocked-port.htm b/testing/web-platform/tests/websockets/Create-Secure-blocked-port.htm new file mode 100644 index 000000000..e55bc31af --- /dev/null +++ b/testing/web-platform/tests/websockets/Create-Secure-blocked-port.htm @@ -0,0 +1,88 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Create Secure WebSocket - blocked port</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script> + test(function () { + // list of bad ports according to + // https://fetch.spec.whatwg.org/#port-blocking + var BLOCKED_PORTS_LIST = [ + 1, // tcpmux + 7, // echo + 9, // discard + 11, // systat + 13, // daytime + 15, // netstat + 17, // qotd + 19, // chargen + 20, // ftp-data + 21, // ftp + 22, // ssh + 23, // telnet + 25, // smtp + 37, // time + 42, // name + 43, // nicname + 53, // domain + 77, // priv-rjs + 79, // finger + 87, // ttylink + 95, // supdup + 101, // hostriame + 102, // iso-tsap + 103, // gppitnp + 104, // acr-nema + 109, // pop2 + 110, // pop3 + 111, // sunrpc + 113, // auth + 115, // sftp + 117, // uucp-path + 119, // nntp + 123, // ntp + 135, // loc-srv / epmap + 139, // netbios + 143, // imap2 + 179, // bgp + 389, // ldap + 465, // smtp+ssl + 512, // print / exec + 513, // login + 514, // shell + 515, // printer + 526, // tempo + 530, // courier + 531, // chat + 532, // netnews + 540, // uucp + 556, // remotefs + 563, // nntp+ssl + 587, // smtp + 601, // syslog-conn + 636, // ldap+ssl + 993, // imap+ssl + 995, // pop3+ssl + 2049, // nfs + 3659, // apple-sasl + 4045, // lockd + 6000, // x11 + 6665, // irc (alternate) + 6666, // irc (alternate) + 6667, // irc (default) + 6668, // irc (alternate) + 6669, // irc (alternate) + ]; + for (var i = 0; i < BLOCKED_PORTS_LIST.length; i++) { + var blockedPort = BLOCKED_PORTS_LIST[i]; + assert_throws("SECURITY_ERR", function () { CreateWebSocketWithBlockedPort(blockedPort) }); + } + }, "W3C WebSocket API - Create Secure WebSocket - Pass a URL with a blocked port - SECURITY_ERR should be thrown") + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Create-Secure-extensions-empty.htm b/testing/web-platform/tests/websockets/Create-Secure-extensions-empty.htm new file mode 100644 index 000000000..2f9f79765 --- /dev/null +++ b/testing/web-platform/tests/websockets/Create-Secure-extensions-empty.htm @@ -0,0 +1,33 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Create Secure WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Create Secure WebSocket - wsocket.extensions should be set to '' after connection is established - Connection should be opened"); + var testClose = async_test("W3C WebSocket API - Create Secure WebSocket - wsocket.extensions should be set to '' after connection is established - Connection should be closed"); + + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + assert_equals(wsocket.extensions, "", "extensions should be empty"); + wsocket.close(); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be closed"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Create-Secure-url-with-space.htm b/testing/web-platform/tests/websockets/Create-Secure-url-with-space.htm new file mode 100644 index 000000000..d2dfe1bd7 --- /dev/null +++ b/testing/web-platform/tests/websockets/Create-Secure-url-with-space.htm @@ -0,0 +1,19 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Create Secure WebSocket - url with space</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + test(function () { + var wsocket; + var spaceUrl = "web platform.test"; + assert_throws("SYNTAX_ERR", function () { wsocket = CreateWebSocketWithSpaceInUrl(spaceUrl) }); + }, "W3C WebSocket API - Create Secure WebSocket - Pass a URL with a space - SYNTAX_ERR should be thrown") + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Create-Secure-valid-url-array-protocols.htm b/testing/web-platform/tests/websockets/Create-Secure-valid-url-array-protocols.htm new file mode 100644 index 000000000..d61a429c5 --- /dev/null +++ b/testing/web-platform/tests/websockets/Create-Secure-valid-url-array-protocols.htm @@ -0,0 +1,34 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Create Secure WebSocket with valid url and array of protocols</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Create Secure WebSocket - Pass a valid URL and array of protocol strings - Connection should be opened"); + var testClose = async_test("W3C WebSocket API - Create Secure WebSocket - Pass a valid URL and array of protocol strings - Connection should be closed"); + + var wsocket = CreateWebSocket(true, false, true); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + assert_equals(wsocket.readyState, 1, "readyState should be 1(OPEN)"); + wsocket.close(); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Create-Secure-valid-url-binaryType-blob.htm b/testing/web-platform/tests/websockets/Create-Secure-valid-url-binaryType-blob.htm new file mode 100644 index 000000000..0261fb48a --- /dev/null +++ b/testing/web-platform/tests/websockets/Create-Secure-valid-url-binaryType-blob.htm @@ -0,0 +1,34 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Create Secure WebSocket - binaryType set correctly</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Create Secure WebSocket - wsocket.binaryType should be set to 'blob' after connection is established - Connection should be opened"); + var testClose = async_test("W3C WebSocket API - Create Secure WebSocket - wsocket.binaryType should be set to 'blob' after connection is established - Connection should be closed"); + + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + assert_equals(wsocket.binaryType, "blob", "binaryType should be set to Blob"); + wsocket.close(); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Create-Secure-valid-url-protocol-setCorrectly.htm b/testing/web-platform/tests/websockets/Create-Secure-valid-url-protocol-setCorrectly.htm new file mode 100644 index 000000000..a7f1510a0 --- /dev/null +++ b/testing/web-platform/tests/websockets/Create-Secure-valid-url-protocol-setCorrectly.htm @@ -0,0 +1,33 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Create Secure WebSocket and verify if protocol is set correctly after connection</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Create Secure WebSocket - Pass a valid URL and protocol string - protocol should be set correctly - Connection should be opened"); + var testClose = async_test("W3C WebSocket API - Create Secure WebSocket - Pass a valid URL and protocol string - Connection should be closed"); + + var wsocket = CreateWebSocket(true, true, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + assert_equals(wsocket.protocol, "echo", "protocol should be set to echo"); + wsocket.close(); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Create-Secure-valid-url-protocol-string.htm b/testing/web-platform/tests/websockets/Create-Secure-valid-url-protocol-string.htm new file mode 100644 index 000000000..7250b4e7b --- /dev/null +++ b/testing/web-platform/tests/websockets/Create-Secure-valid-url-protocol-string.htm @@ -0,0 +1,34 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Create Secure WebSocket with valid url and protocol string</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Create Secure WebSocket - Check readyState is 1"); + var testClose = async_test("W3C WebSocket API - Create Secure WebSocket - Pass a valid URL and protocol string - Connection should be closed"); + + var wsocket = CreateWebSocket(true, true, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + assert_equals(wsocket.readyState, 1, "readyState should be 1(OPEN)"); + wsocket.close(); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Create-Secure-valid-url.htm b/testing/web-platform/tests/websockets/Create-Secure-valid-url.htm new file mode 100644 index 000000000..1fe6c0f43 --- /dev/null +++ b/testing/web-platform/tests/websockets/Create-Secure-valid-url.htm @@ -0,0 +1,34 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Create Secure WebSocket with valid url</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Create Secure WebSocket - Pass a valid URL - Connection should be opened"); + var testClose = async_test("W3C WebSocket API - Create Secure WebSocket - Pass a valid URL - Connection should be closed"); + + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + assert_equals(wsocket.readyState, 1, "readyState should be 1(OPEN)"); + wsocket.close(); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Create-Secure-verify-url-set-non-default-port.htm b/testing/web-platform/tests/websockets/Create-Secure-verify-url-set-non-default-port.htm new file mode 100644 index 000000000..63e49f4f7 --- /dev/null +++ b/testing/web-platform/tests/websockets/Create-Secure-verify-url-set-non-default-port.htm @@ -0,0 +1,19 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Create Secure WebSocket - wsocket.url is set correctly - non default port</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + test(function () { + var urlNonDefaultPort = "wss://" + __SERVER__NAME + ":" + __NEW__SECURE__PORT + "/" + __PATH; + var wsocket = new WebSocket(urlNonDefaultPort); + assert_equals(wsocket.url, urlNonDefaultPort, "wsocket.url is set correctly"); + }, "W3C WebSocket API - Create Secure WebSocket - wsocket.url should be set correctly") + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Create-asciiSep-protocol-string.htm b/testing/web-platform/tests/websockets/Create-asciiSep-protocol-string.htm new file mode 100644 index 000000000..0d0480eb7 --- /dev/null +++ b/testing/web-platform/tests/websockets/Create-asciiSep-protocol-string.htm @@ -0,0 +1,21 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Create WebSocket - ascii protocol string with separator</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + if(window.WebSocket) { + test(function () { + var asciiWithSep = "/echo"; + var wsocket; + assert_throws("SYNTAX_ERR", function () { wsocket = CreateWebSocketWithAsciiSep(asciiWithSep) }); + }, "W3C WebSocket API - Create WebSocket - Pass a valid URL and a protocol string with an ascii separator character - SYNTAX_ERR is thrown") + } + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Create-invalid-urls.htm b/testing/web-platform/tests/websockets/Create-invalid-urls.htm new file mode 100644 index 000000000..c4a4c7986 --- /dev/null +++ b/testing/web-platform/tests/websockets/Create-invalid-urls.htm @@ -0,0 +1,34 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Create WebSocket - pass in list of invalid urls</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + var wsocket; + test(function() { + assert_throws("SYNTAX_ERR", function () { wsocket = new WebSocket("/echo") }); + }, "Url is /echo - should throw SYNTAX_ERR"); + + test(function () { + assert_throws("SYNTAX_ERR", function () { wsocket = new WebSocket("mailto:microsoft@microsoft.com") }); + }, "Url is a mail address - should throw SYNTAX_ERR"); + + test(function () { + assert_throws("SYNTAX_ERR", function () { wsocket = new WebSocket("about:blank") }); + }, "Url is about:blank - should throw SYNTAX_ERR"); + + test(function () { + assert_throws("SYNTAX_ERR", function () { wsocket = new WebSocket("?test") }); + }, "Url is ?test - should throw SYNTAX_ERR"); + + test(function () { + assert_throws("SYNTAX_ERR", function () { wsocket = new WebSocket("#test") }); + }, "Url is #test - should throw SYNTAX_ERR"); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Create-non-absolute-url.htm b/testing/web-platform/tests/websockets/Create-non-absolute-url.htm new file mode 100644 index 000000000..2ed8ece16 --- /dev/null +++ b/testing/web-platform/tests/websockets/Create-non-absolute-url.htm @@ -0,0 +1,18 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Create WebSocket - non absolute url</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + test(function () { + var wsocket; + assert_throws("SYNTAX_ERR", function () { wsocket = CreateWebSocketNonAbsolute() }); + }, "W3C WebSocket API - Create WebSocket - Pass a non absolute URL - SYNTAX_ERR is thrown") + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Create-nonAscii-protocol-string.htm b/testing/web-platform/tests/websockets/Create-nonAscii-protocol-string.htm new file mode 100644 index 000000000..fd3401801 --- /dev/null +++ b/testing/web-platform/tests/websockets/Create-nonAscii-protocol-string.htm @@ -0,0 +1,21 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Create WebSocket - non ascii protocol string</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + if(window.WebSocket) { + test(function () { + var nonAsciiProtocol = "\u0080echo"; + var wsocket; + assert_throws("SYNTAX_ERR", function () { wsocket = CreateWebSocketNonAsciiProtocol(nonAsciiProtocol) }); + }, "W3C WebSocket API - Create WebSocket - Pass a valid URL and a protocol string with non-ascii values - SYNTAX_ERR is thrown") + } + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Create-protocol-with-space.htm b/testing/web-platform/tests/websockets/Create-protocol-with-space.htm new file mode 100644 index 000000000..023a49831 --- /dev/null +++ b/testing/web-platform/tests/websockets/Create-protocol-with-space.htm @@ -0,0 +1,18 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Create WebSocket - protocol with space</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + test(function () { + var wsocket; + assert_throws("SYNTAX_ERR", function () { wsocket = CreateWebSocketWithSpaceInProtocol("ec ho") }); + }, "W3C WebSocket API - Create WebSocket - Pass a valid URL and a protocol string with a space in it - SYNTAX_ERR is thrown") + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Create-protocols-repeated-case-insensitive.htm b/testing/web-platform/tests/websockets/Create-protocols-repeated-case-insensitive.htm new file mode 100644 index 000000000..47225ef2e --- /dev/null +++ b/testing/web-platform/tests/websockets/Create-protocols-repeated-case-insensitive.htm @@ -0,0 +1,18 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Create WebSocket - repeated protocols with different case</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + test(function () { + var wsocket; + assert_throws("SYNTAX_ERR", function () { wsocket = CreateWebSocketWithRepeatedProtocolsCaseInsensitive() }); + }, "W3C WebSocket API - Create WebSocket - Pass a valid URL and an array of protocol strings with repeated values but different case - SYNTAX_ERR is thrown") + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Create-protocols-repeated.htm b/testing/web-platform/tests/websockets/Create-protocols-repeated.htm new file mode 100644 index 000000000..6a62bca50 --- /dev/null +++ b/testing/web-platform/tests/websockets/Create-protocols-repeated.htm @@ -0,0 +1,18 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Create WebSocket - repeated protocols</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + test(function () { + var wsocket; + assert_throws("SYNTAX_ERR", function () { wsocket = CreateWebSocketWithRepeatedProtocols() }); + }, "W3C WebSocket API - Create WebSocket - Pass a valid URL and an array of protocol strings with repeated values - SYNTAX_ERR is thrown") + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Create-valid-url-array-protocols.htm b/testing/web-platform/tests/websockets/Create-valid-url-array-protocols.htm new file mode 100644 index 000000000..3ebf3f562 --- /dev/null +++ b/testing/web-platform/tests/websockets/Create-valid-url-array-protocols.htm @@ -0,0 +1,35 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Create WebSocket with valid url and array of protocols</title> + <script type="text/javascript" src="websocket.sub.js"></script> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Create WebSocket - Pass a valid URL and array of protocol strings - Connection should be opened"); + var testClose = async_test("W3C WebSocket API - Create WebSocket - Pass a valid URL and array of protocol strings - Connection should be closed"); + + var wsocket = CreateWebSocket(false, false, true); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + assert_equals(wsocket.readyState, 1, "readyState should be 1(OPEN)"); + wsocket.close(); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Create-valid-url-protocol-empty.htm b/testing/web-platform/tests/websockets/Create-valid-url-protocol-empty.htm new file mode 100644 index 000000000..9146937ba --- /dev/null +++ b/testing/web-platform/tests/websockets/Create-valid-url-protocol-empty.htm @@ -0,0 +1,19 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Create WebSocket - wsocket.protocol is empty before connection is established</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + test(function () { + var wsocket = CreateWebSocket(false, true, false); + assert_equals(wsocket.protocol, "", "protocol should be empty"); + wsocket.close(); + }, "W3C WebSocket API - Create WebSocket - wsocket.protocol should be empty before connection is established") + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Create-valid-url-protocol.htm b/testing/web-platform/tests/websockets/Create-valid-url-protocol.htm new file mode 100644 index 000000000..0a6dd97f0 --- /dev/null +++ b/testing/web-platform/tests/websockets/Create-valid-url-protocol.htm @@ -0,0 +1,34 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Create WebSocket with a valid url and protocol string</title> + <script type="text/javascript" src="websocket.sub.js"></script> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Create WebSocket - Pass a valid URL and a protocol string - Connection should be opened"); + var testClose = async_test("W3C WebSocket API - Create WebSocket - Pass a valid URL and a protocol string - Connection should be closed"); + + var wsocket = CreateWebSocket(false, true, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + assert_equals(wsocket.readyState, 1, "readyState should be 1(OPEN)"); + wsocket.close(); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Create-valid-url.htm b/testing/web-platform/tests/websockets/Create-valid-url.htm new file mode 100644 index 000000000..e74a7bfef --- /dev/null +++ b/testing/web-platform/tests/websockets/Create-valid-url.htm @@ -0,0 +1,34 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Create WebSocket with valid url</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Create WebSocket - Pass a valid URL - Connection should be opened"); + var testClose = async_test("W3C WebSocket API - Create WebSocket - Pass a valid URL - Connection should be closed"); + + var wsocket = CreateWebSocket(false, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + assert_equals(wsocket.readyState, 1, "readyState should be 1(OPEN)"); + wsocket.close(); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Create-verify-url-set-non-default-port.htm b/testing/web-platform/tests/websockets/Create-verify-url-set-non-default-port.htm new file mode 100644 index 000000000..181794df9 --- /dev/null +++ b/testing/web-platform/tests/websockets/Create-verify-url-set-non-default-port.htm @@ -0,0 +1,19 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Create WebSocket - wsocket.url is set correctly - non default port</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + test(function () { + var urlNonDefaultPort = "ws://" + __SERVER__NAME + ":" + __NEW__PORT + "/" + __PATH; + var wsocket = new WebSocket(urlNonDefaultPort); + assert_equals(wsocket.url, urlNonDefaultPort, "wsocket.url is set correctly"); + }, "W3C WebSocket API - Create WebSocket - wsocket.url should be set correctly"); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Create-wrong-scheme.htm b/testing/web-platform/tests/websockets/Create-wrong-scheme.htm new file mode 100644 index 000000000..a0a98205e --- /dev/null +++ b/testing/web-platform/tests/websockets/Create-wrong-scheme.htm @@ -0,0 +1,18 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Create WebSocket - non ws/wss scheme in url</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + test(function () { + var wsocket; + assert_throws("SYNTAX_ERR", function () { wsocket = CreateWebSocketNonWsScheme() }); + }, "W3C WebSocket API - Create WebSocket - Pass a URL with a non ws/wss scheme - SYNTAX_ERR is thrown") + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/OWNERS b/testing/web-platform/tests/websockets/OWNERS new file mode 100644 index 000000000..de8d614a7 --- /dev/null +++ b/testing/web-platform/tests/websockets/OWNERS @@ -0,0 +1,8 @@ +@kristijanburnik +@zcorpan +@plehegar +@zqzhang +@sideshowbarker +@Jxck +@jdm +@Ms2ger diff --git a/testing/web-platform/tests/websockets/README.md b/testing/web-platform/tests/websockets/README.md new file mode 100644 index 000000000..f03192230 --- /dev/null +++ b/testing/web-platform/tests/websockets/README.md @@ -0,0 +1,10 @@ +This directory contains the WebSocket API test suite. + +The following document contains a list of each test file in the test suite and the results of running the test file on several browsers <http://www.w3.org/wiki/Webapps/Interop/WebSockets>. + +To run this test suite within a browser, go to: <http://w3c-test.org/websockets/>. + +The latest Editor's Draft of WebSocket API is: <http://dev.w3.org/html5/websockets/>. + +The latest W3C Technical Report of WebSocket API is <http://www.w3.org/TR/websockets/>. + diff --git a/testing/web-platform/tests/websockets/Secure-Close-0.htm b/testing/web-platform/tests/websockets/Secure-Close-0.htm new file mode 100644 index 000000000..03f8aa5fa --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Close-0.htm @@ -0,0 +1,25 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close Secure WebSocket - Code is 0</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var test = async_test("W3C WebSocket API - Create Secure WebSocket - Close the Connection - close(0) - INVALID_ACCESS_ERR is thrown"); + + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', test.step_func(function (evt) { + assert_throws("INVALID_ACCESS_ERR", function () { wsocket.close(0, "Close not in range 3000-4999") }); + test.done(); + }), true); + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Close-1000-reason.htm b/testing/web-platform/tests/websockets/Secure-Close-1000-reason.htm new file mode 100644 index 000000000..3dead6bfb --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Close-1000-reason.htm @@ -0,0 +1,35 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close Secure WebSocket - Code is 1000 and reason</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Create Secure WebSocket - Close the Connection - close(1000, reason) - Connection should be opened"); + var testClose = async_test("W3C WebSocket API - Create Secure WebSocket - Close the Connection - close(1000, reason) - readyState should be in CLOSED state and wasClean is TRUE - Connection should be closed"); + + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.close(1000, "Clean Close"); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(wsocket.readyState, 3, "readyState should be 3(CLOSED)"); + assert_equals(evt.wasClean, true, "wasClean should be TRUE"); + testClose.done(); + }), true); + + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Close-1000-verify-code.htm b/testing/web-platform/tests/websockets/Secure-Close-1000-verify-code.htm new file mode 100644 index 000000000..0cac622f3 --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Close-1000-verify-code.htm @@ -0,0 +1,35 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close Secure WebSocket - Code is 1000 - verify code in CloseEvent is 1000</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Create Secure WebSocket - Close the Connection - close(1000, reason) - Connection should be opened"); + var testClose = async_test("W3C WebSocket API - Create Secure WebSocket - Close the Connection - close(1000, reason) - event.code == 1000 and event.reason = 'Clean Close'"); + + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.close(1000, "Clean Close"); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.code, 1000, "CloseEvent.code should be 1000"); + assert_equals(evt.reason, "Clean Close", "CloseEvent.reason should be the same as the reason sent in close"); + testClose.done(); + }), true); + + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Close-1000.htm b/testing/web-platform/tests/websockets/Secure-Close-1000.htm new file mode 100644 index 000000000..3da86305a --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Close-1000.htm @@ -0,0 +1,35 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close Secure WebSocket - Code is 1000</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Create Secure WebSocket - Close the Connection - close(1000) - Connection should be opened"); + var testClose = async_test("W3C WebSocket API - Create Secure WebSocket - Close the Connection - close(1000) - readyState should be in CLOSED state and wasClean is TRUE - Connection should be closed"); + + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.close(1000); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(wsocket.readyState, 3, "readyState should be 3(CLOSED)"); + assert_equals(evt.wasClean, true, "wasClean should be TRUE"); + testClose.done(); + }), true); + + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Close-1005-verify-code.htm b/testing/web-platform/tests/websockets/Secure-Close-1005-verify-code.htm new file mode 100644 index 000000000..6414b770c --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Close-1005-verify-code.htm @@ -0,0 +1,35 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close Secure WebSocket - verify return code is 1005</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Create Secure WebSocket - Close the Connection - close() - Connection should be opened"); + var testClose = async_test("W3C WebSocket API - Create Secure WebSocket - Close the Connection - close() - return close code is 1005 - Connection should be closed"); + + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.close(); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.code, 1005, "CloseEvent.code should be 1005"); + assert_equals(evt.reason, "", "CloseEvent.reason should be empty"); + testClose.done(); + }), true); + + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Close-1005.htm b/testing/web-platform/tests/websockets/Secure-Close-1005.htm new file mode 100644 index 000000000..de8f51f28 --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Close-1005.htm @@ -0,0 +1,25 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close Secure WebSocket - Code is 1005</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var test = async_test("W3C WebSocket API - Create Secure WebSocket - Close the Connection - close(1005) - see '7.1.5. The WebSocket Connection Close Code' in http://www.ietf.org/rfc/rfc6455.txt"); + + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', test.step_func(function (evt) { + assert_throws("INVALID_ACCESS_ERR", function () { wsocket.close(1005, "1005 - reserved code") }); + test.done(); + }), true); + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Close-2999-reason.htm b/testing/web-platform/tests/websockets/Secure-Close-2999-reason.htm new file mode 100644 index 000000000..223fc62ef --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Close-2999-reason.htm @@ -0,0 +1,24 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close Secure WebSocket - Code is 2999 and reason</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var test = async_test("W3C WebSocket API - Create Secure WebSocket - Close the Connection - close(2999, reason) - INVALID_ACCESS_ERR is thrown"); + + var wsocket = CreateWebSocket(true, false, false); + + wsocket.addEventListener('open', test.step_func(function (evt) { + assert_throws("INVALID_ACCESS_ERR", function () { wsocket.close(2999, "Close not in range 3000-4999") }); + test.done(); + }), true); + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Close-3000-reason.htm b/testing/web-platform/tests/websockets/Secure-Close-3000-reason.htm new file mode 100644 index 000000000..80a8be781 --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Close-3000-reason.htm @@ -0,0 +1,35 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close Secure WebSocket - Code is 3000 and reason</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Create Secure WebSocket - Close the Connection - close(3000, reason) - Connection should be opened"); + var testClose = async_test("W3C WebSocket API - Create Secure WebSocket - Close the Connection - close(3000, reason) - readyState should be in CLOSED state and wasClean is TRUE - Connection should be closed"); + + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.close(3000, "Clean Close with code - 3000"); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(wsocket.readyState, 3, "readyState should be 3(CLOSED)"); + assert_equals(evt.wasClean, true, "wasClean should be TRUE"); + testClose.done(); + }), true); + + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Close-3000-verify-code.htm b/testing/web-platform/tests/websockets/Secure-Close-3000-verify-code.htm new file mode 100644 index 000000000..9d385d99b --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Close-3000-verify-code.htm @@ -0,0 +1,34 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close Secure WebSocket - Code is 3000 - verify code in CloseEvent is 3000</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Create Secure WebSocket - Close the Connection - close(3000, reason) - Connection should be opened"); + var testClose = async_test("W3C WebSocket API - Create Secure WebSocket - Close the Connection - close(3000, reason) - verify return code is 3000 - Connection should be closed"); + + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.close(3000, "Clean Close"); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.code, 3000, "CloseEvent.code should be 3000"); + testClose.done(); + }), true); + + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Close-4999-reason.htm b/testing/web-platform/tests/websockets/Secure-Close-4999-reason.htm new file mode 100644 index 000000000..a6ea06949 --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Close-4999-reason.htm @@ -0,0 +1,35 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close Secure WebSocket - Code is 4999 and reason</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Create Secure WebSocket - Close the Connection - close(4999, reason) - Connection should be opened"); + var testClose = async_test("W3C WebSocket API - Create Secure WebSocket - Close the Connection - close(4999, reason) - readyState should be in CLOSED state and wasClean is TRUE - Connection should be closed"); + + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.close(3000, "Clean Close with code - 4999"); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(wsocket.readyState, 3, "readyState should be 3(CLOSED)"); + assert_equals(evt.wasClean, true, "wasClean should be TRUE"); + testClose.done(); + }), true); + + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Close-NaN.htm b/testing/web-platform/tests/websockets/Secure-Close-NaN.htm new file mode 100644 index 000000000..aae6075dc --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Close-NaN.htm @@ -0,0 +1,25 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close Secure WebSocket - Code is NaN</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var test = async_test("W3C WebSocket API - Create WebSocket - Close the Connection - close(NaN) - INVALID_ACCESS_ERR is thrown"); + + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', test.step_func(function (evt) { + assert_throws("INVALID_ACCESS_ERR", function () { wsocket.close(NaN) }); + test.done(); + }), true); + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Close-Reason-124Bytes.htm b/testing/web-platform/tests/websockets/Secure-Close-Reason-124Bytes.htm new file mode 100644 index 000000000..94feb0f27 --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Close-Reason-124Bytes.htm @@ -0,0 +1,27 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close Secure WebSocket - Reason is more than 123 bytes long</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var test = async_test("W3C WebSocket API - Create Secure WebSocket - Close the Connection - close(code, 'reason more than 123 bytes') - SYNTAX_ERR is thrown"); + + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', test.step_func(function (evt) { + var reason = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123"; + assert_equals(reason.length, 124); + assert_throws("SYNTAX_ERR", function () { wsocket.close(1000, reason) }); + test.done(); + }), true); + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Close-Reason-Unpaired-surrogates.htm b/testing/web-platform/tests/websockets/Secure-Close-Reason-Unpaired-surrogates.htm new file mode 100644 index 000000000..694717332 --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Close-Reason-Unpaired-surrogates.htm @@ -0,0 +1,37 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close Secure WebSocket - Reason with unpaired surrogates</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Create Secure WebSocket - Close the Connection - close(reason with unpaired surrogates) - connection should get opened"); + var testClose = async_test("W3C WebSocket API - Create Secure WebSocket - Close the Connection - close(reason with unpaired surrogates) - connection should get closed"); + + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + var replacementChar = "\uFFFD"; + var reason = "\uD807"; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.close(1000, reason); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be opened"); + assert_equals(evt.reason, replacementChar, "reason replaced with replacement character"); + testClose.done(); + }), true); + + </script> + +</body> +</html> + diff --git a/testing/web-platform/tests/websockets/Secure-Close-null.htm b/testing/web-platform/tests/websockets/Secure-Close-null.htm new file mode 100644 index 000000000..f6b67d5ff --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Close-null.htm @@ -0,0 +1,25 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close Secure WebSocket - Code is null</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var test = async_test("W3C WebSocket API - Create WebSocket - Close the Connection - close(null) - INVALID_ACCESS_ERR is thrown"); + + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', test.step_func(function (evt) { + assert_throws("INVALID_ACCESS_ERR", function () { wsocket.close(null) }); + test.done(); + }), true); + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Close-onlyReason.htm b/testing/web-platform/tests/websockets/Secure-Close-onlyReason.htm new file mode 100644 index 000000000..278d7aa33 --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Close-onlyReason.htm @@ -0,0 +1,24 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close Secure WebSocket - Only reason</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var test = async_test("W3C WebSocket API - Create Secure WebSocket - Close the Connection - close(only reason) - INVALID_ACCESS_ERR is thrown"); + + var wsocket = CreateWebSocket(true, false, false); + + wsocket.addEventListener('open', test.step_func(function (evt) { + assert_throws("INVALID_ACCESS_ERR", function () { wsocket.close("Close with only reason") }); + test.done(); + }), true); + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Close-readyState-Closed.htm b/testing/web-platform/tests/websockets/Secure-Close-readyState-Closed.htm new file mode 100644 index 000000000..3ed38a8fe --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Close-readyState-Closed.htm @@ -0,0 +1,35 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close Secure WebSocket - verify readyState is 3 when onclose is fired</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Create Secure WebSocket - Close the Connection - Connection should be opened"); + var testClose = async_test("W3C WebSocket API - Create Secure WebSocket - Close the Connection - readyState should be in CLOSED state and wasClean is TRUE - Connection should be closed"); + + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.close(); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(wsocket.readyState, 3, "readyState should be 3(CLOSED)"); + assert_equals(evt.wasClean, true, "wasClean should be TRUE"); + testClose.done(); + }), true); + + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Close-readyState-Closing.htm b/testing/web-platform/tests/websockets/Secure-Close-readyState-Closing.htm new file mode 100644 index 000000000..10483965f --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Close-readyState-Closing.htm @@ -0,0 +1,27 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close Secure WebSocket - verify readyState is 2 before onclose is fired</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var test = async_test("W3C WebSocket API - Create Secure WebSocket - Close the Connection - readyState should be in CLOSING state just before onclose is called"); + + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', test.step_func(function (evt) { + wsocket.close(); + assert_equals(wsocket.readyState, 2, "readyState should be 2(CLOSING)"); + test.done(); + }), true); + + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Close-server-initiated-close.htm b/testing/web-platform/tests/websockets/Secure-Close-server-initiated-close.htm new file mode 100644 index 000000000..4262754cb --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Close-server-initiated-close.htm @@ -0,0 +1,35 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close Secure WebSocket - Server Initiated close</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Create Secure WebSocket - Server initiated Close - Client sends back a CLOSE - Connection should be opened"); + var testClose = async_test("W3C WebSocket API - Create Secure WebSocket - Server initiated Close - Client sends back a CLOSE - readyState should be in CLOSED state and wasClean is TRUE - Connection should be closed"); + + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.send("Goodbye"); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(wsocket.readyState, 3, "readyState should be 3(CLOSED)"); + assert_equals(evt.wasClean, true, "wasClean should be TRUE"); + testClose.done(); + }), true); + + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Close-string.htm b/testing/web-platform/tests/websockets/Secure-Close-string.htm new file mode 100644 index 000000000..64bf16b1e --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Close-string.htm @@ -0,0 +1,25 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close Secure WebSocket - Code is string</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var test = async_test("W3C WebSocket API - Create WebSocket - Close the Connection - close(string) - INVALID_ACCESS_ERR is thrown"); + + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', test.step_func(function (evt) { + assert_throws("INVALID_ACCESS_ERR", function () { wsocket.close('string') }); + test.done(); + }), true); + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Close-undefined.htm b/testing/web-platform/tests/websockets/Secure-Close-undefined.htm new file mode 100644 index 000000000..9bd4861f0 --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Close-undefined.htm @@ -0,0 +1,25 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Close Secure WebSocket - Code is undefined</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var test = async_test(); + + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', test.step_func(function (evt) { + wsocket.close(undefined); + test.done(); + }), true); + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Send-65K-data.htm b/testing/web-platform/tests/websockets/Secure-Send-65K-data.htm new file mode 100644 index 000000000..f9bbe376d --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Send-65K-data.htm @@ -0,0 +1,44 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send 65K data - Secure WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send 65K data on a Secure WebSocket - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send 65K data on a Secure WebSocket - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send 65K data on a Secure WebSocket - Connection should be closed"); + + var data = ""; + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + for (var i = 0; i < 65000; i++) { + data = data + "c"; + } + wsocket.send(data); + assert_equals(data.length, wsocket.bufferedAmount); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + assert_equals(evt.data, data); + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Send-binary-65K-arraybuffer.htm b/testing/web-platform/tests/websockets/Secure-Send-binary-65K-arraybuffer.htm new file mode 100644 index 000000000..64cfc0241 --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Send-binary-65K-arraybuffer.htm @@ -0,0 +1,44 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send 65K binary data - ArrayBuffer - Secure WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send 65K binary data on a Secure WebSocket - ArrayBuffer - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send 65K binary data on a Secure WebSocket - ArrayBuffer - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send 65K binary data on a Secure WebSocket - ArrayBuffer - Connection should be closed"); + + var data = ""; + var datasize = 65000; + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.binaryType = "arraybuffer"; + data = new ArrayBuffer(datasize); + wsocket.send(data); + assert_equals(datasize, wsocket.bufferedAmount); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + assert_equals(evt.data.byteLength, datasize); + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Send-binary-arraybuffer.htm b/testing/web-platform/tests/websockets/Secure-Send-binary-arraybuffer.htm new file mode 100644 index 000000000..0e068ff57 --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Send-binary-arraybuffer.htm @@ -0,0 +1,44 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send binary data - ArrayBuffer - Secure WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send binary data on a Secure WebSocket - ArrayBuffer - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send binary data on a Secure WebSocket - ArrayBuffer - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send binary data on a Secure WebSocket - ArrayBuffer - Connection should be closed"); + + var data = ""; + var datasize = 15; + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.binaryType = "arraybuffer"; + data = new ArrayBuffer(datasize); + wsocket.send(data); + assert_equals(datasize, wsocket.bufferedAmount); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + assert_equals(evt.data.byteLength, datasize); + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Send-binary-arraybufferview-float32.htm b/testing/web-platform/tests/websockets/Secure-Send-binary-arraybufferview-float32.htm new file mode 100644 index 000000000..30a8010a2 --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Send-binary-arraybufferview-float32.htm @@ -0,0 +1,51 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send binary data - ArrayBufferView - Float32Array - WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Float32Array - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Float32Array - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Float32Array - Connection should be closed"); + + var data = ""; + var datasize = 8; + var view; + var wsocket = CreateWebSocket(false, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.binaryType = "arraybuffer"; + data = new ArrayBuffer(datasize); + view = new Float32Array(data); + for(var i = 0; i < 2; i++) { + view[i] = i; + } + wsocket.send(view); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + var resultView = new Float32Array(evt.data); + for(var i = 0; i < resultView.length; i++) { + assert_equals(resultView[i], view[i], "ArrayBufferView returned is the same"); + } + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Send-binary-arraybufferview-float64.htm b/testing/web-platform/tests/websockets/Secure-Send-binary-arraybufferview-float64.htm new file mode 100644 index 000000000..1e121a882 --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Send-binary-arraybufferview-float64.htm @@ -0,0 +1,51 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send binary data - ArrayBufferView - Float32Array - WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Float64Array - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Float64Array - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Float64Array - Connection should be closed"); + + var data = ""; + var datasize = 8; + var view; + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.binaryType = "arraybuffer"; + data = new ArrayBuffer(datasize); + view = new Float64Array(data); + for (var i = 0; i < 1; i++) { + view[i] = i; + } + wsocket.send(view); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + var resultView = new Float64Array(evt.data); + for(var i = 0; i < resultView.length; i++) { + assert_equals(resultView[i], view[i], "ArrayBufferView returned is the same"); + } + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Send-binary-arraybufferview-int32.htm b/testing/web-platform/tests/websockets/Secure-Send-binary-arraybufferview-int32.htm new file mode 100644 index 000000000..316c62c96 --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Send-binary-arraybufferview-int32.htm @@ -0,0 +1,51 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send binary data - ArrayBufferView - Int32Array - WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Int32Array - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Int32Array - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Int32Array - Connection should be closed"); + + var data = ""; + var datasize = 8; + var view; + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.binaryType = "arraybuffer"; + data = new ArrayBuffer(datasize); + view = new Int32Array(data); + for(var i = 0; i < 2; i++) { + view[i] = i; + } + wsocket.send(view); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + var resultView = new Int32Array(evt.data); + for(var i = 0; i < resultView.length; i++) { + assert_equals(resultView[i], view[i], "ArrayBufferView returned is the same"); + } + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Send-binary-arraybufferview-uint16-offset-length.htm b/testing/web-platform/tests/websockets/Secure-Send-binary-arraybufferview-uint16-offset-length.htm new file mode 100644 index 000000000..1737d93b1 --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Send-binary-arraybufferview-uint16-offset-length.htm @@ -0,0 +1,51 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send binary data - ArrayBufferView - Uint16Array with offset and length - WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Uint16Array with offset and length - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Uint16Array with offset and length - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Uint16Array with offset and length - Connection should be closed"); + + var data = ""; + var datasize = 8; + var view; + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.binaryType = "arraybuffer"; + data = new ArrayBuffer(datasize); + view = new Uint16Array(data, 2, 2); + for(var i = 0; i < 4; i++) { + view[i] = i; + } + wsocket.send(view); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + var resultView = new Uint16Array(evt.data); + for(var i = 0; i < resultView.length; i++) { + assert_equals(resultView[i], view[i], "ArrayBufferView returned is the same"); + } + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Send-binary-arraybufferview-uint32-offset.htm b/testing/web-platform/tests/websockets/Secure-Send-binary-arraybufferview-uint32-offset.htm new file mode 100644 index 000000000..735bae5ff --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Send-binary-arraybufferview-uint32-offset.htm @@ -0,0 +1,51 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send binary data - ArrayBufferView - Uint32Array with offset - WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Uint32Array with offset - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Uint32Array with offset - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Uint32Array with offset - Connection should be closed"); + + var data = ""; + var datasize = 8; + var view; + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.binaryType = "arraybuffer"; + data = new ArrayBuffer(datasize); + view = new Uint32Array(data, 0); + for(var i = 0; i < 2; i++) { + view[i] = i; + } + wsocket.send(view); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + var resultView = new Uint32Array(evt.data); + for(var i = 0; i < resultView.length; i++) { + assert_equals(resultView[i], view[i], "ArrayBufferView returned is the same"); + } + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Send-binary-arraybufferview-uint8-offset-length.htm b/testing/web-platform/tests/websockets/Secure-Send-binary-arraybufferview-uint8-offset-length.htm new file mode 100644 index 000000000..83e14351a --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Send-binary-arraybufferview-uint8-offset-length.htm @@ -0,0 +1,51 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send binary data - ArrayBufferView - Uint8Array with offset and length - WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Uint8Array with offset and length - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Uint8Array with offset and length - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Uint8Array with offset and length - Connection should be closed"); + + var data = ""; + var datasize = 8; + var view; + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.binaryType = "arraybuffer"; + data = new ArrayBuffer(datasize); + view = new Uint8Array(data, 2, 4); + for(var i = 0; i < 8; i++) { + view[i] = i; + } + wsocket.send(view); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + var resultView = new Uint8Array(evt.data); + for(var i = 0; i < resultView.length; i++) { + assert_equals(resultView[i], view[i], "ArrayBufferView returned is the same"); + } + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Send-binary-arraybufferview-uint8-offset.htm b/testing/web-platform/tests/websockets/Secure-Send-binary-arraybufferview-uint8-offset.htm new file mode 100644 index 000000000..413ec3431 --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Send-binary-arraybufferview-uint8-offset.htm @@ -0,0 +1,51 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send binary data - ArrayBufferView - Uint8Array with offset - WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Uint8Array with offset - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Uint8Array with offset - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Uint8Array with offset - Connection should be closed"); + + var data = ""; + var datasize = 8; + var view; + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.binaryType = "arraybuffer"; + data = new ArrayBuffer(datasize); + view = new Uint8Array(data, 2); + for(var i = 0; i < 8; i++) { + view[i] = i; + } + wsocket.send(view); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + var resultView = new Uint8Array(evt.data); + for(var i = 0; i < resultView.length; i++) { + assert_equals(resultView[i], view[i], "ArrayBufferView returned is the same"); + } + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Send-binary-blob.htm b/testing/web-platform/tests/websockets/Secure-Send-binary-blob.htm new file mode 100644 index 000000000..6d52aa7e8 --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Send-binary-blob.htm @@ -0,0 +1,48 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send binary data - Blob - Secure WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send binary data on a Secure WebSocket - Blob - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send binary data on a Secure WebSocket - Blob - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send binary data on a Secure WebSocket - Blob - Connection should be closed"); + + var data = ""; + var datasize = 65000; + var isOpenCalled = false; + + var wsocket = CreateWebSocket(true, false, false); + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.binaryType = "blob"; + for (var i = 0; i < datasize; i++) + data += String.fromCharCode(0); + data = new Blob([data]); + isOpenCalled = true; + wsocket.send(data); + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + assert_true(evt.data instanceof Blob); + assert_equals(evt.data.size, datasize); + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_true(evt.wasClean, "wasClean should be true"); + testClose.done(); + }), true); + + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Send-data.htm b/testing/web-platform/tests/websockets/Secure-Send-data.htm new file mode 100644 index 000000000..d7c1595b3 --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Send-data.htm @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send data - Secure WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send data on a Secure WebSocket - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send data on a Secure WebSocket - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send data on a Secure WebSocket - Connection should be closed"); + + var data = "Message to send"; + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.send(data); + assert_equals(data.length, wsocket.bufferedAmount); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + assert_equals(evt.data, data); + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Send-null.htm b/testing/web-platform/tests/websockets/Secure-Send-null.htm new file mode 100644 index 000000000..0a203359b --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Send-null.htm @@ -0,0 +1,43 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send null data - Secure WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send null data on a Secure WebSocket - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send null data on a Secure WebSocket - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send null data on a Secure WebSocket - Connection should be closed"); + + var data = null; + var nullReturned = false; + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.send(data); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + if ("null" == evt.data || "" == evt.data) + nullReturned = true; + assert_true(nullReturned); + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Send-paired-surrogates.htm b/testing/web-platform/tests/websockets/Secure-Send-paired-surrogates.htm new file mode 100644 index 000000000..959e307d2 --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Send-paired-surrogates.htm @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send (paired surrogates) data - Secure WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send paired surrogates data on a Secure WebSocket - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send paired surrogates data on a Secure WebSocket - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send paired surrogates data on a Secure WebSocket - Connection should be closed"); + + var data = "\uD801\uDC07"; + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.send(data); + assert_equals(data.length * 2, wsocket.bufferedAmount); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + assert_equals(evt.data, data); + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Send-unicode-data.htm b/testing/web-platform/tests/websockets/Secure-Send-unicode-data.htm new file mode 100644 index 000000000..42de64164 --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Send-unicode-data.htm @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send unicode data - Secure WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send unicode data on a Secure WebSocket - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send unicode data on a Secure WebSocket - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send unicode data on a Secure WebSocket - Connection should be closed"); + + var data = "¥¥¥¥¥¥"; + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.send(data); + assert_equals(data.length * 2, wsocket.bufferedAmount); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + assert_equals(evt.data, data); + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Secure-Send-unpaired-surrogates.htm b/testing/web-platform/tests/websockets/Secure-Send-unpaired-surrogates.htm new file mode 100644 index 000000000..11df504b1 --- /dev/null +++ b/testing/web-platform/tests/websockets/Secure-Send-unpaired-surrogates.htm @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send unpaired surrogates - Secure WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send unpaired surrogates on a Secure WebSocket - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send unpaired surrogates on a Secure WebSocket - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send unpaired surrogates on a Secure WebSocket - Connection should be closed"); + + var data = "\uD807"; + var replacementChar = "\uFFFD"; + var wsocket = CreateWebSocket(true, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.send(data); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + assert_equals(evt.data, replacementChar); + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Send-0byte-data.htm b/testing/web-platform/tests/websockets/Send-0byte-data.htm new file mode 100644 index 000000000..52ab7ca5b --- /dev/null +++ b/testing/web-platform/tests/websockets/Send-0byte-data.htm @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send 0 byte data - WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send 0 byte data on a WebSocket - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send 0 byte data on a WebSocket - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send 0 byte data on a WebSocket - Connection should be closed"); + + var data = ""; + var wsocket = CreateWebSocket(false, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.send(data); + assert_equals(data.length, wsocket.bufferedAmount); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + assert_equals(evt.data, data); + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Send-65K-data.htm b/testing/web-platform/tests/websockets/Send-65K-data.htm new file mode 100644 index 000000000..7d223403c --- /dev/null +++ b/testing/web-platform/tests/websockets/Send-65K-data.htm @@ -0,0 +1,44 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send 65K data - WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send 65K data on a WebSocket - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send 65K data on a WebSocket - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send 65K data on a WebSocket - Connection should be closed"); + + var data = ""; + var wsocket = CreateWebSocket(false, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + for (var i = 0; i < 65000; i++) { + data = data + "c"; + } + wsocket.send(data); + assert_equals(data.length, wsocket.bufferedAmount); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + assert_equals(evt.data, data); + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Send-Unpaired-Surrogates.htm b/testing/web-platform/tests/websockets/Send-Unpaired-Surrogates.htm new file mode 100644 index 000000000..6697e687a --- /dev/null +++ b/testing/web-platform/tests/websockets/Send-Unpaired-Surrogates.htm @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send unpaired surrogates - WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send unpaired surrogates on a WebSocket - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send unpaired surrogates on a WebSocket - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send unpaired surrogates on a WebSocket - Connection should be closed"); + + var data = "\uD807"; + var replacementChar = "\uFFFD"; + var wsocket = CreateWebSocket(false, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.send(data); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + assert_equals(evt.data, replacementChar); + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Send-before-open.htm b/testing/web-platform/tests/websockets/Send-before-open.htm new file mode 100644 index 000000000..1aace5405 --- /dev/null +++ b/testing/web-platform/tests/websockets/Send-before-open.htm @@ -0,0 +1,18 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send WebSocket - Send before connection in established</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + test(function () { + var wsocket = CreateWebSocket(false, false, false); + assert_throws("INVALID_STATE_ERR", function () { wsocket.send("Message to send") }); + }, "W3C WebSocket API - Send data on a WebSocket before connection is opened - INVALID_STATE_ERR is returned") + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Send-binary-65K-arraybuffer.htm b/testing/web-platform/tests/websockets/Send-binary-65K-arraybuffer.htm new file mode 100644 index 000000000..95c12cf80 --- /dev/null +++ b/testing/web-platform/tests/websockets/Send-binary-65K-arraybuffer.htm @@ -0,0 +1,44 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send 65K binary data - ArrayBuffer - WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send 65K binary data on a WebSocket - ArrayBuffer - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send 65K binary data on a WebSocket - ArrayBuffer - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send 65K binary data on a WebSocket - ArrayBuffer - Connection should be closed"); + + var data = ""; + var datasize = 65000; + var wsocket = CreateWebSocket(false, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.binaryType = "arraybuffer"; + data = new ArrayBuffer(datasize); + wsocket.send(data); + assert_equals(datasize, wsocket.bufferedAmount); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + assert_equals(evt.data.byteLength, datasize); + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Send-binary-arraybuffer.htm b/testing/web-platform/tests/websockets/Send-binary-arraybuffer.htm new file mode 100644 index 000000000..b960b921a --- /dev/null +++ b/testing/web-platform/tests/websockets/Send-binary-arraybuffer.htm @@ -0,0 +1,44 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send binary data - ArrayBuffer - WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBuffer - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBuffer - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBuffer - Connection should be closed"); + + var data = ""; + var datasize = 15; + var wsocket = CreateWebSocket(false, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.binaryType = "arraybuffer"; + data = new ArrayBuffer(datasize); + wsocket.send(data); + assert_equals(datasize, wsocket.bufferedAmount); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + assert_equals(evt.data.byteLength, datasize); + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Send-binary-arraybufferview-int16-offset.htm b/testing/web-platform/tests/websockets/Send-binary-arraybufferview-int16-offset.htm new file mode 100644 index 000000000..0ebd3ac2a --- /dev/null +++ b/testing/web-platform/tests/websockets/Send-binary-arraybufferview-int16-offset.htm @@ -0,0 +1,51 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send binary data - ArrayBufferView - Int16Array with offset - WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Int16Array with offset - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Int16Array with offset - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Int16Array with offset - Connection should be closed"); + + var data = ""; + var datasize = 8; + var view; + var wsocket = CreateWebSocket(false, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.binaryType = "arraybuffer"; + data = new ArrayBuffer(datasize); + view = new Int16Array(data, 2); + for(var i = 0; i < 4; i++) { + view[i] = i; + } + wsocket.send(view); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + var resultView = new Int16Array(evt.data); + for(var i = 0; i < resultView.length; i++) { + assert_equals(resultView[i], view[i], "ArrayBufferView returned is the same"); + } + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Send-binary-arraybufferview-int8.htm b/testing/web-platform/tests/websockets/Send-binary-arraybufferview-int8.htm new file mode 100644 index 000000000..5336a8778 --- /dev/null +++ b/testing/web-platform/tests/websockets/Send-binary-arraybufferview-int8.htm @@ -0,0 +1,51 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send binary data - ArrayBufferView - Int8Array - WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Int8Array - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Int8Array - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send binary data on a WebSocket - ArrayBufferView - Int8Array - Connection should be closed"); + + var data = ""; + var datasize = 8; + var int8View; + var wsocket = CreateWebSocket(false, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.binaryType = "arraybuffer"; + data = new ArrayBuffer(datasize); + int8View = new Int8Array(data); + for (var i = 0; i < 8; i++) { + int8View[i] = i; + } + wsocket.send(int8View); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + var resultView = new Int8Array(evt.data); + for (var i = 0; i < resultView.length; i++) { + assert_equals(resultView[i], int8View[i], "ArrayBufferView returned is the same"); + } + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Send-binary-blob.htm b/testing/web-platform/tests/websockets/Send-binary-blob.htm new file mode 100644 index 000000000..fa14f4cd4 --- /dev/null +++ b/testing/web-platform/tests/websockets/Send-binary-blob.htm @@ -0,0 +1,48 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send binary data - Blob - WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send binary data on a WebSocket - Blob - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send binary data on a WebSocket - Blob - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send binary data on a WebSocket - Blob - Connection should be closed"); + + var data = ""; + var datasize = 65000; + var isOpenCalled = false; + + var wsocket = CreateWebSocket(false, false, false); + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.binaryType = "blob"; + for (var i = 0; i < datasize; i++) + data += String.fromCharCode(0); + data = new Blob([data]); + isOpenCalled = true; + wsocket.send(data); + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + assert_true(evt.data instanceof Blob); + assert_equals(evt.data.size, datasize); + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_true(evt.wasClean, "wasClean should be true"); + testClose.done(); + }), true); + + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Send-data.htm b/testing/web-platform/tests/websockets/Send-data.htm new file mode 100644 index 000000000..547a15f86 --- /dev/null +++ b/testing/web-platform/tests/websockets/Send-data.htm @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send data - WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send data on a WebSocket - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send data on a WebSocket - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send data on a WebSocket - Connection should be closed"); + + var data = "Message to send"; + var wsocket = CreateWebSocket(false, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.send(data); + assert_equals(data.length, wsocket.bufferedAmount); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + assert_equals(evt.data, data); + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Send-data.worker.js b/testing/web-platform/tests/websockets/Send-data.worker.js new file mode 100644 index 000000000..f607fd7cf --- /dev/null +++ b/testing/web-platform/tests/websockets/Send-data.worker.js @@ -0,0 +1,21 @@ +importScripts("/resources/testharness.js"); +importScripts('websocket.sub.js') + +var data = "test data"; + +async_test(function(t) { + + var wsocket = CreateWebSocket(false, false, false); + + wsocket.addEventListener('open', function (e) { + wsocket.send(data) + }, true) + + wsocket.addEventListener('message', t.step_func_done(function(e) { + assert_equals(e.data, data); + done(); + }), true); + +}, "W3C WebSocket API - Send data on a WebSocket in a Worker") + + diff --git a/testing/web-platform/tests/websockets/Send-null.htm b/testing/web-platform/tests/websockets/Send-null.htm new file mode 100644 index 000000000..5b7a6f150 --- /dev/null +++ b/testing/web-platform/tests/websockets/Send-null.htm @@ -0,0 +1,43 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send null data - WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send null data on a WebSocket - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send null data on a WebSocket - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send null data on a WebSocket - Connection should be closed"); + + var data = null; + var nullReturned = false; + var wsocket = CreateWebSocket(false, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.send(data); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + if ("null" == evt.data || "" == evt.data) + nullReturned = true; + assert_true(nullReturned); + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Send-paired-surrogates.htm b/testing/web-platform/tests/websockets/Send-paired-surrogates.htm new file mode 100644 index 000000000..44132212b --- /dev/null +++ b/testing/web-platform/tests/websockets/Send-paired-surrogates.htm @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send (paired surrogates) data - WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send (paired surrogates) data on a WebSocket - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send (paired surrogates) data on a WebSocket - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send (paired surrogates) data on a WebSocket - Connection should be closed"); + + var data = "\uD801\uDC07"; + var wsocket = CreateWebSocket(false, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.send(data); + assert_equals(data.length * 2, wsocket.bufferedAmount); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + assert_equals(evt.data, data); + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/Send-unicode-data.htm b/testing/web-platform/tests/websockets/Send-unicode-data.htm new file mode 100644 index 000000000..aba791837 --- /dev/null +++ b/testing/web-platform/tests/websockets/Send-unicode-data.htm @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Send unicode data - WebSocket</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Send unicode data on a WebSocket - Connection should be opened"); + var testMessage = async_test("W3C WebSocket API - Send unicode data on a WebSocket - Message should be received"); + var testClose = async_test("W3C WebSocket API - Send unicode data on a WebSocket - Connection should be closed"); + + var data = "¥¥¥¥¥¥"; + var wsocket = CreateWebSocket(false, false, false); + var isOpenCalled = false; + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + wsocket.send(data); + assert_equals(data.length * 2, wsocket.bufferedAmount); + isOpenCalled = true; + testOpen.done(); + }), true); + + wsocket.addEventListener('message', testMessage.step_func(function (evt) { + assert_equals(evt.data, data); + wsocket.close(); + testMessage.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(isOpenCalled, "WebSocket connection should be open"); + assert_equals(evt.wasClean, true, "wasClean should be true"); + testClose.done(); + }), true); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/websockets/binary/001.html b/testing/web-platform/tests/websockets/binary/001.html new file mode 100644 index 000000000..4631ebcf7 --- /dev/null +++ b/testing/web-platform/tests/websockets/binary/001.html @@ -0,0 +1,26 @@ +<!doctype html> +<title>WebSockets: Send/Receive blob, blob size less than network array buffer</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 = ""; + var datasize = 10; + ws.onopen = t.step_func(function(e) { + ws.binaryType = "blob"; + data = new ArrayBuffer(datasize); + ws.send(data); + }) + 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/binary/002.html b/testing/web-platform/tests/websockets/binary/002.html new file mode 100644 index 000000000..f2fa16a61 --- /dev/null +++ b/testing/web-platform/tests/websockets/binary/002.html @@ -0,0 +1,27 @@ +<!doctype html> +<title>WebSockets: Send/Receive blob, blob size greater than network array buffer</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 = ""; + var datasize = 100000; + ws.onopen = t.step_func(function(e) { + ws.binaryType = "blob"; + data = new ArrayBuffer(datasize); + ws.send(data); + }); + ws.onmessage = t.step_func(function(e) { + assert_true(e.data instanceof Blob); + assert_equals(e.data.size, datasize); + t.done(); + }); + +}, null, {timeout:20000}); +</script> diff --git a/testing/web-platform/tests/websockets/binary/004.html b/testing/web-platform/tests/websockets/binary/004.html new file mode 100644 index 000000000..59b06d700 --- /dev/null +++ b/testing/web-platform/tests/websockets/binary/004.html @@ -0,0 +1,26 @@ +<!doctype html> +<title>WebSockets: Send/Receive ArrayBuffer, size greater than network array buffer</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 = ""; + var datasize = 100000; + ws.onopen = t.step_func(function(e) { + ws.binaryType = "arraybuffer"; + data = new ArrayBuffer(datasize); + ws.send(data); + }) + ws.onmessage = t.step_func(function(e) { + assert_equals(e.data.byteLength, datasize); + t.done(); + }) + +}, null, {timeout:20000}); +</script> diff --git a/testing/web-platform/tests/websockets/binary/005.html b/testing/web-platform/tests/websockets/binary/005.html new file mode 100644 index 000000000..54c1aae90 --- /dev/null +++ b/testing/web-platform/tests/websockets/binary/005.html @@ -0,0 +1,24 @@ +<!doctype html> +<title>WebSockets: Send/Receive ArrayBuffer, size less than network array buffer</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 = ""; + var datasize = 10; + ws.onopen = t.step_func(function(e) { + ws.binaryType = "arraybuffer"; + data = new ArrayBuffer(datasize); + ws.send(data); + }); + ws.onmessage = t.step_func(function(e) { + assert_equals(e.data.byteLength, datasize); + t.done(); + }); + }); +</script> diff --git a/testing/web-platform/tests/websockets/binaryType-wrong-value.htm b/testing/web-platform/tests/websockets/binaryType-wrong-value.htm new file mode 100644 index 000000000..2bab6710c --- /dev/null +++ b/testing/web-platform/tests/websockets/binaryType-wrong-value.htm @@ -0,0 +1,34 @@ +<!DOCTYPE html> +<html> +<head> + <title>W3C WebSocket API - Create Secure WebSocket - binaryType is set to something other than blob/arraybuffer</title> + <script type="text/javascript" src="/resources/testharness.js"></script> + <script type="text/javascript" src="/resources/testharnessreport.js"></script> + <script type="text/javascript" src="websocket.sub.js"></script> +</head> +<body> + <div id="log"></div> + <script type="text/javascript"> + + var testOpen = async_test("W3C WebSocket API - Create WebSocket - set binaryType to something other than blob or arraybuffer - SYNTAX_ERR is returned - Connection should be opened"); + var testClose = async_test("W3C WebSocket API - Create WebSocket - set binaryType to something other than blob or arraybuffer - SYNTAX_ERR is returned - Connection should be closed"); + + var wsocket = CreateWebSocket(true, false, false); + + wsocket.addEventListener('open', testOpen.step_func(function (evt) { + assert_equals(wsocket.binaryType, "blob"); + wsocket.binaryType = "notBlobOrArrayBuffer"; + assert_equals(wsocket.binaryType, "blob"); + wsocket.close(); + testOpen.done(); + }), true); + + wsocket.addEventListener('close', testClose.step_func(function (evt) { + assert_true(evt.wasClean, "wasClean should be true"); + testClose.done(); + }), true); + + </script> + +</body> +</html> diff --git a/testing/web-platform/tests/websockets/closing-handshake/002.html b/testing/web-platform/tests/websockets/closing-handshake/002.html new file mode 100644 index 000000000..f60604d40 --- /dev/null +++ b/testing/web-platform/tests/websockets/closing-handshake/002.html @@ -0,0 +1,22 @@ +<!doctype html> +<title>WebSockets: server sends closing handshake</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_exit'); + ws.onmessage = ws.onerror = t.step_func(function() {assert_unreached()}); + ws.onopen = t.step_func(function(e) { + ws.send('Goodbye'); + }) + ws.onclose = t.step_func(function(e) { + assert_equals(e.wasClean, true, 'e.wasClean'); + ws.onclose = t.step_func(function() {assert_unreached()}); + setTimeout(t.step_func(function() {t.done();}), 50) + }); +}); +</script> diff --git a/testing/web-platform/tests/websockets/closing-handshake/003.html b/testing/web-platform/tests/websockets/closing-handshake/003.html new file mode 100644 index 000000000..c032d498a --- /dev/null +++ b/testing/web-platform/tests/websockets/closing-handshake/003.html @@ -0,0 +1,23 @@ +<!doctype html> +<title>WebSockets: client sends closing handshake</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.onmessage = ws.onerror = t.step_func(function() {assert_unreached()}); + ws.onopen = t.step_func(function(e) { + ws.close(); + }); + ws.onclose = t.step_func(function(e) { + assert_equals(e.code, 1005, 'e.code'); + assert_equals(e.wasClean, true, 'e.wasClean'); + ws.onclose = t.step_func(function() {assert_unreached()}); + setTimeout(t.step_func(function() {t.done()}), 50); + }); +}); +</script> diff --git a/testing/web-platform/tests/websockets/closing-handshake/004.html b/testing/web-platform/tests/websockets/closing-handshake/004.html new file mode 100644 index 000000000..343a28a23 --- /dev/null +++ b/testing/web-platform/tests/websockets/closing-handshake/004.html @@ -0,0 +1,24 @@ +<!doctype html> +<title>WebSockets: data after closing handshake</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_close_data'); + ws.onmessage = ws.onerror = t.step_func(function() {assert_unreached()}); + + ws.onopen = t.step_func(function(e) { + ws.send('Goodbye'); + }) + + ws.onclose = t.step_func(function(e) { + assert_equals(e.wasClean, true); + ws.onclose = t.step_func(function() {assert_unreached()}); + setTimeout(t.step_func(function() {t.done()}), 50); + }) +}); +</script> diff --git a/testing/web-platform/tests/websockets/constants.js b/testing/web-platform/tests/websockets/constants.js new file mode 100644 index 000000000..8312cd253 --- /dev/null +++ b/testing/web-platform/tests/websockets/constants.js @@ -0,0 +1,12 @@ +//This file requires server-side substitutions and must be included as constants.js?pipe=sub + +var PORT = "{{ports[ws][0]}}"; +//FIXME: Add support for wss +var PORT_SSL = "{{ports[ws][0]}}"; + +var SCHEME_DOMAIN_PORT; +if (location.search == '?wss') { + SCHEME_DOMAIN_PORT = 'wss://{{host}}:' + PORT_SSL; +} else { + SCHEME_DOMAIN_PORT = 'ws://{{host}}:' + PORT; +} diff --git a/testing/web-platform/tests/websockets/constructor.html b/testing/web-platform/tests/websockets/constructor.html new file mode 100644 index 000000000..c135b325e --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor.html @@ -0,0 +1,13 @@ +<!DOCTYPE html> +<title>WebSocket constructor</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="websocket.sub.js"></script> +<div id="log"></div> +<script> +test(function() { + var ws = new WebSocket("ws://" + __SERVER__NAME + ":" + __PORT + "/" + __PATH, + "echo", "Stray argument") + assert_true(ws instanceof WebSocket, "Expected a WebSocket instance.") +}, "Calling the WebSocket constructor with too many arguments should not throw.") +</script> diff --git a/testing/web-platform/tests/websockets/constructor/001.html b/testing/web-platform/tests/websockets/constructor/001.html new file mode 100644 index 000000000..2a868bfa0 --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/001.html @@ -0,0 +1,13 @@ +<!doctype html> +<title>WebSockets: new WebSocket() with no args</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function() { + assert_throws(new TypeError(), function(){new WebSocket()}); +}); +</script> diff --git a/testing/web-platform/tests/websockets/constructor/002.html b/testing/web-platform/tests/websockets/constructor/002.html new file mode 100644 index 000000000..94015979b --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/002.html @@ -0,0 +1,20 @@ +<!doctype html> +<title>WebSockets: new WebSocket(invalid url)</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function() {assert_throws("SyntaxError", function(){new WebSocket("/test")})}); +test(function() {assert_throws("SyntaxError", function(){new WebSocket("ws://foo bar.com/")})}); +test(function() {assert_throws("SyntaxError", function(){new WebSocket("wss://foo bar.com/")})}); +test(function() {assert_throws("SyntaxError", function(){new WebSocket("http://"+location.host+"/")})}); +test(function() {assert_throws("SyntaxError", function(){new WebSocket("mailto:example@example.org")})}); +test(function() {assert_throws("SyntaxError", function(){new WebSocket("about:blank")})}); +test(function() {assert_throws("SyntaxError", function(){new WebSocket(SCHEME_DOMAIN_PORT+"/#")})}); +test(function() {assert_throws("SyntaxError", function(){new WebSocket(SCHEME_DOMAIN_PORT+"/#test")})}); +test(function() {assert_throws("SyntaxError", function(){new WebSocket("?test")})}); +test(function() {assert_throws("SyntaxError", function(){new WebSocket("#test")})}); +</script> diff --git a/testing/web-platform/tests/websockets/constructor/004.html b/testing/web-platform/tests/websockets/constructor/004.html new file mode 100644 index 000000000..f35802154 --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/004.html @@ -0,0 +1,35 @@ +<!doctype html> +<title>WebSockets: new WebSocket(url, invalid protocol)</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +// empty string +test(function() { + assert_throws("SyntaxError", function() { + new WebSocket(SCHEME_DOMAIN_PORT + '/empty-message', "") + }) +}); + +// chars below U+0020 except U+0000; U+0000 is tested in a separate test +for (var i = 1; i < 0x20; ++i) { + test(function() { + assert_throws("SyntaxError", function() { + new WebSocket(SCHEME_DOMAIN_PORT + '/empty-message', + "a"+String.fromCharCode(i)+"b") + }, 'char code '+i); + }) +} +// some chars above U+007E +for (var i = 0x7F; i < 0x100; ++i) { + test(function() { + assert_throws("SyntaxError", function() { + new WebSocket(SCHEME_DOMAIN_PORT + '/empty-message', + "a"+String.fromCharCode(i)+"b") + }, 'char code '+i); + }) +} +</script> diff --git a/testing/web-platform/tests/websockets/constructor/005.html b/testing/web-platform/tests/websockets/constructor/005.html new file mode 100644 index 000000000..63e61ddb0 --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/005.html @@ -0,0 +1,13 @@ +<!doctype html> +<title>WebSockets: return value</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function() { + assert_true(new WebSocket(SCHEME_DOMAIN_PORT + '/empty-message') instanceof WebSocket); +}); +</script> diff --git a/testing/web-platform/tests/websockets/constructor/006.html b/testing/web-platform/tests/websockets/constructor/006.html new file mode 100644 index 000000000..a9d01bbf3 --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/006.html @@ -0,0 +1,28 @@ +<!doctype html> +<title>WebSockets: converting first arguments</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(t) { + var a = document.createElement('a'); + a.href = SCHEME_DOMAIN_PORT+'/echo'; + var ws = new WebSocket(a); // should stringify arguments; <a> stringifies to its .href + assert_equals(ws.url, a.href); + ws.onopen = t.step_func(function(e) { + ws.send('test'); + }); + ws.onmessage = t.step_func(function(e) { + assert_equals(e.data, 'test'); + ws.onclose = t.step_func(function(e) { + ws.onclose = t.step_func(function() {assert_unreached()}); + setTimeout(t.step_func(function() {t.done()}), 50); + }); + ws.close(); + }); + ws.onerror = ws.onclose = t.step_func(function() {assert_unreached()}); +}); +</script> diff --git a/testing/web-platform/tests/websockets/constructor/007.html b/testing/web-platform/tests/websockets/constructor/007.html new file mode 100644 index 000000000..6f141a541 --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/007.html @@ -0,0 +1,16 @@ +<!doctype html> +<title>WebSockets: new WebSocket(url, null char)</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function() { + assert_throws("SyntaxError", function() { + new WebSocket(SCHEME_DOMAIN_PORT + '/empty-message', + 'a' + String.fromCharCode(0) + 'b') + }) +}); +</script> diff --git a/testing/web-platform/tests/websockets/constructor/008.html b/testing/web-platform/tests/websockets/constructor/008.html new file mode 100644 index 000000000..f425ff058 --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/008.html @@ -0,0 +1,15 @@ +<!doctype html> +<title>WebSockets: new WebSocket(url with not blocked port)</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +//Pass condition is to not throw +test(function(){new WebSocket('ws://example.invalid:80/')}); +test(function(){new WebSocket('ws://example.invalid:443/')}); +test(function(){new WebSocket('wss://example.invalid:80/')}); +test(function(){new WebSocket('wss://example.invalid:443/')}); +</script> diff --git a/testing/web-platform/tests/websockets/constructor/009.html b/testing/web-platform/tests/websockets/constructor/009.html new file mode 100644 index 000000000..56eb912c8 --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/009.html @@ -0,0 +1,23 @@ +<!doctype html> +<title>WebSockets: protocol</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/protocol', 'foobar'); + + ws.onmessage = t.step_func(function(e) { + assert_equals(ws.protocol, 'foobar'); + ws.onclose = t.step_func(function(e) { + ws.onclose = t.step_func(function() {assert_unreached()}); + setTimeout(t.step_func(function() {t.done()}), 50); + }) + ws.close(); + }) + ws.onerror = t.step_func(function() {assert_unreached()}); +}); +</script> diff --git a/testing/web-platform/tests/websockets/constructor/010.html b/testing/web-platform/tests/websockets/constructor/010.html new file mode 100644 index 000000000..da2a9bf59 --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/010.html @@ -0,0 +1,22 @@ +<!doctype html> +<title>WebSockets: protocol in response but no requested protocol</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/handshake_protocol'); + ws.onerror = ws.onmessage = ws.onclose = t.step_func(function(e) {assert_unreached(e.type)}); + ws.onopen = t.step_func(function(e) { + ws.onclose = t.step_func(function(e) { + ws.onclose = t.step_func(function(e) {assert_unreached(e.type)}); + setTimeout(t.step_func(function() {t.done();}), 50); + }) + ws.close(); + }) +}); +</script> + diff --git a/testing/web-platform/tests/websockets/constructor/011.html b/testing/web-platform/tests/websockets/constructor/011.html new file mode 100644 index 000000000..e8d0b3aaf --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/011.html @@ -0,0 +1,27 @@ +<!doctype html> +<title>WebSockets: protocol mismatch</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/handshake_protocol', 'FOOBAR'); + var gotOpen = false; + var gotError = false; + ws.onopen = t.step_func(function(e) { + gotOpen = true; + }) + ws.onerror = t.step_func(function(e) { + gotError = true; + }) + ws.onclose = t.step_func(function(e) { + assert_true(gotOpen, 'got open'); + assert_true(gotError, 'got error'); + ws.onclose = t.step_func(function() {assert_unreached()}); + setTimeout(t.step_func(function() {t.done();}), 50); + }) +}); +</script> diff --git a/testing/web-platform/tests/websockets/constructor/012.html b/testing/web-platform/tests/websockets/constructor/012.html new file mode 100644 index 000000000..29ac6d53f --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/012.html @@ -0,0 +1,19 @@ +<!doctype html> +<title>WebSockets: no protocol in response</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/handshake_no_protocol', 'foobar'); + ws.onclose = t.step_func(function(e) { + ws.onclose = t.step_func(function() {assert_unreached()}); + setTimeout(t.step_func(function() {t.done();}), 50) + }) + ws.onmessage = t.step_func(function() {assert_unreached()}); +}); +</script> + diff --git a/testing/web-platform/tests/websockets/constructor/013.html b/testing/web-platform/tests/websockets/constructor/013.html new file mode 100644 index 000000000..fe777af19 --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/013.html @@ -0,0 +1,41 @@ +<!doctype html> +<title>WebSockets: multiple WebSocket objects</title> +<meta name=timeout content=long> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(t) { + // test that the events are fired as they should when opening 25 websockets and + // sending a message on each and then closing when getting the message back + var ws = []; + var events = 0; + for (var i = 0; i < 25; ++i) { + ws[i] = new WebSocket(SCHEME_DOMAIN_PORT+'/echo'); + ws[i].id = i; + ws[i].onopen = t.step_func(function(e) { + events++; + this.send(this.id); + this.onopen = t.step_func(function() {assert_unreached()}); + }, ws[i]); + ws[i].onmessage = t.step_func(function(e) { + events++; + assert_equals(e.data, ''+this.id); + this.close(); + this.onmessage = t.step_func(function() {assert_unreached()}); + }, ws[i]); + ws[i].onclose = t.step_func(function(e) { + events++; + if (events == 75) { + t.done(); + } + this.onclose = t.step_func(function() {assert_unreached()}); + }, ws[i]); + ws[i].onerror = t.step_func(function() {assert_unreached()}); + } +}, null, {timeout:25000}); +</script> + diff --git a/testing/web-platform/tests/websockets/constructor/014.html b/testing/web-platform/tests/websockets/constructor/014.html new file mode 100644 index 000000000..579a5d3ed --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/014.html @@ -0,0 +1,39 @@ +<!doctype html> +<title>WebSockets: serialize establish a connection</title> +<meta name=timeout content=long> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> + +async_test(function(t) { + var ws = []; + var events = 0; + var prevDate; + var date; + for (var i = 0; i < 4; ++i) { + ws[i] = new WebSocket(SCHEME_DOMAIN_PORT+'/handshake_sleep_2'); + ws[i].id = i; + ws[i].onopen = t.step_func(function(e) { + events++; + date = new Date(); + if (prevDate) { + assert_greater_than(date - prevDate, 1000); + } + prevDate = date; + this.onopen = t.step_func(function() {assert_unreached()}); + }.bind(ws[i])) + ws[i].onclose = t.step_func(function() { + events++; + if (events == 8) { + t.done(); + } + this.onclose = t.step_func(function() {assert_unreached()}); + }.bind(ws[i])); + ws[i].onerror = ws[i].onmessage = t.step_func(function() {assert_unreached()}); + } +}); +</script> diff --git a/testing/web-platform/tests/websockets/constructor/016.html b/testing/web-platform/tests/websockets/constructor/016.html new file mode 100644 index 000000000..a1bf28167 --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/016.html @@ -0,0 +1,19 @@ +<!doctype html> +<meta charset=windows-1252> +<title>WebSockets: non-ascii URL in query, document encoding windows-1252</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/echo-query_v13?åäö'); + ws.onclose = t.step_func(function() {assert_unreached()}); + ws.onmessage = t.step_func(function(e) { + assert_equals(e.data, '%C3%A5%C3%A4%C3%B6'); + t.done(); + }); +}); +</script> diff --git a/testing/web-platform/tests/websockets/constructor/017.html b/testing/web-platform/tests/websockets/constructor/017.html new file mode 100644 index 000000000..8a7960d88 --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/017.html @@ -0,0 +1,20 @@ +<!doctype html> +<title>WebSockets: too few slashes after ws: and wss:</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +var tests = [ + ['ws:', PORT], + ['ws:/', PORT], + ['wss:', PORT_SSL], + ['wss:/', PORT_SSL] +]; +//Pass condition is to not throw +for (var i = 0; i < tests.length; ++i) { + test(function(){new WebSocket(tests[i][0] + location.hostname + ':' + tests[i][1] + '/echo')}, tests[i][0]); +} +</script> diff --git a/testing/web-platform/tests/websockets/constructor/018.html b/testing/web-platform/tests/websockets/constructor/018.html new file mode 100644 index 000000000..d96d4be6b --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/018.html @@ -0,0 +1,19 @@ +<!doctype html> +<title>WebSockets: NULL char in url</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/echo-query?x\u0000y\u0000'); + ws.onmessage = t.step_func(function(e) { + assert_equals(e.data, 'x%00y'); + ws.close(); + t.done(); + }) + ws.onclose = ws.onerror = t.step_func(function(e) {assert_unreached(e.type)}); +}); +</script> diff --git a/testing/web-platform/tests/websockets/constructor/019.html b/testing/web-platform/tests/websockets/constructor/019.html new file mode 100644 index 000000000..b56745aa2 --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/019.html @@ -0,0 +1,20 @@ +<!doctype html> +<title>WebSockets: uppercase 'WS:'</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(t) { + var scheme = SCHEME_DOMAIN_PORT.split('://')[0]; + var domain = SCHEME_DOMAIN_PORT.split('://')[1]; + var ws = new WebSocket(scheme.toUpperCase()+'://'+domain+'/echo'); + ws.onopen = t.step_func(function(e) { + ws.close(); + t.done(); + }) + ws.onclose = ws.onerror = ws.onmessage = t.step_func(function() {assert_unreached()}); +}); +</script> diff --git a/testing/web-platform/tests/websockets/constructor/020.html b/testing/web-platform/tests/websockets/constructor/020.html new file mode 100644 index 000000000..55ca9934b --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/020.html @@ -0,0 +1,20 @@ +<!doctype html> +<title>WebSockets: uppercase host</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(t) { + var scheme = SCHEME_DOMAIN_PORT.split('://')[0]; + var domain = SCHEME_DOMAIN_PORT.split('://')[1]; + var ws = new WebSocket(scheme+'://'+domain.toUpperCase()+'/echo'); + ws.onopen = t.step_func(function(e) { + ws.close(); + t.done(); + }); + ws.onclose = ws.onerror = ws.onmessage = t.step_func(function() {assert_unreached()}); +}); +</script> diff --git a/testing/web-platform/tests/websockets/constructor/021.html b/testing/web-platform/tests/websockets/constructor/021.html new file mode 100644 index 000000000..80156540f --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/021.html @@ -0,0 +1,11 @@ +<!doctype html> +<title>WebSockets: Same sub protocol twice</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +test(function() {assert_throws("SyntaxError", function(){new WebSocket("ws://certo2.oslo.osa/protocol_array",["foobar, foobar"])})}); +</script> diff --git a/testing/web-platform/tests/websockets/constructor/022.html b/testing/web-platform/tests/websockets/constructor/022.html new file mode 100644 index 000000000..136a40d10 --- /dev/null +++ b/testing/web-platform/tests/websockets/constructor/022.html @@ -0,0 +1,22 @@ +<!doctype html> +<title>WebSockets: protocol array</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +async_test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/protocol_array',['foobar','foobar2']); + ws.onmessage = t.step_func(function(e) { + assert_equals(ws.protocol, 'foobar'); + ws.onclose = t.step_func(function(e) { + ws.onclose = t.step_func(function() {assert_unreached()}); + setTimeout(t.step_func(function() {t.done();}), 50) + }); + ws.close(); + }); + ws.onerror = t.step_func(function() {assert_unreached()}); +}); +</script> diff --git a/testing/web-platform/tests/websockets/cookies/001.html b/testing/web-platform/tests/websockets/cookies/001.html new file mode 100644 index 000000000..4f3514a20 --- /dev/null +++ b/testing/web-platform/tests/websockets/cookies/001.html @@ -0,0 +1,27 @@ +<!doctype html> +<title>WebSockets: Cookie in request</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 cookie_id = ((new Date())-0) + '.' + Math.random(); +async_test(function(t) { + if (window.WebSocket) { + document.cookie = 'ws_test_'+cookie_id+'=test; Path=/'; + } + t.add_cleanup(function() { + // remove cookie + document.cookie = 'ws_test_'+cookie_id+'=; Path=/; Expires=Sun, 06 Nov 1994 08:49:37 GMT'; + }); + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/echo-cookie'); + ws.onmessage = t.step_func(function(e) { + assert_regexp_match(e.data, new RegExp('ws_test_'+cookie_id+'=test')); + ws.close(); + t.done(); + }); + ws.onerror = ws.onclose = t.step_func(function(e) {assert_unreached(e.type)}); +}); +</script> diff --git a/testing/web-platform/tests/websockets/cookies/002.html b/testing/web-platform/tests/websockets/cookies/002.html new file mode 100644 index 000000000..934d4e936 --- /dev/null +++ b/testing/web-platform/tests/websockets/cookies/002.html @@ -0,0 +1,24 @@ +<!doctype html> +<title>WebSockets: Set-Cookie in response</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<div id=log></div> +<script> +var cookie_id = ((new Date())-0) + '.' + Math.random(); +async_test(function(t) { + t.add_cleanup(function() { + // remove cookie + document.cookie = 'ws_test_'+cookie_id+'=; Path=/; Expires=Sun, 06 Nov 1994 08:49:37 GMT'; + }); + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/set-cookie?'+cookie_id); + ws.onopen = t.step_func(function(e) { + assert_regexp_match(document.cookie, new RegExp('ws_test_'+cookie_id+'=test')); + ws.close(); + t.done(); + }); + ws.onerror = ws.onclose = t.step_func(function(e) {assert_unreached(e.type)}); +}); +</script> diff --git a/testing/web-platform/tests/websockets/cookies/003.html b/testing/web-platform/tests/websockets/cookies/003.html new file mode 100644 index 000000000..eb27437e5 --- /dev/null +++ b/testing/web-platform/tests/websockets/cookies/003.html @@ -0,0 +1,32 @@ +<!doctype html> +<title>WebSockets: sending HttpOnly cookies in ws request</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> +setup({explict_done:true}) +var cookie_id = ((new Date())-0) + '.' + Math.random(); + +var t = async_test(function(t) { + var iframe = document.createElement('iframe'); + t.add_cleanup(function() { + // remove cookie + iframe.src = 'support/set-cookie.py?'+encodeURIComponent('ws_test_'+cookie_id+'=; Path=/; HttpOnly; Expires=Sun, 06 Nov 1994 08:49:37 GMT'); + iframe.onload = done; + }); + iframe.src = 'support/set-cookie.py?'+encodeURIComponent('ws_test_'+cookie_id+'=test; Path=/; HttpOnly'); + iframe.onload = t.step_func(function() { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/echo-cookie'); + ws.onmessage = t.step_func(function(e) { + ws.close(); + assert_regexp_match(e.data, new RegExp('ws_test_'+cookie_id+'=test')); + t.done(); + }); + ws.onerror = ws.onclose = t.step_func(function(e) {assert_unreached(e.type)}); + }); + document.body.appendChild(iframe); +}, null, {timeout:9900}); +</script> diff --git a/testing/web-platform/tests/websockets/cookies/004.html b/testing/web-platform/tests/websockets/cookies/004.html new file mode 100644 index 000000000..c172892b3 --- /dev/null +++ b/testing/web-platform/tests/websockets/cookies/004.html @@ -0,0 +1,30 @@ +<!doctype html> +<title>WebSockets: setting HttpOnly cookies in ws response, checking document.cookie</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> +setup({explicit_done:true}) +var cookie_id = ((new Date())-0) + '.' + Math.random(); + +var t = async_test(function(t) { + var iframe = document.createElement('iframe'); + t.add_cleanup(function() { + // remove cookie + iframe.src = 'support/set-cookie.py?'+encodeURIComponent('ws_test_'+cookie_id+'=; Path=/; HttpOnly; Expires=Sun, 06 Nov 1994 08:49:37 GMT'); + iframe.onload = done; + }); + var url = SCHEME_DOMAIN_PORT+'/set-cookie_http?'+cookie_id; + var ws = new WebSocket(url); + ws.onopen = t.step_func(function(e) { + ws.close(); + assert_false(new RegExp('ws_test_'+cookie_id+'=test').test(document.cookie)); + t.done(); + }); + ws.onerror = ws.onclose = t.step_func(function(e) {assert_unreached(e.type)}); + document.body.appendChild(iframe); +}, null, {timeout:9900}) +</script> diff --git a/testing/web-platform/tests/websockets/cookies/005.html b/testing/web-platform/tests/websockets/cookies/005.html new file mode 100644 index 000000000..731fbfa12 --- /dev/null +++ b/testing/web-platform/tests/websockets/cookies/005.html @@ -0,0 +1,34 @@ +<!doctype html> +<title>WebSockets: setting HttpOnly cookies in ws response, checking ws request</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> +setup({explicit_done:true}) +var cookie_id = ((new Date())-0) + '.' + Math.random(); + +var t = async_test(function(t) { + var iframe = document.createElement('iframe'); + t.add_cleanup(function() { + // remove cookie + iframe.src = 'support/set-cookie.py?'+encodeURIComponent('ws_test_'+cookie_id+'=; Path=/; HttpOnly; Expires=Sun, 06 Nov 1994 08:49:37 GMT'); + iframe.onload = done; + }); + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/set-cookie_http?'+cookie_id); + ws.onopen = t.step_func(function(e) { + var ws2 = new WebSocket(SCHEME_DOMAIN_PORT+'/echo-cookie'); + ws2.onmessage = t.step_func(function(e) { + ws.close(); + ws2.close(); + assert_regexp_match(e.data, new RegExp('ws_test_'+cookie_id+'=test')); + t.done(); + }); + }); + ws.onerror = ws.onclose = t.step_func(function(e) {assert_unreached(e.type)}); + document.body.appendChild(iframe); +}) +</script> diff --git a/testing/web-platform/tests/websockets/cookies/006.html b/testing/web-platform/tests/websockets/cookies/006.html new file mode 100644 index 000000000..7e975879a --- /dev/null +++ b/testing/web-platform/tests/websockets/cookies/006.html @@ -0,0 +1,31 @@ +<!doctype html> +<title>WebSockets: setting Secure cookie with document.cookie, checking ws request</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 cookie_id = ((new Date())-0) + '.' + Math.random(); +async_test(function(t) { + if (window.WebSocket) { + document.cookie = 'ws_test_'+cookie_id+'=test; Path=/; Secure'; + } + t.add_cleanup(function() { + // remove cookie + document.cookie = 'ws_test_'+cookie_id+'=; Path=/; Secure; Expires=Sun, 06 Nov 1994 08:49:37 GMT'; + }); + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/echo-cookie'); + ws.onmessage = t.step_func(function(e) { + ws.close(); + if (SCHEME_DOMAIN_PORT.substr(0,3) == 'wss') { + assert_regexp_match(e.data, new RegExp('ws_test_'+cookie_id+'=test')); + } else { + assert_false(new RegExp('ws_test_'+cookie_id+'=test').test(e.data)); + } + t.done(); + }) + ws.onerror = ws.onclose = t.step_func(function(e) {assert_unreached(e.type)}); +}); +</script> diff --git a/testing/web-platform/tests/websockets/cookies/007.html b/testing/web-platform/tests/websockets/cookies/007.html new file mode 100644 index 000000000..f4fc8c640 --- /dev/null +++ b/testing/web-platform/tests/websockets/cookies/007.html @@ -0,0 +1,34 @@ +<!doctype html> +<title>WebSockets: when to process set-cookie fields in ws response</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> +var cookie_id = ((new Date())-0) + '.' + Math.random(); +async_test(function(t) { + t.add_cleanup(function() { + // remove cookie + document.cookie = 'ws_test_'+cookie_id+'; Path=/; Expires=Sun, 06 Nov 1994 08:49:37 GMT'; + }); + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/set-cookie?'+cookie_id); + ws.onopen = t.step_func(function(e) { + ws.close(); + assert_regexp_match(document.cookie, new RegExp('ws_test_'+cookie_id+'=test')); + t.done(); + }); + ws.onerror = ws.onclose = t.step_func(function() {assert_unreached()}); + + // sleep for 2 seconds with sync xhr + var sleep = new XMLHttpRequest(); + sleep.open('GET', '/common/blank.html?pipe=trickle(d2)', false); + sleep.send(null); + + if (new RegExp('ws_test_'+cookie_id+'=test').test(document.cookie)) { + assert_unreached('cookie was set during script execution'); + } +}, null, {timeout:12000}); +</script> diff --git a/testing/web-platform/tests/websockets/cookies/support/set-cookie.py b/testing/web-platform/tests/websockets/cookies/support/set-cookie.py new file mode 100644 index 000000000..8a47d7cdd --- /dev/null +++ b/testing/web-platform/tests/websockets/cookies/support/set-cookie.py @@ -0,0 +1,5 @@ +import urllib + +def main(request, response): + response.headers.set('Set-Cookie', urllib.unquote(request.url_parts.query)) + return [("Content-Type", "text/plain")], "" diff --git a/testing/web-platform/tests/websockets/eventhandlers.html b/testing/web-platform/tests/websockets/eventhandlers.html new file mode 100644 index 000000000..95aeb0b12 --- /dev/null +++ b/testing/web-platform/tests/websockets/eventhandlers.html @@ -0,0 +1,19 @@ +<!DOCTYPE html> +<title>WebSocket event handlers</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="websocket.sub.js"></script> +<div id="log"></div> +<script> +function testEventHandler(name) { + test(function() { + var ws = new WebSocket("ws://" + __SERVER__NAME + ":" + __PORT + "/" + __PATH, + "echo") + assert_equals(ws["on" + name], null); + ws["on" + name] = function() {}; + ws["on" + name] = 2; + assert_equals(ws["on" + name], null); + }, "Event handler for " + name + " should have [TreatNonCallableAsNull]") +} +["open", "error", "close", "message"].forEach(testEventHandler); +</script> diff --git a/testing/web-platform/tests/websockets/extended-payload-length.html b/testing/web-platform/tests/websockets/extended-payload-length.html new file mode 100644 index 000000000..9e586a98d --- /dev/null +++ b/testing/web-platform/tests/websockets/extended-payload-length.html @@ -0,0 +1,67 @@ +<!doctype html> +<title>WebSockets : Boundary-value tests for the 'Extended payload length' field in RFC6455 section5.2 'Base Framing Protocol'</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 datasize = 125; + var data = null; + ws.onopen = t.step_func(function(e) { + data = new Array(datasize + 1).join('a'); + ws.send(data); + }); + ws.onmessage = t.step_func(function(e) { + assert_equals(e.data, data); + t.done(); + }); +}, "Application data is 125 byte which means any 'Extended payload length' field isn't used at all.", {timeout:20000}); + +async_test(function(t){ + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/echo'); + var datasize = 126; + var data = null; + ws.onopen = t.step_func(function(e) { + data = new Array(datasize + 1).join('a'); + ws.send(data); + }); + ws.onmessage = t.step_func(function(e) { + assert_equals(e.data, data); + t.done(); + }); +}, "Application data is 126 byte which starts to use the 16 bit 'Extended payload length' field.", {timeout:20000}); + +async_test(function(t){ + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/echo'); + var datasize = 0xFFFF; + var data = null; + ws.onopen = t.step_func(function(e) { + data = new Array(datasize + 1).join('a'); + ws.send(data); + }); + ws.onmessage = t.step_func(function(e) { + assert_equals(e.data, data); + t.done(); + }); +}, "Application data is 0xFFFF byte which means the upper bound of the 16 bit 'Extended payload length' field.", {timeout:20000}); + +async_test(function(t){ + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/echo'); + var datasize = 0xFFFF + 1; + var data = null; + ws.onopen = t.step_func(function(e) { + data = new Array(datasize + 1).join('a'); + ws.send(data); + }); + ws.onmessage = t.step_func(function(e) { + assert_equals(e.data, data); + t.done(); + }); +}, "Application data is (0xFFFF + 1) byte which starts to use the 64 bit 'Extended payload length' field", {timeout:20000}); + +</script> diff --git a/testing/web-platform/tests/websockets/handlers/echo-cookie_wsh.py b/testing/web-platform/tests/websockets/handlers/echo-cookie_wsh.py new file mode 100755 index 000000000..367d03190 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/echo-cookie_wsh.py @@ -0,0 +1,12 @@ +#!/usr/bin/python + +from mod_pywebsocket import msgutil + +def web_socket_do_extra_handshake(request): + request.ws_cookie = request.headers_in.get('Cookie') + +def web_socket_transfer_data(request): + if request.ws_cookie is not None: + msgutil.send_message(request, request.ws_cookie) + else: + msgutil.send_message(request, '(none)') diff --git a/testing/web-platform/tests/websockets/handlers/echo-query_v13_wsh.py b/testing/web-platform/tests/websockets/handlers/echo-query_v13_wsh.py new file mode 100755 index 000000000..4083c49bc --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/echo-query_v13_wsh.py @@ -0,0 +1,11 @@ +#!/usr/bin/python + +from mod_pywebsocket import msgutil, util + +def web_socket_do_extra_handshake(request): + pass + +def web_socket_transfer_data(request): + while True: + msgutil.send_message(request, request.unparsed_uri.split('?')[1] or '') + return diff --git a/testing/web-platform/tests/websockets/handlers/echo-query_wsh.py b/testing/web-platform/tests/websockets/handlers/echo-query_wsh.py new file mode 100755 index 000000000..8fd7ac36b --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/echo-query_wsh.py @@ -0,0 +1,9 @@ +#!/usr/bin/python + +from mod_pywebsocket import msgutil, util + +def web_socket_do_extra_handshake(request): + pass # Always accept. + +def web_socket_transfer_data(request): + msgutil.send_message(request, request.unparsed_uri.split('?', 1)[1] or '') diff --git a/testing/web-platform/tests/websockets/handlers/echo_close_data_wsh.py b/testing/web-platform/tests/websockets/handlers/echo_close_data_wsh.py new file mode 100755 index 000000000..4da4ce61f --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/echo_close_data_wsh.py @@ -0,0 +1,22 @@ +#!/usr/bin/python +from mod_pywebsocket import msgutil + +_GOODBYE_MESSAGE = u'Goodbye' + +def web_socket_do_extra_handshake(request): + # This example handler accepts any request. See origin_check_wsh.py for how + # to reject access from untrusted scripts based on origin value. + + pass # Always accept. + + +def web_socket_transfer_data(request): + while True: + line = request.ws_stream.receive_message() + if line is None: + return + if isinstance(line, unicode): + if line == _GOODBYE_MESSAGE: + return + request.ws_stream.send_message(line, binary=False) + diff --git a/testing/web-platform/tests/websockets/handlers/echo_exit_wsh.py b/testing/web-platform/tests/websockets/handlers/echo_exit_wsh.py new file mode 100755 index 000000000..200b92e58 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/echo_exit_wsh.py @@ -0,0 +1,21 @@ +#!/usr/bin/python +from mod_pywebsocket import msgutil + +_GOODBYE_MESSAGE = u'Goodbye' + +def web_socket_do_extra_handshake(request): + # This example handler accepts any request. See origin_check_wsh.py for how + # to reject access from untrusted scripts based on origin value. + + pass # Always accept. + + +def web_socket_transfer_data(request): + while True: + line = request.ws_stream.receive_message() + if line is None: + return + if isinstance(line, unicode): + if line == _GOODBYE_MESSAGE: + return + diff --git a/testing/web-platform/tests/websockets/handlers/echo_raw_wsh.py b/testing/web-platform/tests/websockets/handlers/echo_raw_wsh.py new file mode 100755 index 000000000..c3a030c96 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/echo_raw_wsh.py @@ -0,0 +1,15 @@ +#!/usr/bin/python + +from mod_pywebsocket import msgutil +import urllib + + +def web_socket_do_extra_handshake(request): + pass # Always accept. + +def web_socket_transfer_data(request): + while True: + line = msgutil.receive_message(request) + if line == 'exit': + return + request.connection.write(line.decode("string-escape")) diff --git a/testing/web-platform/tests/websockets/handlers/echo_wsh.py b/testing/web-platform/tests/websockets/handlers/echo_wsh.py new file mode 100755 index 000000000..41bcd1694 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/echo_wsh.py @@ -0,0 +1,36 @@ +#!/usr/bin/python +from mod_pywebsocket import msgutil +from mod_pywebsocket import common + +_GOODBYE_MESSAGE = u'Goodbye' + +def web_socket_do_extra_handshake(request): + # This example handler accepts any request. See origin_check_wsh.py for how + # to reject access from untrusted scripts based on origin value. + if request.ws_requested_protocols: + if "echo" in request.ws_requested_protocols: + request.ws_protocol = "echo" + + +def web_socket_transfer_data(request): + while True: + line = request.ws_stream.receive_message() + if line is None: + return + if isinstance(line, unicode): + request.ws_stream.send_message(line, binary=False) + if line == _GOODBYE_MESSAGE: + return + else: + request.ws_stream.send_message(line, binary=True) + +def web_socket_passive_closing_handshake(request): + # Echo close status code and reason + code, reason = request.ws_close_code, request.ws_close_reason + + # No status received is a reserved pseudo code representing an empty code, + # so echo back an empty code in this case. + if code == common.STATUS_NO_STATUS_RECEIVED: + code = None + + return code, reason diff --git a/testing/web-platform/tests/websockets/handlers/empty-message_wsh.py b/testing/web-platform/tests/websockets/handlers/empty-message_wsh.py new file mode 100755 index 000000000..0eb107f0b --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/empty-message_wsh.py @@ -0,0 +1,13 @@ +#!/usr/bin/python + +from mod_pywebsocket import msgutil + +def web_socket_do_extra_handshake(request): + pass # Always accept. + +def web_socket_transfer_data(request): + line = msgutil.receive_message(request) + if line == "": + msgutil.send_message(request, 'pass') + else: + msgutil.send_message(request, 'fail') diff --git a/testing/web-platform/tests/websockets/handlers/handshake_no_protocol_wsh.py b/testing/web-platform/tests/websockets/handlers/handshake_no_protocol_wsh.py new file mode 100755 index 000000000..3e6b8e664 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/handshake_no_protocol_wsh.py @@ -0,0 +1,12 @@ +#!/usr/bin/python + +from mod_pywebsocket import common, msgutil, util +from mod_pywebsocket.handshake import hybi + +def web_socket_do_extra_handshake(request): + request.connection.write('HTTP/1.1 101 Switching Protocols:\x0D\x0AConnection: Upgrade\x0D\x0AUpgrade: WebSocket\x0D\x0ASec-WebSocket-Origin: '+request.ws_origin+'\x0D\x0ASec-WebSocket-Accept: '+hybi.compute_accept(request.headers_in.get(common.SEC_WEBSOCKET_KEY_HEADER))[0]+'\x0D\x0A\x0D\x0A') + return + +def web_socket_transfer_data(request): + while True: + return diff --git a/testing/web-platform/tests/websockets/handlers/handshake_protocol_wsh.py b/testing/web-platform/tests/websockets/handlers/handshake_protocol_wsh.py new file mode 100755 index 000000000..d3ebb273d --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/handshake_protocol_wsh.py @@ -0,0 +1,12 @@ +#!/usr/bin/python + +from mod_pywebsocket import common, msgutil, util +from mod_pywebsocket.handshake import hybi + +def web_socket_do_extra_handshake(request): + request.connection.write('HTTP/1.1 101 Switching Protocols:\x0D\x0AConnection: Upgrade\x0D\x0AUpgrade: WebSocket\x0D\x0ASec-WebSocket-Protocol: foobar\x0D\x0ASec-WebSocket-Origin: '+request.ws_origin+'\x0D\x0ASec-WebSocket-Accept: '+hybi.compute_accept(request.headers_in.get(common.SEC_WEBSOCKET_KEY_HEADER))[0]+'\x0D\x0A\x0D\x0A') + return + +def web_socket_transfer_data(request): + while True: + return
\ No newline at end of file diff --git a/testing/web-platform/tests/websockets/handlers/handshake_sleep_2_wsh.py b/testing/web-platform/tests/websockets/handlers/handshake_sleep_2_wsh.py new file mode 100755 index 000000000..3367ed8f8 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/handshake_sleep_2_wsh.py @@ -0,0 +1,10 @@ +#!/usr/bin/python + +from mod_pywebsocket import msgutil +import time + +def web_socket_do_extra_handshake(request): + time.sleep(2) + +def web_socket_transfer_data(request): + pass diff --git a/testing/web-platform/tests/websockets/handlers/invalid_wsh.py b/testing/web-platform/tests/websockets/handlers/invalid_wsh.py new file mode 100755 index 000000000..886e970b8 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/invalid_wsh.py @@ -0,0 +1,9 @@ +#!/usr/bin/python + +from mod_pywebsocket import msgutil + +def web_socket_do_extra_handshake(request): + request.connection.write("FOO BAR BAZ\r\n\r\n") + +def web_socket_transfer_data(request): + pass diff --git a/testing/web-platform/tests/websockets/handlers/origin_wsh.py b/testing/web-platform/tests/websockets/handlers/origin_wsh.py new file mode 100755 index 000000000..ce5f3a7f6 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/origin_wsh.py @@ -0,0 +1,11 @@ +#!/usr/bin/python + +from mod_pywebsocket import msgutil + + +def web_socket_do_extra_handshake(request): + pass # Always accept. + + +def web_socket_transfer_data(request): + msgutil.send_message(request, request.ws_origin) diff --git a/testing/web-platform/tests/websockets/handlers/protocol_array_wsh.py b/testing/web-platform/tests/websockets/handlers/protocol_array_wsh.py new file mode 100755 index 000000000..5d46c588c --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/protocol_array_wsh.py @@ -0,0 +1,14 @@ +#!/usr/bin/python + +from mod_pywebsocket import msgutil, util + +def web_socket_do_extra_handshake(request): + line = request.headers_in.get('Sec-WebSocket-Protocol') + request.ws_protocol = line.split(',', 1)[0] + +#pass + +def web_socket_transfer_data(request): + while True: + msgutil.send_message(request, request.ws_protocol) + return diff --git a/testing/web-platform/tests/websockets/handlers/protocol_wsh.py b/testing/web-platform/tests/websockets/handlers/protocol_wsh.py new file mode 100755 index 000000000..96a452584 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/protocol_wsh.py @@ -0,0 +1,12 @@ +#!/usr/bin/python + +from mod_pywebsocket import msgutil, util + +def web_socket_do_extra_handshake(request): + request.ws_protocol = request.headers_in.get('Sec-WebSocket-Protocol') +#pass + +def web_socket_transfer_data(request): + while True: + msgutil.send_message(request, request.ws_protocol) + return diff --git a/testing/web-platform/tests/websockets/handlers/set-cookie-secure_wsh.py b/testing/web-platform/tests/websockets/handlers/set-cookie-secure_wsh.py new file mode 100755 index 000000000..0daf72856 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/set-cookie-secure_wsh.py @@ -0,0 +1,15 @@ +#!/usr/bin/python +import urlparse + +from mod_pywebsocket import common, msgutil, util +from mod_pywebsocket.handshake import hybi + + +def web_socket_do_extra_handshake(request): + url_parts = urlparse.urlsplit(request.uri) + request.connection.write('HTTP/1.1 101 Switching Protocols:\x0D\x0AConnection: Upgrade\x0D\x0AUpgrade: WebSocket\x0D\x0ASet-Cookie: ws_test_'+(url_parts.query or '')+'=test; Secure; Path=/\x0D\x0ASec-WebSocket-Origin: '+request.ws_origin+'\x0D\x0ASec-WebSocket-Accept: '+hybi.compute_accept(request.headers_in.get(common.SEC_WEBSOCKET_KEY_HEADER))[0]+'\x0D\x0A\x0D\x0A') + return + +def web_socket_transfer_data(request): + while True: + return diff --git a/testing/web-platform/tests/websockets/handlers/set-cookie_http_wsh.py b/testing/web-platform/tests/websockets/handlers/set-cookie_http_wsh.py new file mode 100755 index 000000000..147842457 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/set-cookie_http_wsh.py @@ -0,0 +1,14 @@ +#!/usr/bin/python + +from mod_pywebsocket import common, msgutil, util +from mod_pywebsocket.handshake import hybi +import urlparse + +def web_socket_do_extra_handshake(request): + url_parts = urlparse.urlsplit(request.uri) + request.connection.write('HTTP/1.1 101 Switching Protocols:\x0D\x0AConnection: Upgrade\x0D\x0AUpgrade: WebSocket\x0D\x0ASet-Cookie: ws_test_'+(url_parts.query or '')+'=test; Path=/; HttpOnly\x0D\x0ASec-WebSocket-Origin: '+request.ws_origin+'\x0D\x0ASec-WebSocket-Accept: '+hybi.compute_accept(request.headers_in.get(common.SEC_WEBSOCKET_KEY_HEADER))[0]+'\x0D\x0A\x0D\x0A') + return + +def web_socket_transfer_data(request): + while True: + return diff --git a/testing/web-platform/tests/websockets/handlers/set-cookie_wsh.py b/testing/web-platform/tests/websockets/handlers/set-cookie_wsh.py new file mode 100755 index 000000000..b0e650476 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/set-cookie_wsh.py @@ -0,0 +1,15 @@ +#!/usr/bin/python +import urlparse + +from mod_pywebsocket import common, msgutil, util +from mod_pywebsocket.handshake import hybi + + +def web_socket_do_extra_handshake(request): + url_parts = urlparse.urlsplit(request.uri) + request.connection.write('HTTP/1.1 101 Switching Protocols:\x0D\x0AConnection: Upgrade\x0D\x0AUpgrade: WebSocket\x0D\x0ASet-Cookie: ws_test_'+(url_parts.query or '')+'=test; Path=/\x0D\x0ASec-WebSocket-Origin: '+request.ws_origin+'\x0D\x0ASec-WebSocket-Accept: '+hybi.compute_accept(request.headers_in.get(common.SEC_WEBSOCKET_KEY_HEADER))[0]+'\x0D\x0A\x0D\x0A') + return + +def web_socket_transfer_data(request): + while True: + return diff --git a/testing/web-platform/tests/websockets/handlers/simple_handshake_wsh.py b/testing/web-platform/tests/websockets/handlers/simple_handshake_wsh.py new file mode 100755 index 000000000..075009907 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/simple_handshake_wsh.py @@ -0,0 +1,13 @@ +#!/usr/bin/python + +from mod_pywebsocket import common, msgutil, util +from mod_pywebsocket.handshake import hybi + + +def web_socket_do_extra_handshake(request): + request.connection.write('HTTP/1.1 101 Switching Protocols:\x0D\x0AConnection: Upgrade\x0D\x0AUpgrade: WebSocket\x0D\x0ASet-Cookie: ws_test=test\x0D\x0ASec-WebSocket-Origin: '+request.ws_origin+'\x0D\x0ASec-WebSocket-Accept: '+hybi.compute_accept(request.headers_in.get(common.SEC_WEBSOCKET_KEY_HEADER))[0]+'\x0D\x0A\x0D\x0A') + return + +def web_socket_transfer_data(request): + while True: + return diff --git a/testing/web-platform/tests/websockets/handlers/sleep_10_v13_wsh.py b/testing/web-platform/tests/websockets/handlers/sleep_10_v13_wsh.py new file mode 100755 index 000000000..e1a6d9640 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/sleep_10_v13_wsh.py @@ -0,0 +1,25 @@ +#!/usr/bin/python + +import sys, urllib, time +from mod_pywebsocket import common, msgutil, util + +def web_socket_do_extra_handshake(request): + request.connection.write('x') + time.sleep(2) + request.connection.write('x') + time.sleep(2) + request.connection.write('x') + time.sleep(2) + request.connection.write('x') + time.sleep(2) + request.connection.write('x') + time.sleep(2) + return + +def web_socket_transfer_data(request): + while True: + line = msgutil.receive_message(request) + if line == 'Goodbye': + return + request.ws_stream.send_message(line, binary=False) + diff --git a/testing/web-platform/tests/websockets/handlers/stash_responder_wsh.py b/testing/web-platform/tests/websockets/handlers/stash_responder_wsh.py new file mode 100644 index 000000000..bc6f4fd6e --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/stash_responder_wsh.py @@ -0,0 +1,45 @@ +#!/usr/bin/python +import urlparse, json +from mod_pywebsocket import common, msgutil, util +from mod_pywebsocket.handshake import hybi +from wptserve import stash + +address, authkey = stash.load_env_config() +stash = stash.Stash("/stash_responder", address=address, authkey=authkey) + +def web_socket_do_extra_handshake(request): + return + +def web_socket_transfer_data(request): + while True: + line = request.ws_stream.receive_message() + if line == "echo": + query = request.unparsed_uri.split('?')[1] + GET = dict(urlparse.parse_qsl(query)) + + # TODO(kristijanburnik): This code should be reused from + # /mixed-content/generic/expect.py or implemented more generally + # for other tests. + path = GET.get("path", request.unparsed_uri.split('?')[0]) + key = GET["key"] + action = GET["action"] + + if action == "put": + value = GET["value"] + stash.take(key=key, path=path) + stash.put(key=key, value=value, path=path) + response_data = json.dumps({"status": "success", "result": key}) + elif action == "purge": + value = stash.take(key=key, path=path) + response_data = json.dumps({"status": "success", "result": value}) + elif action == "take": + value = stash.take(key=key, path=path) + if value is None: + status = "allowed" + else: + status = "blocked" + response_data = json.dumps({"status": status, "result": value}) + + msgutil.send_message(request, response_data) + + return diff --git a/testing/web-platform/tests/websockets/handlers/wrong_accept_key_wsh.py b/testing/web-platform/tests/websockets/handlers/wrong_accept_key_wsh.py new file mode 100755 index 000000000..f504a81f4 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/wrong_accept_key_wsh.py @@ -0,0 +1,13 @@ +#!/usr/bin/python + +import sys, urllib, time +from mod_pywebsocket import common, msgutil, util + +def web_socket_do_extra_handshake(request): + request.connection.write('HTTP/1.1 101 Switching Protocols:\x0D\x0AConnection: Upgrade\x0D\x0AUpgrade: WebSocket\x0D\x0ASec-WebSocket-Origin: '+request.ws_origin+'\x0D\x0ASec-WebSocket-Accept: thisisawrongacceptkey\x0D\x0A\x0D\x0A') + return + +def web_socket_transfer_data(request): + while True: + request.ws_stream.send_message('test', binary=False) + return 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> diff --git a/testing/web-platform/tests/websockets/keeping-connection-open/001.html b/testing/web-platform/tests/websockets/keeping-connection-open/001.html new file mode 100644 index 000000000..ec18fe67e --- /dev/null +++ b/testing/web-platform/tests/websockets/keeping-connection-open/001.html @@ -0,0 +1,28 @@ +<!doctype html> +<title>WebSockets: 20s inactivity after handshake</title> +<meta name=timeout content=long> +<p>Note: This test takes 20 seconds to run.</p> +<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.onclose = ws.onerror = ws.onmessage = t.step_func(function() {assert_unreached()}); + ws.onopen = t.step_func(function(e) { + setTimeout(t.step_func(function() { + ws.send('test'); + ws.onmessage = t.step_func(function(e) { + assert_equals(e.data, 'test'); + ws.onclose = t.step_func(function(e) { + setTimeout(t.step_func(function() {t.done();}), 50) + }); + ws.close(); + }); + }), 20000); + }) +}, null, {timeout:30000}); +</script> diff --git a/testing/web-platform/tests/websockets/opening-handshake/001.html b/testing/web-platform/tests/websockets/opening-handshake/001.html new file mode 100644 index 000000000..9683a3595 --- /dev/null +++ b/testing/web-platform/tests/websockets/opening-handshake/001.html @@ -0,0 +1,19 @@ +<!doctype html> +<title>WebSockets: invalid handshake</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+'/invalid'); + ws.onclose = t.step_func(function(e) { + assert_false(e.wasClean); + ws.onclose = t.step_func(function() {assert_unreached()}); + setTimeout(t.step_func(function() {t.done();}), 50) + }); + ws.onmessage = ws.onopen = t.step_func(function() {assert_unreached()}); +}, null, {timeout:9900}); +</script> diff --git a/testing/web-platform/tests/websockets/opening-handshake/002.html b/testing/web-platform/tests/websockets/opening-handshake/002.html new file mode 100644 index 000000000..d18ec6e43 --- /dev/null +++ b/testing/web-platform/tests/websockets/opening-handshake/002.html @@ -0,0 +1,23 @@ +<!doctype html> +<title>WebSockets: valid handshake</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'); + ws.onopen = t.step_func(function(e) { + ws.onclose = t.step_func(function(e) { + assert_equals(e.wasClean, true); + ws.onclose = t.step_func(function() {assert_unreached()}); + setTimeout(t.step_func(function() {t.done();}), 50) + }) + ws.close(); + }); + ws.onerror = ws.onmessage = ws.onclose = t.step_func(function() {assert_unreached()}); +}, null, {timeout:9900}); +</script> diff --git a/testing/web-platform/tests/websockets/opening-handshake/003-sets-origin.worker.js b/testing/web-platform/tests/websockets/opening-handshake/003-sets-origin.worker.js new file mode 100644 index 000000000..85954ca2b --- /dev/null +++ b/testing/web-platform/tests/websockets/opening-handshake/003-sets-origin.worker.js @@ -0,0 +1,19 @@ +importScripts("/resources/testharness.js"); +importScripts('../constants.js?pipe=sub'); +importScripts('../websocket.sub.js'); + +async_test(function(t) { + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/origin'); + ws.onmessage = t.step_func(function(e) { + assert_equals(e.data, location.protocol+'//'+location.host); + ws.onclose = t.step_func(function(e) { + assert_equals(e.wasClean, true); + ws.onclose = t.step_func(function() {assert_unreached()}); + setTimeout(t.step_func_done(), 50) + }) + ws.close(); + }) + ws.onerror = ws.onclose = t.step_func(function() {assert_unreached()}); +}, "W3C WebSocket API - origin set in a Worker"); + +done(); diff --git a/testing/web-platform/tests/websockets/opening-handshake/003.html b/testing/web-platform/tests/websockets/opening-handshake/003.html new file mode 100644 index 000000000..6c634b0e9 --- /dev/null +++ b/testing/web-platform/tests/websockets/opening-handshake/003.html @@ -0,0 +1,23 @@ +<!doctype html> +<title>WebSockets: origin</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+'/origin'); + ws.onmessage = t.step_func(function(e) { + assert_equals(e.data, location.protocol+'//'+location.host); + ws.onclose = t.step_func(function(e) { + assert_equals(e.wasClean, true); + ws.onclose = t.step_func(function() {assert_unreached()}); + setTimeout(t.step_func(function() {t.done();}), 50) + }) + ws.close(); + }) + ws.onerror = ws.onclose = t.step_func(function() {assert_unreached()}); +}); +</script> diff --git a/testing/web-platform/tests/websockets/opening-handshake/005.html b/testing/web-platform/tests/websockets/opening-handshake/005.html new file mode 100644 index 000000000..3a1a964c2 --- /dev/null +++ b/testing/web-platform/tests/websockets/opening-handshake/005.html @@ -0,0 +1,22 @@ +<!doctype html> +<title>WebSockets: proper first line</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+'/simple_handshake'); + ws.onmessage = t.step_func(function() {assert_unreached()}); + ws.onopen = t.step_func(function(e) { + ws.onclose = t.step_func(function(e) { + assert_equals(e.wasClean, true); + ws.onclose = t.step_func(function() {assert_unreached()}); + setTimeout(t.step_func(function() {t.done();}), 50) + }) + ws.close(); + }) +}); +</script> diff --git a/testing/web-platform/tests/websockets/security/001.html b/testing/web-platform/tests/websockets/security/001.html new file mode 100644 index 000000000..4cc24598b --- /dev/null +++ b/testing/web-platform/tests/websockets/security/001.html @@ -0,0 +1,16 @@ +<!doctype html> +<title>WebSockets: wrong accept key</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+'/wrong_accept_key'); + ws.onclose = t.step_func(function(e) { + t.done(); + }); +}); +</script> diff --git a/testing/web-platform/tests/websockets/security/002.html b/testing/web-platform/tests/websockets/security/002.html new file mode 100644 index 000000000..2bdc133ec --- /dev/null +++ b/testing/web-platform/tests/websockets/security/002.html @@ -0,0 +1,20 @@ +<!doctype html> +<title>WebSockets: check Sec-WebSocket-Key</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 xhr = new XMLHttpRequest(); + xhr.onload = t.step_func(function() { + assert_equals(xhr.responseText, 'PASS'); + t.done(); + }); + xhr.open("GET", "check.py", true); + xhr.setRequestHeader('Sec-WebSocket-Key', 'jW7qmdXj5Kk5jTClF1BN3'); + xhr.send(null); +}); +</script> diff --git a/testing/web-platform/tests/websockets/security/check.py b/testing/web-platform/tests/websockets/security/check.py new file mode 100644 index 000000000..f1414376d --- /dev/null +++ b/testing/web-platform/tests/websockets/security/check.py @@ -0,0 +1,2 @@ +def main(request, response): + return "FAIL" if 'Sec-WebSocket-Key' in request.headers else "PASS" diff --git a/testing/web-platform/tests/websockets/unload-a-document/001-1.html b/testing/web-platform/tests/websockets/unload-a-document/001-1.html new file mode 100644 index 000000000..214246b2e --- /dev/null +++ b/testing/web-platform/tests/websockets/unload-a-document/001-1.html @@ -0,0 +1,28 @@ +<!doctype html> +<title>WebSockets: navigating top-level browsing context</title> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<script> +var controller = opener || parent; +var t = controller.t; +var assert_equals = controller.asset_equals; +var assert_unreached = controller.assert_unreached; +var uuid = controller.uuid; +t.add_cleanup(function() {delete sessionStorage[uuid];}); +t.step(function() { + if (sessionStorage[uuid]) { + t.done(); + } else { + sessionStorage[uuid] = 'true'; + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/echo'); + ws.onopen = t.step_func(function(e) { + setTimeout(t.step_func(function() { + assert_unreached('document was not discarded'); + }), 1000); + controller.navigate(); + }) + ws.onerror = ws.onmessage = ws.onclose = t.step_func(function(e) {assert_unreached("Got unexpected event " + e.type)}); + } +}); +</script> diff --git a/testing/web-platform/tests/websockets/unload-a-document/001.html b/testing/web-platform/tests/websockets/unload-a-document/001.html new file mode 100644 index 000000000..d949b6eba --- /dev/null +++ b/testing/web-platform/tests/websockets/unload-a-document/001.html @@ -0,0 +1,25 @@ +<!doctype html> +<title>WebSockets: navigating top-level browsing context</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=/common/utils.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<p>Test requires popup blocker disabled</p> +<div id=log></div> +<script> +var t = async_test(); +var w; +var uuid; +t.step(function() { + uuid = token() + w = window.open("001-1.html"); + add_result_callback(function() { + w.close(); + }); +}); +navigate = t.step_func(function() { + w.location = 'data:text/html,<body onload="history.back()">'; +}); +</script> diff --git a/testing/web-platform/tests/websockets/unload-a-document/002-1.html b/testing/web-platform/tests/websockets/unload-a-document/002-1.html new file mode 100644 index 000000000..86a852b10 --- /dev/null +++ b/testing/web-platform/tests/websockets/unload-a-document/002-1.html @@ -0,0 +1,34 @@ +<!doctype html> +<title>WebSockets: navigating top-level browsing context with closed websocket</title> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<script> +var controller = opener || parent; +var t = controller.t; +var assert_equals = controller.asset_equals; +var assert_unreached = controller.assert_unreached ; +var uuid = controller.token; +t.add_cleanup(function() {delete sessionStorage[uuid];}); +t.step(function() { + // this test can fail if the document is unloaded on navigation e.g. due to OOM + if (sessionStorage[uuid]) { + assert_unreached('document was discarded'); + } else { + sessionStorage[uuid] = 'true'; + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/echo'); + ws.onopen = t.step_func(function(e) { + + setTimeout(t.step_func(function() { + assert_equals(ws.readyState, ws.CLOSED, 'ws.readyState'); + t.done(); + }), 4000); + ws.close(); + ws.onclose = t.step_func(function() { + controller.navigate(); + }); + }) + ws.onerror = ws.onmessage = ws.onclose = t.step_func(function(e) {assert_unreached("Got unexpected event " + e.type)}); + } +}); +</script> diff --git a/testing/web-platform/tests/websockets/unload-a-document/002.html b/testing/web-platform/tests/websockets/unload-a-document/002.html new file mode 100644 index 000000000..df35192d6 --- /dev/null +++ b/testing/web-platform/tests/websockets/unload-a-document/002.html @@ -0,0 +1,26 @@ +<!doctype html> +<title>WebSockets: navigating top-level browsing context with closed websocket</title> +<meta name=timeout content=long> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=/common/utils.js></script> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<p>Test requires popup blocker disabled</p> +<div id=log></div> +<script> +var t = async_test(null, {timeout:15000}); +var w; +var uuid; +t.step(function() { + uuid = token() + w = window.open("002-1.html"); + add_result_callback(function() { + w.close(); + }); +}); +navigate = t.step_func(function() { + w.location = 'data:text/html,<body onload="history.back()">'; +}); +</script> diff --git a/testing/web-platform/tests/websockets/unload-a-document/003.html b/testing/web-platform/tests/websockets/unload-a-document/003.html new file mode 100644 index 000000000..554daf458 --- /dev/null +++ b/testing/web-platform/tests/websockets/unload-a-document/003.html @@ -0,0 +1,14 @@ +<!doctype html> +<title>WebSockets: navigating nested browsing context</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=/common/utils.js></script> +<div id=log></div> +<script> +var uuid; +var t = async_test(function() {uuid = token()}); +var navigate = t.step_func(function() { + document.getElementsByTagName("iframe")[0].src = 'data:text/html,<body onload="history.back()">'; +}); +</script> +<iframe src=001-1.html></iframe>
\ No newline at end of file diff --git a/testing/web-platform/tests/websockets/unload-a-document/004.html b/testing/web-platform/tests/websockets/unload-a-document/004.html new file mode 100644 index 000000000..0ef4fbc9f --- /dev/null +++ b/testing/web-platform/tests/websockets/unload-a-document/004.html @@ -0,0 +1,16 @@ +<!doctype html> +<title>WebSockets: navigating nested browsing context with closed websocket</title> +<meta name=timeout content=long> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=/common/utils.js></script> +<div id=log></div> +<script> +var uuid; +var t = async_test(null, {timeout:15000}) +t.step(function() {uuid = token()}); +var navigate = t.step_func(function() { + document.getElementsByTagName("iframe")[0].src = 'data:text/html,<body onload="history.back()">'; +}); +</script> +<iframe src=002-1.html></iframe> diff --git a/testing/web-platform/tests/websockets/unload-a-document/005-1.html b/testing/web-platform/tests/websockets/unload-a-document/005-1.html new file mode 100644 index 000000000..04a14874a --- /dev/null +++ b/testing/web-platform/tests/websockets/unload-a-document/005-1.html @@ -0,0 +1,25 @@ +<!doctype html> +<title>WebSockets: navigating nested browsing context with a websocket in top-level</title> +<script src=../constants.js?pipe=sub></script> +<meta name="variant" content=""> +<meta name="variant" content="?wss"> +<script> +var t = opener.t; +var assert_unreached = opener.assert_unreached; +var hasRun = false; +function run(){ + var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/echo'); + ws.onopen = t.step_func(function(e) { + setTimeout(t.step_func(function() { + ws.send('test'); + }), 1000); + window[0].location = 'data:text/html,<body onload="history.back()">'; + ws.onmessage = t.step_func(function(e) { + ws.close(); + t.done(); + }); + }); + ws.onerror = ws.onmessage = ws.onclose = t.step_func(function(e) {assert_unreached("Got unexpected event " + e.type)}); +} +</script> +<iframe src='data:text/html,foo' onload='if (hasRun) return; hasRun = true; t.step(run)'></iframe> diff --git a/testing/web-platform/tests/websockets/unload-a-document/005.html b/testing/web-platform/tests/websockets/unload-a-document/005.html new file mode 100644 index 000000000..4bafe8b60 --- /dev/null +++ b/testing/web-platform/tests/websockets/unload-a-document/005.html @@ -0,0 +1,20 @@ +<!doctype html> +<title>WebSockets: navigating nested browsing context with a websocket in top-level</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> +<p>Test requires popup blocker disabled</p> +<div id=log></div> +<script> +var t = async_test(null, {timeout:15000}); +t.step(function() { + var w = window.open("005-1.html"); + add_result_callback(function() { + w.close(); + }); +}); +</script> diff --git a/testing/web-platform/tests/websockets/websocket.sub.js b/testing/web-platform/tests/websockets/websocket.sub.js new file mode 100644 index 000000000..65c4c3036 --- /dev/null +++ b/testing/web-platform/tests/websockets/websocket.sub.js @@ -0,0 +1,107 @@ +var __SERVER__NAME = "{{host}}"; +var __PORT = {{ports[ws][0]}}; +var __SECURE__PORT = {{ports[wss][0]}}; +var __NEW__PORT = __PORT; //All ports are non-default for now +var __NEW__SECURE__PORT = __SECURE__PORT; //All ports are non-default for now +var __PATH = "echo"; +var wsocket; +var data; + +function IsWebSocket() { + if (!self.WebSocket) { + assert_true(false, "Browser does not support WebSocket"); + } +} + +function CreateWebSocketNonAbsolute() { + IsWebSocket(); + var url = __SERVER__NAME; + wsocket = new WebSocket(url); +} + +function CreateWebSocketNonWsScheme() { + IsWebSocket(); + var url = "http://" + __SERVER__NAME + ":" + __PORT + "/" + __PATH; + wsocket = new WebSocket(url); +} + +function CreateWebSocketNonAsciiProtocol(nonAsciiProtocol) { + IsWebSocket(); + var url = "ws://" + __SERVER__NAME + ":" + __PORT + "/" + __PATH; + wsocket = new WebSocket(url, nonAsciiProtocol); +} + +function CreateWebSocketWithAsciiSep(asciiWithSep) { + IsWebSocket(); + var url = "ws://" + __SERVER__NAME + ":" + __PORT + "/" + __PATH; + wsocket = new WebSocket(url, asciiWithSep); +} + +function CreateWebSocketWithBlockedPort(blockedPort) { + IsWebSocket(); + var url = "wss://" + __SERVER__NAME + ":" + blockedPort + "/" + __PATH; + wsocket = new WebSocket(url); +} + +function CreateWebSocketWithSpaceInUrl(urlWithSpace) { + IsWebSocket(); + var url = "ws://" + urlWithSpace + ":" + __PORT + "/" + __PATH; + wsocket = new WebSocket(url); +} + +function CreateWebSocketWithSpaceInProtocol(protocolWithSpace) { + IsWebSocket(); + var url = "ws://" + __SERVER__NAME + ":" + __PORT + "/" + __PATH; + wsocket = new WebSocket(url, protocolWithSpace); +} + +function CreateWebSocketWithRepeatedProtocols() { + IsWebSocket(); + var url = "ws://" + __SERVER__NAME + ":" + __PORT + "/" + __PATH; + wsocket = new WebSocket(url, ["echo", "echo"]); +} + +function CreateWebSocketWithRepeatedProtocolsCaseInsensitive() { + IsWebSocket(); + var url = "ws://" + __SERVER__NAME + ":" + __PORT + "/" + __PATH; + wsocket = new WebSocket(url, ["echo", "eCho"]); +} + +function CreateWebSocket(isSecure, isProtocol, isProtocols) { + IsWebSocket(); + var url; + if (isSecure) { + if (__SECURE__PORT === null) { + throw new Error("wss not yet supported"); + } + url = "wss://" + __SERVER__NAME + ":" + __SECURE__PORT + "/" + __PATH; + } + else { + url = "ws://" + __SERVER__NAME + ":" + __PORT + "/" + __PATH; + } + + if (isProtocol) { + wsocket = new WebSocket(url, "echo"); + } + else if (isProtocols) { + wsocket = new WebSocket(url, ["echo", "chat"]); + } + else { + wsocket = new WebSocket(url); + } + return wsocket; +} + +function CreateControlWebSocket(isSecure) { + IsWebSocket(); + var url; + if (isSecure) { + url = "wss://" + __SERVER__NAME + ":" + __SECURE__PORT + "/control"; + } + else { + url = "ws://" + __SERVER__NAME + ":" + __PORT + "/control"; + } + + return new WebSocket(url); +} + |