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

Unified Diff: content/browser/bluetooth/bluetooth_allowed_devices_map_unittest.cc

Issue 1502663003: bluetooth: Implement allowed devices map (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Forgot test file Created 5 years 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: content/browser/bluetooth/bluetooth_allowed_devices_map_unittest.cc
diff --git a/content/browser/bluetooth/bluetooth_allowed_devices_map_unittest.cc b/content/browser/bluetooth/bluetooth_allowed_devices_map_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..03f48a2274958f593019b373549db64ee036af26
--- /dev/null
+++ b/content/browser/bluetooth/bluetooth_allowed_devices_map_unittest.cc
@@ -0,0 +1,77 @@
+// Copyright 2015 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.
+
+#include "content/browser/bluetooth/bluetooth_allowed_devices_map.h"
+
+#include "content/common/bluetooth/bluetooth_scan_filter.h"
+#include "device/bluetooth/bluetooth_uuid.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace content {
+namespace {
+const std::string& test_origin1 = "test_origin1";
+const std::string& test_origin2 = "test_origin2";
+
+const std::string& device_address1 = "00:00:00";
+const std::string& device_address2 = "11:11:11";
+
+const std::vector<content::BluetoothScanFilter> filters =
+ std::vector<BluetoothScanFilter>();
+const std::vector<device::BluetoothUUID> optional_services =
+ std::vector<device::BluetoothUUID>();
+} // namespace
+
+class BluetoothAllowedDevicesMapTest : public testing::Test {};
Jeffrey Yasskin 2016/01/06 00:47:57 Could you add tests that: 1) A device added to the
ortuno 2016/01/13 01:41:44 Done.
+
+TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceToMap) {
+ // Test that a device is correctly added to the map.
Jeffrey Yasskin 2016/01/06 00:47:57 This comment is probably unnecessary. The test nam
ortuno 2016/01/13 01:41:44 Done.
+
+ BluetoothAllowedDevicesMap allowed_devices_map;
+
+ const std::string& device_id = allowed_devices_map.AddDevice(
+ test_origin1, device_address1, filters, optional_services);
+
+ // Test that the origin is allowed to use the device.
+ EXPECT_TRUE(allowed_devices_map.HasDevicePermissionFromDeviceAddress(
+ test_origin1, device_address1));
+ EXPECT_TRUE(allowed_devices_map.HasDevicePermissionFromDeviceId(test_origin1,
+ device_id));
+
+ // Test that we can retrieve the device address/id.
+ EXPECT_EQ(device_id,
+ allowed_devices_map.GetDeviceId(test_origin1, device_address1));
+ EXPECT_EQ(device_address1,
+ allowed_devices_map.GetDeviceAddress(test_origin1, device_id));
+}
+
+TEST_F(BluetoothAllowedDevicesMapTest, RemoveDeviceFromMap) {
+ // Test that a device is correctly removed from map.
+
+ BluetoothAllowedDevicesMap allowed_devices_map;
+
+ const std::string& device_id = allowed_devices_map.AddDevice(
+ test_origin1, device_address1, filters, optional_services);
+
+ allowed_devices_map.RemoveDevice(test_origin1, device_address1);
+
+ EXPECT_FALSE(allowed_devices_map.HasDevicePermissionFromDeviceAddress(
+ test_origin1, device_address1));
+ EXPECT_FALSE(allowed_devices_map.HasDevicePermissionFromDeviceId(test_origin1,
+ device_id));
+}
+
+TEST_F(BluetoothAllowedDevicesMapTest, CorrectIdFormat) {
+ // Test that the generated if has the correct format
Jeffrey Yasskin 2016/01/06 00:47:57 s/if/id/?
ortuno 2016/01/13 01:41:44 Removed comment.
+ BluetoothAllowedDevicesMap allowed_devices_map;
+
+ const std::string& device_id = allowed_devices_map.AddDevice(
+ test_origin1, device_address1, filters, optional_services);
+
+ EXPECT_TRUE(device_id.size() == 24)
+ << "Expected Lenghth of a 128bit string encoded to Base64.";
+ EXPECT_TRUE((device_id[22] == '=') && (device_id[23] == '='))
+ << "Expected padding characters for a 128bit string encoded to Base64.";
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698