f065636e738f3903109f5040312655a9521f788c
[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_writeValue_errorCallback_TypeMismatch</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_writeValue_errorCallback_TypeMismatch
32 //==== LABEL Check if writeValue throws exception when errorCallback is incorrect
33 //==== EXECUTION_TYPE manual
34 //==== ONLOAD_DELAY 30
35 //==== SPEC Tizen Web API:TBD:Bluetooth:BluetoothGATTDescriptor:writeValue M
36 //==== SPEC_URL TBD
37 //==== PRIORITY P2
38 //==== PRE The bluetooth of the remote/test device MUST support BLE and be turned on and discoverable from other devices.
39 //==== TEST_CRITERIA MC
40
41 setup({timeout: 60000});
42
43 var t = async_test(document.title, {timeout: 60000}), adapter, bleScanSuccessCallback, bleScanErrorCallback, data = new Array(1, 2, 3, 4, 5, 6),
44     service, device = null,  onconnected, onerror, characteristic, descriptor, WriteValueSuccessCallback,
45     WriteValueErrorCallback, conversionTable, exceptionName, i, flag = false, j;
46
47 t.step(function () {
48     conversionTable = getTypeConversionExceptions("functionObject", true);
49
50     WriteValueSuccessCallback = t.step_func(function (value) {
51         assert_unreached("writeValue() success callback should not be invoked.");
52     });
53
54     onconnected = t.step_func(function () {
55         service = device.getService(device.uuids[0]);
56         for (j = 0; j < service.characteristics.length; j++) {
57             characteristic = service.characteristics[j];
58             if (characteristic != undefined) {
59                 descriptor = characteristic.descriptors[0];
60                 if (descriptor != undefined) {
61                     for (i = 0; i < conversionTable.length; i++) {
62                         WriteValueErrorCallback = conversionTable[i][0];
63                         exceptionName = conversionTable[i][1];
64                         assert_throws({name: exceptionName},
65                             function () {
66                                 descriptor.writeValue(data, WriteValueSuccessCallback, WriteValueErrorCallback);
67                             }, "Given incorrect error callback.");
68                     }
69                     device.disconnect();
70                     t.done();
71                 }
72             }
73         }
74     });
75
76     onerror = t.step_func(function (error) {
77         assert_unreached("connect() error callback was invoked: " + error.name + " msg: " + error.message);
78     });
79
80     bleScanSuccessCallback = t.step_func(function (bledevice) {
81         if (bledevice.address == REMOTE_BLE_DEVICE_ADDRESS && device == null) {
82             adapter.stopScan();
83             device = bledevice;
84             if (flag == false) {
85                 device.connect(onconnected, onerror);
86                 flag = true;
87             }
88         }
89     });
90
91     bleScanErrorCallback = t.step_func(function (error) {
92         assert_unreached("startScan() error callback was invoked: " + error.name + " msg: " + error.message);
93     });
94
95     adapter = tizen.bluetooth.getLEAdapter();
96     adapter.stopScan();
97     adapter.startScan(bleScanSuccessCallback, bleScanErrorCallback);
98 });
99
100 </script>
101 </body>
102 </html>