| 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 // TODO(miket): opening Bluetooth ports on OSX is unreliable. Investigate. | 5 // TODO(miket): opening Bluetooth ports on OSX is unreliable. Investigate. |
| 6 function shouldSkipPort(portName) { | 6 function shouldSkipPort(portName) { |
| 7 return portName.match(/[Bb]luetooth/); | 7 return portName.match(/[Bb]luetooth/); |
| 8 } | 8 } |
| 9 | 9 |
| 10 var testGetPorts = function() { | 10 var testGetPorts = function() { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 while (portNumber < ports.length) { | 130 while (portNumber < ports.length) { |
| 131 if (shouldSkipPort(ports[portNumber])) { | 131 if (shouldSkipPort(ports[portNumber])) { |
| 132 portNumber++; | 132 portNumber++; |
| 133 continue; | 133 continue; |
| 134 } else | 134 } else |
| 135 break; | 135 break; |
| 136 } | 136 } |
| 137 if (portNumber < ports.length) { | 137 if (portNumber < ports.length) { |
| 138 serialPort = ports[portNumber]; | 138 serialPort = ports[portNumber]; |
| 139 var bitrate = 57600; | 139 var bitrate = 57600; |
| 140 console.log('Connecting to serial device ' + serialPort + ' at ' + | 140 console.log('Opening serial device ' + serialPort + ' at ' + |
| 141 bitrate + ' bps.'); | 141 bitrate + ' bps.'); |
| 142 chrome.experimental.serial.open(serialPort, {bitrate: bitrate}, | 142 chrome.experimental.serial.open(serialPort, {bitrate: bitrate}, |
| 143 onOpen); | 143 onOpen); |
| 144 } else { | 144 } else { |
| 145 // We didn't find a port that we think we should try. | 145 // We didn't find a port that we think we should try. |
| 146 chrome.test.succeed(); | 146 chrome.test.succeed(); |
| 147 } | 147 } |
| 148 } else { | 148 } else { |
| 149 // No serial device found. This is still considered a success because we | 149 // No serial device found. This is still considered a success because we |
| 150 // can't rely on specific hardware being present on the machine. | 150 // can't rely on specific hardware being present on the machine. |
| 151 chrome.test.succeed(); | 151 chrome.test.succeed(); |
| 152 } | 152 } |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 chrome.experimental.serial.getPorts(onGetPorts); | 155 chrome.experimental.serial.getPorts(onGetPorts); |
| 156 }; | 156 }; |
| 157 | 157 |
| 158 var onMessageReply = function(message) { | 158 var tests = [testGetPorts, testMaybeOpenPort, testSerial]; |
| 159 var tests = [testGetPorts, testMaybeOpenPort]; | 159 chrome.test.runTests(tests); |
| 160 | |
| 161 // Another way to force the test to run. | |
| 162 var runTest = false; | |
| 163 | |
| 164 if (runTest || message == 'echo_device_attached') { | |
| 165 // We have a specific serial port set up to respond to test traffic. This | |
| 166 // is a rare situation. TODO(miket): mock to make it testable under any | |
| 167 // hardware conditions. | |
| 168 tests.push(testSerial); | |
| 169 } | |
| 170 chrome.test.runTests(tests); | |
| 171 }; | |
| 172 | |
| 173 chrome.test.sendMessage('serial_port', onMessageReply); | |
| OLD | NEW |