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

Unified 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 reviews, clean up tests 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
« no previous file with comments | « extensions/common/api/sockets_udp.idl ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ]);
}
};
« 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