Bug 1119593 - Update WebRTC data channel tests, r=drno

--HG--
extra : rebase_source : baf9f9b04c7eb0cf4471ebb29600def300424af8
This commit is contained in:
Martin Thomson 2015-01-28 14:05:56 -08:00
Родитель b636521712
Коммит 2319bf1e85
3 изменённых файлов: 158 добавлений и 233 удалений

Просмотреть файл

@ -2,229 +2,179 @@
* 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/. */
/**
* 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) {
chain.insertBefore('PC_LOCAL_CREATE_OFFER', [
['PC_LOCAL_CREATE_DATA_CHANNEL',
function (test) {
var channel = test.pcLocal.createDataChannel({});
function PC_REMOTE_EXPECT_DATA_CHANNEL(test) {
test.pcRemote.expectDataChannel();
},
is(channel.binaryType, "blob", channel + " is of binary type 'blob'");
is(channel.readyState, "connecting", channel + " is in state: 'connecting'");
function PC_LOCAL_CREATE_DATA_CHANNEL(test) {
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,
"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();
}
]
is(test.pcLocal.signalingState, STABLE,
"Create datachannel does not change signaling state");
}
]);
chain.insertBefore('PC_LOCAL_CHECK_MEDIA_TRACKS', [
[
'PC_LOCAL_VERIFY_DATA_CHANNEL_STATE',
function (test) {
test.waitForInitialDataChannel(test.pcLocal, function() {
test.next();
}, function() {
ok(false, test.pcLocal + " 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();
});
}
],
[
'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();
});
}
]
function PC_LOCAL_VERIFY_DATA_CHANNEL_STATE(test) {
return test.pcLocal.dataChannels[0].opened
.then(() =>
ok(true, test.pcLocal + " dataChannels[0] switched to 'open'"));
},
function PC_REMOTE_VERIFY_DATA_CHANNEL_STATE(test) {
return test.pcRemote.nextDataChannel
.then(channel => channel.opened)
.then(channel =>
is(channel.readyState, "open",
test.pcRemote + " dataChannels[0] switched to 'open'"));
}
]);
chain.removeAfter('PC_REMOTE_CHECK_ICE_CONNECTIONS');
chain.append([
[
'SEND_MESSAGE',
function (test) {
var message = "Lorem ipsum dolor sit amet";
function SEND_MESSAGE(test) {
var message = "Lorem ipsum dolor sit amet";
test.send(message, function (channel, data) {
is(data, message, "Message correctly transmitted from pcLocal to pcRemote.");
return test.send(message).then(result => {
is(result.data, message, "Message correctly transmitted from pcLocal to pcRemote.");
});
},
test.next();
});
}
],
[
'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" });
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" });
test.send(blob, function (channel, data) {
ok(data instanceof Blob, "Received data is of instance Blob");
is(data.size, blob.size, "Received data has the correct size.");
return test.send(blob).then(result => {
ok(result.data instanceof Blob, "Received data is of instance Blob");
is(result.data.size, blob.size, "Received data has the correct size.");
getBlobContent(data, function (recv_contents) {
is(recv_contents, contents, "Received data has the correct content.");
return getBlobContent(result.data);
}).then(recv_contents =>
is(recv_contents, contents, "Received data has the correct content."));
},
test.next();
});
});
}
],
[
'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'");
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'");
is(targetChannel.binaryType, "blob", targetChannel + " is of binary type 'blob'");
is(targetChannel.readyState, "open", targetChannel + " is in state: 'open'");
is(targetChannel.binaryType, "blob", targetChannel + " is of binary type 'blob'");
});
},
test.next();
});
}
],
[
'SEND_MESSAGE_THROUGH_LAST_OPENED_CHANNEL',
function (test) {
var channels = test.pcRemote.dataChannels;
var message = "Lorem ipsum dolor sit amet";
function SEND_MESSAGE_THROUGH_LAST_OPENED_CHANNEL(test) {
var channels = test.pcRemote.dataChannels;
var message = "I am the Omega";
test.send(message, function (channel, data) {
is(channels.indexOf(channel), channels.length - 1, "Last channel used");
is(data, message, "Received message has the correct content.");
return test.send(message).then(result => {
is(channels.indexOf(result.channel), channels.length - 1, "Last channel used");
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) {
is(test.pcRemote.dataChannels.indexOf(channel), 0, "1st channel used");
is(data, message, "Received message has the correct content.");
function SEND_MESSAGE_THROUGH_FIRST_CHANNEL(test) {
var message = "Message through 1st channel";
var options = {
sourceChannel: test.pcLocal.dataChannels[0],
targetChannel: test.pcRemote.dataChannels[0]
};
test.next();
}, options);
}
],
[
'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]
};
return test.send(message, options).then(result => {
is(test.pcRemote.dataChannels.indexOf(result.channel), 0, "1st channel used");
is(result.data, message, "Received message has the correct content.");
});
},
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();
}, options);
}
],
[
'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'");
function SEND_MESSAGE_BACK_THROUGH_FIRST_CHANNEL(test) {
var message = "Return a message also through 1st channel";
var options = {
sourceChannel: test.pcRemote.dataChannels[0],
targetChannel: test.pcLocal.dataChannels[0]
};
is(targetChannel2.binaryType, "blob", targetChannel2 + " is of binary type 'blob'");
is(targetChannel2.readyState, "open", targetChannel2 + " is in state: 'open'");
return test.send(message, options).then(result => {
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) {
is(sourceChannel2.id, options.id, sourceChannel2 + " id is:" + sourceChannel2.id);
}
else {
options.id = 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
function CREATE_NEGOTIATED_DATA_CHANNEL(test) {
var options = {
negotiated:true,
id: 5,
protocol: "foo/bar",
ordered: false,
maxRetransmits: 500
};
return test.createDataChannel(options).then(result => {
var sourceChannel2 = result.local;
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.maxRetransmits, options.maxRetransmits, sourceChannel2 + " maxRetransmits is:" +
sourceChannel2.maxRetransmits);
sourceChannel2.maxRetransmits);
is(sourceChannel2.maxRetransmitTime, options.maxRetransmitTime, sourceChannel2 + " maxRetransmitTime is:" +
sourceChannel2.maxRetransmitTime);
*/
sourceChannel2.maxRetransmitTime);
*/
is(targetChannel2.id, options.id, targetChannel2 + " id is:" + targetChannel2.id);
is(targetChannel2.protocol, options.protocol, targetChannel2 + " protocol is:" + targetChannel2.protocol);
is(targetChannel2.reliable, reliable, targetChannel2 + " reliable is:" + targetChannel2.reliable);
/*
These aren't exposed by IDL yet
is(targetChannel2.ordered, options.ordered, targetChannel2 + " ordered is:" + targetChannel2.ordered);
is(targetChannel2.id, options.id, targetChannel2 + " id is:" + targetChannel2.id);
is(targetChannel2.protocol, options.protocol, targetChannel2 + " protocol is:" + targetChannel2.protocol);
is(targetChannel2.reliable, reliable, targetChannel2 + " reliable is:" + targetChannel2.reliable);
/*
These aren't exposed by IDL yet
is(targetChannel2.ordered, options.ordered, targetChannel2 + " ordered is:" + targetChannel2.ordered);
is(targetChannel2.maxRetransmits, options.maxRetransmits, targetChannel2 + " maxRetransmits is:" +
targetChannel2.maxRetransmits);
targetChannel2.maxRetransmits);
is(targetChannel2.maxRetransmitTime, options.maxRetransmitTime, targetChannel2 + " maxRetransmitTime is:" +
targetChannel2.maxRetransmitTime);
*/
targetChannel2.maxRetransmitTime);
*/
});
},
test.next();
});
}
],
[
'SEND_MESSAGE_THROUGH_LAST_OPENED_CHANNEL2',
function (test) {
var channels = test.pcRemote.dataChannels;
var message = "Lorem ipsum dolor sit amet";
function SEND_MESSAGE_THROUGH_LAST_OPENED_CHANNEL2(test) {
var channels = test.pcRemote.dataChannels;
var message = "I am the walrus; Goo goo g' joob";
test.send(message, function (channel, data) {
is(channels.indexOf(channel), channels.length - 1, "Last channel used");
is(data, message, "Received message has the correct content.");
test.next();
});
}
]
return test.send(message).then(result => {
is(channels.indexOf(result.channel), channels.length - 1, "Last channel used");
is(result.data, message, "Received message has the correct content.");
});
}
]);
}

