Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1036)

Side by Side Diff: extensions/test/data/sockets_udp/api/background.js

Issue 2378763003: Add ability to reuse address in chrome.sockets.udp
Patch Set: Respond to code review Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/common/api/sockets_udp.idl ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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) {
carlosk 2016/09/30 02:16:24 nit: it would be clearer to me if these 3 methods
srsudar 2016/09/30 15:07:17 Done.
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 numSocketsCreated += 1;
101 chrome.test.assertEq(address, info.localAddress,
102 'Bound to wrong address');
103 chrome.test.assertEq(port, info.localPort, 'Bound to wrong port');
104 chrome.test.assertEq(true, info.addressReusable, 'Should be reusable');
105
106 if (numSocketsCreated < numSocketsExpected) {
107 // Bind again to ensure the address is reusable.
108 createAndBindToSharedAddress();
109 } else {
110 chrome.test.assertEq(numSocketsCreated, numSocketsExpected,
111 'Not all sockets created during test');
carlosk 2016/09/30 02:16:24 Is this trying to check if too many sockets were c
srsudar 2016/09/30 15:07:17 Good point. I was trying to use this call to ensur
112 chrome.sockets.udp.close(socketIds[0], function() {
113 chrome.sockets.udp.close(socketIds[1], function() {
114 chrome.test.succeed();
carlosk 2016/09/30 02:16:24 IIUC you created numSocketsExpected to store the a
srsudar 2016/09/30 15:07:17 Done.
115 });
116 });
117 }
118 }
119
120 chrome.test.assertTrue(createInfo.socketId > 0);
121 socketIds.push(createInfo.socketId);
122
123 chrome.sockets.udp.getInfo(createInfo.socketId, onGetInfoBeforeBind);
124 }
125
126 function createAndBindToSharedAddress() {
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
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);
OLDNEW
« no previous file with comments | « extensions/common/api/sockets_udp.idl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698