| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/proximity_auth/remote_device_loader.h" | 5 #include "components/proximity_auth/remote_device_loader.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "components/proximity_auth/cryptauth/fake_secure_message_delegate.h" | 14 #include "components/cryptauth/fake_secure_message_delegate.h" |
| 15 #include "components/proximity_auth/proximity_auth_pref_manager.h" | 15 #include "components/proximity_auth/proximity_auth_pref_manager.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 namespace proximity_auth { | 19 namespace proximity_auth { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // Prefixes for RemoteDevice fields. | 22 // Prefixes for RemoteDevice fields. |
| 23 const char kDeviceNamePrefix[] = "device"; | 23 const char kDeviceNamePrefix[] = "device"; |
| 24 const char kPublicKeyPrefix[] = "pk"; | 24 const char kPublicKeyPrefix[] = "pk"; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 47 ~MockProximityAuthPrefManager() override {} | 47 ~MockProximityAuthPrefManager() override {} |
| 48 | 48 |
| 49 MOCK_CONST_METHOD1(GetDeviceAddress, std::string(const std::string&)); | 49 MOCK_CONST_METHOD1(GetDeviceAddress, std::string(const std::string&)); |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 } // namespace | 52 } // namespace |
| 53 | 53 |
| 54 class ProximityAuthRemoteDeviceLoaderTest : public testing::Test { | 54 class ProximityAuthRemoteDeviceLoaderTest : public testing::Test { |
| 55 public: | 55 public: |
| 56 ProximityAuthRemoteDeviceLoaderTest() | 56 ProximityAuthRemoteDeviceLoaderTest() |
| 57 : secure_message_delegate_(new FakeSecureMessageDelegate()), | 57 : secure_message_delegate_(new cryptauth::FakeSecureMessageDelegate()), |
| 58 user_private_key_(secure_message_delegate_->GetPrivateKeyForPublicKey( | 58 user_private_key_(secure_message_delegate_->GetPrivateKeyForPublicKey( |
| 59 kUserPublicKey)), | 59 kUserPublicKey)), |
| 60 pref_manager_(new MockProximityAuthPrefManager()) {} | 60 pref_manager_(new MockProximityAuthPrefManager()) {} |
| 61 | 61 |
| 62 ~ProximityAuthRemoteDeviceLoaderTest() {} | 62 ~ProximityAuthRemoteDeviceLoaderTest() {} |
| 63 | 63 |
| 64 void OnRemoteDevicesLoaded(const std::vector<RemoteDevice>& remote_devices) { | 64 void OnRemoteDevicesLoaded(const std::vector<RemoteDevice>& remote_devices) { |
| 65 remote_devices_ = remote_devices; | 65 remote_devices_ = remote_devices; |
| 66 LoadCompleted(); | 66 LoadCompleted(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 MOCK_METHOD0(LoadCompleted, void()); | 69 MOCK_METHOD0(LoadCompleted, void()); |
| 70 | 70 |
| 71 protected: | 71 protected: |
| 72 // Handles deriving the PSK. Ownership will be passed to the | 72 // Handles deriving the PSK. Ownership will be passed to the |
| 73 // RemoteDeviceLoader under test. | 73 // RemoteDeviceLoader under test. |
| 74 std::unique_ptr<FakeSecureMessageDelegate> secure_message_delegate_; | 74 std::unique_ptr<cryptauth::FakeSecureMessageDelegate> |
| 75 secure_message_delegate_; |
| 75 | 76 |
| 76 // The private key of the user local device. | 77 // The private key of the user local device. |
| 77 std::string user_private_key_; | 78 std::string user_private_key_; |
| 78 | 79 |
| 79 // Stores the result of the RemoteDeviceLoader. | 80 // Stores the result of the RemoteDeviceLoader. |
| 80 std::vector<RemoteDevice> remote_devices_; | 81 std::vector<RemoteDevice> remote_devices_; |
| 81 | 82 |
| 82 // Stores the bluetooth address for BLE devices. | 83 // Stores the bluetooth address for BLE devices. |
| 83 std::unique_ptr<MockProximityAuthPrefManager> pref_manager_; | 84 std::unique_ptr<MockProximityAuthPrefManager> pref_manager_; |
| 84 | 85 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 for (size_t i = 0; i < 3; ++i) { | 168 for (size_t i = 0; i < 3; ++i) { |
| 168 EXPECT_FALSE(remote_devices_[i].persistent_symmetric_key.empty()); | 169 EXPECT_FALSE(remote_devices_[i].persistent_symmetric_key.empty()); |
| 169 EXPECT_EQ(unlock_keys[i].friendly_device_name(), remote_devices_[i].name); | 170 EXPECT_EQ(unlock_keys[i].friendly_device_name(), remote_devices_[i].name); |
| 170 EXPECT_EQ(unlock_keys[i].public_key(), remote_devices_[i].public_key); | 171 EXPECT_EQ(unlock_keys[i].public_key(), remote_devices_[i].public_key); |
| 171 EXPECT_EQ(unlock_keys[i].bluetooth_address(), | 172 EXPECT_EQ(unlock_keys[i].bluetooth_address(), |
| 172 remote_devices_[i].bluetooth_address); | 173 remote_devices_[i].bluetooth_address); |
| 173 } | 174 } |
| 174 } | 175 } |
| 175 | 176 |
| 176 } // namespace proximity_auth | 177 } // namespace proximity_auth |
| OLD | NEW |