Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / extensions / test / data / api_test / bluetooth_socket / connect / runtest.js
blob90286a92c96389694eb71b3a448f5e8ac11090ed
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(
40 function(socket) {
41 failOnError();
42 chrome.bluetoothSocket.connect(
43 socket.socketId, address, uuid,
44 function() {
45 callback(socket);
46 });
47 });
50 function runSocketErrorTests(callback) {
51 chrome.bluetoothSocket.connect(1234, address, uuid,
52 function() {
53 expectError("Socket not found");
55 createConnectedSocket('aa:aa:aa:aa:aa:aa', uuid,
56 function(socket) {
57 expectError("Device not found");
59 createConnectedSocket(address, 'not a valid uuid',
60 function(socket) {
61 expectError("Invalid UUID");
63 createConnectedSocket(address, '1234',
64 function(socket) {
65 expectError("Permission denied");
67 callback();
68 });
69 });
70 });
71 });
74 createConnectedSocket(address, uuid,
75 function(socket) {
76 failOnError();
78 // Make sure that the socket appears in the sockets list.
79 chrome.bluetoothSocket.getSockets(
80 function(result) {
81 failOnError();
82 sockets = result;
83 socketId = socket.socketId;
85 // Run some error checks.
86 runSocketErrorTests(
87 function() {
88 chrome.bluetoothSocket.disconnect(socket.socketId);
89 chrome.test.sendMessage('ready', startTests);
90 });
91 });
92 });