зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1119593 - Update WebRTC data channel tests, r=drno
--HG-- extra : rebase_source : baf9f9b04c7eb0cf4471ebb29600def300424af8
This commit is contained in:
Родитель
b636521712
Коммит
2319bf1e85
|
@ -2,229 +2,179 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the contents of a blob as text
|
||||||
|
*
|
||||||
|
* @param {Blob} blob
|
||||||
|
The blob to retrieve the contents from
|
||||||
|
*/
|
||||||
|
function getBlobContent(blob) {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
var reader = new FileReader();
|
||||||
|
|
||||||
|
// Listen for 'onloadend' which will always be called after a success or failure
|
||||||
|
reader.onloadend = function (event) {
|
||||||
|
resolve(event.target.result);
|
||||||
|
};
|
||||||
|
|
||||||
|
reader.readAsText(blob);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function addInitialDataChannel(chain) {
|
function addInitialDataChannel(chain) {
|
||||||
chain.insertBefore('PC_LOCAL_CREATE_OFFER', [
|
chain.insertBefore('PC_LOCAL_CREATE_OFFER', [
|
||||||
['PC_LOCAL_CREATE_DATA_CHANNEL',
|
function PC_REMOTE_EXPECT_DATA_CHANNEL(test) {
|
||||||
function (test) {
|
test.pcRemote.expectDataChannel();
|
||||||
var channel = test.pcLocal.createDataChannel({});
|
},
|
||||||
|
|
||||||
is(channel.binaryType, "blob", channel + " is of binary type 'blob'");
|
function PC_LOCAL_CREATE_DATA_CHANNEL(test) {
|
||||||
is(channel.readyState, "connecting", channel + " is in state: 'connecting'");
|
var channel = test.pcLocal.createDataChannel({});
|
||||||
|
is(channel.binaryType, "blob", channel + " is of binary type 'blob'");
|
||||||
|
is(channel.readyState, "connecting", channel + " is in state: 'connecting'");
|
||||||
|
|
||||||
is(test.pcLocal.signalingState, STABLE,
|
is(test.pcLocal.signalingState, STABLE,
|
||||||
"Create datachannel does not change signaling state");
|
"Create datachannel does not change signaling state");
|
||||||
|
}
|
||||||
test.next();
|
|
||||||
}
|
|
||||||
]
|
|
||||||
]);
|
|
||||||
chain.insertAfter('PC_REMOTE_CREATE_ANSWER', [
|
|
||||||
[
|
|
||||||
'PC_LOCAL_SETUP_DATA_CHANNEL_CALLBACK',
|
|
||||||
function (test) {
|
|
||||||
test.waitForInitialDataChannel(test.pcLocal, function () {
|
|
||||||
ok(true, test.pcLocal + " dataChannels[0] switched to 'open'");
|
|
||||||
},
|
|
||||||
// At this point a timeout failure will be of no value
|
|
||||||
null);
|
|
||||||
test.next();
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'PC_REMOTE_SETUP_DATA_CHANNEL_CALLBACK',
|
|
||||||
function (test) {
|
|
||||||
test.waitForInitialDataChannel(test.pcRemote, function () {
|
|
||||||
ok(true, test.pcRemote + " dataChannels[0] switched to 'open'");
|
|
||||||
},
|
|
||||||
// At this point a timeout failure will be of no value
|
|
||||||
null);
|
|
||||||
test.next();
|
|
||||||
}
|
|
||||||
]
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
chain.insertBefore('PC_LOCAL_CHECK_MEDIA_TRACKS', [
|
chain.insertBefore('PC_LOCAL_CHECK_MEDIA_TRACKS', [
|
||||||
[
|
function PC_LOCAL_VERIFY_DATA_CHANNEL_STATE(test) {
|
||||||
'PC_LOCAL_VERIFY_DATA_CHANNEL_STATE',
|
return test.pcLocal.dataChannels[0].opened
|
||||||
function (test) {
|
.then(() =>
|
||||||
test.waitForInitialDataChannel(test.pcLocal, function() {
|
ok(true, test.pcLocal + " dataChannels[0] switched to 'open'"));
|
||||||
test.next();
|
},
|
||||||
}, function() {
|
|
||||||
ok(false, test.pcLocal + " initial dataChannels[0] failed to switch to 'open'");
|
function PC_REMOTE_VERIFY_DATA_CHANNEL_STATE(test) {
|
||||||
//TODO: use stopAndExit() once bug 1019323 has landed
|
return test.pcRemote.nextDataChannel
|
||||||
unexpectedEventAndFinish(this, 'timeout')
|
.then(channel => channel.opened)
|
||||||
// to prevent test framework timeouts
|
.then(channel =>
|
||||||
test.next();
|
is(channel.readyState, "open",
|
||||||
});
|
test.pcRemote + " dataChannels[0] switched to 'open'"));
|
||||||
}
|
}
|
||||||
],
|
|
||||||
[
|
|
||||||
'PC_REMOTE_VERIFY_DATA_CHANNEL_STATE',
|
|
||||||
function (test) {
|
|
||||||
test.waitForInitialDataChannel(test.pcRemote, function() {
|
|
||||||
test.next();
|
|
||||||
}, function() {
|
|
||||||
ok(false, test.pcRemote + " initial dataChannels[0] failed to switch to 'open'");
|
|
||||||
//TODO: use stopAndExit() once bug 1019323 has landed
|
|
||||||
unexpectedEventAndFinish(this, 'timeout');
|
|
||||||
// to prevent test framework timeouts
|
|
||||||
test.next();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
]
|
|
||||||
]);
|
]);
|
||||||
chain.removeAfter('PC_REMOTE_CHECK_ICE_CONNECTIONS');
|
chain.removeAfter('PC_REMOTE_CHECK_ICE_CONNECTIONS');
|
||||||
chain.append([
|
chain.append([
|
||||||
[
|
function SEND_MESSAGE(test) {
|
||||||
'SEND_MESSAGE',
|
var message = "Lorem ipsum dolor sit amet";
|
||||||
function (test) {
|
|
||||||
var message = "Lorem ipsum dolor sit amet";
|
|
||||||
|
|
||||||
test.send(message, function (channel, data) {
|
return test.send(message).then(result => {
|
||||||
is(data, message, "Message correctly transmitted from pcLocal to pcRemote.");
|
is(result.data, message, "Message correctly transmitted from pcLocal to pcRemote.");
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
test.next();
|
function SEND_BLOB(test) {
|
||||||
});
|
var contents = ["At vero eos et accusam et justo duo dolores et ea rebum."];
|
||||||
}
|
var blob = new Blob(contents, { "type" : "text/plain" });
|
||||||
],
|
|
||||||
[
|
|
||||||
'SEND_BLOB',
|
|
||||||
function (test) {
|
|
||||||
var contents = ["At vero eos et accusam et justo duo dolores et ea rebum."];
|
|
||||||
var blob = new Blob(contents, { "type" : "text/plain" });
|
|
||||||
|
|
||||||
test.send(blob, function (channel, data) {
|
return test.send(blob).then(result => {
|
||||||
ok(data instanceof Blob, "Received data is of instance Blob");
|
ok(result.data instanceof Blob, "Received data is of instance Blob");
|
||||||
is(data.size, blob.size, "Received data has the correct size.");
|
is(result.data.size, blob.size, "Received data has the correct size.");
|
||||||
|
|
||||||
getBlobContent(data, function (recv_contents) {
|
return getBlobContent(result.data);
|
||||||
is(recv_contents, contents, "Received data has the correct content.");
|
}).then(recv_contents =>
|
||||||
|
is(recv_contents, contents, "Received data has the correct content."));
|
||||||
|
},
|
||||||
|
|
||||||
test.next();
|
function CREATE_SECOND_DATA_CHANNEL(test) {
|
||||||
});
|
return test.createDataChannel({ }).then(result => {
|
||||||
});
|
var sourceChannel = result.local;
|
||||||
}
|
var targetChannel = result.remote;
|
||||||
],
|
is(sourceChannel.readyState, "open", sourceChannel + " is in state: 'open'");
|
||||||
[
|
is(targetChannel.readyState, "open", targetChannel + " is in state: 'open'");
|
||||||
'CREATE_SECOND_DATA_CHANNEL',
|
|
||||||
function (test) {
|
|
||||||
test.createDataChannel({ }, function (sourceChannel, targetChannel) {
|
|
||||||
is(sourceChannel.readyState, "open", sourceChannel + " is in state: 'open'");
|
|
||||||
is(targetChannel.readyState, "open", targetChannel + " is in state: 'open'");
|
|
||||||
|
|
||||||
is(targetChannel.binaryType, "blob", targetChannel + " is of binary type 'blob'");
|
is(targetChannel.binaryType, "blob", targetChannel + " is of binary type 'blob'");
|
||||||
is(targetChannel.readyState, "open", targetChannel + " is in state: 'open'");
|
});
|
||||||
|
},
|
||||||
|
|
||||||
test.next();
|
function SEND_MESSAGE_THROUGH_LAST_OPENED_CHANNEL(test) {
|
||||||
});
|
var channels = test.pcRemote.dataChannels;
|
||||||
}
|
var message = "I am the Omega";
|
||||||
],
|
|
||||||
[
|
|
||||||
'SEND_MESSAGE_THROUGH_LAST_OPENED_CHANNEL',
|
|
||||||
function (test) {
|
|
||||||
var channels = test.pcRemote.dataChannels;
|
|
||||||
var message = "Lorem ipsum dolor sit amet";
|
|
||||||
|
|
||||||
test.send(message, function (channel, data) {
|
return test.send(message).then(result => {
|
||||||
is(channels.indexOf(channel), channels.length - 1, "Last channel used");
|
is(channels.indexOf(result.channel), channels.length - 1, "Last channel used");
|
||||||
is(data, message, "Received message has the correct content.");
|
is(result.data, message, "Received message has the correct content.");
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
test.next();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'SEND_MESSAGE_THROUGH_FIRST_CHANNEL',
|
|
||||||
function (test) {
|
|
||||||
var message = "Message through 1st channel";
|
|
||||||
var options = {
|
|
||||||
sourceChannel: test.pcLocal.dataChannels[0],
|
|
||||||
targetChannel: test.pcRemote.dataChannels[0]
|
|
||||||
};
|
|
||||||
|
|
||||||
test.send(message, function (channel, data) {
|
function SEND_MESSAGE_THROUGH_FIRST_CHANNEL(test) {
|
||||||
is(test.pcRemote.dataChannels.indexOf(channel), 0, "1st channel used");
|
var message = "Message through 1st channel";
|
||||||
is(data, message, "Received message has the correct content.");
|
var options = {
|
||||||
|
sourceChannel: test.pcLocal.dataChannels[0],
|
||||||
|
targetChannel: test.pcRemote.dataChannels[0]
|
||||||
|
};
|
||||||
|
|
||||||
test.next();
|
return test.send(message, options).then(result => {
|
||||||
}, options);
|
is(test.pcRemote.dataChannels.indexOf(result.channel), 0, "1st channel used");
|
||||||
}
|
is(result.data, message, "Received message has the correct content.");
|
||||||
],
|
});
|
||||||
[
|
},
|
||||||
'SEND_MESSAGE_BACK_THROUGH_FIRST_CHANNEL',
|
|
||||||
function (test) {
|
|
||||||
var message = "Return a message also through 1st channel";
|
|
||||||
var options = {
|
|
||||||
sourceChannel: test.pcRemote.dataChannels[0],
|
|
||||||
targetChannel: test.pcLocal.dataChannels[0]
|
|
||||||
};
|
|
||||||
|
|
||||||
test.send(message, function (channel, data) {
|
|
||||||
is(test.pcLocal.dataChannels.indexOf(channel), 0, "1st channel used");
|
|
||||||
is(data, message, "Return message has the correct content.");
|
|
||||||
|
|
||||||
test.next();
|
function SEND_MESSAGE_BACK_THROUGH_FIRST_CHANNEL(test) {
|
||||||
}, options);
|
var message = "Return a message also through 1st channel";
|
||||||
}
|
var options = {
|
||||||
],
|
sourceChannel: test.pcRemote.dataChannels[0],
|
||||||
[
|
targetChannel: test.pcLocal.dataChannels[0]
|
||||||
'CREATE_NEGOTIATED_DATA_CHANNEL',
|
};
|
||||||
function (test) {
|
|
||||||
var options = {negotiated:true, id: 5, protocol:"foo/bar", ordered:false,
|
|
||||||
maxRetransmits:500};
|
|
||||||
test.createDataChannel(options, function (sourceChannel2, targetChannel2) {
|
|
||||||
is(sourceChannel2.readyState, "open", sourceChannel2 + " is in state: 'open'");
|
|
||||||
is(targetChannel2.readyState, "open", targetChannel2 + " is in state: 'open'");
|
|
||||||
|
|
||||||
is(targetChannel2.binaryType, "blob", targetChannel2 + " is of binary type 'blob'");
|
return test.send(message, options).then(result => {
|
||||||
is(targetChannel2.readyState, "open", targetChannel2 + " is in state: 'open'");
|
is(test.pcLocal.dataChannels.indexOf(result.channel), 0, "1st channel used");
|
||||||
|
is(result.data, message, "Return message has the correct content.");
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
if (options.id != undefined) {
|
function CREATE_NEGOTIATED_DATA_CHANNEL(test) {
|
||||||
is(sourceChannel2.id, options.id, sourceChannel2 + " id is:" + sourceChannel2.id);
|
var options = {
|
||||||
}
|
negotiated:true,
|
||||||
else {
|
id: 5,
|
||||||
options.id = sourceChannel2.id;
|
protocol: "foo/bar",
|
||||||
}
|
ordered: false,
|
||||||
var reliable = !options.ordered ? false : (options.maxRetransmits || options.maxRetransmitTime);
|
maxRetransmits: 500
|
||||||
is(sourceChannel2.protocol, options.protocol, sourceChannel2 + " protocol is:" + sourceChannel2.protocol);
|
};
|
||||||
is(sourceChannel2.reliable, reliable, sourceChannel2 + " reliable is:" + sourceChannel2.reliable);
|
return test.createDataChannel(options).then(result => {
|
||||||
/*
|
var sourceChannel2 = result.local;
|
||||||
These aren't exposed by IDL yet
|
var targetChannel2 = result.remote;
|
||||||
|
is(sourceChannel2.readyState, "open", sourceChannel2 + " is in state: 'open'");
|
||||||
|
is(targetChannel2.readyState, "open", targetChannel2 + " is in state: 'open'");
|
||||||
|
|
||||||
|
is(targetChannel2.binaryType, "blob", targetChannel2 + " is of binary type 'blob'");
|
||||||
|
|
||||||
|
is(sourceChannel2.id, options.id, sourceChannel2 + " id is:" + sourceChannel2.id);
|
||||||
|
var reliable = !options.ordered ? false : (options.maxRetransmits || options.maxRetransmitTime);
|
||||||
|
is(sourceChannel2.protocol, options.protocol, sourceChannel2 + " protocol is:" + sourceChannel2.protocol);
|
||||||
|
is(sourceChannel2.reliable, reliable, sourceChannel2 + " reliable is:" + sourceChannel2.reliable);
|
||||||
|
/*
|
||||||
|
These aren't exposed by IDL yet
|
||||||
is(sourceChannel2.ordered, options.ordered, sourceChannel2 + " ordered is:" + sourceChannel2.ordered);
|
is(sourceChannel2.ordered, options.ordered, sourceChannel2 + " ordered is:" + sourceChannel2.ordered);
|
||||||
is(sourceChannel2.maxRetransmits, options.maxRetransmits, sourceChannel2 + " maxRetransmits is:" +
|
is(sourceChannel2.maxRetransmits, options.maxRetransmits, sourceChannel2 + " maxRetransmits is:" +
|
||||||
sourceChannel2.maxRetransmits);
|
sourceChannel2.maxRetransmits);
|
||||||
is(sourceChannel2.maxRetransmitTime, options.maxRetransmitTime, sourceChannel2 + " maxRetransmitTime is:" +
|
is(sourceChannel2.maxRetransmitTime, options.maxRetransmitTime, sourceChannel2 + " maxRetransmitTime is:" +
|
||||||
sourceChannel2.maxRetransmitTime);
|
sourceChannel2.maxRetransmitTime);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
is(targetChannel2.id, options.id, targetChannel2 + " id is:" + targetChannel2.id);
|
is(targetChannel2.id, options.id, targetChannel2 + " id is:" + targetChannel2.id);
|
||||||
is(targetChannel2.protocol, options.protocol, targetChannel2 + " protocol is:" + targetChannel2.protocol);
|
is(targetChannel2.protocol, options.protocol, targetChannel2 + " protocol is:" + targetChannel2.protocol);
|
||||||
is(targetChannel2.reliable, reliable, targetChannel2 + " reliable is:" + targetChannel2.reliable);
|
is(targetChannel2.reliable, reliable, targetChannel2 + " reliable is:" + targetChannel2.reliable);
|
||||||
/*
|
/*
|
||||||
These aren't exposed by IDL yet
|
These aren't exposed by IDL yet
|
||||||
is(targetChannel2.ordered, options.ordered, targetChannel2 + " ordered is:" + targetChannel2.ordered);
|
is(targetChannel2.ordered, options.ordered, targetChannel2 + " ordered is:" + targetChannel2.ordered);
|
||||||
is(targetChannel2.maxRetransmits, options.maxRetransmits, targetChannel2 + " maxRetransmits is:" +
|
is(targetChannel2.maxRetransmits, options.maxRetransmits, targetChannel2 + " maxRetransmits is:" +
|
||||||
targetChannel2.maxRetransmits);
|
targetChannel2.maxRetransmits);
|
||||||
is(targetChannel2.maxRetransmitTime, options.maxRetransmitTime, targetChannel2 + " maxRetransmitTime is:" +
|
is(targetChannel2.maxRetransmitTime, options.maxRetransmitTime, targetChannel2 + " maxRetransmitTime is:" +
|
||||||
targetChannel2.maxRetransmitTime);
|
targetChannel2.maxRetransmitTime);
|
||||||
*/
|
*/
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
test.next();
|
function SEND_MESSAGE_THROUGH_LAST_OPENED_CHANNEL2(test) {
|
||||||
});
|
var channels = test.pcRemote.dataChannels;
|
||||||
}
|
var message = "I am the walrus; Goo goo g' joob";
|
||||||
],
|
|
||||||
[
|
|
||||||
'SEND_MESSAGE_THROUGH_LAST_OPENED_CHANNEL2',
|
|
||||||
function (test) {
|
|
||||||
var channels = test.pcRemote.dataChannels;
|
|
||||||
var message = "Lorem ipsum dolor sit amet";
|
|
||||||
|
|
||||||
test.send(message, function (channel, data) {
|
return test.send(message).then(result => {
|
||||||
is(channels.indexOf(channel), channels.length - 1, "Last channel used");
|
is(channels.indexOf(result.channel), channels.length - 1, "Last channel used");
|
||||||
is(data, message, "Received message has the correct content.");
|
is(result.data, message, "Received message has the correct content.");
|
||||||
|
});
|
||||||
test.next();
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
]
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -215,26 +215,6 @@ function waitUntil(func, time) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the contents of a blob as text
|
|
||||||
*
|
|
||||||
* @param {Blob} blob
|
|
||||||
The blob to retrieve the contents from
|
|
||||||
*/
|
|
||||||
function getBlobContent(blob) {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
var reader = new FileReader();
|
|
||||||
|
|
||||||
// Listen for 'onloadend' which will always be called after a success or failure
|
|
||||||
reader.onloadend = function (event) {
|
|
||||||
resolve(event.target.result);
|
|
||||||
};
|
|
||||||
|
|
||||||
reader.readAsText(blob);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/*** Test control flow methods */
|
/*** Test control flow methods */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -17,27 +17,22 @@
|
||||||
title: "Basic data channel audio/video connection without bundle"
|
title: "Basic data channel audio/video connection without bundle"
|
||||||
});
|
});
|
||||||
|
|
||||||
var test;
|
var test;
|
||||||
runNetworkTest(function () {
|
runNetworkTest(function () {
|
||||||
test = new PeerConnectionTest();
|
test = new PeerConnectionTest();
|
||||||
addInitialDataChannel(test.chain);
|
addInitialDataChannel(test.chain);
|
||||||
test.chain.insertAfter("PC_LOCAL_CREATE_OFFER",
|
test.chain.insertAfter("PC_LOCAL_CREATE_OFFER", [
|
||||||
[[
|
function PC_LOCAL_REMOVE_BUNDLE_FROM_OFFER(test) {
|
||||||
'PC_LOCAL_REMOVE_BUNDLE_FROM_OFFER',
|
// Just replace a=group:BUNDLE with something that will be ignored.
|
||||||
function (test) {
|
test.originalOffer.sdp = test.originalOffer.sdp.replace(
|
||||||
// Just replace a=group:BUNDLE with something that will be ignored.
|
"a=group:BUNDLE",
|
||||||
test.originalOffer.sdp = test.originalOffer.sdp.replace(
|
"a=foo:");
|
||||||
"a=group:BUNDLE",
|
}
|
||||||
"a=foo:");
|
]);
|
||||||
test.next();
|
test.setMediaConstraints([{audio: true}, {video: true}],
|
||||||
}
|
[{audio: true}, {video: true}]);
|
||||||
]]
|
test.run();
|
||||||
);
|
});
|
||||||
test.setMediaConstraints([{audio: true}, {video: true}],
|
|
||||||
[{audio: true}, {video: true}]);
|
|
||||||
test.run();
|
|
||||||
});
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</pre>
|
</pre>
|
||||||
</body>
|
</body>
|
||||||
|
|
Загрузка…
Ссылка в новой задаче