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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } | 96 } |
97 | 97 |
98 function onSetNoDelay(result) { | 98 function onSetNoDelay(result) { |
99 if (protocol == "tcp") | 99 if (protocol == "tcp") |
100 chrome.test.assertTrue(result, "setNoDelay failed for TCP."); | 100 chrome.test.assertTrue(result, "setNoDelay failed for TCP."); |
101 else | 101 else |
102 chrome.test.assertFalse(result, "setNoDelay did not fail for UDP."); | 102 chrome.test.assertFalse(result, "setNoDelay did not fail for UDP."); |
103 socket.setKeepAlive(socketId, true, 1000, onSetKeepAlive); | 103 socket.setKeepAlive(socketId, true, 1000, onSetKeepAlive); |
104 } | 104 } |
105 | 105 |
| 106 function onGetInfo(result) { |
| 107 chrome.test.assertTrue(!!result.local, |
| 108 "Bound socket should always have local part"); |
| 109 chrome.test.assertEq(result.socketType, protocol, "Unexpected socketType"); |
| 110 |
| 111 if (protocol == "tcp") { |
| 112 // NOTE: We're always called with 'localhost', but getInfo will only return |
| 113 // IPs, not names. |
| 114 chrome.test.assertEq(result.peer, "127.0.0.1:" + port, |
| 115 "Peer address was not the listen server"); |
| 116 chrome.test.assertTrue(result.connected, "Socket should be connected"); |
| 117 } else { |
| 118 chrome.test.assertFalse(result.connected, "UDP socket was not connected"); |
| 119 chrome.test.assertTrue(!result.peer, |
| 120 "Unconnected UDP socket must not have peer"); |
| 121 } |
| 122 |
| 123 socket.setNoDelay(socketId, true, onSetNoDelay);; |
| 124 } |
| 125 |
106 function onConnectOrBindComplete(result) { | 126 function onConnectOrBindComplete(result) { |
107 chrome.test.assertEq(0, result, | 127 chrome.test.assertEq(0, result, |
108 "Connect or bind failed with error " + result); | 128 "Connect or bind failed with error " + result); |
109 if (result == 0) { | 129 if (result == 0) { |
110 socket.setNoDelay(socketId, true, onSetNoDelay); | 130 socket.getInfo(socketId, onGetInfo); |
111 } | 131 } |
112 } | 132 } |
113 | 133 |
114 function onCreate(socketInfo) { | 134 function onCreate(socketInfo) { |
115 socketId = socketInfo.socketId; | 135 socketId = socketInfo.socketId; |
116 chrome.test.assertTrue(socketId > 0, "failed to create socket"); | 136 chrome.test.assertTrue(socketId > 0, "failed to create socket"); |
117 if (protocol == "tcp") | 137 if (protocol == "tcp") |
118 socket.connect(socketId, address, port, onConnectOrBindComplete); | 138 socket.connect(socketId, address, port, onConnectOrBindComplete); |
119 else | 139 else |
120 socket.bind(socketId, "0.0.0.0", 0, onConnectOrBindComplete); | 140 socket.bind(socketId, "0.0.0.0", 0, onConnectOrBindComplete); |
(...skipping 24 matching lines...) Expand all Loading... |
145 address = parts[1]; | 165 address = parts[1]; |
146 port = parseInt(parts[2]); | 166 port = parseInt(parts[2]); |
147 console.log("Running tests, protocol " + protocol + ", echo server " + | 167 console.log("Running tests, protocol " + protocol + ", echo server " + |
148 address + ":" + port); | 168 address + ":" + port); |
149 chrome.test.runTests([ testSocketCreation, testSending ]); | 169 chrome.test.runTests([ testSocketCreation, testSending ]); |
150 }; | 170 }; |
151 | 171 |
152 // Find out which protocol we're supposed to test, and which echo server we | 172 // Find out which protocol we're supposed to test, and which echo server we |
153 // should be using, then kick off the tests. | 173 // should be using, then kick off the tests. |
154 chrome.test.sendMessage("info_please", onMessageReply); | 174 chrome.test.sendMessage("info_please", onMessageReply); |
OLD | NEW |