mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 10:00:54 +00:00
Bug 1317946: unit test for zero length UDP messages. r=schien
MozReview-Commit-ID: Gemk8EiUO31 --HG-- extra : rebase_source : cd3fc124e4a710b6613b19a79028df5aae4a227c
This commit is contained in:
parent
73dd4c356c
commit
0a462392c1
@ -7,6 +7,7 @@
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const HELLO_WORLD = "Hello World";
|
||||
const EMPTY_MESSAGE = "";
|
||||
|
||||
add_test(function test_udp_message_raw_data() {
|
||||
do_print("test for nsIUDPMessage.rawData");
|
||||
@ -57,6 +58,30 @@ add_test(function test_udp_send_stream() {
|
||||
socket.sendBinaryStream("127.0.0.1", socket.port, stream);
|
||||
});
|
||||
|
||||
add_test(function test_udp_message_zero_length() {
|
||||
do_print("test for nsIUDPMessage with zero length");
|
||||
|
||||
let socket = Cc["@mozilla.org/network/udp-socket;1"].createInstance(Ci.nsIUDPSocket);
|
||||
|
||||
socket.init(-1, true, Services.scriptSecurityManager.getSystemPrincipal());
|
||||
do_print("Port assigned : " + socket.port);
|
||||
socket.asyncListen({
|
||||
QueryInterface : XPCOMUtils.generateQI([Ci.nsIUDPSocketListener]),
|
||||
onPacketReceived : function(aSocket, aMessage){
|
||||
let recv_data = String.fromCharCode.apply(null, aMessage.rawData);
|
||||
do_check_eq(recv_data, EMPTY_MESSAGE);
|
||||
do_check_eq(recv_data, aMessage.data);
|
||||
socket.close();
|
||||
run_next_test();
|
||||
},
|
||||
onStopListening: function(aSocket, aStatus){}
|
||||
});
|
||||
|
||||
let rawData = new Uint8Array(EMPTY_MESSAGE.length);
|
||||
let written = socket.send("127.0.0.1", socket.port, rawData, rawData.length);
|
||||
do_check_eq(written, EMPTY_MESSAGE.length);
|
||||
});
|
||||
|
||||
function run_test(){
|
||||
run_next_test();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user