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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 // | 69 // |
70 //socket.destroy(socketInfo.socketId); | 70 //socket.destroy(socketInfo.socketId); |
71 | 71 |
72 chrome.test.succeed(); | 72 chrome.test.succeed(); |
73 } | 73 } |
74 | 74 |
75 socket.create(protocol, address, port, {onEvent: function(e) {}}, onCreate); | 75 socket.create(protocol, address, port, {onEvent: function(e) {}}, onCreate); |
76 }; | 76 }; |
77 | 77 |
78 function onDataRead(readInfo) { | 78 function onDataRead(readInfo) { |
| 79 if (readInfo.resultCode > 0 || readInfo.data.length > 0) { |
| 80 chrome.test.assertEq(readInfo.resultCode, readInfo.data.length); |
| 81 } |
| 82 |
79 // TODO(miket): this isn't correct for multiple calls of onDataRead. | 83 // TODO(miket): this isn't correct for multiple calls of onDataRead. |
80 arrayBuffer2String(arrayOfLongsToArrayBuffer(readInfo.data), function(s) { | 84 arrayBuffer2String(arrayOfLongsToArrayBuffer(readInfo.data), function(s) { |
81 dataAsString = s; // save this for error reporting | 85 dataAsString = s; // save this for error reporting |
82 if (s.match(expectedResponsePattern)) { | 86 if (s.match(expectedResponsePattern)) { |
83 succeeded = true; | 87 succeeded = true; |
84 chrome.test.succeed(); | 88 chrome.test.succeed(); |
85 } | 89 } |
86 }); | 90 }); |
87 // Blocked. Wait for onEvent. | 91 // Blocked. Wait for onEvent. |
88 } | 92 } |
(...skipping 19 matching lines...) Expand all Loading... |
108 function onCreate(socketInfo) { | 112 function onCreate(socketInfo) { |
109 socketId = socketInfo.socketId; | 113 socketId = socketInfo.socketId; |
110 chrome.test.assertTrue(socketId > 0, "failed to create socket"); | 114 chrome.test.assertTrue(socketId > 0, "failed to create socket"); |
111 socket.connect(socketId, onConnectComplete); | 115 socket.connect(socketId, onConnectComplete); |
112 } | 116 } |
113 | 117 |
114 function onEvent(socketEvent) { | 118 function onEvent(socketEvent) { |
115 if (socketEvent.type == "connectComplete") { | 119 if (socketEvent.type == "connectComplete") { |
116 onConnectComplete(socketEvent.resultCode); | 120 onConnectComplete(socketEvent.resultCode); |
117 } else if (socketEvent.type == "dataRead") { | 121 } else if (socketEvent.type == "dataRead") { |
118 onDataRead({data: socketEvent.data}); | 122 onDataRead({resultCode: socketEvent.resultCode, data: socketEvent.data}); |
119 } else if (socketEvent.type == "writeComplete") { | 123 } else if (socketEvent.type == "writeComplete") { |
120 onWriteComplete(socketEvent.resultCode); | 124 onWriteComplete(socketEvent.resultCode); |
121 } else { | 125 } else { |
122 console.log("Received unhandled socketEvent of type " + socketEvent.type); | 126 console.log("Received unhandled socketEvent of type " + socketEvent.type); |
123 } | 127 } |
124 }; | 128 }; |
125 | 129 |
126 function waitForBlockingOperation() { | 130 function waitForBlockingOperation() { |
127 if (++waitCount < 10) { | 131 if (++waitCount < 10) { |
128 setTimeout(waitForBlockingOperation, 1000); | 132 setTimeout(waitForBlockingOperation, 1000); |
(...skipping 19 matching lines...) Expand all Loading... |
148 address = parts[1]; | 152 address = parts[1]; |
149 port = parseInt(parts[2]); | 153 port = parseInt(parts[2]); |
150 console.log("Running tests, protocol " + protocol + ", echo server " + | 154 console.log("Running tests, protocol " + protocol + ", echo server " + |
151 address + ":" + port); | 155 address + ":" + port); |
152 chrome.test.runTests([ testSocketCreation, testSending ]); | 156 chrome.test.runTests([ testSocketCreation, testSending ]); |
153 }; | 157 }; |
154 | 158 |
155 // Find out which protocol we're supposed to test, and which echo server we | 159 // Find out which protocol we're supposed to test, and which echo server we |
156 // should be using, then kick off the tests. | 160 // should be using, then kick off the tests. |
157 chrome.test.sendMessage("info_please", onMessageReply); | 161 chrome.test.sendMessage("info_please", onMessageReply); |
OLD | NEW |