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

Side by Side Diff: chrome/test/data/extensions/api_test/serial/real_hardware/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 // 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() {
11 var onGetPorts = function(ports) { 11 var onGetPorts = function(ports) {
12 // Any length is potentially valid, because we're on unknown hardware. But 12 // Any length is potentially valid, because we're on unknown hardware. But
13 // we are testing at least that the ports member was filled in, so it's 13 // we are testing at least that the ports member was filled in, so it's
14 // still a somewhat meaningful test. 14 // still a somewhat meaningful test.
15 chrome.test.assertTrue(ports.length >= 0); 15 chrome.test.assertTrue(ports.length >= 0);
16 chrome.test.succeed(); 16 chrome.test.succeed();
17 } 17 }
18 18
19 chrome.experimental.serial.getPorts(onGetPorts); 19 chrome.serial.getPorts(onGetPorts);
20 }; 20 };
21 21
22 var testMaybeOpenPort = function() { 22 var testMaybeOpenPort = function() {
23 var onGetPorts = function(ports) { 23 var onGetPorts = function(ports) {
24 // We're testing as much as we can here without actually assuming the 24 // We're testing as much as we can here without actually assuming the
25 // existence of attached hardware. 25 // existence of attached hardware.
26 // 26 //
27 // TODO(miket): is there any chance that just opening a serial port but not 27 // TODO(miket): is there any chance that just opening a serial port but not
28 // doing anything could be harmful to devices attached to a developer's 28 // doing anything could be harmful to devices attached to a developer's
29 // machine? 29 // machine?
30 if (ports.length > 0) { 30 if (ports.length > 0) {
31 var currentPort = 0; 31 var currentPort = 0;
32 32
33 var onFinishedWithPort = function() { 33 var onFinishedWithPort = function() {
34 if (currentPort >= ports.length) 34 if (currentPort >= ports.length)
35 chrome.test.succeed(); 35 chrome.test.succeed();
36 else 36 else
37 testPort(); 37 testPort();
38 }; 38 };
39 39
40 var onClose = function(r) { 40 var onClose = function(r) {
41 onFinishedWithPort(); 41 onFinishedWithPort();
42 }; 42 };
43 43
44 var onOpen = function(connectionInfo) { 44 var onOpen = function(connectionInfo) {
45 var id = connectionInfo.connectionId; 45 var id = connectionInfo.connectionId;
46 if (id > 0) 46 if (id > 0)
47 chrome.experimental.serial.close(id, onClose); 47 chrome.serial.close(id, onClose);
48 else 48 else
49 onFinishedWithPort(); 49 onFinishedWithPort();
50 }; 50 };
51 51
52 var testPort = function() { 52 var testPort = function() {
53 var port = ports[currentPort++]; 53 var port = ports[currentPort++];
54 54
55 if (shouldSkipPort(port)) { 55 if (shouldSkipPort(port)) {
56 onFinishedWithPort(); 56 onFinishedWithPort();
57 } else { 57 } else {
58 console.log("Opening serial device " + port); 58 console.log("Opening serial device " + port);
59 chrome.experimental.serial.open(port, onOpen); 59 chrome.serial.open(port, onOpen);
60 } 60 }
61 } 61 }
62 62
63 testPort(); 63 testPort();
64 } else { 64 } else {
65 // There aren't any valid ports on this machine. That's OK. 65 // There aren't any valid ports on this machine. That's OK.
66 chrome.test.succeed(); 66 chrome.test.succeed();
67 } 67 }
68 } 68 }
69 69
70 chrome.experimental.serial.getPorts(onGetPorts); 70 chrome.serial.getPorts(onGetPorts);
71 }; 71 };
72 72
73 var tests = [testGetPorts, testMaybeOpenPort]; 73 var tests = [testGetPorts, testMaybeOpenPort];
74 chrome.test.runTests(tests); 74 chrome.test.runTests(tests);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698