Просмотреть файл

@ -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 */
/**

Просмотреть файл

@ -17,27 +17,22 @@
title: "Basic data channel audio/video connection without bundle"
});
var test;
runNetworkTest(function () {
test = new PeerConnectionTest();
addInitialDataChannel(test.chain);
test.chain.insertAfter("PC_LOCAL_CREATE_OFFER",
[[
'PC_LOCAL_REMOVE_BUNDLE_FROM_OFFER',
function (test) {
// Just replace a=group:BUNDLE with something that will be ignored.
test.originalOffer.sdp = test.originalOffer.sdp.replace(
"a=group:BUNDLE",
"a=foo:");
test.next();
}
]]
);
test.setMediaConstraints([{audio: true}, {video: true}],
[{audio: true}, {video: true}]);
test.run();
});
var test;
runNetworkTest(function () {
test = new PeerConnectionTest();
addInitialDataChannel(test.chain);
test.chain.insertAfter("PC_LOCAL_CREATE_OFFER", [
function PC_LOCAL_REMOVE_BUNDLE_FROM_OFFER(test) {
// Just replace a=group:BUNDLE with something that will be ignored.
test.originalOffer.sdp = test.originalOffer.sdp.replace(
"a=group:BUNDLE",
"a=foo:");
}
]);
test.setMediaConstraints([{audio: true}, {video: true}],
[{audio: true}, {video: true}]);
test.run();
});
</script>
</pre>
</body>