- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / bluetooth / discovery_callback / runtest.js
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
3 // found in the LICENSE file.
4
5 var kExpectedDeviceNames = ["d1"];
6
7 function testDiscovery() {
8   chrome.test.assertEq(kExpectedDeviceNames.length,
9       discoveredDevices.length);
10   for (var i = 0; i < kExpectedDeviceNames.length; ++i) {
11     chrome.test.assertEq(kExpectedDeviceNames[i],
12         discoveredDevices[i].name);
13   }
14
15   chrome.test.succeed();
16 }
17
18 function startTests() {
19   chrome.test.runTests([testDiscovery]);
20 }
21
22 function sendReady(callback) {
23   chrome.test.sendMessage('ready', callback);
24 }
25
26 function stopDiscoveryAndContinue() {
27   chrome.bluetooth.stopDiscovery();
28   sendReady(startTests);
29 }
30
31 var discoveredDevices = [];
32 function recordDevice(device) {
33   discoveredDevices.push(device);
34 }
35
36 chrome.bluetooth.startDiscovery(
37     { deviceCallback:recordDevice },
38     function() { sendReady(stopDiscoveryAndContinue); });