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.
5 var address
= '11:12:13:14:15:16';
6 var uuid
= '8e3ad063-db38-4289-aa8f-b30e4223cf40';
8 function testConnect() {
9 chrome
.test
.assertEq(1, sockets
.length
);
10 chrome
.test
.assertEq(socketId
, sockets
[0].socketId
);
11 chrome
.test
.assertEq(false, sockets
[0].persistent
);
12 chrome
.test
.assertEq(undefined, sockets
[0].name
);
13 chrome
.test
.assertEq(false, sockets
[0].paused
);
14 chrome
.test
.assertEq(true, sockets
[0].connected
);
15 chrome
.test
.assertEq(address
, sockets
[0].address
);
16 chrome
.test
.assertEq(uuid
, sockets
[0].uuid
);
18 chrome
.test
.succeed();
21 function startTests() {
22 chrome
.test
.runTests([testConnect
]);
25 function expectError(message
) {
26 if (!chrome
.runtime
.lastError
) {
27 chrome
.test
.fail("Expected an error");
29 chrome
.test
.assertEq(message
, chrome
.runtime
.lastError
.message
);
32 function failOnError() {
33 if (chrome
.runtime
.lastError
) {
34 chrome
.test
.fail(chrome
.runtime
.lastError
.message
);
38 function createConnectedSocket(address
, uuid
, callback
) {
39 chrome
.bluetoothSocket
.create(
42 chrome
.bluetoothSocket
.connect(
43 socket
.socketId
, address
, uuid
,
50 function runSocketErrorTests(callback
) {
51 chrome
.bluetoothSocket
.connect(1234, address
, uuid
,
53 expectError("Socket not found");
55 createConnectedSocket('aa:aa:aa:aa:aa:aa', uuid
,
57 expectError("Device not found");
59 createConnectedSocket(address
, 'not a valid uuid',
61 expectError("Invalid UUID");
63 createConnectedSocket(address
, '1234',
65 expectError("Permission denied");
74 createConnectedSocket(address
, uuid
,
78 // Make sure that the socket appears in the sockets list.
79 chrome
.bluetoothSocket
.getSockets(
83 socketId
= socket
.socketId
;
85 // Run some error checks.
88 chrome
.bluetoothSocket
.disconnect(socket
.socketId
);
89 chrome
.test
.sendMessage('ready', startTests
);