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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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.
4
5 #include "content/browser/bluetooth/bluetooth_allowed_devices_map.h"
6
7 #include "content/common/bluetooth/bluetooth_scan_filter.h"
8 #include "device/bluetooth/bluetooth_uuid.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace content {
12 namespace {
13 const std::string& test_origin1 = "test_origin1";
14 const std::string& test_origin2 = "test_origin2";
15
16 const std::string& device_address1 = "00:00:00";
17 const std::string& device_address2 = "11:11:11";
18
19 const std::vector<content::BluetoothScanFilter> filters =
20 std::vector<BluetoothScanFilter>();
21 const std::vector<device::BluetoothUUID> optional_services =
22 std::vector<device::BluetoothUUID>();
23 } // namespace
24
25 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.
26
27 TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceToMap) {
28 // 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.
29
30 BluetoothAllowedDevicesMap allowed_devices_map;
31
32 const std::string& device_id = allowed_devices_map.AddDevice(
33 test_origin1, device_address1, filters, optional_services);
34
35 // Test that the origin is allowed to use the device.
36 EXPECT_TRUE(allowed_devices_map.HasDevicePermissionFromDeviceAddress(
37 test_origin1, device_address1));
38 EXPECT_TRUE(allowed_devices_map.HasDevicePermissionFromDeviceId(test_origin1,
39 device_id));
40
41 // Test that we can retrieve the device address/id.
42 EXPECT_EQ(device_id,
43 allowed_devices_map.GetDeviceId(test_origin1, device_address1));
44 EXPECT_EQ(device_address1,
45 allowed_devices_map.GetDeviceAddress(test_origin1, device_id));
46 }
47
48 TEST_F(BluetoothAllowedDevicesMapTest, RemoveDeviceFromMap) {
49 // Test that a device is correctly removed from map.
50
51 BluetoothAllowedDevicesMap allowed_devices_map;
52
53 const std::string& device_id = allowed_devices_map.AddDevice(
54 test_origin1, device_address1, filters, optional_services);
55
56 allowed_devices_map.RemoveDevice(test_origin1, device_address1);
57
58 EXPECT_FALSE(allowed_devices_map.HasDevicePermissionFromDeviceAddress(
59 test_origin1, device_address1));
60 EXPECT_FALSE(allowed_devices_map.HasDevicePermissionFromDeviceId(test_origin1,
61 device_id));
62 }
63
64 TEST_F(BluetoothAllowedDevicesMapTest, CorrectIdFormat) {
65 // 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.
66 BluetoothAllowedDevicesMap allowed_devices_map;
67
68 const std::string& device_id = allowed_devices_map.AddDevice(
69 test_origin1, device_address1, filters, optional_services);
70
71 EXPECT_TRUE(device_id.size() == 24)
72 << "Expected Lenghth of a 128bit string encoded to Base64.";
73 EXPECT_TRUE((device_id[22] == '=') && (device_id[23] == '='))
74 << "Expected padding characters for a 128bit string encoded to Base64.";
75 }
76
77 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698