Commit 909633fc authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Commit Bot

[CrOS Nearby] Move mock classes to //chromeos/services/nearby

These classes were in //chrome, making them inaccessible to tests that
are not also in //chrome due to dependency issues. This CL moves them to
//chromeos/services/nearby, alongside their associated .mojom
definitions. These mocks are used in a follow-up CL to implement tests.

This CL also initializes a SharedRemote associated with these classes
and a getter to retrieve a reference to the SharedRemote.

Bug: 1130069
Change-Id: I1bb87403a64a17c5b6f4da1b9f9daaf3ce414d64
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2464844Reviewed-by: default avatarJames Vecore <vecore@google.com>
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816606}
parent 909a9a4c
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/nearby_sharing/fake_nearby_connection.h" #include "chrome/browser/nearby_sharing/fake_nearby_connection.h"
#include "chrome/browser/nearby_sharing/mock_nearby_process_manager.h" #include "chrome/browser/nearby_sharing/mock_nearby_process_manager.h"
#include "chrome/browser/nearby_sharing/mock_nearby_sharing_decoder.h"
#include "chrome/services/sharing/public/proto/wire_format.pb.h" #include "chrome/services/sharing/public/proto/wire_format.pb.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "chromeos/services/nearby/public/cpp/mock_nearby_sharing_decoder.h"
#include "content/public/test/browser_task_environment.h" #include "content/public/test/browser_task_environment.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -78,7 +78,7 @@ class IncomingFramesReaderTest : public testing::Test { ...@@ -78,7 +78,7 @@ class IncomingFramesReaderTest : public testing::Test {
FakeNearbyConnection& connection() { return mock_nearby_connection_; } FakeNearbyConnection& connection() { return mock_nearby_connection_; }
testing::StrictMock<MockNearbySharingDecoder>& decoder() { testing::StrictMock<chromeos::nearby::MockNearbySharingDecoder>& decoder() {
return mock_decoder_; return mock_decoder_;
} }
...@@ -89,7 +89,7 @@ class IncomingFramesReaderTest : public testing::Test { ...@@ -89,7 +89,7 @@ class IncomingFramesReaderTest : public testing::Test {
TestingProfile profile_; TestingProfile profile_;
FakeNearbyConnection mock_nearby_connection_; FakeNearbyConnection mock_nearby_connection_;
testing::StrictMock<MockNearbyProcessManager> mock_process_manager_; testing::StrictMock<MockNearbyProcessManager> mock_process_manager_;
testing::StrictMock<MockNearbySharingDecoder> mock_decoder_; testing::StrictMock<chromeos::nearby::MockNearbySharingDecoder> mock_decoder_;
IncomingFramesReader frames_reader_; IncomingFramesReader frames_reader_;
}; };
...@@ -116,7 +116,8 @@ TEST_F(IncomingFramesReaderTest, ReadAnyFrameSuccessful) { ...@@ -116,7 +116,8 @@ TEST_F(IncomingFramesReaderTest, ReadAnyFrameSuccessful) {
DecodeFrame(testing::Eq(introduction_frame), testing::_)) DecodeFrame(testing::Eq(introduction_frame), testing::_))
.WillOnce(testing::Invoke( .WillOnce(testing::Invoke(
[&](const std::vector<uint8_t>& data, [&](const std::vector<uint8_t>& data,
MockNearbySharingDecoder::DecodeFrameCallback callback) { chromeos::nearby::MockNearbySharingDecoder::DecodeFrameCallback
callback) {
sharing::mojom::V1FramePtr mojo_v1frame = sharing::mojom::V1FramePtr mojo_v1frame =
sharing::mojom::V1Frame::New(); sharing::mojom::V1Frame::New();
mojo_v1frame->set_introduction( mojo_v1frame->set_introduction(
...@@ -144,7 +145,8 @@ TEST_F(IncomingFramesReaderTest, ReadSuccessful) { ...@@ -144,7 +145,8 @@ TEST_F(IncomingFramesReaderTest, ReadSuccessful) {
DecodeFrame(testing::Eq(introduction_frame), testing::_)) DecodeFrame(testing::Eq(introduction_frame), testing::_))
.WillOnce(testing::Invoke( .WillOnce(testing::Invoke(
[&](const std::vector<uint8_t>& data, [&](const std::vector<uint8_t>& data,
MockNearbySharingDecoder::DecodeFrameCallback callback) { chromeos::nearby::MockNearbySharingDecoder::DecodeFrameCallback
callback) {
sharing::mojom::V1FramePtr mojo_v1frame = sharing::mojom::V1FramePtr mojo_v1frame =
sharing::mojom::V1Frame::New(); sharing::mojom::V1Frame::New();
mojo_v1frame->set_introduction( mojo_v1frame->set_introduction(
...@@ -177,7 +179,8 @@ TEST_F(IncomingFramesReaderTest, ReadSuccessful_JumbledFramesOrdering) { ...@@ -177,7 +179,8 @@ TEST_F(IncomingFramesReaderTest, ReadSuccessful_JumbledFramesOrdering) {
EXPECT_CALL(decoder(), DecodeFrame(testing::_, testing::_)) EXPECT_CALL(decoder(), DecodeFrame(testing::_, testing::_))
.WillOnce(testing::Invoke( .WillOnce(testing::Invoke(
[&](const std::vector<uint8_t>& data, [&](const std::vector<uint8_t>& data,
MockNearbySharingDecoder::DecodeFrameCallback callback) { chromeos::nearby::MockNearbySharingDecoder::DecodeFrameCallback
callback) {
EXPECT_EQ(cancel_frame, data); EXPECT_EQ(cancel_frame, data);
sharing::mojom::V1FramePtr mojo_v1frame = sharing::mojom::V1FramePtr mojo_v1frame =
sharing::mojom::V1Frame::New(); sharing::mojom::V1Frame::New();
...@@ -189,7 +192,8 @@ TEST_F(IncomingFramesReaderTest, ReadSuccessful_JumbledFramesOrdering) { ...@@ -189,7 +192,8 @@ TEST_F(IncomingFramesReaderTest, ReadSuccessful_JumbledFramesOrdering) {
})) }))
.WillOnce(testing::Invoke( .WillOnce(testing::Invoke(
[&](const std::vector<uint8_t>& data, [&](const std::vector<uint8_t>& data,
MockNearbySharingDecoder::DecodeFrameCallback callback) { chromeos::nearby::MockNearbySharingDecoder::DecodeFrameCallback
callback) {
EXPECT_EQ(introduction_frame, data); EXPECT_EQ(introduction_frame, data);
sharing::mojom::V1FramePtr mojo_v1frame = sharing::mojom::V1FramePtr mojo_v1frame =
sharing::mojom::V1Frame::New(); sharing::mojom::V1Frame::New();
...@@ -223,7 +227,8 @@ TEST_F(IncomingFramesReaderTest, JumbledFramesOrdering_ReadFromCache) { ...@@ -223,7 +227,8 @@ TEST_F(IncomingFramesReaderTest, JumbledFramesOrdering_ReadFromCache) {
EXPECT_CALL(decoder(), DecodeFrame(testing::_, testing::_)) EXPECT_CALL(decoder(), DecodeFrame(testing::_, testing::_))
.WillOnce(testing::Invoke( .WillOnce(testing::Invoke(
[&](const std::vector<uint8_t>& data, [&](const std::vector<uint8_t>& data,
MockNearbySharingDecoder::DecodeFrameCallback callback) { chromeos::nearby::MockNearbySharingDecoder::DecodeFrameCallback
callback) {
EXPECT_EQ(cancel_frame, data); EXPECT_EQ(cancel_frame, data);
sharing::mojom::V1FramePtr mojo_v1frame = sharing::mojom::V1FramePtr mojo_v1frame =
sharing::mojom::V1Frame::New(); sharing::mojom::V1Frame::New();
...@@ -235,7 +240,8 @@ TEST_F(IncomingFramesReaderTest, JumbledFramesOrdering_ReadFromCache) { ...@@ -235,7 +240,8 @@ TEST_F(IncomingFramesReaderTest, JumbledFramesOrdering_ReadFromCache) {
})) }))
.WillOnce(testing::Invoke( .WillOnce(testing::Invoke(
[&](const std::vector<uint8_t>& data, [&](const std::vector<uint8_t>& data,
MockNearbySharingDecoder::DecodeFrameCallback callback) { chromeos::nearby::MockNearbySharingDecoder::DecodeFrameCallback
callback) {
EXPECT_EQ(introduction_frame, data); EXPECT_EQ(introduction_frame, data);
sharing::mojom::V1FramePtr mojo_v1frame = sharing::mojom::V1FramePtr mojo_v1frame =
sharing::mojom::V1Frame::New(); sharing::mojom::V1Frame::New();
......
...@@ -12,11 +12,11 @@ ...@@ -12,11 +12,11 @@
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
#include "base/test/mock_callback.h" #include "base/test/mock_callback.h"
#include "chrome/browser/nearby_sharing/constants.h" #include "chrome/browser/nearby_sharing/constants.h"
#include "chrome/browser/nearby_sharing/mock_nearby_connections.h"
#include "chrome/browser/nearby_sharing/mock_nearby_process_manager.h" #include "chrome/browser/nearby_sharing/mock_nearby_process_manager.h"
#include "chrome/browser/nearby_sharing/nearby_connection_impl.h" #include "chrome/browser/nearby_sharing/nearby_connection_impl.h"
#include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "chromeos/services/nearby/public/cpp/mock_nearby_connections.h"
#include "chromeos/services/nearby/public/mojom/nearby_connections_types.mojom.h" #include "chromeos/services/nearby/public/mojom/nearby_connections_types.mojom.h"
#include "content/public/test/browser_task_environment.h" #include "content/public/test/browser_task_environment.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
...@@ -363,7 +363,8 @@ class NearbyConnectionsManagerImplTest : public testing::Test { ...@@ -363,7 +363,8 @@ class NearbyConnectionsManagerImplTest : public testing::Test {
std::unique_ptr<net::test::MockNetworkChangeNotifier> network_notifier_ = std::unique_ptr<net::test::MockNetworkChangeNotifier> network_notifier_ =
net::test::MockNetworkChangeNotifier::Create(); net::test::MockNetworkChangeNotifier::Create();
base::ScopedDisallowBlocking disallow_blocking_; base::ScopedDisallowBlocking disallow_blocking_;
testing::NiceMock<MockNearbyConnections> nearby_connections_; testing::NiceMock<chromeos::nearby::MockNearbyConnections>
nearby_connections_;
testing::NiceMock<MockNearbyProcessManager> nearby_process_manager_; testing::NiceMock<MockNearbyProcessManager> nearby_process_manager_;
NearbyConnectionsManagerImpl nearby_connections_manager_{ NearbyConnectionsManagerImpl nearby_connections_manager_{
&nearby_process_manager_, &profile_}; &nearby_process_manager_, &profile_};
......
...@@ -16,13 +16,13 @@ ...@@ -16,13 +16,13 @@
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/nearby_sharing/common/nearby_share_prefs.h" #include "chrome/browser/nearby_sharing/common/nearby_share_prefs.h"
#include "chrome/browser/nearby_sharing/mock_nearby_connections.h"
#include "chrome/browser/nearby_sharing/mock_nearby_sharing_decoder.h"
#include "chrome/browser/profiles/profile_attributes_entry.h" #include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_attributes_storage.h" #include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h" #include "chrome/test/base/testing_profile_manager.h"
#include "chromeos/services/nearby/public/cpp/mock_nearby_connections.h"
#include "chromeos/services/nearby/public/cpp/mock_nearby_sharing_decoder.h"
#include "chromeos/services/nearby/public/mojom/nearby_connections.mojom.h" #include "chromeos/services/nearby/public/mojom/nearby_connections.mojom.h"
#include "chromeos/services/nearby/public/mojom/nearby_connections_types.mojom.h" #include "chromeos/services/nearby/public/mojom/nearby_connections_types.mojom.h"
#include "chromeos/services/nearby/public/mojom/nearby_decoder.mojom.h" #include "chromeos/services/nearby/public/mojom/nearby_decoder.mojom.h"
...@@ -57,8 +57,9 @@ class FakeSharingMojoService : public sharing::mojom::Sharing { ...@@ -57,8 +57,9 @@ class FakeSharingMojoService : public sharing::mojom::Sharing {
CreateNearbyConnectionsCallback callback) override { CreateNearbyConnectionsCallback callback) override {
dependencies_ = std::move(dependencies); dependencies_ = std::move(dependencies);
mojo::PendingRemote<NearbyConnectionsMojom> remote; mojo::PendingRemote<NearbyConnectionsMojom> remote;
mojo::MakeSelfOwnedReceiver(std::make_unique<MockNearbyConnections>(), mojo::MakeSelfOwnedReceiver(
remote.InitWithNewPipeAndPassReceiver()); std::make_unique<chromeos::nearby::MockNearbyConnections>(),
remote.InitWithNewPipeAndPassReceiver());
std::move(callback).Run(std::move(remote)); std::move(callback).Run(std::move(remote));
run_loop_connections.Quit(); run_loop_connections.Quit();
...@@ -67,8 +68,9 @@ class FakeSharingMojoService : public sharing::mojom::Sharing { ...@@ -67,8 +68,9 @@ class FakeSharingMojoService : public sharing::mojom::Sharing {
void CreateNearbySharingDecoder( void CreateNearbySharingDecoder(
CreateNearbySharingDecoderCallback callback) override { CreateNearbySharingDecoderCallback callback) override {
mojo::PendingRemote<NearbySharingDecoderMojom> remote; mojo::PendingRemote<NearbySharingDecoderMojom> remote;
mojo::MakeSelfOwnedReceiver(std::make_unique<MockNearbySharingDecoder>(), mojo::MakeSelfOwnedReceiver(
remote.InitWithNewPipeAndPassReceiver()); std::make_unique<chromeos::nearby::MockNearbySharingDecoder>(),
remote.InitWithNewPipeAndPassReceiver());
std::move(callback).Run(std::move(remote)); std::move(callback).Run(std::move(remote));
run_loop_decoder.Quit(); run_loop_decoder.Quit();
......
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include "chrome/browser/nearby_sharing/local_device_data/fake_nearby_share_local_device_data_manager.h" #include "chrome/browser/nearby_sharing/local_device_data/fake_nearby_share_local_device_data_manager.h"
#include "chrome/browser/nearby_sharing/local_device_data/nearby_share_local_device_data_manager_impl.h" #include "chrome/browser/nearby_sharing/local_device_data/nearby_share_local_device_data_manager_impl.h"
#include "chrome/browser/nearby_sharing/mock_nearby_process_manager.h" #include "chrome/browser/nearby_sharing/mock_nearby_process_manager.h"
#include "chrome/browser/nearby_sharing/mock_nearby_sharing_decoder.h"
#include "chrome/browser/nearby_sharing/nearby_connections_manager.h" #include "chrome/browser/nearby_sharing/nearby_connections_manager.h"
#include "chrome/browser/nearby_sharing/nearby_share_default_device_name.h" #include "chrome/browser/nearby_sharing/nearby_share_default_device_name.h"
#include "chrome/browser/nearby_sharing/power_client.h" #include "chrome/browser/nearby_sharing/power_client.h"
...@@ -51,6 +50,7 @@ ...@@ -51,6 +50,7 @@
#include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h" #include "chrome/test/base/testing_profile_manager.h"
#include "chromeos/services/nearby/public/cpp/mock_nearby_sharing_decoder.h"
#include "chromeos/services/nearby/public/mojom/nearby_connections_types.mojom.h" #include "chromeos/services/nearby/public/mojom/nearby_connections_types.mojom.h"
#include "components/sync_preferences/testing_pref_service_syncable.h" #include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/test/browser_task_environment.h" #include "content/public/test/browser_task_environment.h"
...@@ -520,7 +520,8 @@ class NearbySharingServiceImplTest : public testing::Test { ...@@ -520,7 +520,8 @@ class NearbySharingServiceImplTest : public testing::Test {
.WillOnce(testing::Invoke( .WillOnce(testing::Invoke(
[is_incoming]( [is_incoming](
const std::vector<uint8_t>& data, const std::vector<uint8_t>& data,
MockNearbySharingDecoder::DecodeFrameCallback callback) { chromeos::nearby::MockNearbySharingDecoder::DecodeFrameCallback
callback) {
sharing::mojom::V1FramePtr mojo_v1frame = sharing::mojom::V1FramePtr mojo_v1frame =
sharing::mojom::V1Frame::New(); sharing::mojom::V1Frame::New();
mojo_v1frame->set_paired_key_encryption( mojo_v1frame->set_paired_key_encryption(
...@@ -542,7 +543,8 @@ class NearbySharingServiceImplTest : public testing::Test { ...@@ -542,7 +543,8 @@ class NearbySharingServiceImplTest : public testing::Test {
DecodeFrame(testing::Eq(result_bytes), testing::_)) DecodeFrame(testing::Eq(result_bytes), testing::_))
.WillOnce(testing::Invoke( .WillOnce(testing::Invoke(
[=](const std::vector<uint8_t>& data, [=](const std::vector<uint8_t>& data,
MockNearbySharingDecoder::DecodeFrameCallback callback) { chromeos::nearby::MockNearbySharingDecoder::DecodeFrameCallback
callback) {
sharing::mojom::V1FramePtr mojo_v1frame = sharing::mojom::V1FramePtr mojo_v1frame =
sharing::mojom::V1Frame::New(); sharing::mojom::V1Frame::New();
mojo_v1frame->set_paired_key_result( mojo_v1frame->set_paired_key_result(
...@@ -560,10 +562,10 @@ class NearbySharingServiceImplTest : public testing::Test { ...@@ -560,10 +562,10 @@ class NearbySharingServiceImplTest : public testing::Test {
bool return_empty_advertisement) { bool return_empty_advertisement) {
EXPECT_CALL(mock_decoder_, EXPECT_CALL(mock_decoder_,
DecodeAdvertisement(testing::Eq(endpoint_info), testing::_)) DecodeAdvertisement(testing::Eq(endpoint_info), testing::_))
.WillOnce(testing::Invoke( .WillOnce(
[=](const std::vector<uint8_t>& data, testing::Invoke([=](const std::vector<uint8_t>& data,
MockNearbySharingDecoder::DecodeAdvertisementCallback chromeos::nearby::MockNearbySharingDecoder::
callback) { DecodeAdvertisementCallback callback) {
if (return_empty_advertisement) { if (return_empty_advertisement) {
std::move(callback).Run(nullptr); std::move(callback).Run(nullptr);
return; return;
...@@ -584,7 +586,8 @@ class NearbySharingServiceImplTest : public testing::Test { ...@@ -584,7 +586,8 @@ class NearbySharingServiceImplTest : public testing::Test {
EXPECT_CALL(mock_decoder_, DecodeFrame(testing::Eq(bytes), testing::_)) EXPECT_CALL(mock_decoder_, DecodeFrame(testing::Eq(bytes), testing::_))
.WillOnce(testing::Invoke( .WillOnce(testing::Invoke(
[=](const std::vector<uint8_t>& data, [=](const std::vector<uint8_t>& data,
MockNearbySharingDecoder::DecodeFrameCallback callback) { chromeos::nearby::MockNearbySharingDecoder::DecodeFrameCallback
callback) {
std::move(callback).Run(return_empty_introduction_frame std::move(callback).Run(return_empty_introduction_frame
? GetEmptyIntroductionFrame() ? GetEmptyIntroductionFrame()
: GetValidIntroductionFrame()); : GetValidIntroductionFrame());
...@@ -599,7 +602,8 @@ class NearbySharingServiceImplTest : public testing::Test { ...@@ -599,7 +602,8 @@ class NearbySharingServiceImplTest : public testing::Test {
EXPECT_CALL(mock_decoder_, DecodeFrame(testing::Eq(bytes), testing::_)) EXPECT_CALL(mock_decoder_, DecodeFrame(testing::Eq(bytes), testing::_))
.WillOnce(testing::Invoke( .WillOnce(testing::Invoke(
[=](const std::vector<uint8_t>& data, [=](const std::vector<uint8_t>& data,
MockNearbySharingDecoder::DecodeFrameCallback callback) { chromeos::nearby::MockNearbySharingDecoder::DecodeFrameCallback
callback) {
std::move(callback).Run(GetConnectionResponseFrame(status)); std::move(callback).Run(GetConnectionResponseFrame(status));
})); }));
connection_.AppendReadableData(bytes); connection_.AppendReadableData(bytes);
...@@ -886,7 +890,7 @@ class NearbySharingServiceImplTest : public testing::Test { ...@@ -886,7 +890,7 @@ class NearbySharingServiceImplTest : public testing::Test {
bool is_bluetooth_powered_ = true; bool is_bluetooth_powered_ = true;
device::BluetoothAdapter::Observer* adapter_observer_ = nullptr; device::BluetoothAdapter::Observer* adapter_observer_ = nullptr;
scoped_refptr<NiceMock<device::MockBluetoothAdapter>> mock_bluetooth_adapter_; scoped_refptr<NiceMock<device::MockBluetoothAdapter>> mock_bluetooth_adapter_;
NiceMock<MockNearbySharingDecoder> mock_decoder_; NiceMock<chromeos::nearby::MockNearbySharingDecoder> mock_decoder_;
FakeNearbyConnection connection_; FakeNearbyConnection connection_;
}; };
...@@ -2121,7 +2125,8 @@ TEST_F(NearbySharingServiceImplTest, IncomingConnection_OutOfStorage) { ...@@ -2121,7 +2125,8 @@ TEST_F(NearbySharingServiceImplTest, IncomingConnection_OutOfStorage) {
EXPECT_CALL(mock_decoder_, DecodeFrame(testing::Eq(bytes), testing::_)) EXPECT_CALL(mock_decoder_, DecodeFrame(testing::Eq(bytes), testing::_))
.WillOnce(testing::Invoke( .WillOnce(testing::Invoke(
[](const std::vector<uint8_t>& data, [](const std::vector<uint8_t>& data,
MockNearbySharingDecoder::DecodeFrameCallback callback) { chromeos::nearby::MockNearbySharingDecoder::DecodeFrameCallback
callback) {
std::vector<sharing::mojom::FileMetadataPtr> mojo_file_metadatas; std::vector<sharing::mojom::FileMetadataPtr> mojo_file_metadatas;
mojo_file_metadatas.push_back(sharing::mojom::FileMetadata::New( mojo_file_metadatas.push_back(sharing::mojom::FileMetadata::New(
"name", sharing::mojom::FileMetadata::Type::kAudio, "name", sharing::mojom::FileMetadata::Type::kAudio,
...@@ -2191,7 +2196,8 @@ TEST_F(NearbySharingServiceImplTest, IncomingConnection_FileSizeOverflow) { ...@@ -2191,7 +2196,8 @@ TEST_F(NearbySharingServiceImplTest, IncomingConnection_FileSizeOverflow) {
EXPECT_CALL(mock_decoder_, DecodeFrame(testing::Eq(bytes), testing::_)) EXPECT_CALL(mock_decoder_, DecodeFrame(testing::Eq(bytes), testing::_))
.WillOnce(testing::Invoke( .WillOnce(testing::Invoke(
[](const std::vector<uint8_t>& data, [](const std::vector<uint8_t>& data,
MockNearbySharingDecoder::DecodeFrameCallback callback) { chromeos::nearby::MockNearbySharingDecoder::DecodeFrameCallback
callback) {
std::vector<sharing::mojom::FileMetadataPtr> mojo_file_metadatas; std::vector<sharing::mojom::FileMetadataPtr> mojo_file_metadatas;
mojo_file_metadatas.push_back(sharing::mojom::FileMetadata::New( mojo_file_metadatas.push_back(sharing::mojom::FileMetadata::New(
"name_1", sharing::mojom::FileMetadata::Type::kAudio, "name_1", sharing::mojom::FileMetadata::Type::kAudio,
......
...@@ -4841,12 +4841,8 @@ test("unit_tests") { ...@@ -4841,12 +4841,8 @@ test("unit_tests") {
"../browser/nearby_sharing/instantmessaging/receive_messages_express_unittest.cc", "../browser/nearby_sharing/instantmessaging/receive_messages_express_unittest.cc",
"../browser/nearby_sharing/instantmessaging/send_message_express_unittest.cc", "../browser/nearby_sharing/instantmessaging/send_message_express_unittest.cc",
"../browser/nearby_sharing/instantmessaging/stream_parser_unittest.cc", "../browser/nearby_sharing/instantmessaging/stream_parser_unittest.cc",
"../browser/nearby_sharing/mock_nearby_connections.cc",
"../browser/nearby_sharing/mock_nearby_connections.h",
"../browser/nearby_sharing/mock_nearby_process_manager.cc", "../browser/nearby_sharing/mock_nearby_process_manager.cc",
"../browser/nearby_sharing/mock_nearby_process_manager.h", "../browser/nearby_sharing/mock_nearby_process_manager.h",
"../browser/nearby_sharing/mock_nearby_sharing_decoder.cc",
"../browser/nearby_sharing/mock_nearby_sharing_decoder.h",
"../browser/nearby_sharing/mock_nearby_sharing_service.cc", "../browser/nearby_sharing/mock_nearby_sharing_service.cc",
"../browser/nearby_sharing/mock_nearby_sharing_service.h", "../browser/nearby_sharing/mock_nearby_sharing_service.h",
"../browser/nearby_sharing/nearby_confirmation_manager_unittest.cc", "../browser/nearby_sharing/nearby_confirmation_manager_unittest.cc",
...@@ -4981,6 +4977,7 @@ test("unit_tests") { ...@@ -4981,6 +4977,7 @@ test("unit_tests") {
"//chrome/services/sharing/nearby/platform_v2:unit_tests", "//chrome/services/sharing/nearby/platform_v2:unit_tests",
"//chromeos/assistant:buildflags", "//chromeos/assistant:buildflags",
"//chromeos/services/machine_learning/public/cpp:test_support", "//chromeos/services/machine_learning/public/cpp:test_support",
"//chromeos/services/nearby/public/cpp:test_support",
"//components/arc:arc_test_support", "//components/arc:arc_test_support",
] ]
} }
......
# Copyright 2020 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.
static_library("test_support") {
testonly = true
sources = [
"mock_nearby_connections.cc",
"mock_nearby_connections.h",
"mock_nearby_sharing_decoder.cc",
"mock_nearby_sharing_decoder.h",
]
deps = [
"//base",
"//chromeos/services/nearby/public/mojom",
"//mojo/public/cpp/bindings/",
"//testing/gmock",
]
}
...@@ -2,8 +2,18 @@ ...@@ -2,8 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/nearby_sharing/mock_nearby_connections.h" #include "chromeos/services/nearby/public/cpp/mock_nearby_connections.h"
MockNearbyConnections::MockNearbyConnections() = default; namespace chromeos {
namespace nearby {
MockNearbyConnections::MockNearbyConnections() {
mojo::PendingRemote<NearbyConnectionsMojom> pending_remote;
receiver_.Bind(pending_remote.InitWithNewPipeAndPassReceiver());
shared_remote_.Bind(std::move(pending_remote), /*bind_task_runner=*/nullptr);
}
MockNearbyConnections::~MockNearbyConnections() = default; MockNearbyConnections::~MockNearbyConnections() = default;
} // namespace nearby
} // namespace chromeos
...@@ -2,11 +2,12 @@ ...@@ -2,11 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_NEARBY_SHARING_MOCK_NEARBY_CONNECTIONS_H_ #ifndef CHROMEOS_SERVICES_NEARBY_PUBLIC_CPP_MOCK_NEARBY_CONNECTIONS_H_
#define CHROME_BROWSER_NEARBY_SHARING_MOCK_NEARBY_CONNECTIONS_H_ #define CHROMEOS_SERVICES_NEARBY_PUBLIC_CPP_MOCK_NEARBY_CONNECTIONS_H_
#include "chromeos/services/nearby/public/mojom/nearby_connections.mojom.h" #include "chromeos/services/nearby/public/mojom/nearby_connections.mojom.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/shared_remote.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
using NearbyConnectionsMojom = using NearbyConnectionsMojom =
...@@ -24,6 +25,9 @@ using EndpointDiscoveryListener = ...@@ -24,6 +25,9 @@ using EndpointDiscoveryListener =
using PayloadListener = location::nearby::connections::mojom::PayloadListener; using PayloadListener = location::nearby::connections::mojom::PayloadListener;
using PayloadPtr = location::nearby::connections::mojom::PayloadPtr; using PayloadPtr = location::nearby::connections::mojom::PayloadPtr;
namespace chromeos {
namespace nearby {
class MockNearbyConnections : public NearbyConnectionsMojom { class MockNearbyConnections : public NearbyConnectionsMojom {
public: public:
MockNearbyConnections(); MockNearbyConnections();
...@@ -31,6 +35,10 @@ class MockNearbyConnections : public NearbyConnectionsMojom { ...@@ -31,6 +35,10 @@ class MockNearbyConnections : public NearbyConnectionsMojom {
MockNearbyConnections& operator=(const MockNearbyConnections&) = delete; MockNearbyConnections& operator=(const MockNearbyConnections&) = delete;
~MockNearbyConnections() override; ~MockNearbyConnections() override;
const mojo::SharedRemote<NearbyConnectionsMojom>& shared_remote() const {
return shared_remote_;
}
MOCK_METHOD(void, MOCK_METHOD(void,
StartAdvertising, StartAdvertising,
(const std::vector<uint8_t>& endpoint_info, (const std::vector<uint8_t>& endpoint_info,
...@@ -97,6 +105,13 @@ class MockNearbyConnections : public NearbyConnectionsMojom { ...@@ -97,6 +105,13 @@ class MockNearbyConnections : public NearbyConnectionsMojom {
base::File output_file, base::File output_file,
RegisterPayloadFileCallback callback), RegisterPayloadFileCallback callback),
(override)); (override));
private:
mojo::Receiver<NearbyConnectionsMojom> receiver_{this};
mojo::SharedRemote<NearbyConnectionsMojom> shared_remote_;
}; };
#endif // CHROME_BROWSER_NEARBY_SHARING_MOCK_NEARBY_CONNECTIONS_H_ } // namespace nearby
} // namespace chromeos
#endif // CHROMEOS_SERVICES_NEARBY_PUBLIC_CPP_MOCK_NEARBY_CONNECTIONS_H_
...@@ -2,8 +2,18 @@ ...@@ -2,8 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/nearby_sharing/mock_nearby_sharing_decoder.h" #include "chromeos/services/nearby/public/cpp/mock_nearby_sharing_decoder.h"
MockNearbySharingDecoder::MockNearbySharingDecoder() = default; namespace chromeos {
namespace nearby {
MockNearbySharingDecoder::MockNearbySharingDecoder() {
mojo::PendingRemote<sharing::mojom::NearbySharingDecoder> pending_remote;
receiver_.Bind(pending_remote.InitWithNewPipeAndPassReceiver());
shared_remote_.Bind(std::move(pending_remote), /*bind_task_runner=*/nullptr);
}
MockNearbySharingDecoder::~MockNearbySharingDecoder() = default; MockNearbySharingDecoder::~MockNearbySharingDecoder() = default;
} // namespace nearby
} // namespace chromeos
...@@ -2,12 +2,17 @@ ...@@ -2,12 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_NEARBY_SHARING_MOCK_NEARBY_SHARING_DECODER_H_ #ifndef CHROMEOS_SERVICES_NEARBY_PUBLIC_CPP_MOCK_NEARBY_SHARING_DECODER_H_
#define CHROME_BROWSER_NEARBY_SHARING_MOCK_NEARBY_SHARING_DECODER_H_ #define CHROMEOS_SERVICES_NEARBY_PUBLIC_CPP_MOCK_NEARBY_SHARING_DECODER_H_
#include "chromeos/services/nearby/public/mojom/nearby_decoder.mojom.h" #include "chromeos/services/nearby/public/mojom/nearby_decoder.mojom.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/shared_remote.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
namespace chromeos {
namespace nearby {
class MockNearbySharingDecoder : public sharing::mojom::NearbySharingDecoder { class MockNearbySharingDecoder : public sharing::mojom::NearbySharingDecoder {
public: public:
MockNearbySharingDecoder(); MockNearbySharingDecoder();
...@@ -15,6 +20,11 @@ class MockNearbySharingDecoder : public sharing::mojom::NearbySharingDecoder { ...@@ -15,6 +20,11 @@ class MockNearbySharingDecoder : public sharing::mojom::NearbySharingDecoder {
MockNearbySharingDecoder& operator=(const MockNearbySharingDecoder&) = delete; MockNearbySharingDecoder& operator=(const MockNearbySharingDecoder&) = delete;
~MockNearbySharingDecoder() override; ~MockNearbySharingDecoder() override;
const mojo::SharedRemote<sharing::mojom::NearbySharingDecoder>&
shared_remote() const {
return shared_remote_;
}
// sharing::mojom::NearbySharingDecoder: // sharing::mojom::NearbySharingDecoder:
MOCK_METHOD(void, MOCK_METHOD(void,
DecodeAdvertisement, DecodeAdvertisement,
...@@ -25,6 +35,13 @@ class MockNearbySharingDecoder : public sharing::mojom::NearbySharingDecoder { ...@@ -25,6 +35,13 @@ class MockNearbySharingDecoder : public sharing::mojom::NearbySharingDecoder {
DecodeFrame, DecodeFrame,
(const std::vector<uint8_t>& data, DecodeFrameCallback callback), (const std::vector<uint8_t>& data, DecodeFrameCallback callback),
(override)); (override));
private:
mojo::Receiver<sharing::mojom::NearbySharingDecoder> receiver_{this};
mojo::SharedRemote<sharing::mojom::NearbySharingDecoder> shared_remote_;
}; };
#endif // CHROME_BROWSER_NEARBY_SHARING_MOCK_NEARBY_SHARING_DECODER_H_ } // namespace nearby
} // namespace chromeos
#endif // CHROMEOS_SERVICES_NEARBY_PUBLIC_CPP_MOCK_NEARBY_SHARING_DECODER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment