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

Unified Diff: chrome/test/data/extensions/api_test/bluetooth/device_events/runtest.js

Issue 177113013: Bluetooth: add Device events, and cleanup JS API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@arman-patch
Patch Set: Created 6 years, 10 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/device_events/runtest.js
diff --git a/chrome/test/data/extensions/api_test/bluetooth/device_events/runtest.js b/chrome/test/data/extensions/api_test/bluetooth/device_events/runtest.js
new file mode 100644
index 0000000000000000000000000000000000000000..603c33f09046567b6b007b6afd0596f4299cad54
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/bluetooth/device_events/runtest.js
@@ -0,0 +1,44 @@
+// Copyright (c) 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 kExpectedDeviceNames = {
+ "21:22:23:24:25:26": "the real d2",
+ "31:32:33:34:35:36": "d3"
+};
+
+function testDeviceEvents() {
+ var expectedAddresses = Object.keys(kExpectedDeviceNames);
+ chrome.test.assertEq(expectedAddresses.length, Object.keys(devices).length);
+
+ for (var i = 0; i < expectedAddresses.length; ++i) {
+ var address = expectedAddresses[i];
+ chrome.test.assertTrue(address in devices);
+ chrome.test.assertEq(kExpectedDeviceNames[address], devices[address].name);
+ }
+
+ chrome.test.succeed();
+}
+
+function startTests() {
+ chrome.test.runTests([testDeviceEvents]);
+}
+
+var devices = {};
+function recordDevice(device) {
+ devices[device.address] = device;
+}
+function removeDevice(device) {
+ delete devices[device.address];
+ chrome.test.sendMessage('ready', startTests);
+}
+
+function stopDiscoveryAndContinue() {
+ chrome.bluetooth.stopDiscovery();
+ chrome.bluetooth.onDeviceAdded.removeListener(recordDevice);
+ sendReady(startTests);
+}
+
+chrome.bluetooth.onDeviceAdded.addListener(recordDevice);
+chrome.bluetooth.onDeviceChanged.addListener(recordDevice);
+chrome.bluetooth.onDeviceRemoved.addListener(removeDevice);

Powered by Google App Engine
This is Rietveld 408576698