0bf435d5a6701d5ecfa30c16befd97c3ae8fa3d7
[test/tct/web/api.git] /
1 <!DOCTYPE html>
2 <!--
3 Copyright (c) 2015 Samsung Electronics Co., Ltd.
4
5 Licensed under the Apache License, Version 2.0 (the License);
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9     http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16
17 Authors:
18         Xiaoyan Qian <xy.qian@samsung.com>
19
20 -->
21 <html>
22 <head>
23 <title>BluetoothGATTDescriptor_readValue_with_errorCallback</title>
24 <meta charset="utf-8"/>
25 <script src="support/unitcommon.js"></script>
26 <script src="support/bluetooth_common.js"></script>
27 </head>
28 <body>
29 <div id="log"></div>
30 <script>
31 //==== TEST: BluetoothGATTDescriptor_readValue_with_errorCallback
32 //==== LABEL Check if BluetoothGATTDescriptor readValue method with all optional arguments works properly
33 //==== EXECUTION_TYPE manual
34 //==== ONLOAD_DELAY 30
35 //==== SPEC Tizen Web API:TBD:Bluetooth:BluetoothGATTDescriptor:readValue M
36 //==== SPEC_URL TBD
37 //==== PRIORITY P1
38 //==== PRE The bluetooth of the remote/test device MUST support BLE and be turned on and discoverable from other devices.
39 //==== TEST_CRITERIA MOA MR
40
41 setup({timeout: 60000});
42
43 var t = async_test(document.title, {timeout: 60000}), adapter, bleScanSuccessCallback, bleScanErrorCallback, service,
44     onconnected, onerror, characteristic, descriptor, ReadValueSuccessCallback, ReadValueErrorCallback, retVal = null,
45     device = null, flag = false, i, descFlag;
46
47 t.step(function () {
48     ReadValueSuccessCallback = t.step_func(function (value) {
49         assert_equals(retVal, undefined, "readValue should return undefined");
50         device.disconnect();
51         t.done();
52     });
53
54     ReadValueErrorCallback = t.step_func(function (error) {
55         assert_unreached("readValue() error callback was invoked: " + error.name + " msg: " + error.message);
56     });
57
58     onconnected = t.step_func(function () {
59         service = device.getService(device.uuids[0]);
60         descFlag = false;
61         for (i = 0; i < service.characteristics.length; i++) {
62             characteristic = service.characteristics[i];
63             if (characteristic != undefined) {
64                 descriptor = characteristic.descriptors[0];
65                 if (descFlag == false && descriptor != undefined) {
66                     retVal = descriptor.readValue(ReadValueSuccessCallback, ReadValueErrorCallback);
67                     descFlag = true;
68                 }
69             }
70         }
71     });
72
73     onerror = t.step_func(function (error) {
74         assert_unreached("connect() error callback was invoked: " + error.name + " msg: " + error.message);
75     });
76
77     bleScanSuccessCallback = t.step_func(function (bledevice) {
78         if (bledevice.address == REMOTE_BLE_DEVICE_ADDRESS && device == null) {
79             adapter.stopScan();
80             device = bledevice;
81             if (flag == false) {
82                 device.connect(onconnected, onerror);
83                 flag = true;
84             }
85         }
86     });
87
88     bleScanErrorCallback = t.step_func(function (error) {
89         assert_unreached("startScan() error callback was invoked: " + error.name + " msg: " + error.message);
90     });
91
92     adapter = tizen.bluetooth.getLEAdapter();
93     adapter.stopScan();
94     adapter.startScan(bleScanSuccessCallback, bleScanErrorCallback);
95 });
96
97 </script>
98 </body>
99 </html>