Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 chrome.test.assertTrue(createInfo.socketId > 0); | 64 chrome.test.assertTrue(createInfo.socketId > 0); |
| 65 | 65 |
| 66 // Obtaining socket information before a connect() call should be safe, but | 66 // Obtaining socket information before a connect() call should be safe, but |
| 67 // return empty values. | 67 // return empty values. |
| 68 chrome.sockets.udp.getInfo(createInfo.socketId, onGetInfo); | 68 chrome.sockets.udp.getInfo(createInfo.socketId, onGetInfo); |
| 69 } | 69 } |
| 70 | 70 |
| 71 chrome.sockets.udp.create({}, onCreate); | 71 chrome.sockets.udp.create({}, onCreate); |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 var testSocketReusable = function() { | |
| 75 var address = '224.0.0.251'; | |
| 76 var port = 5353; | |
| 77 | |
| 78 var numSocketsCreated = 0; | |
| 79 var numSocketsExpected = 2; | |
| 80 | |
| 81 var socketIds = []; | |
| 82 | |
| 83 function onCreate(createInfo) { | |
| 84 function onBind(result) { | |
| 85 chrome.test.assertEq(0, result, 'Bind failed with error: ' + result); | |
| 86 chrome.sockets.udp.getInfo(createInfo.socketId, onGetInfoAfterBind); | |
| 87 } | |
| 88 | |
| 89 function onGetInfoBeforeBind(info) { | |
| 90 if (info.localAddress || info.localPort) { | |
| 91 chrome.test.fail('Unconnected socket should not have local binding'); | |
| 92 } | |
| 93 | |
| 94 chrome.test.assertEq(true, info.addressReusable, 'Should be reusable'); | |
| 95 | |
| 96 chrome.sockets.udp.bind(createInfo.socketId, address, port, onBind); | |
| 97 } | |
| 98 | |
| 99 function onGetInfoAfterBind(info) { | |
| 100 chrome.test.assertEq(address, info.localAddress, | |
| 101 'Bound to wrong address'); | |
| 102 chrome.test.assertEq(port, info.localPort, 'Bound to wrong port'); | |
| 103 chrome.test.assertEq(true, info.addressReusable, 'Should be reusable'); | |
| 104 | |
| 105 if (numSocketsCreated < numSocketsExpected) { | |
| 106 // Bind again to ensure the address is reusable. | |
| 107 createAndBindToSharedAddress(); | |
| 108 } else { | |
| 109 chrome.test.assertEq(2, numSocketsExpected, | |
| 110 'Not all sockets created during test'); | |
|
Reilly Grant (use Gerrit)
2016/09/29 06:55:55
This assert is vacuously true. I assume you meant
srsudar
2016/09/29 19:32:58
Done.
| |
| 111 chrome.sockets.udp.close(socketIds[0], function() { | |
| 112 chrome.sockets.udp.close(socketIds[1], function() { | |
| 113 chrome.test.succeed(); | |
| 114 }); | |
| 115 }); | |
| 116 } | |
| 117 } | |
| 118 | |
| 119 chrome.test.assertTrue(createInfo.socketId > 0); | |
| 120 socketIds.push(createInfo.socketId); | |
| 121 | |
| 122 chrome.sockets.udp.getInfo(createInfo.socketId, onGetInfoBeforeBind); | |
| 123 } | |
| 124 | |
| 125 function createAndBindToSharedAddress() { | |
| 126 numSocketsCreated += 1; | |
| 127 chrome.sockets.udp.create({ "allowAddressReuse": true }, onCreate); | |
| 128 } | |
| 129 | |
| 130 createAndBindToSharedAddress(); | |
| 131 }; | |
| 132 | |
| 133 | |
| 74 /////////////////////////////////////////////////////////////////////////////// | 134 /////////////////////////////////////////////////////////////////////////////// |
| 75 // Test socket send/receive | 135 // Test socket send/receive |
| 76 // | 136 // |
| 77 | 137 |
| 78 function waitForBlockingOperation() { | 138 function waitForBlockingOperation() { |
| 79 if (++waitCount < 10) { | 139 if (++waitCount < 10) { |
| 80 setTimeout(waitForBlockingOperation, 1000); | 140 setTimeout(waitForBlockingOperation, 1000); |
| 81 } else { | 141 } else { |
| 82 // We weren't able to succeed in the given time. | 142 // We weren't able to succeed in the given time. |
| 83 chrome.test.fail("Operations didn't complete after " + waitCount + " " + | 143 chrome.test.fail("Operations didn't complete after " + waitCount + " " + |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 var test_type = parts[0]; | 385 var test_type = parts[0]; |
| 326 address = parts[1]; | 386 address = parts[1]; |
| 327 port = parseInt(parts[2]); | 387 port = parseInt(parts[2]); |
| 328 console.log("Running tests, echo server " + | 388 console.log("Running tests, echo server " + |
| 329 address + ":" + port); | 389 address + ":" + port); |
| 330 if (test_type == 'multicast') { | 390 if (test_type == 'multicast') { |
| 331 console.log("Running multicast tests"); | 391 console.log("Running multicast tests"); |
| 332 chrome.test.runTests([ testMulticast ]); | 392 chrome.test.runTests([ testMulticast ]); |
| 333 } else { | 393 } else { |
| 334 console.log("Running udp tests"); | 394 console.log("Running udp tests"); |
| 335 chrome.test.runTests([ testSocketCreation, testSending, testSetPaused, | 395 chrome.test.runTests([ testSocketCreation, testSocketReusable, testSending, |
| 336 testBroadcast ]); | 396 testSetPaused, testBroadcast ]); |
| 337 } | 397 } |
| 338 }; | 398 }; |
| 339 | 399 |
| 340 // Find out which protocol we're supposed to test, and which echo server we | 400 // Find out which protocol we're supposed to test, and which echo server we |
| 341 // should be using, then kick off the tests. | 401 // should be using, then kick off the tests. |
| 342 chrome.test.sendMessage("info_please", onMessageReply); | 402 chrome.test.sendMessage("info_please", onMessageReply); |
| OLD | NEW |