| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // net/tools/testserver/testserver.py is picky about the format of what it | 5 // net/tools/testserver/testserver.py is picky about the format of what it |
| 6 // calls its "echo" messages. One might go so far as to mutter to oneself that | 6 // calls its "echo" messages. One might go so far as to mutter to oneself that |
| 7 // it isn't an echo server at all. | 7 // it isn't an echo server at all. |
| 8 // | 8 // |
| 9 // The response is based on the request but obfuscated using a random key. | 9 // The response is based on the request but obfuscated using a random key. |
| 10 const request = "0100000005320000005hello"; | 10 const request = "0100000005320000005hello"; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 63 |
| 64 // Obtaining socket information before a connect() call should be safe, but | 64 // Obtaining socket information before a connect() call should be safe, but |
| 65 // return empty values. | 65 // return empty values. |
| 66 socket.getInfo(socketInfo.socketId, onGetInfo); | 66 socket.getInfo(socketInfo.socketId, onGetInfo); |
| 67 } | 67 } |
| 68 | 68 |
| 69 socket.create(protocol, {}, onCreate); | 69 socket.create(protocol, {}, onCreate); |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 | 72 |
| 73 var testAllowAddressReuseUDP = function() { |
| 74 var otherSocketId = null; |
| 75 function onCreate(socketInfo) { |
| 76 function onAllowAddressReuse(result) { |
| 77 function onBind(result) { |
| 78 chrome.test.assertEq( |
| 79 0, result, |
| 80 "Bind for " + (otherSocketId ? "second" : "first") + " socket " + |
| 81 "failed with error code " + result); |
| 82 |
| 83 if (otherSocketId) { |
| 84 socket.destroy(socketInfo.socketId); |
| 85 socket.destroy(otherSocketId); |
| 86 otherSocketId = null; |
| 87 chrome.test.succeed(); |
| 88 } else { |
| 89 otherSocketId = socketInfo.socketId; |
| 90 } |
| 91 } |
| 92 |
| 93 chrome.test.assertEq( |
| 94 0, result, |
| 95 "AllowAddressReuse failed with " + result); |
| 96 socket.bind(socketInfo.socketId, "127.0.0.1", 9999, onBind); |
| 97 } |
| 98 |
| 99 chrome.test.assertTrue(socketInfo.socketId > 0); |
| 100 socket.allowAddressReuse(socketInfo.socketId, onAllowAddressReuse); |
| 101 } |
| 102 |
| 103 socket.create(protocol, {}, onCreate); |
| 104 socket.create(protocol, {}, onCreate); |
| 105 }; |
| 106 |
| 107 var testAllowAddressReuseTCP = function() { |
| 108 var otherSocketId = null; |
| 109 function onCreate(socketInfo) { |
| 110 function onAllowAddressReuse(result) { |
| 111 chrome.test.assertTrue(result < 0); |
| 112 chrome.test.succeed(); |
| 113 } |
| 114 chrome.test.assertTrue(socketInfo.socketId > 0); |
| 115 socket.allowAddressReuse(socketInfo.socketId, onAllowAddressReuse); |
| 116 } |
| 117 |
| 118 socket.create(protocol, {}, onCreate); |
| 119 }; |
| 120 |
| 121 var testAllowAddressReuse = function() { |
| 122 if (protocol == "tcp") testAllowAddressReuseTCP(); |
| 123 else testAllowAddressReuseUDP(); |
| 124 }; |
| 125 |
| 73 var testGetInfo = function() { | 126 var testGetInfo = function() { |
| 74 }; | 127 }; |
| 75 | 128 |
| 76 function onDataRead(readInfo) { | 129 function onDataRead(readInfo) { |
| 77 if (readInfo.resultCode > 0 || readInfo.data.byteLength > 0) { | 130 if (readInfo.resultCode > 0 || readInfo.data.byteLength > 0) { |
| 78 chrome.test.assertEq(readInfo.resultCode, readInfo.data.byteLength); | 131 chrome.test.assertEq(readInfo.resultCode, readInfo.data.byteLength); |
| 79 } | 132 } |
| 80 | 133 |
| 81 arrayBuffer2String(readInfo.data, function(s) { | 134 arrayBuffer2String(readInfo.data, function(s) { |
| 82 dataAsString = s; // save this for error reporting | 135 dataAsString = s; // save this for error reporting |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 port = parseInt(parts[2]); | 291 port = parseInt(parts[2]); |
| 239 console.log("Running tests, protocol " + protocol + ", echo server " + | 292 console.log("Running tests, protocol " + protocol + ", echo server " + |
| 240 address + ":" + port); | 293 address + ":" + port); |
| 241 if (test_type == 'tcp_server') { | 294 if (test_type == 'tcp_server') { |
| 242 chrome.test.runTests([ testSocketListening ]); | 295 chrome.test.runTests([ testSocketListening ]); |
| 243 } else if (test_type == 'multicast') { | 296 } else if (test_type == 'multicast') { |
| 244 console.log("Running multicast tests"); | 297 console.log("Running multicast tests"); |
| 245 chrome.test.runTests([ testMulticast ]); | 298 chrome.test.runTests([ testMulticast ]); |
| 246 } else { | 299 } else { |
| 247 protocol = test_type; | 300 protocol = test_type; |
| 248 chrome.test.runTests([ testSocketCreation, testSending ]); | 301 chrome.test.runTests([ testSocketCreation, testSending, |
| 302 testAllowAddressReuse ]); |
| 249 } | 303 } |
| 250 }; | 304 }; |
| 251 | 305 |
| 252 // Find out which protocol we're supposed to test, and which echo server we | 306 // Find out which protocol we're supposed to test, and which echo server we |
| 253 // should be using, then kick off the tests. | 307 // should be using, then kick off the tests. |
| 254 chrome.test.sendMessage("info_please", onMessageReply); | 308 chrome.test.sendMessage("info_please", onMessageReply); |
| OLD | NEW |