Update To 11.40.268.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 var error;
6
7 function testGetIncludedServices() {
8   if (error !== undefined) {
9     chrome.test.sendMessage('fail');
10     chrome.test.fail(error);
11   }
12   chrome.test.assertTrue(services != null, '\'services\' is null');
13   chrome.test.assertEq(1, services.length);
14   chrome.test.assertEq(includedId, services[0].instanceId);
15
16   chrome.test.succeed();
17 }
18
19 var serviceId = 'service_id0';
20 var includedId = 'service_id1';
21 var services = null;
22
23 function earlyError(message) {
24   error = message;
25   chrome.test.runTests([testGetIncludedServices]);
26 }
27
28 function failOnError() {
29   if (chrome.runtime.lastError) {
30     earlyError(chrome.runtime.lastError.message);
31     return true;
32   }
33   return false;
34 }
35
36 chrome.bluetoothLowEnergy.getIncludedServices(serviceId, function (result) {
37   // No mapping for |serviceId|.
38   if (result || !chrome.runtime.lastError) {
39     earlyError('getIncludedServices should have failed');
40     return;
41   }
42
43   chrome.test.sendMessage('ready', function (message) {
44     chrome.bluetoothLowEnergy.getIncludedServices(serviceId, function (result) {
45       if (failOnError())
46         return;
47
48       if (!result || result.length != 0) {
49         earlyError('Included services should be empty.');
50         return;
51       }
52
53       chrome.bluetoothLowEnergy.getIncludedServices(serviceId,
54           function (result) {
55             if (failOnError())
56               return;
57
58             services = result;
59
60             chrome.test.sendMessage('ready', function (message) {
61               chrome.test.runTests([testGetIncludedServices]);
62             });
63           });
64     });
65   });
66 });