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 // Called by the common.js module. | 4 // Called by the common.js module. |
| 5 |
| 6 function runTCPEchoServer(port) { |
| 7 console.log("Starting server on TCP port: " + port); |
| 8 chrome.socket.create("tcp", {}, function(createInfo) { |
| 9 var listeningSocket = createInfo.socketId; |
| 10 chrome.socket.listen(listeningSocket, |
| 11 '127.0.0.1', |
| 12 port, |
| 13 10, |
| 14 function(result) { |
| 15 if (result !== 0) { |
| 16 console.log("Listen failed: " + result); |
| 17 return; |
| 18 } |
| 19 |
| 20 chrome.socket.accept(listeningSocket, function(acceptInfo) { |
| 21 if (result !== 0) { |
| 22 console.log("Accept failed: " + result); |
| 23 return; |
| 24 } |
| 25 |
| 26 var newSock = acceptInfo.socketId; |
| 27 |
| 28 var readCallback = function(readInfo) { |
| 29 if (readInfo.resultCode < 0) { |
| 30 console.log("Read failed: " + readInfo.resultCode); |
| 31 chrome.socket.destroy(newSock); |
| 32 return; |
| 33 } |
| 34 |
| 35 chrome.socket.write(newSock, readInfo.data, function(writeInfo) {}) |
| 36 chrome.socket.read(newSock, readCallback); |
| 37 } |
| 38 |
| 39 chrome.socket.read(newSock, readCallback); |
| 40 }) |
| 41 }) |
| 42 }) |
| 43 } |
| 44 |
5 function moduleDidLoad() { | 45 function moduleDidLoad() { |
6 // The module is not hidden by default so we can easily see if the plugin | 46 // The module is not hidden by default so we can easily see if the plugin |
7 // failed to load. | 47 // failed to load. |
8 common.hideModule(); | 48 common.hideModule(); |
| 49 runTCPEchoServer(4006); |
9 } | 50 } |
10 | 51 |
11 var currentTestEl = null; | 52 var currentTestEl = null; |
12 | 53 |
13 function startCommand(testName) { | 54 function startCommand(testName) { |
14 var testListEl = document.getElementById('tests'); | 55 var testListEl = document.getElementById('tests'); |
15 var testEl = document.createElement('li'); | 56 var testEl = document.createElement('li'); |
16 var testRowEl = document.createElement('div'); | 57 var testRowEl = document.createElement('div'); |
17 var testNameEl = document.createElement('span'); | 58 var testNameEl = document.createElement('span'); |
18 var testResultEl = document.createElement('span'); | 59 var testResultEl = document.createElement('span'); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 argList = argList.substr(comma + 1); | 117 argList = argList.substr(comma + 1); |
77 } | 118 } |
78 args.push(arg); | 119 args.push(arg); |
79 } | 120 } |
80 | 121 |
81 // Last argument is the rest of the message. | 122 // Last argument is the rest of the message. |
82 args.push(argList); | 123 args.push(argList); |
83 | 124 |
84 cmdFunction.apply(null, args); | 125 cmdFunction.apply(null, args); |
85 } | 126 } |
OLD | NEW |