| 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 24 matching lines...) Expand all Loading... |
| 35 function arrayBuffer2String(buf, callback) { | 35 function arrayBuffer2String(buf, callback) { |
| 36 var blob = new Blob([new Uint8Array(buf)]); | 36 var blob = new Blob([new Uint8Array(buf)]); |
| 37 var f = new FileReader(); | 37 var f = new FileReader(); |
| 38 f.onload = function(e) { | 38 f.onload = function(e) { |
| 39 callback(e.target.result); | 39 callback(e.target.result); |
| 40 }; | 40 }; |
| 41 f.readAsText(blob); | 41 f.readAsText(blob); |
| 42 } | 42 } |
| 43 | 43 |
| 44 var testSocketCreation = function() { | 44 var testSocketCreation = function() { |
| 45 function onGetInfo(info) { | 45 function onCreate(socketInfo) { |
| 46 chrome.test.assertEq(info.socketType, protocol); | 46 function onGetInfo(info) { |
| 47 chrome.test.assertFalse(info.connected); | 47 chrome.test.assertEq(info.socketType, protocol); |
| 48 chrome.test.assertFalse(info.connected); |
| 48 | 49 |
| 49 if (info.peerAddress || info.peerPort) { | 50 if (info.peerAddress || info.peerPort) { |
| 50 chrome.test.fail('Unconnected socket should not have peer'); | 51 chrome.test.fail('Unconnected socket should not have peer'); |
| 51 } | 52 } |
| 52 if (info.localAddress || info.localPort) { | 53 if (info.localAddress || info.localPort) { |
| 53 chrome.test.fail('Unconnected socket should not have local binding'); | 54 chrome.test.fail('Unconnected socket should not have local binding'); |
| 55 } |
| 56 |
| 57 socket.destroy(socketInfo.socketId); |
| 58 |
| 59 chrome.test.succeed(); |
| 54 } | 60 } |
| 55 | 61 |
| 56 // TODO(miket): this doesn't work yet. It's possible this will become | |
| 57 // automatic, but either way we can't forget to clean up. | |
| 58 // | |
| 59 //socket.destroy(socketInfo.socketId); | |
| 60 | |
| 61 chrome.test.succeed(); | |
| 62 } | |
| 63 | |
| 64 function onCreate(socketInfo) { | |
| 65 chrome.test.assertTrue(socketInfo.socketId > 0); | 62 chrome.test.assertTrue(socketInfo.socketId > 0); |
| 66 | 63 |
| 67 // Obtaining socket information before a connect() call should be safe, but | 64 // Obtaining socket information before a connect() call should be safe, but |
| 68 // return empty values. | 65 // return empty values. |
| 69 socket.getInfo(socketInfo.socketId, onGetInfo); | 66 socket.getInfo(socketInfo.socketId, onGetInfo); |
| 70 } | 67 } |
| 71 | 68 |
| 72 socket.create(protocol, {}, onCreate); | 69 socket.create(protocol, {}, onCreate); |
| 73 }; | 70 }; |
| 74 | 71 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 function onServerSocketCreate(socketInfo) { | 226 function onServerSocketCreate(socketInfo) { |
| 230 socketId = socketInfo.socketId; | 227 socketId = socketInfo.socketId; |
| 231 socket.listen(socketId, address, port, onListen); | 228 socket.listen(socketId, address, port, onListen); |
| 232 } | 229 } |
| 233 | 230 |
| 234 socket.create('tcp', {}, onServerSocketCreate); | 231 socket.create('tcp', {}, onServerSocketCreate); |
| 235 }; | 232 }; |
| 236 | 233 |
| 237 var onMessageReply = function(message) { | 234 var onMessageReply = function(message) { |
| 238 var parts = message.split(":"); | 235 var parts = message.split(":"); |
| 239 test_type = parts[0]; | 236 var test_type = parts[0]; |
| 240 address = parts[1]; | 237 address = parts[1]; |
| 241 port = parseInt(parts[2]); | 238 port = parseInt(parts[2]); |
| 242 console.log("Running tests, protocol " + protocol + ", echo server " + | 239 console.log("Running tests, protocol " + protocol + ", echo server " + |
| 243 address + ":" + port); | 240 address + ":" + port); |
| 244 if (test_type == 'tcp_server') { | 241 if (test_type == 'tcp_server') { |
| 245 chrome.test.runTests([ testSocketListening ]); | 242 chrome.test.runTests([ testSocketListening ]); |
| 243 } else if (test_type == 'multicast') { |
| 244 console.log("Running multicast tests"); |
| 245 chrome.test.runTests([ testMulticast ]); |
| 246 } else { | 246 } else { |
| 247 protocol = test_type; | 247 protocol = test_type; |
| 248 chrome.test.runTests([ testSocketCreation, testSending ]); | 248 chrome.test.runTests([ testSocketCreation, testSending ]); |
| 249 } | 249 } |
| 250 }; | 250 }; |
| 251 | 251 |
| 252 // Find out which protocol we're supposed to test, and which echo server we | 252 // Find out which protocol we're supposed to test, and which echo server we |
| 253 // should be using, then kick off the tests. | 253 // should be using, then kick off the tests. |
| 254 chrome.test.sendMessage("info_please", onMessageReply); | 254 chrome.test.sendMessage("info_please", onMessageReply); |
| OLD | NEW |