Skip to content

Commit

Permalink
Bug 1523562 [wpt PR 14417] - Update RTCPeerConnection-helper.js, a=te…
Browse files Browse the repository at this point in the history
…stonly

Automatic update from web-platform-tests
Update RTCPeerConnection-helper.js (#14417)

* Update RTCPeerConnection-helper.js according changes proposed in web-platform-tests/wpt#13499
* Modernize doSignalingHandshake
--

wpt-commits: b75b876e7d5843582f21e5b52c54d509dffb6da0
wpt-pr: 14417

UltraBlame original commit: 118c5c41cfd03c68da65ed6775072450154c86dc
  • Loading branch information
marco-c committed Oct 3, 2019
1 parent 7d30b86 commit e6440e3
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 40 deletions.
16 changes: 8 additions & 8 deletions testing/web-platform/tests/webrtc/RTCDataChannel-send.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// createDataChannelPair
// awaitMessage
// blobToArrayBuffer
// assert_equals_array_buffer
// assert_equals_typed_array

/*
6.2. RTCDataChannel
Expand Down Expand Up @@ -140,7 +140,7 @@
assert_true(messageBuffer instanceof ArrayBuffer,
'Expect messageBuffer to be an ArrayBuffer');

assert_equals_array_buffer(messageBuffer, helloBuffer.buffer);
assert_equals_typed_array(messageBuffer, helloBuffer.buffer);
});
}, 'Data channel should be able to send Uint8Array message and receive as ArrayBuffer');

Expand All @@ -162,7 +162,7 @@
assert_true(messageBuffer instanceof ArrayBuffer,
'Expect messageBuffer to be an ArrayBuffer');

assert_equals_array_buffer(messageBuffer, helloBuffer.buffer);
assert_equals_typed_array(messageBuffer, helloBuffer.buffer);
});
}, 'Data channel should be able to send ArrayBuffer message and receive as ArrayBuffer');

Expand All @@ -183,7 +183,7 @@
assert_true(messageBuffer instanceof ArrayBuffer,
'Expect messageBuffer to be an ArrayBuffer');

assert_equals_array_buffer(messageBuffer, helloBuffer.buffer);
assert_equals_typed_array(messageBuffer, helloBuffer.buffer);
});
}, 'Data channel should be able to send Blob message and receive as ArrayBuffer');

Expand All @@ -210,7 +210,7 @@
assert_true(messageBuffer instanceof ArrayBuffer,
'Expect messageBuffer to be an ArrayBuffer');

assert_equals_array_buffer(messageBuffer, helloBuffer.buffer);
assert_equals_typed_array(messageBuffer, helloBuffer.buffer);
});
}, 'Data channel should be able to send ArrayBuffer message and receive as Blob');

Expand Down Expand Up @@ -240,7 +240,7 @@
assert_true(messageBuffer instanceof ArrayBuffer,
'Expect messageBuffer to be an ArrayBuffer');

assert_equals_array_buffer(messageBuffer, helloBuffer.buffer);
assert_equals_typed_array(messageBuffer, helloBuffer.buffer);
});
}, 'Data channel binaryType should receive message as Blob by default');

Expand All @@ -253,9 +253,9 @@
receivedMessages.push(data);

if(receivedMessages.length === 3) {
assert_equals_array_buffer(receivedMessages[0], helloBuffer.buffer);
assert_equals_typed_array(receivedMessages[0], helloBuffer.buffer);
assert_equals(receivedMessages[1], unicodeString);
assert_equals_array_buffer(receivedMessages[2], helloBuffer.buffer);
assert_equals_typed_array(receivedMessages[2], helloBuffer.buffer);

t.done();
}
Expand Down
122 changes: 91 additions & 31 deletions testing/web-platform/tests/webrtc/RTCPeerConnection-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,26 @@ function exchangeIceCandidates(pc1, pc2) {



function doSignalingHandshake(localPc, remotePc) {
return localPc.createOffer()
.then(offer => Promise.all([
localPc.setLocalDescription(offer),
remotePc.setRemoteDescription(offer)]))
.then(() => remotePc.createAnswer())
.then(answer => Promise.all([
remotePc.setLocalDescription(answer),
localPc.setRemoteDescription(answer)]))
async function doSignalingHandshake(localPc, remotePc, options={}) {
let offer = await localPc.createOffer();

if (options.modifyOffer) {
offer = await options.modifyOffer(offer);
}


await localPc.setLocalDescription(offer);
await remotePc.setRemoteDescription(offer);

let answer = await remotePc.createAnswer();

if (options.modifyAnswer) {
answer = await options.modifyAnswer(answer);
}


await remotePc.setLocalDescription(answer);
await localPc.setRemoteDescription(answer);
}


Expand Down Expand Up @@ -296,22 +307,24 @@ function blobToArrayBuffer(blob) {
}


function assert_equals_array_buffer(buffer1, buffer2) {
assert_true(buffer1 instanceof ArrayBuffer,
'Expect buffer to be instance of ArrayBuffer');

assert_true(buffer2 instanceof ArrayBuffer,
'Expect buffer to be instance of ArrayBuffer');
function assert_equals_typed_array(array1, array2) {
const [view1, view2] = [array1, array2].map((array) => {
if (array instanceof ArrayBuffer) {
return new DataView(array);
} else {
assert_true(array.buffer instanceof ArrayBuffer,
'Expect buffer to be instance of ArrayBuffer');
return new DataView(array.buffer, array.byteOffset, array.byteLength);
}
});

assert_equals(buffer1.byteLength, buffer2.byteLength,
'Expect both array buffers to be of the same byte length');
assert_equals(view1.byteLength, view2.byteLength,
'Expect both arrays to be of the same byte length');

const byteLength = buffer1.byteLength;
const byteArray1 = new Uint8Array(buffer1);
const byteArray2 = new Uint8Array(buffer2);
const byteLength = view1.byteLength;

for(let i=0; i<byteLength; i++) {
assert_equals(byteArray1[i], byteArray2[i],
for (let i = 0; i < byteLength; ++i) {
assert_equals(view1.getUint8(i), view2.getUint8(i),
`Expect byte at buffer position ${i} to be equal`);
}
}
Expand Down Expand Up @@ -480,16 +493,43 @@ async function exchangeOfferAndListenToOntrack(t, caller, callee) {



class Resolver {
constructor() {
let promiseResolve;
let promiseReject;
this.promise = new Promise(function(resolve, reject) {
promiseResolve = resolve;
promiseReject = reject;
class Resolver extends Promise {
constructor(executor) {
let resolve, reject;
super((resolve_, reject_) => {
resolve = resolve_;
reject = reject_;
if (executor) {
return executor(resolve_, reject_);
}
});
this.resolve = promiseResolve;
this.reject = promiseReject;

this._done = false;
this._resolve = resolve;
this._reject = reject;
}




get done() {
return this._done;
}




resolve(...args) {
this._done = true;
return this._resolve(...args);
}




reject(...args) {
this._done = true;
return this._reject(...args);
}
}

Expand Down Expand Up @@ -526,3 +566,23 @@ function findTransceiverForSender(pc, sender) {
}
return null;
}


class UniqueSet extends Set {
constructor(items) {
super();
if (items !== undefined) {
for (const item of items) {
this.add(item);
}
}
}

add(value, message) {
if (message === undefined) {
message = `Value '${value}' needs to be unique but it is already in the set`;
}
assert_true(!this.has(value), message);
super.add(value);
}
}
2 changes: 1 addition & 1 deletion testing/web-platform/tests/webrtc/tools/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ module.exports = {
createDataChannelPair: true,
awaitMessage: true,
blobToArrayBuffer: true,
assert_equals_array_buffer: true,
assert_equals_typed_array: true,
generateMediaStreamTrack: true,
getTrackFromUserMedia: true,
getUserMediaTracksAndStreams: true,
Expand Down

0 comments on commit e6440e3

Please sign in to comment.