summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount')
-rw-r--r--testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-arraybuffer.html25
-rw-r--r--testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-blob.html26
-rw-r--r--testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-defineProperty-getter.html18
-rw-r--r--testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-defineProperty-setter.html20
-rw-r--r--testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-deleting.html23
-rw-r--r--testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-getting.html53
-rw-r--r--testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-initial.html15
-rw-r--r--testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-large.html27
-rw-r--r--testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-readonly.html16
-rw-r--r--testing/web-platform/tests/websockets/interfaces/WebSocket/bufferedAmount/bufferedAmount-unicode.html23
10 files changed, 246 insertions, 0 deletions
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>