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

Unified Diff: chrome/test/data/extensions/api_test/socket/api/background.js

Issue 1463293004: Reset server_socket_ when listen fails in extensions::TCPSocket. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 | « no previous file | extensions/browser/api/socket/tcp_socket.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/extensions/api_test/socket/api/background.js
diff --git a/chrome/test/data/extensions/api_test/socket/api/background.js b/chrome/test/data/extensions/api_test/socket/api/background.js
index 35ecffa416a0c4d294bc911c8d2a6a62b053791c..ff4864a40c13f7b6ab946847fdd452b535d0c1e0 100644
--- a/chrome/test/data/extensions/api_test/socket/api/background.js
+++ b/chrome/test/data/extensions/api_test/socket/api/background.js
@@ -206,6 +206,7 @@ var testSocketListening = function() {
setTimeout(function() {
socket.getInfo(acceptedSocketId, function(info) {
chrome.test.assertFalse(info.connected);
+ socket.destroy(socketId);
chrome.test.succeed();
});
}, 500);
@@ -247,6 +248,46 @@ var testSocketListening = function() {
socket.create('tcp', {}, onServerSocketCreate);
};
+// Tests creation of a TCP listening socket on a port that is already in use.
+var testSocketListenInUse = function() {
+ var tmpSocketId;
+
+ function onAccept(result) {
+ chrome.test.assertNoLastError();
+ chrome.test.assertEq(-2, result.resultCode);
+ socket.destroy(socketId);
+ socket.destroy(tmpSocketId);
+ chrome.test.succeed();
+ }
+
+ function onSecondSocketListen(result) {
+ chrome.test.assertLastError("Could not listen on the specified port.");
+ chrome.test.assertEq(-147, result);
+ // Calling accept on this socket should fail since it isn't listening.
+ socket.accept(tmpSocketId, onAccept);
+ }
+
+ function onSecondSocketCreate(socketInfo) {
+ chrome.test.assertNoLastError();
+ tmpSocketId = socketInfo.socketId;
+ socket.listen(tmpSocketId, address, port, onSecondSocketListen);
+ }
+
+ function onFirstSocketListen(result) {
+ chrome.test.assertNoLastError();
+ chrome.test.assertEq(0, result);
+ socket.create('tcp', {}, onSecondSocketCreate);
+ }
+
+ function onFirstSocketCreate(socketInfo) {
+ chrome.test.assertNoLastError();
+ socketId = socketInfo.socketId;
+ socket.listen(socketId, address, port, onFirstSocketListen);
+ }
+
+ socket.create('tcp', {}, onFirstSocketCreate);
+};
+
var testPendingCallback = function() {
dataRead = "";
succeeded = false;
@@ -374,7 +415,10 @@ var onMessageReply = function(message) {
console.log("Running tests, protocol " + protocol + ", echo server " +
address + ":" + port);
if (test_type == 'tcp_server') {
- chrome.test.runTests([ testSocketListening ]);
+ chrome.test.runTests([
+ testSocketListening,
+ testSocketListenInUse
+ ]);
} else if (test_type == 'multicast') {
console.log("Running multicast tests");
chrome.test.runTests([ testMulticast ]);
« no previous file with comments | « no previous file | extensions/browser/api/socket/tcp_socket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698