| OLD | NEW |
| 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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 if (protocol == "tcp") | 303 if (protocol == "tcp") |
| 304 chrome.socket.connect(socketId, address, port, onConnect1); | 304 chrome.socket.connect(socketId, address, port, onConnect1); |
| 305 else | 305 else |
| 306 chrome.socket.bind(socketId, "0.0.0.0", 0, onConnect1); | 306 chrome.socket.bind(socketId, "0.0.0.0", 0, onConnect1); |
| 307 } | 307 } |
| 308 | 308 |
| 309 function onConnect1(result) { | 309 function onConnect1(result) { |
| 310 chrome.test.assertEq(0, result, "failed to connect"); | 310 chrome.test.assertEq(0, result, "failed to connect"); |
| 311 console.log("Socket connect: result=" + result, chrome.runtime.lastError); | 311 console.log("Socket connect: result=" + result, chrome.runtime.lastError); |
| 312 | 312 |
| 313 console.log("calling read with readCB2 callback"); | 313 console.log("calling read with readCB1 callback"); |
| 314 if (protocol == "tcp") | 314 if (protocol == "tcp") |
| 315 chrome.socket.read(socketId, readCB1); | 315 chrome.socket.read(socketId, readCB1); |
| 316 else | 316 else |
| 317 chrome.socket.recvFrom(socketId, readCB1); | 317 chrome.socket.recvFrom(socketId, readCB1); |
| 318 | 318 |
| 319 console.log("calling disconnect"); | 319 console.log("calling disconnect"); |
| 320 chrome.socket.disconnect(socketId); | 320 chrome.socket.disconnect(socketId); |
| 321 | 321 |
| 322 console.log("calling connect"); | 322 console.log("calling connect"); |
| 323 if (protocol == "tcp") | 323 if (protocol == "tcp") |
| 324 chrome.socket.connect(socketId, address, port, onConnect2); | 324 chrome.socket.connect(socketId, address, port, onConnect2); |
| 325 else | 325 else |
| 326 chrome.socket.bind(socketId, "0.0.0.0", 0, onConnect2); | 326 chrome.socket.bind(socketId, "0.0.0.0", 0, onConnect2); |
| 327 } | 327 } |
| 328 | 328 |
| 329 function onConnect2(result) { | 329 function onConnect2(result) { |
| 330 chrome.test.assertEq(0, result, "failed to connect"); | 330 chrome.test.assertEq(0, result, "failed to connect"); |
| 331 console.log("Socket connect: result=" + result, chrome.runtime.lastError); | 331 console.log("Socket connect: result=" + result, chrome.runtime.lastError); |
| 332 | 332 |
| 333 console.log("calling read with readCB1 callback"); | 333 console.log("calling read with readCB2 callback"); |
| 334 if (protocol == "tcp") | 334 if (protocol == "tcp") |
| 335 chrome.socket.read(socketId, readCB2); | 335 chrome.socket.read(socketId, readCB2); |
| 336 else | 336 else |
| 337 chrome.socket.recvFrom(socketId, readCB2); | 337 chrome.socket.recvFrom(socketId, readCB2); |
| 338 | 338 |
| 339 string2ArrayBuffer(request, function (arrayBuffer) { | 339 string2ArrayBuffer(request, function (arrayBuffer) { |
| 340 if (protocol == "tcp") | 340 if (protocol == "tcp") |
| 341 chrome.socket.write(socketId, arrayBuffer, onWriteComplete); | 341 chrome.socket.write(socketId, arrayBuffer, onWriteComplete); |
| 342 else | 342 else |
| 343 chrome.socket.sendTo( | 343 chrome.socket.sendTo( |
| 344 socketId, arrayBuffer, address, port, onWriteComplete); | 344 socketId, arrayBuffer, address, port, onWriteComplete); |
| 345 }); | 345 }); |
| 346 } | 346 } |
| 347 | 347 |
| 348 function onWriteComplete(res) { | 348 function onWriteComplete(res) { |
| 349 console.log("write callback: bytesWritten=" + res.bytesWritten); | 349 console.log("write callback: bytesWritten=" + res.bytesWritten); |
| 350 } | 350 } |
| 351 | 351 |
| 352 // Callback 1 for initial read call | 352 // Callback 1 for initial read call |
| 353 function readCB1(readInfo) { | 353 function readCB1(readInfo) { |
| 354 console.log("Socket read CB1: result=" + readInfo.resultCode, | 354 console.log("Socket read CB1: result=" + readInfo.resultCode, |
| 355 chrome.runtime.lastError); | 355 chrome.runtime.lastError); |
| 356 | 356 // We disconnect the socket right after calling read(), so behavior here |
| 357 if (readInfo.resultCode < 0) { | 357 // is undefined. |
| 358 chrome.test.fail("Error reading from socket: " + readInfo.resultCode); | 358 // TODO(devlin): Why do we do that? What are we trying to do? |
| 359 } | |
| 360 } | 359 } |
| 361 | 360 |
| 362 // Second callback, for read call after re-connect | 361 // Second callback, for read call after re-connect |
| 363 function readCB2(readInfo) { | 362 function readCB2(readInfo) { |
| 364 console.log("Socket read CB2: result=" + readInfo.resultCode, | 363 console.log("Socket read CB2: result=" + readInfo.resultCode, |
| 365 chrome.runtime.lastError); | 364 chrome.runtime.lastError); |
| 366 if (readInfo.resultCode === -1) { | 365 if (readInfo.resultCode === -1) { |
| 367 chrome.test.fail("Unable to register a read 2nd callback on the socket!"); | 366 chrome.test.fail("Unable to register a read 2nd callback on the socket!"); |
| 368 } else if (readInfo.resultCode < 0) { | 367 } else if (readInfo.resultCode < 0) { |
| 369 chrome.test.fail("Error reading from socket: " + readInfo.resultCode); | 368 chrome.test.fail("Error reading from socket: " + readInfo.resultCode); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 testSocketCreation, | 427 testSocketCreation, |
| 429 testSending, | 428 testSending, |
| 430 testPendingCallback, | 429 testPendingCallback, |
| 431 testUsingTCPSocketOnUDPMethods]); | 430 testUsingTCPSocketOnUDPMethods]); |
| 432 } | 431 } |
| 433 }; | 432 }; |
| 434 | 433 |
| 435 // Find out which protocol we're supposed to test, and which echo server we | 434 // Find out which protocol we're supposed to test, and which echo server we |
| 436 // should be using, then kick off the tests. | 435 // should be using, then kick off the tests. |
| 437 chrome.test.sendMessage("info_please", onMessageReply); | 436 chrome.test.sendMessage("info_please", onMessageReply); |
| OLD | NEW |