| Index: extensions/test/data/sockets_udp/api/background.js
|
| diff --git a/extensions/test/data/sockets_udp/api/background.js b/extensions/test/data/sockets_udp/api/background.js
|
| index 8382292050250fea22aa4da9f0ae30bcf2e1fafb..a145e97aed3ebb2782b93290d4c7477b2899a33c 100644
|
| --- a/extensions/test/data/sockets_udp/api/background.js
|
| +++ b/extensions/test/data/sockets_udp/api/background.js
|
| @@ -71,6 +71,70 @@ var testSocketCreation = function() {
|
| chrome.sockets.udp.create({}, onCreate);
|
| };
|
|
|
| +var testSocketReusable = function() {
|
| + var address = '224.0.0.251';
|
| + var port = 5353;
|
| +
|
| + var numSocketsCreated = 0;
|
| + var numSocketsExpected = 2;
|
| + var numSocketsClosed = 0;
|
| +
|
| + var socketIds = [];
|
| +
|
| + function onCreate(createInfo) {
|
| + function onGetInfoBeforeBind(info) {
|
| + if (info.localAddress || info.localPort) {
|
| + chrome.test.fail('Unconnected socket should not have local binding');
|
| + }
|
| +
|
| + chrome.test.assertEq(true, info.addressReusable, 'Should be reusable');
|
| +
|
| + chrome.sockets.udp.bind(createInfo.socketId, address, port, onBind);
|
| + }
|
| +
|
| + function onBind(result) {
|
| + chrome.test.assertEq(0, result, 'Bind failed with error: ' + result);
|
| + chrome.sockets.udp.getInfo(createInfo.socketId, onGetInfoAfterBind);
|
| + }
|
| +
|
| + function onGetInfoAfterBind(info) {
|
| + numSocketsCreated += 1;
|
| + chrome.test.assertEq(address, info.localAddress,
|
| + 'Bound to wrong address');
|
| + chrome.test.assertEq(port, info.localPort, 'Bound to wrong port');
|
| + chrome.test.assertEq(true, info.addressReusable, 'Should be reusable');
|
| +
|
| + if (numSocketsCreated < numSocketsExpected) {
|
| + // Bind again to ensure the address is reusable.
|
| + createAndBindToSharedAddress();
|
| + } else {
|
| + for (var i = 0; i < socketIds.length; i++) {
|
| + chrome.sockets.udp.close(socketIds[i], onClose);
|
| + }
|
| + }
|
| + }
|
| +
|
| + function onClose() {
|
| + numSocketsClosed += 1;
|
| + if (numSocketsClosed == numSocketsExpected) {
|
| + chrome.test.succeed();
|
| + }
|
| + }
|
| +
|
| + chrome.test.assertTrue(createInfo.socketId > 0);
|
| + socketIds.push(createInfo.socketId);
|
| +
|
| + chrome.sockets.udp.getInfo(createInfo.socketId, onGetInfoBeforeBind);
|
| + }
|
| +
|
| + function createAndBindToSharedAddress() {
|
| + chrome.sockets.udp.create({ "allowAddressReuse": true }, onCreate);
|
| + }
|
| +
|
| + createAndBindToSharedAddress();
|
| +};
|
| +
|
| +
|
| ///////////////////////////////////////////////////////////////////////////////
|
| // Test socket send/receive
|
| //
|
| @@ -332,8 +396,8 @@ var onMessageReply = function(message) {
|
| chrome.test.runTests([ testMulticast ]);
|
| } else {
|
| console.log("Running udp tests");
|
| - chrome.test.runTests([ testSocketCreation, testSending, testSetPaused,
|
| - testBroadcast ]);
|
| + chrome.test.runTests([ testSocketCreation, testSocketReusable, testSending,
|
| + testSetPaused, testBroadcast ]);
|
| }
|
| };
|
|
|
|
|