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

Side by Side Diff: chrome/test/data/extensions/api_test/bluetooth/discovery_in_progress/runtest.js

Issue 177113013: Bluetooth: add Device events, and cleanup JS API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@arman-patch
Patch Set: I suck at rebase Created 6 years, 9 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
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 var kExpectedDeviceNames = ["d2"]; 5 var kExpectedDeviceNames = ["d2"];
6 6
7 function testDiscovery() { 7 function testDiscovery() {
8 chrome.test.assertEq(kExpectedDeviceNames.length, 8 chrome.test.assertEq(kExpectedDeviceNames.length,
9 discoveredDevices.length); 9 discoveredDevices.length);
10 for (var i = 0; i < kExpectedDeviceNames.length; ++i) { 10 for (var i = 0; i < kExpectedDeviceNames.length; ++i) {
11 chrome.test.assertEq(kExpectedDeviceNames[i], 11 chrome.test.assertEq(kExpectedDeviceNames[i],
12 discoveredDevices[i].name); 12 discoveredDevices[i].name);
13 } 13 }
14 14
15 chrome.test.succeed(); 15 chrome.test.succeed();
16 } 16 }
17 17
18 function startTests() { 18 function startTests() {
19 chrome.test.runTests([testDiscovery]); 19 chrome.test.runTests([testDiscovery]);
20 } 20 }
21 21
22 function sendReady(callback) { 22 function sendReady(callback) {
23 chrome.test.sendMessage('ready', callback); 23 chrome.test.sendMessage('ready', callback);
24 } 24 }
25 25
26 function stopDiscoveryAndContinue() {
27 chrome.bluetooth.stopDiscovery();
28 sendReady(startTests);
29 }
30
31 var discoveredDevices = []; 26 var discoveredDevices = [];
32 function recordDevice(device) { 27 function recordDevice(device) {
33 discoveredDevices.push(device); 28 discoveredDevices.push(device);
34 } 29 }
35 30
31 function stopDiscoveryAndContinue() {
32 chrome.bluetooth.stopDiscovery();
33 chrome.bluetooth.onDeviceAdded.removeListener(recordDevice);
34 sendReady(startTests);
35 }
36
37 chrome.bluetooth.onDeviceAdded.addListener(recordDevice);
36 chrome.bluetooth.startDiscovery( 38 chrome.bluetooth.startDiscovery(
37 { deviceCallback:recordDevice },
38 function() { sendReady(stopDiscoveryAndContinue); }); 39 function() { sendReady(stopDiscoveryAndContinue); });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698