Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(498)

Unified Diff: chrome/test/data/extensions/api_test/bluetooth_socket/listen/runtest.js

Issue 278663002: Implement chrome.bluetoothSocket.listenUsing*() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix BluetoothAdapterMac include typo Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/bluetooth_socket/listen/runtest.js
diff --git a/chrome/test/data/extensions/api_test/bluetooth_socket/listen/runtest.js b/chrome/test/data/extensions/api_test/bluetooth_socket/listen/runtest.js
new file mode 100644
index 0000000000000000000000000000000000000000..1de1e414dd8ff03ece15d608a2f9ee276b963db7
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/bluetooth_socket/listen/runtest.js
@@ -0,0 +1,111 @@
+// 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(undefined, 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, 0,
+ function() {
+ expectError("Socket not found");
+
+ chrome.bluetoothSocket.create(
+ function(socket) {
+ failOnError();
+ chrome.bluetoothSocket.listenUsingRfcomm(
+ socket.socketId, 'not a valid uuid', 0,
+ function() {
+ expectError("Invalid UUID");
+
+ chrome.bluetoothSocket.listenUsingRfcomm(
+ socket.socketId, '1234', 0,
+ function() {
+ expectError("Permission denied");
+
+ chrome.test.sendMessage('ready', startTests);
+ });
+ });
+ });
+ });
+ });
+}
+
+chrome.bluetoothSocket.create(
+ 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, 0,
+ function() {
+ failOnError();
+
+ chrome.test.sendMessage('ready', secondStage);
+ });
+ });

Powered by Google App Engine
This is Rietveld 408576698