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

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

Issue 10852016: Move serial out of experimental. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
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 const serial = chrome.serial;
6
5 // TODO(miket): opening Bluetooth ports on OSX is unreliable. Investigate. 7 // TODO(miket): opening Bluetooth ports on OSX is unreliable. Investigate.
6 function shouldSkipPort(portName) { 8 function shouldSkipPort(portName) {
7 return portName.match(/[Bb]luetooth/); 9 return portName.match(/[Bb]luetooth/);
8 } 10 }
9 11
10 var createTestArrayBuffer = function() { 12 var createTestArrayBuffer = function() {
11 var bufferSize = 8; 13 var bufferSize = 8;
12 var buffer = new ArrayBuffer(bufferSize); 14 var buffer = new ArrayBuffer(bufferSize);
13 15
14 var uint8View = new Uint8Array(buffer); 16 var uint8View = new Uint8Array(buffer);
(...skipping 11 matching lines...) Expand all
26 var writeBufferUint8View = new Uint8Array(writeBuffer); 28 var writeBufferUint8View = new Uint8Array(writeBuffer);
27 var bufferLength = writeBufferUint8View.length; 29 var bufferLength = writeBufferUint8View.length;
28 var readBuffer = new ArrayBuffer(bufferLength); 30 var readBuffer = new ArrayBuffer(bufferLength);
29 var readBufferUint8View = new Uint8Array(readBuffer); 31 var readBufferUint8View = new Uint8Array(readBuffer);
30 var bytesToRead = bufferLength; 32 var bytesToRead = bufferLength;
31 33
32 var operation = 0; 34 var operation = 0;
33 var doNextOperation = function() { 35 var doNextOperation = function() {
34 switch (operation++) { 36 switch (operation++) {
35 case 0: 37 case 0:
36 chrome.experimental.serial.getPorts(onGetPorts); 38 serial.getPorts(onGetPorts);
37 break; 39 break;
38 case 1: 40 case 1:
39 var bitrate = 57600; 41 var bitrate = 57600;
40 console.log('Opening serial device ' + serialPort + ' at ' + 42 console.log('Opening serial device ' + serialPort + ' at ' +
41 bitrate + ' bps.'); 43 bitrate + ' bps.');
42 chrome.experimental.serial.open(serialPort, {bitrate: bitrate}, 44 serial.open(serialPort, {bitrate: bitrate}, onOpen);
43 onOpen);
44 break; 45 break;
45 case 2: 46 case 2:
46 chrome.experimental.serial.setControlSignals( 47 serial.setControlSignals(connectionId, {dtr: true}, onSetControlSignals);
47 connectionId, {dtr: true}, onSetControlSignals);
48 break; 48 break;
49 case 3: 49 case 3:
50 chrome.experimental.serial.getControlSignals(connectionId, 50 serial.getControlSignals(connectionId,onGetControlSignals);
51 onGetControlSignals);
52 break; 51 break;
53 case 4: 52 case 4:
54 chrome.experimental.serial.write(connectionId, writeBuffer, onWrite); 53 serial.write(connectionId, writeBuffer, onWrite);
55 break; 54 break;
56 case 5: 55 case 5:
57 chrome.experimental.serial.read(connectionId, bytesToRead, onRead); 56 serial.read(connectionId, bytesToRead, onRead);
58 break; 57 break;
59 case 6: 58 case 6:
60 chrome.experimental.serial.flush(connectionId, onFlush); 59 serial.flush(connectionId, onFlush);
61 break; 60 break;
62 case 50: // GOTO 4 EVER 61 case 50: // GOTO 4 EVER
63 chrome.experimental.serial.close(connectionId, onClose); 62 serial.close(connectionId, onClose);
64 break; 63 break;
65 default: 64 default:
66 // Beware! If you forget to assign a case for your next test, the whole 65 // Beware! If you forget to assign a case for your next test, the whole
67 // test suite will appear to succeed! 66 // test suite will appear to succeed!
68 chrome.test.succeed(); 67 chrome.test.succeed();
69 break; 68 break;
70 } 69 }
71 } 70 }
72 71
73 var skipToTearDown = function() { 72 var skipToTearDown = function() {
(...skipping 13 matching lines...) Expand all
87 86
88 var onFlush = function(result) { 87 var onFlush = function(result) {
89 chrome.test.assertTrue(result); 88 chrome.test.assertTrue(result);
90 doNextOperation(); 89 doNextOperation();
91 } 90 }
92 91
93 var onRead = function(readInfo) { 92 var onRead = function(readInfo) {
94 bytesToRead -= readInfo.bytesRead; 93 bytesToRead -= readInfo.bytesRead;
95 var readBufferIndex = bufferLength - readInfo.bytesRead; 94 var readBufferIndex = bufferLength - readInfo.bytesRead;
96 var messageUint8View = new Uint8Array(readInfo.data); 95 var messageUint8View = new Uint8Array(readInfo.data);
97 for (var i = 0; i < readInfo.bytesRead; i++) { 96 for (var i = 0; i < readInfo.bytesRead; i++)
98 readBufferUint8View[i + readBufferIndex] = messageUint8View[i]; 97 readBufferUint8View[i + readBufferIndex] = messageUint8View[i];
99 }
100 if (bytesToRead == 0) { 98 if (bytesToRead == 0) {
101 chrome.test.assertEq(writeBufferUint8View, readBufferUint8View, 99 chrome.test.assertEq(writeBufferUint8View, readBufferUint8View,
102 'Buffer read was not equal to buffer written.'); 100 'Buffer read was not equal to buffer written.');
103 doNextOperation(); 101 doNextOperation();
104 } else { 102 } else {
105 if (--readTries > 0) 103 if (--readTries > 0)
106 setTimeout(repeatOperation, 100); 104 setTimeout(repeatOperation, 100);
107 else 105 else
108 chrome.test.assertTrue( 106 chrome.test.assertTrue(
109 false, 107 false,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 // No serial device found. This is still considered a success because we 153 // No serial device found. This is still considered a success because we
156 // can't rely on specific hardware being present on the machine. 154 // can't rely on specific hardware being present on the machine.
157 chrome.test.succeed(); 155 chrome.test.succeed();
158 } 156 }
159 }; 157 };
160 158
161 doNextOperation(); 159 doNextOperation();
162 }; 160 };
163 161
164 chrome.test.runTests([testSerial]); 162 chrome.test.runTests([testSerial]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698