diff options
author | jamescook <jamescook@chromium.org> | 2015-02-06 11:57:19 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-06 19:57:53 +0000 |
commit | 49fec4b43edc61f40fe8574921e6a26509452dc8 (patch) | |
tree | b96a931c7eebbe1a3718c34750c0d0c7f0fae952 /extensions/test | |
parent | 34f8293d798313b84fd29ca804a8c50a797dc55f (diff) | |
download | chromium_src-49fec4b43edc61f40fe8574921e6a26509452dc8.zip chromium_src-49fec4b43edc61f40fe8574921e6a26509452dc8.tar.gz chromium_src-49fec4b43edc61f40fe8574921e6a26509452dc8.tar.bz2 |
Move BluetoothSocketApiTest into extensions_browsertests
It doesn't need to run in Chrome's browser_tests.
BUG=388893
TEST=browser_tests and extensions_browsertests for Bluetooth*
Review URL: https://codereview.chromium.org/902213002
Cr-Commit-Position: refs/heads/master@{#315090}
Diffstat (limited to 'extensions/test')
6 files changed, 284 insertions, 0 deletions
diff --git a/extensions/test/data/api_test/bluetooth_socket/connect/manifest.json b/extensions/test/data/api_test/bluetooth_socket/connect/manifest.json new file mode 100644 index 0000000..f067c87 --- /dev/null +++ b/extensions/test/data/api_test/bluetooth_socket/connect/manifest.json @@ -0,0 +1,18 @@ +{ + "manifest_version": 2, + "name": "Test Bluetooth Socket Connect Function", + "version": "1.0", + "description": "Tests chrome.bluetoothSocket.connect Function", + "app": { + "background": { + "scripts": ["runtest.js"] + } + }, + "bluetooth": { + "uuids": [ + "8e3ad063-db38-4289-aa8f-b30e4223cf40" + ], + "socket": true + }, + "key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqbc71rRrqz+62pGVmZGDzTK8P4IHTTyN4jBLBJasDTrRllQp4Pb6INnSr08HQM3aaZMYKWkAJTm4gbCDNzvHfIZMAMY6OZfnm0eqiZnxFFgKgIzdr4Z/EyAXVd1Rm1JKhncde2S/U3zWStDb5iYfWZJBIiWVT98q7cW6sstsMOmrHAIAKCzK+mzycFptlRWzAf+8NR9bq1jNZe+h1kJBgY0xnVlGZm+NIhZd/Ke8Y+G2vM4rtuDvp5971HVV294HD28hWbsoOqBf85gPa6tKE57FhLomi/aJVBVBiCfHExXjK1hB2QeM/r7e8P//ZZPoYszSzHJVBw/heRLFOMezIwIDAQAB" +} diff --git a/extensions/test/data/api_test/bluetooth_socket/connect/runtest.js b/extensions/test/data/api_test/bluetooth_socket/connect/runtest.js new file mode 100644 index 0000000..90286a9 --- /dev/null +++ b/extensions/test/data/api_test/bluetooth_socket/connect/runtest.js @@ -0,0 +1,92 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +var address = '11:12:13:14:15:16'; +var uuid = '8e3ad063-db38-4289-aa8f-b30e4223cf40'; + +function testConnect() { + chrome.test.assertEq(1, sockets.length); + chrome.test.assertEq(socketId, sockets[0].socketId); + chrome.test.assertEq(false, sockets[0].persistent); + chrome.test.assertEq(undefined, sockets[0].name); + chrome.test.assertEq(false, sockets[0].paused); + chrome.test.assertEq(true, sockets[0].connected); + chrome.test.assertEq(address, sockets[0].address); + chrome.test.assertEq(uuid, sockets[0].uuid); + + chrome.test.succeed(); +} + +function startTests() { + chrome.test.runTests([testConnect]); +} + +function expectError(message) { + if (!chrome.runtime.lastError) { + chrome.test.fail("Expected an error"); + } + chrome.test.assertEq(message, chrome.runtime.lastError.message); +} + +function failOnError() { + if (chrome.runtime.lastError) { + chrome.test.fail(chrome.runtime.lastError.message); + } +} + +function createConnectedSocket(address, uuid, callback) { + chrome.bluetoothSocket.create( + function(socket) { + failOnError(); + chrome.bluetoothSocket.connect( + socket.socketId, address, uuid, + function() { + callback(socket); + }); + }); +} + +function runSocketErrorTests(callback) { + chrome.bluetoothSocket.connect(1234, address, uuid, + function() { + expectError("Socket not found"); + + createConnectedSocket('aa:aa:aa:aa:aa:aa', uuid, + function(socket) { + expectError("Device not found"); + + createConnectedSocket(address, 'not a valid uuid', + function(socket) { + expectError("Invalid UUID"); + + createConnectedSocket(address, '1234', + function(socket) { + expectError("Permission denied"); + + callback(); + }); + }); + }); + }); +} + +createConnectedSocket(address, uuid, + function(socket) { + failOnError(); + + // Make sure that the socket appears in the sockets list. + chrome.bluetoothSocket.getSockets( + function(result) { + failOnError(); + sockets = result; + socketId = socket.socketId; + + // Run some error checks. + runSocketErrorTests( + function() { + chrome.bluetoothSocket.disconnect(socket.socketId); + chrome.test.sendMessage('ready', startTests); + }); + }); + }); diff --git a/extensions/test/data/api_test/bluetooth_socket/listen/manifest.json b/extensions/test/data/api_test/bluetooth_socket/listen/manifest.json new file mode 100644 index 0000000..7df7f5a --- /dev/null +++ b/extensions/test/data/api_test/bluetooth_socket/listen/manifest.json @@ -0,0 +1,18 @@ +{ + "manifest_version": 2, + "name": "Test Bluetooth Socket RFCOMM Listen Function", + "version": "1.0", + "description": "Tests chrome.bluetoothSocket.listenUsingRfcomm Function", + "app": { + "background": { + "scripts": ["runtest.js"] + } + }, + "bluetooth": { + "uuids": [ + "2de497f9-ab28-49db-b6d2-066ea69f1737" + ], + "socket": true + }, + "key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqbc71rRrqz+62pGVmZGDzTK8P4IHTTyN4jBLBJasDTrRllQp4Pb6INnSr08HQM3aaZMYKWkAJTm4gbCDNzvHfIZMAMY6OZfnm0eqiZnxFFgKgIzdr4Z/EyAXVd1Rm1JKhncde2S/U3zWStDb5iYfWZJBIiWVT98q7cW6sstsMOmrHAIAKCzK+mzycFptlRWzAf+8NR9bq1jNZe+h1kJBgY0xnVlGZm+NIhZd/Ke8Y+G2vM4rtuDvp5971HVV294HD28hWbsoOqBf85gPa6tKE57FhLomi/aJVBVBiCfHExXjK1hB2QeM/r7e8P//ZZPoYszSzHJVBw/heRLFOMezIwIDAQAB" +} diff --git a/extensions/test/data/api_test/bluetooth_socket/listen/runtest.js b/extensions/test/data/api_test/bluetooth_socket/listen/runtest.js new file mode 100644 index 0000000..63a05af --- /dev/null +++ b/extensions/test/data/api_test/bluetooth_socket/listen/runtest.js @@ -0,0 +1,131 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +var uuid = '2de497f9-ab28-49db-b6d2-066ea69f1737'; +var clientAddress = '11:12:13:14:15:16'; + +function testListen() { + chrome.test.assertEq(2, sockets.length); + + // First socket should be the listening one. + chrome.test.assertEq(serverSocketId, sockets[0].socketId); + chrome.test.assertEq(false, sockets[0].persistent); + chrome.test.assertEq('MyServiceName', sockets[0].name); + chrome.test.assertEq(false, sockets[0].paused); + chrome.test.assertEq(false, sockets[0].connected); + chrome.test.assertEq(undefined, sockets[0].address); + chrome.test.assertEq(uuid, sockets[0].uuid); + + // Second socket should be the client one, which unlike the server should + // be created paused. + chrome.test.assertEq(clientSocketId, sockets[1].socketId); + chrome.test.assertEq(false, sockets[1].persistent); + chrome.test.assertEq(undefined, sockets[1].name); + chrome.test.assertEq(true, sockets[1].paused); + chrome.test.assertEq(true, sockets[1].connected); + chrome.test.assertEq(clientAddress, sockets[1].address); + chrome.test.assertEq(uuid, sockets[1].uuid); + + chrome.test.succeed(); +} + +function startTests() { + chrome.test.runTests([testListen]); +} + +function expectError(message) { + if (!chrome.runtime.lastError) { + chrome.test.fail("Expected an error"); + } + chrome.test.assertEq(message, chrome.runtime.lastError.message); +} + +function failOnError() { + if (chrome.runtime.lastError) { + chrome.test.fail(chrome.runtime.lastError.message); + } +} + +function secondStage() { + chrome.bluetoothSocket.getSockets( + function(result) { + failOnError(); + sockets = result; + + chrome.bluetoothSocket.disconnect(serverSocketId); + chrome.bluetoothSocket.disconnect(clientSocketId); + + // Check for error conditions. + chrome.bluetoothSocket.listenUsingRfcomm( + 1234, uuid, + function() { + expectError("Socket not found"); + + chrome.bluetoothSocket.create( + function(socket) { + failOnError(); + chrome.bluetoothSocket.listenUsingRfcomm( + socket.socketId, 'not a valid uuid', + function() { + expectError("Invalid UUID"); + + chrome.bluetoothSocket.listenUsingRfcomm( + socket.socketId, '1234', + function() { + expectError("Permission denied"); + + chrome.bluetoothSocket.listenUsingL2cap( + socket.socketId, uuid, {'psm': 1234}, + function() { + expectError("Invalid PSM"); + + chrome.bluetoothSocket.listenUsingL2cap( + socket.socketId, uuid, {'psm': 4369}, + function() { + expectError("Invalid PSM"); + + chrome.bluetoothSocket.listenUsingL2cap( + socket.socketId, uuid, {'psm': 13}, + function() { + expectError("Invalid PSM"); + + chrome.test.sendMessage( + 'ready', startTests); + }); + }); + }); + }); + }); + }); + }); + }); +} + +chrome.bluetoothSocket.create( + {'name': 'MyServiceName'}, + function(socket) { + failOnError(); + + serverSocketId = socket.socketId; + + chrome.bluetoothSocket.onAccept.addListener( + function(info) { + if (info.socketId != socket.socketId) + return; + + clientSocketId = info.clientSocketId; + }); + chrome.bluetoothSocket.onAcceptError.addListener( + function(error_info) { + chrome.test.fail(error_info.errorMessage); + }); + + chrome.bluetoothSocket.listenUsingRfcomm( + socket.socketId, uuid, + function() { + failOnError(); + + chrome.test.sendMessage('ready', secondStage); + }); + }); diff --git a/extensions/test/data/api_test/bluetooth_socket/permission_denied/manifest.json b/extensions/test/data/api_test/bluetooth_socket/permission_denied/manifest.json new file mode 100644 index 0000000..729f8d0 --- /dev/null +++ b/extensions/test/data/api_test/bluetooth_socket/permission_denied/manifest.json @@ -0,0 +1,13 @@ +{ + "manifest_version": 2, + "name": "Test Bluetooth Socket without manifest permission", + "version": "1.0", + "description": "Tests chrome.bluetoothSocket API doesn't function without permission", + "app": { + "background": { + "scripts": ["runtest.js"] + } + }, + "bluetooth": { }, + "key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqbc71rRrqz+62pGVmZGDzTK8P4IHTTyN4jBLBJasDTrRllQp4Pb6INnSr08HQM3aaZMYKWkAJTm4gbCDNzvHfIZMAMY6OZfnm0eqiZnxFFgKgIzdr4Z/EyAXVd1Rm1JKhncde2S/U3zWStDb5iYfWZJBIiWVT98q7cW6sstsMOmrHAIAKCzK+mzycFptlRWzAf+8NR9bq1jNZe+h1kJBgY0xnVlGZm+NIhZd/Ke8Y+G2vM4rtuDvp5971HVV294HD28hWbsoOqBf85gPa6tKE57FhLomi/aJVBVBiCfHExXjK1hB2QeM/r7e8P//ZZPoYszSzHJVBw/heRLFOMezIwIDAQAB" +} diff --git a/extensions/test/data/api_test/bluetooth_socket/permission_denied/runtest.js b/extensions/test/data/api_test/bluetooth_socket/permission_denied/runtest.js new file mode 100644 index 0000000..7b0f1d8 --- /dev/null +++ b/extensions/test/data/api_test/bluetooth_socket/permission_denied/runtest.js @@ -0,0 +1,12 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +chrome.bluetoothSocket.create( + function(socket) { + if (!chrome.runtime.lastError) { + chrome.test.fail("Expected an error"); + } + chrome.test.assertEq("Permission denied", chrome.runtime.lastError.message); + chrome.test.succeed(); + }); |