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

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

Issue 10537017: Allow hostnames in socket.connect(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: mihaip's comments + clang fix. Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « chrome/test/data/extensions/api_test/dns/api/background.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 function onWriteOrSendToComplete(writeInfo) { 74 function onWriteOrSendToComplete(writeInfo) {
75 bytesWritten += writeInfo.bytesWritten; 75 bytesWritten += writeInfo.bytesWritten;
76 if (bytesWritten == request.length) { 76 if (bytesWritten == request.length) {
77 if (protocol == "tcp") 77 if (protocol == "tcp")
78 socket.read(socketId, onDataRead); 78 socket.read(socketId, onDataRead);
79 else 79 else
80 socket.recvFrom(socketId, onDataRead); 80 socket.recvFrom(socketId, onDataRead);
81 } 81 }
82 } 82 }
83 83
84 function onSetKeepAlive(result) {
85 if (protocol == "tcp")
86 chrome.test.assertTrue(result, "setKeepAlive failed for TCP.");
87 else
88 chrome.test.assertFalse(result, "setKeepAlive did not fail for UDP.");
89
90 string2ArrayBuffer(request, function(arrayBuffer) {
91 if (protocol == "tcp")
92 socket.write(socketId, arrayBuffer, onWriteOrSendToComplete);
93 else
94 socket.sendTo(socketId, arrayBuffer, address, port,
95 onWriteOrSendToComplete);
96 });
97 }
98
99 function onSetNoDelay(result) {
100 if (protocol == "tcp")
101 chrome.test.assertTrue(result, "setNoDelay failed for TCP.");
102 else
103 chrome.test.assertFalse(result, "setNoDelay did not fail for UDP.");
104 socket.setKeepAlive(socketId, true, 1000, onSetKeepAlive);
105 }
106
84 function onConnectOrBindComplete(result) { 107 function onConnectOrBindComplete(result) {
85 chrome.test.assertEq(0, result, "Connect or bind failed."); 108 chrome.test.assertEq(0, result,
109 "Connect or bind failed with error " + result);
86 if (result == 0) { 110 if (result == 0) {
87 var onSetKeepAlive = function(result) {
88 if (protocol == "tcp")
89 chrome.test.assertTrue(result, "setKeepAlive failed for TCP.");
90 else
91 chrome.test.assertFalse(result, "setKeepAlive did not fail for UDP.");
92
93 string2ArrayBuffer(request, function(arrayBuffer) {
94 if (protocol == "tcp")
95 socket.write(socketId, arrayBuffer, onWriteOrSendToComplete);
96 else
97 socket.sendTo(socketId, arrayBuffer, address, port,
98 onWriteOrSendToComplete);
99 });
100 };
101
102 var onSetNoDelay = function(result) {
103 if (protocol == "tcp")
104 chrome.test.assertTrue(result, "setNoDelay failed for TCP.");
105 else
106 chrome.test.assertFalse(result, "setNoDelay did not fail for UDP.");
107 socket.setKeepAlive(socketId, true, 1000, onSetKeepAlive);
108 };
109
110 socket.setNoDelay(socketId, true, onSetNoDelay); 111 socket.setNoDelay(socketId, true, onSetNoDelay);
111 } 112 }
112 } 113 }
113 114
114 function onCreate(socketInfo) { 115 function onCreate(socketInfo) {
115 socketId = socketInfo.socketId; 116 socketId = socketInfo.socketId;
116 chrome.test.assertTrue(socketId > 0, "failed to create socket"); 117 chrome.test.assertTrue(socketId > 0, "failed to create socket");
117 if (protocol == "tcp") 118 if (protocol == "tcp")
118 socket.connect(socketId, address, port, onConnectOrBindComplete); 119 socket.connect(socketId, address, port, onConnectOrBindComplete);
119 else 120 else
(...skipping 25 matching lines...) Expand all
145 address = parts[1]; 146 address = parts[1];
146 port = parseInt(parts[2]); 147 port = parseInt(parts[2]);
147 console.log("Running tests, protocol " + protocol + ", echo server " + 148 console.log("Running tests, protocol " + protocol + ", echo server " +
148 address + ":" + port); 149 address + ":" + port);
149 chrome.test.runTests([ testSocketCreation, testSending ]); 150 chrome.test.runTests([ testSocketCreation, testSending ]);
150 }; 151 };
151 152
152 // Find out which protocol we're supposed to test, and which echo server we 153 // Find out which protocol we're supposed to test, and which echo server we
153 // should be using, then kick off the tests. 154 // should be using, then kick off the tests.
154 chrome.test.sendMessage("info_please", onMessageReply); 155 chrome.test.sendMessage("info_please", onMessageReply);
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/api_test/dns/api/background.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698