Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / bluetooth_low_energy / get_included_services / runtest.js
1 // Copyright 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.
4
5 function testGetIncludedServices() {
6   chrome.test.assertTrue(services != null, '\'services\' is null');
7   chrome.test.assertEq(1, services.length);
8   chrome.test.assertEq(includedId, services[0].instanceId);
9
10   chrome.test.succeed();
11 }
12
13 var serviceId = 'service_id0';
14 var includedId = 'service_id1';
15 var services = null;
16
17 function failOnError() {
18   if (chrome.runtime.lastError) {
19     chrome.test.fail(chrome.runtime.lastError.message);
20   }
21 }
22
23 chrome.bluetoothLowEnergy.getIncludedServices(serviceId, function (result) {
24   // No mapping for |serviceId|.
25   if (result || !chrome.runtime.lastError) {
26     chrome.test.fail('getIncludedServices should have failed');
27   }
28
29   chrome.test.sendMessage('ready', function (message) {
30     chrome.bluetoothLowEnergy.getIncludedServices(serviceId, function (result) {
31       failOnError();
32       if (!result || result.length != 0) {
33         chrome.test.fail('Included services should be empty.');
34       }
35
36       chrome.bluetoothLowEnergy.getIncludedServices(serviceId,
37           function (result) {
38             failOnError();
39             services = result;
40
41             chrome.test.sendMessage('ready', function (message) {
42               chrome.test.runTests([testGetIncludedServices]);
43             });
44       });
45     });
46   });
47 });