1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 var kExpectedDeviceNames = {
6 "21:22:23:24:25:26": "the real d2",
7 "31:32:33:34:35:36": "d3"
10 function testDeviceEvents() {
11 var expectedAddresses = Object.keys(kExpectedDeviceNames);
12 chrome.test.assertEq(expectedAddresses.length, Object.keys(devices).length);
14 for (var i = 0; i < expectedAddresses.length; ++i) {
15 var address = expectedAddresses[i];
16 chrome.test.assertTrue(address in devices);
17 chrome.test.assertEq(kExpectedDeviceNames[address], devices[address].name);
20 chrome.test.succeed();
23 function startTests() {
24 chrome.test.runTests([testDeviceEvents]);
28 function recordDevice(device) {
29 devices[device.address] = device;
31 function removeDevice(device) {
32 delete devices[device.address];
33 chrome.test.sendMessage('ready', startTests);
36 function stopDiscoveryAndContinue() {
37 chrome.bluetooth.stopDiscovery();
38 chrome.bluetooth.onDeviceAdded.removeListener(recordDevice);
39 sendReady(startTests);
42 chrome.bluetooth.onDeviceAdded.addListener(recordDevice);
43 chrome.bluetooth.onDeviceChanged.addListener(recordDevice);
44 chrome.bluetooth.onDeviceRemoved.addListener(removeDevice);