mirror of
https://github.com/servo/servo.git
synced 2025-08-08 23:15:33 +01:00
Update web-platform-tests to revision 122a4672fa0dc554a6e7528fa3487fd907c792ee
This commit is contained in:
parent
fb1123495f
commit
93d826f7ba
301 changed files with 4775 additions and 1769 deletions
|
@ -5,166 +5,222 @@
|
|||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="RTCPeerConnection-helper.js"></script>
|
||||
<script>
|
||||
'use strict';
|
||||
'use strict';
|
||||
|
||||
// Test is based on the following editor draft:
|
||||
// https://w3c.github.io/webrtc-pc/archives/20170605/webrtc.html
|
||||
// Test is based on the following revision:
|
||||
// https://rawgit.com/w3c/webrtc-pc/1cc5bfc3ff18741033d804c4a71f7891242fb5b3/webrtc.html
|
||||
|
||||
// The following helper functions are called from RTCPeerConnection-helper.js:
|
||||
// createDataChannelPair
|
||||
// awaitMessage
|
||||
// blobToArrayBuffer
|
||||
// assert_equals_array_buffer
|
||||
// The following helper functions are called from RTCPeerConnection-helper.js:
|
||||
// createDataChannelPair
|
||||
// awaitMessage
|
||||
|
||||
/*
|
||||
6.2. RTCDataChannel
|
||||
interface RTCDataChannel : EventTarget {
|
||||
...
|
||||
readonly attribute unsigned long bufferedAmount;
|
||||
void send(USVString data);
|
||||
void send(Blob data);
|
||||
void send(ArrayBuffer data);
|
||||
void send(ArrayBufferView data);
|
||||
};
|
||||
|
||||
bufferedAmount
|
||||
The bufferedAmount attribute must return the number of bytes of application
|
||||
data (UTF-8 text and binary data) that have been queued using send() but that,
|
||||
as of the last time the event loop started executing a task, had not yet been
|
||||
transmitted to the network. (This thus includes any text sent during the
|
||||
execution of the current task, regardless of whether the user agent is able
|
||||
to transmit text asynchronously with script execution.) This does not include
|
||||
framing overhead incurred by the protocol, or buffering done by the operating
|
||||
system or network hardware. If the channel is closed, this attribute's value
|
||||
will only increase with each call to the send() method (the attribute does not
|
||||
reset to zero once the channel closes).
|
||||
|
||||
|
||||
[WebMessaging]
|
||||
interface MessageEvent : Event {
|
||||
readonly attribute any data;
|
||||
/*
|
||||
6.2. RTCDataChannel
|
||||
interface RTCDataChannel : EventTarget {
|
||||
...
|
||||
readonly attribute unsigned long bufferedAmount;
|
||||
void send(USVString data);
|
||||
void send(Blob data);
|
||||
void send(ArrayBuffer data);
|
||||
void send(ArrayBufferView data);
|
||||
};
|
||||
*/
|
||||
|
||||
// Simple ASCII encoded string
|
||||
const helloString = 'hello';
|
||||
// ASCII encoded buffer representation of the string
|
||||
const helloBuffer = Uint8Array.of(0x68, 0x65, 0x6c, 0x6c, 0x6f);
|
||||
const helloBlob = new Blob([helloBuffer]);
|
||||
bufferedAmount
|
||||
The bufferedAmount attribute must return the number of bytes of application
|
||||
data (UTF-8 text and binary data) that have been queued using send() but that,
|
||||
as of the last time the event loop started executing a task, had not yet been
|
||||
transmitted to the network. (This thus includes any text sent during the
|
||||
execution of the current task, regardless of whether the user agent is able
|
||||
to transmit text asynchronously with script execution.) This does not include
|
||||
framing overhead incurred by the protocol, or buffering done by the operating
|
||||
system or network hardware. The value of the [[BufferedAmount]] slot will only
|
||||
increase with each call to the send() method as long as the [[ReadyState]] slot
|
||||
is open; however, the slot does not reset to zero once the channel closes. When
|
||||
the underlying data transport sends data from its queue, the user agent MUST
|
||||
queue a task that reduces [[BufferedAmount]] with the number of bytes that was
|
||||
sent.
|
||||
|
||||
// Unicode string with multiple code units
|
||||
const unicodeString = '世界你好';
|
||||
// UTF-8 encoded buffer representation of the string
|
||||
const unicodeBuffer = Uint8Array.of(
|
||||
0xe4, 0xb8, 0x96, 0xe7, 0x95, 0x8c,
|
||||
0xe4, 0xbd, 0xa0, 0xe5, 0xa5, 0xbd);
|
||||
|
||||
/*
|
||||
6.2. send()
|
||||
3. Execute the sub step that corresponds to the type of the methods argument:
|
||||
[WebMessaging]
|
||||
interface MessageEvent : Event {
|
||||
readonly attribute any data;
|
||||
...
|
||||
};
|
||||
*/
|
||||
|
||||
string object
|
||||
Let data be the object and increase the bufferedAmount attribute
|
||||
by the number of bytes needed to express data as UTF-8.
|
||||
*/
|
||||
promise_test(t => {
|
||||
return createDataChannelPair()
|
||||
.then(([channel1, channel2]) => {
|
||||
channel1.send(unicodeString);
|
||||
assert_equals(channel1.bufferedAmount, unicodeBuffer.byteLength,
|
||||
'Expect bufferedAmount to be the byte length of the unicode string');
|
||||
// Simple ASCII encoded string
|
||||
const helloString = 'hello';
|
||||
// ASCII encoded buffer representation of the string
|
||||
const helloBuffer = Uint8Array.of(0x68, 0x65, 0x6c, 0x6c, 0x6f);
|
||||
const helloBlob = new Blob([helloBuffer]);
|
||||
|
||||
return awaitMessage(channel2)
|
||||
.then(message => {
|
||||
assert_equals(channel1.bufferedAmount, 0,
|
||||
'Expect sender bufferedAmount to be reduced after message is sent');
|
||||
});
|
||||
});
|
||||
}, 'bufferedAmount should increase to byte length of encoded unicode string sent');
|
||||
// Unicode string with multiple code units
|
||||
const unicodeString = '世界你好';
|
||||
// UTF-8 encoded buffer representation of the string
|
||||
const unicodeBuffer = Uint8Array.of(
|
||||
0xe4, 0xb8, 0x96, 0xe7, 0x95, 0x8c,
|
||||
0xe4, 0xbd, 0xa0, 0xe5, 0xa5, 0xbd);
|
||||
|
||||
/*
|
||||
6.2. send()
|
||||
3. Execute the sub step that corresponds to the type of the methods argument:
|
||||
ArrayBuffer object
|
||||
Let data be the data stored in the buffer described by the ArrayBuffer
|
||||
object and increase the bufferedAmount attribute by the length of the
|
||||
ArrayBuffer in bytes.
|
||||
*/
|
||||
promise_test(t => {
|
||||
return createDataChannelPair()
|
||||
.then(([channel1, channel2]) => {
|
||||
channel1.send(helloBuffer.buffer);
|
||||
assert_equals(channel1.bufferedAmount, helloBuffer.byteLength,
|
||||
'Expect bufferedAmount to increase to byte length of sent buffer');
|
||||
/*
|
||||
Ensure .bufferedAmount is 0 initially for both sides.
|
||||
*/
|
||||
promise_test(async (t) => {
|
||||
const pc1 = new RTCPeerConnection();
|
||||
const pc2 = new RTCPeerConnection();
|
||||
t.add_cleanup(() => pc1.close());
|
||||
t.add_cleanup(() => pc2.close());
|
||||
|
||||
return awaitMessage(channel2)
|
||||
.then(messageBuffer => {
|
||||
assert_equals(channel1.bufferedAmount, 0,
|
||||
'Expect sender bufferedAmount to be reduced after message is sent');
|
||||
});
|
||||
});
|
||||
}, 'bufferedAmount should increase to byte length of buffer sent');
|
||||
const [dc1, dc2] = await createDataChannelPair(pc1, pc2);
|
||||
|
||||
/*
|
||||
6.2. send()
|
||||
3. Execute the sub step that corresponds to the type of the methods argument:
|
||||
Blob object
|
||||
Let data be the raw data represented by the Blob object and increase
|
||||
the bufferedAmount attribute by the size of data, in bytes.
|
||||
*/
|
||||
promise_test(t => {
|
||||
return createDataChannelPair()
|
||||
.then(([channel1, channel2]) => {
|
||||
channel1.send(helloBlob);
|
||||
assert_equals(channel1.bufferedAmount, helloBlob.size,
|
||||
'Expect bufferedAmount to increase to size of sent blob');
|
||||
assert_equals(dc1.bufferedAmount, 0, 'Expect bufferedAmount to be 0');
|
||||
assert_equals(dc2.bufferedAmount, 0, 'Expect bufferedAmount to be 0');
|
||||
}, 'bufferedAmount initial value should be 0 for both peers');
|
||||
|
||||
return awaitMessage(channel2)
|
||||
.then(messageBuffer => {
|
||||
assert_equals(channel1.bufferedAmount, 0,
|
||||
'Expect sender bufferedAmount to be reduced after message is sent');
|
||||
});
|
||||
});
|
||||
}, 'bufferedAmount should increase to size of blob sent');
|
||||
/*
|
||||
6.2. send()
|
||||
3. Execute the sub step that corresponds to the type of the methods argument:
|
||||
|
||||
// Test sending 3 messages: helloBuffer, unicodeString, helloBlob
|
||||
async_test(t => {
|
||||
let messageCount = 0;
|
||||
string object
|
||||
Let data be the object and increase the bufferedAmount attribute
|
||||
by the number of bytes needed to express data as UTF-8.
|
||||
*/
|
||||
promise_test(async (t) => {
|
||||
const pc1 = new RTCPeerConnection();
|
||||
const pc2 = new RTCPeerConnection();
|
||||
t.add_cleanup(() => pc1.close());
|
||||
t.add_cleanup(() => pc2.close());
|
||||
|
||||
createDataChannelPair()
|
||||
.then(([channel1, channel2]) => {
|
||||
const onMessage = t.step_func(event => {
|
||||
const { data } = event;
|
||||
messageCount++;
|
||||
const [dc1, dc2] = await createDataChannelPair(pc1, pc2);
|
||||
|
||||
if(messageCount === 3) {
|
||||
assert_equals(channel1.bufferedAmount, 0,
|
||||
'Expect sender bufferedAmount to be reduced after message is sent');
|
||||
dc1.send(unicodeString);
|
||||
assert_equals(dc1.bufferedAmount, unicodeBuffer.byteLength,
|
||||
'Expect bufferedAmount to be the byte length of the unicode string');
|
||||
|
||||
t.done();
|
||||
}
|
||||
});
|
||||
await awaitMessage(dc2);
|
||||
assert_equals(dc1.bufferedAmount, 0,
|
||||
'Expect sender bufferedAmount to be reduced after message is sent');
|
||||
}, 'bufferedAmount should increase to byte length of encoded unicode string sent');
|
||||
|
||||
channel2.addEventListener('message', onMessage);
|
||||
/*
|
||||
6.2. send()
|
||||
3. Execute the sub step that corresponds to the type of the methods argument:
|
||||
ArrayBuffer object
|
||||
Let data be the data stored in the buffer described by the ArrayBuffer
|
||||
object and increase the bufferedAmount attribute by the length of the
|
||||
ArrayBuffer in bytes.
|
||||
*/
|
||||
promise_test(async (t) => {
|
||||
const pc1 = new RTCPeerConnection();
|
||||
const pc2 = new RTCPeerConnection();
|
||||
t.add_cleanup(() => pc1.close());
|
||||
t.add_cleanup(() => pc2.close());
|
||||
|
||||
channel1.send(helloBuffer);
|
||||
assert_equals(channel1.bufferedAmount, helloString.length,
|
||||
'Expect bufferedAmount to be the total length of all messages queued to send');
|
||||
const [dc1, dc2] = await createDataChannelPair(pc1, pc2);
|
||||
|
||||
channel1.send(unicodeString);
|
||||
assert_equals(channel1.bufferedAmount,
|
||||
helloString.length + unicodeBuffer.byteLength,
|
||||
'Expect bufferedAmount to be the total length of all messages queued to send');
|
||||
dc1.send(helloBuffer.buffer);
|
||||
assert_equals(dc1.bufferedAmount, helloBuffer.byteLength,
|
||||
'Expect bufferedAmount to increase to byte length of sent buffer');
|
||||
|
||||
channel1.send(helloBlob);
|
||||
assert_equals(channel1.bufferedAmount,
|
||||
helloString.length*2 + unicodeBuffer.byteLength,
|
||||
'Expect bufferedAmount to be the total length of all messages queued to send');
|
||||
await awaitMessage(dc2);
|
||||
assert_equals(dc1.bufferedAmount, 0,
|
||||
'Expect sender bufferedAmount to be reduced after message is sent');
|
||||
}, 'bufferedAmount should increase to byte length of buffer sent');
|
||||
|
||||
}).catch(t.step_func(err =>
|
||||
assert_unreached(`Unexpected promise rejection: ${err}`)));
|
||||
}, 'bufferedAmount should increase by byte length for each message sent');
|
||||
/*
|
||||
6.2. send()
|
||||
3. Execute the sub step that corresponds to the type of the methods argument:
|
||||
Blob object
|
||||
Let data be the raw data represented by the Blob object and increase
|
||||
the bufferedAmount attribute by the size of data, in bytes.
|
||||
*/
|
||||
promise_test(async (t) => {
|
||||
const pc1 = new RTCPeerConnection();
|
||||
const pc2 = new RTCPeerConnection();
|
||||
t.add_cleanup(() => pc1.close());
|
||||
t.add_cleanup(() => pc2.close());
|
||||
|
||||
const [dc1, dc2] = await createDataChannelPair(pc1, pc2);
|
||||
|
||||
dc1.send(helloBlob);
|
||||
assert_equals(dc1.bufferedAmount, helloBlob.size,
|
||||
'Expect bufferedAmount to increase to size of sent blob');
|
||||
|
||||
await awaitMessage(dc2);
|
||||
assert_equals(dc1.bufferedAmount, 0,
|
||||
'Expect sender bufferedAmount to be reduced after message is sent');
|
||||
}, 'bufferedAmount should increase to size of blob sent');
|
||||
|
||||
// Test sending 3 messages: helloBuffer, unicodeString, helloBlob
|
||||
promise_test(async (t) => {
|
||||
const resolver = new Resolver();
|
||||
const pc1 = new RTCPeerConnection();
|
||||
const pc2 = new RTCPeerConnection();
|
||||
t.add_cleanup(() => pc1.close());
|
||||
t.add_cleanup(() => pc2.close());
|
||||
|
||||
let messageCount = 0;
|
||||
|
||||
const [dc1, dc2] = await createDataChannelPair(pc1, pc2);
|
||||
const onMessage = t.step_func(() => {
|
||||
if (++messageCount === 3) {
|
||||
assert_equals(dc1.bufferedAmount, 0,
|
||||
'Expect sender bufferedAmount to be reduced after message is sent');
|
||||
resolver.resolve();
|
||||
}
|
||||
});
|
||||
|
||||
dc2.addEventListener('message', onMessage);
|
||||
|
||||
dc1.send(helloBuffer);
|
||||
assert_equals(dc1.bufferedAmount, helloString.length,
|
||||
'Expect bufferedAmount to be the total length of all messages queued to send');
|
||||
|
||||
dc1.send(unicodeString);
|
||||
assert_equals(dc1.bufferedAmount,
|
||||
helloString.length + unicodeBuffer.byteLength,
|
||||
'Expect bufferedAmount to be the total length of all messages queued to send');
|
||||
|
||||
dc1.send(helloBlob);
|
||||
assert_equals(dc1.bufferedAmount,
|
||||
helloString.length*2 + unicodeBuffer.byteLength,
|
||||
'Expect bufferedAmount to be the total length of all messages queued to send');
|
||||
|
||||
await resolver;
|
||||
}, 'bufferedAmount should increase by byte length for each message sent');
|
||||
|
||||
promise_test(async (t) => {
|
||||
const pc1 = new RTCPeerConnection();
|
||||
const pc2 = new RTCPeerConnection();
|
||||
t.add_cleanup(() => pc1.close());
|
||||
t.add_cleanup(() => pc2.close());
|
||||
|
||||
const [dc1] = await createDataChannelPair(pc1, pc2);
|
||||
|
||||
dc1.send(helloBuffer.buffer);
|
||||
assert_equals(dc1.bufferedAmount, helloBuffer.byteLength,
|
||||
'Expect bufferedAmount to increase to byte length of sent buffer');
|
||||
|
||||
dc1.close();
|
||||
assert_equals(dc1.bufferedAmount, helloBuffer.byteLength,
|
||||
'Expect bufferedAmount to not decrease immediately after closing the channel');
|
||||
}, 'bufferedAmount should not decrease immediately after initiating closure');
|
||||
|
||||
promise_test(async (t) => {
|
||||
const pc1 = new RTCPeerConnection();
|
||||
const pc2 = new RTCPeerConnection();
|
||||
t.add_cleanup(() => pc1.close());
|
||||
t.add_cleanup(() => pc2.close());
|
||||
|
||||
const [dc1] = await createDataChannelPair(pc1, pc2);
|
||||
|
||||
dc1.send(helloBuffer.buffer);
|
||||
assert_equals(dc1.bufferedAmount, helloBuffer.byteLength,
|
||||
'Expect bufferedAmount to increase to byte length of sent buffer');
|
||||
|
||||
pc1.close();
|
||||
assert_equals(dc1.bufferedAmount, helloBuffer.byteLength,
|
||||
'Expect bufferedAmount to not decrease after closing the peer connection');
|
||||
}, 'bufferedAmount should not decrease after closing the peer connection');
|
||||
|
||||
promise_test(async t => {
|
||||
const [channel1, channel2] = await createDataChannelPair();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue