From 25b337f23700a8552bf5d1f1a3ce4e9c18db2ad6 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Thu, 3 Oct 2019 23:14:58 +0000 Subject: [PATCH] Bug 1523562 [wpt PR 14417] - Update RTCPeerConnection-helper.js, a=testonly Automatic update from web-platform-tests Update RTCPeerConnection-helper.js (#14417) * Update RTCPeerConnection-helper.js according changes proposed in https://github.com/web-platform-tests/wpt/pull/13499 * Modernize doSignalingHandshake -- wpt-commits: b75b876e7d5843582f21e5b52c54d509dffb6da0 wpt-pr: 14417 UltraBlame original commit: 603e8e8097b742115dca2e195f59f65618b97ac0 --- .../tests/webrtc/RTCDataChannel-send.html | 16 +-- .../tests/webrtc/RTCPeerConnection-helper.js | 122 +++++++++++++----- .../tests/webrtc/tools/.eslintrc.js | 2 +- 3 files changed, 100 insertions(+), 40 deletions(-) diff --git a/testing/web-platform/tests/webrtc/RTCDataChannel-send.html b/testing/web-platform/tests/webrtc/RTCDataChannel-send.html index 7cacaa4d37bb..cb8b4edc3fae 100644 --- a/testing/web-platform/tests/webrtc/RTCDataChannel-send.html +++ b/testing/web-platform/tests/webrtc/RTCDataChannel-send.html @@ -14,7 +14,7 @@ // createDataChannelPair // awaitMessage // blobToArrayBuffer - // assert_equals_array_buffer + // assert_equals_typed_array /* 6.2. RTCDataChannel @@ -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'); @@ -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'); @@ -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'); @@ -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'); @@ -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'); @@ -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(); } diff --git a/testing/web-platform/tests/webrtc/RTCPeerConnection-helper.js b/testing/web-platform/tests/webrtc/RTCPeerConnection-helper.js index fa03a7bb6890..6f3dbbf691d4 100644 --- a/testing/web-platform/tests/webrtc/RTCPeerConnection-helper.js +++ b/testing/web-platform/tests/webrtc/RTCPeerConnection-helper.js @@ -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); } @@ -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 { + 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); } } @@ -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); + } +} diff --git a/testing/web-platform/tests/webrtc/tools/.eslintrc.js b/testing/web-platform/tests/webrtc/tools/.eslintrc.js index 01f3b4efa318..a3b25a063bf0 100644 --- a/testing/web-platform/tests/webrtc/tools/.eslintrc.js +++ b/testing/web-platform/tests/webrtc/tools/.eslintrc.js @@ -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,