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

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

Issue 10790137: Adds socket.getInfo to the socket API (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Broke apart local/peer into localAddress,localPort peerAddress,peerPort, and updated the docs Created 8 years, 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } 96 }
97 97
98 function onSetNoDelay(result) { 98 function onSetNoDelay(result) {
99 if (protocol == "tcp") 99 if (protocol == "tcp")
100 chrome.test.assertTrue(result, "setNoDelay failed for TCP."); 100 chrome.test.assertTrue(result, "setNoDelay failed for TCP.");
101 else 101 else
102 chrome.test.assertFalse(result, "setNoDelay did not fail for UDP."); 102 chrome.test.assertFalse(result, "setNoDelay did not fail for UDP.");
103 socket.setKeepAlive(socketId, true, 1000, onSetKeepAlive); 103 socket.setKeepAlive(socketId, true, 1000, onSetKeepAlive);
104 } 104 }
105 105
106 function onGetInfo(result) {
107 chrome.test.assertTrue(!!result.localAddress,
108 "Bound socket should always have local address");
109 chrome.test.assertTrue(!!result.localPort,
110 "Bound socket should always have local port");
111 chrome.test.assertEq(result.socketType, protocol, "Unexpected socketType");
112
113 if (protocol == "tcp") {
114 // NOTE: We're always called with 'localhost', but getInfo will only return
115 // IPs, not names.
116 chrome.test.assertEq(result.peerAddress, "127.0.0.1",
117 "Peer addresss should be the listen server");
118 chrome.test.assertEq(result.peerPort, port,
119 "Peer port should be the listen server");
120 chrome.test.assertTrue(result.connected, "Socket should be connected");
121 } else {
122 chrome.test.assertFalse(result.connected, "UDP socket was not connected");
123 chrome.test.assertTrue(!result.peerAddress,
124 "Unconnected UDP socket should not have peer address");
125 chrome.test.assertTrue(!result.peerPort,
126 "Unconnected UDP socket should not have peer port");
127 }
128
129 socket.setNoDelay(socketId, true, onSetNoDelay);
130 }
131
106 function onConnectOrBindComplete(result) { 132 function onConnectOrBindComplete(result) {
107 chrome.test.assertEq(0, result, 133 chrome.test.assertEq(0, result,
108 "Connect or bind failed with error " + result); 134 "Connect or bind failed with error " + result);
109 if (result == 0) { 135 if (result == 0) {
110 socket.setNoDelay(socketId, true, onSetNoDelay); 136 socket.getInfo(socketId, onGetInfo);
111 } 137 }
112 } 138 }
113 139
114 function onCreate(socketInfo) { 140 function onCreate(socketInfo) {
115 socketId = socketInfo.socketId; 141 socketId = socketInfo.socketId;
116 chrome.test.assertTrue(socketId > 0, "failed to create socket"); 142 chrome.test.assertTrue(socketId > 0, "failed to create socket");
117 if (protocol == "tcp") 143 if (protocol == "tcp")
118 socket.connect(socketId, address, port, onConnectOrBindComplete); 144 socket.connect(socketId, address, port, onConnectOrBindComplete);
119 else 145 else
120 socket.bind(socketId, "0.0.0.0", 0, onConnectOrBindComplete); 146 socket.bind(socketId, "0.0.0.0", 0, onConnectOrBindComplete);
(...skipping 24 matching lines...) Expand all
145 address = parts[1]; 171 address = parts[1];
146 port = parseInt(parts[2]); 172 port = parseInt(parts[2]);
147 console.log("Running tests, protocol " + protocol + ", echo server " + 173 console.log("Running tests, protocol " + protocol + ", echo server " +
148 address + ":" + port); 174 address + ":" + port);
149 chrome.test.runTests([ testSocketCreation, testSending ]); 175 chrome.test.runTests([ testSocketCreation, testSending ]);
150 }; 176 };
151 177
152 // Find out which protocol we're supposed to test, and which echo server we 178 // Find out which protocol we're supposed to test, and which echo server we
153 // should be using, then kick off the tests. 179 // should be using, then kick off the tests.
154 chrome.test.sendMessage("info_please", onMessageReply); 180 chrome.test.sendMessage("info_please", onMessageReply);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698