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

Unified Diff: extensions/test/data/sockets_udp/api/background.js

Issue 2378763003: Add ability to reuse address in chrome.sockets.udp
Patch Set: Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
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..dcc8846c0c6d369462dc0c9b797cdaf1aee67826 100644
--- a/extensions/test/data/sockets_udp/api/background.js
+++ b/extensions/test/data/sockets_udp/api/background.js
@@ -71,6 +71,66 @@ 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 socketIds = [];
+
+ function onCreate(createInfo) {
+ function onBind(result) {
+ chrome.test.assertEq(0, result, 'Bind failed with error: ' + result);
+ chrome.sockets.udp.getInfo(createInfo.socketId, onGetInfoAfterBind);
+ }
+
+ 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 onGetInfoAfterBind(info) {
+ 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 {
+ chrome.test.assertEq(2, numSocketsExpected,
+ '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.
+ chrome.sockets.udp.close(socketIds[0], function() {
+ chrome.sockets.udp.close(socketIds[1], function() {
+ chrome.test.succeed();
+ });
+ });
+ }
+ }
+
+ chrome.test.assertTrue(createInfo.socketId > 0);
+ socketIds.push(createInfo.socketId);
+
+ chrome.sockets.udp.getInfo(createInfo.socketId, onGetInfoBeforeBind);
+ }
+
+ function createAndBindToSharedAddress() {
+ numSocketsCreated += 1;
+ chrome.sockets.udp.create({ "allowAddressReuse": true }, onCreate);
+ }
+
+ createAndBindToSharedAddress();
+};
+
+
///////////////////////////////////////////////////////////////////////////////
// Test socket send/receive
//
@@ -332,8 +392,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 ]);
}
};
« extensions/browser/api/socket/udp_socket.h ('K') | « extensions/common/api/sockets_udp.idl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698