mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Internal change
PiperOrigin-RevId: 663333107
This commit is contained in:
@@ -16,6 +16,8 @@ syntax = "proto2";
|
||||
|
||||
package location.nearby.connections;
|
||||
|
||||
// import "storage/datapol/annotations/proto/semantic_annotations.proto";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
option java_outer_classname = "OfflineWireFormatsProto";
|
||||
option java_package = "com.google.location.nearby.connections.proto";
|
||||
@@ -240,7 +242,8 @@ message BandwidthUpgradeNegotiationFrame {
|
||||
// Accompanies Medium.WIFI_HOTSPOT.
|
||||
message WifiHotspotCredentials {
|
||||
optional string ssid = 1;
|
||||
optional string password = 2;
|
||||
optional string password = 2
|
||||
/* type = ST_ACCOUNT_CREDENTIAL */;
|
||||
optional int32 port = 3;
|
||||
optional string gateway = 4 [default = "0.0.0.0"];
|
||||
// This field can be a band or frequency
|
||||
@@ -263,13 +266,15 @@ message BandwidthUpgradeNegotiationFrame {
|
||||
message WifiAwareCredentials {
|
||||
optional string service_id = 1;
|
||||
optional bytes service_info = 2;
|
||||
optional string password = 3;
|
||||
optional string password = 3
|
||||
/* type = ST_ACCOUNT_CREDENTIAL */;
|
||||
}
|
||||
|
||||
// Accompanies Medium.WIFI_DIRECT.
|
||||
message WifiDirectCredentials {
|
||||
optional string ssid = 1;
|
||||
optional string password = 2;
|
||||
optional string password = 2
|
||||
/* type = ST_ACCOUNT_CREDENTIAL */;
|
||||
optional int32 port = 3;
|
||||
optional int32 frequency = 4;
|
||||
optional string gateway = 5 [default = "0.0.0.0"];
|
||||
|
||||
@@ -16,6 +16,7 @@ syntax = "proto3";
|
||||
|
||||
package nearby.fastpair.proto;
|
||||
|
||||
// import "storage/datapol/annotations/proto/semantic_annotations.proto";
|
||||
import "third_party/nearby/fastpair/proto/data.proto";
|
||||
|
||||
// Represents the type of device that is being registered.
|
||||
@@ -126,7 +127,7 @@ message Device {
|
||||
// broadcasting legitimately.
|
||||
message AntiSpoofingKeyPair {
|
||||
// The private key (restricted to only be viewable by trusted clients).
|
||||
bytes private_key = 1;
|
||||
bytes private_key = 1 /* type = ST_SECURITY_KEY */;
|
||||
|
||||
// The public key.
|
||||
bytes public_key = 2;
|
||||
|
||||
@@ -1219,7 +1219,7 @@ bool BleV2Medium::GetRemotePeripheral(const std::string& mac_address,
|
||||
BleV2Peripheral* peripheral = nullptr;
|
||||
{
|
||||
absl::MutexLock lock(&mutex_);
|
||||
BleV2Peripheral* peripheral = GetOrCreatePeripheral(mac_address);
|
||||
peripheral = GetOrCreatePeripheral(mac_address);
|
||||
}
|
||||
|
||||
if (peripheral != nullptr && peripheral->Ok()) {
|
||||
@@ -1234,7 +1234,7 @@ bool BleV2Medium::GetRemotePeripheral(api::ble_v2::BlePeripheral::UniqueId id,
|
||||
BleV2Peripheral* peripheral = nullptr;
|
||||
{
|
||||
absl::MutexLock lock(&mutex_);
|
||||
BleV2Peripheral* peripheral = GetPeripheral(id);
|
||||
peripheral = GetPeripheral(id);
|
||||
}
|
||||
|
||||
if (peripheral == nullptr) {
|
||||
|
||||
+4
-12
@@ -74,7 +74,6 @@ cc_library(
|
||||
"constants.h",
|
||||
"nearby_connection.h",
|
||||
"nearby_connections_manager.h",
|
||||
"nearby_sharing_decoder.h",
|
||||
"share_target.h",
|
||||
],
|
||||
visibility = [
|
||||
@@ -121,9 +120,8 @@ cc_library(
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "nearby_sharing_decoder_impl",
|
||||
srcs = ["nearby_sharing_decoder_impl.cc"],
|
||||
hdrs = ["nearby_sharing_decoder_impl.h"],
|
||||
name = "nearby_sharing_decoder",
|
||||
hdrs = ["nearby_sharing_decoder.h"],
|
||||
visibility = [
|
||||
"//sharing/fuzzing:__pkg__",
|
||||
],
|
||||
@@ -292,7 +290,7 @@ cc_library(
|
||||
":connection_types",
|
||||
":incoming_frame_reader",
|
||||
":nearby_connection_impl",
|
||||
":nearby_sharing_decoder_impl",
|
||||
":nearby_sharing_decoder",
|
||||
":paired_key_verification_runner",
|
||||
":share_session",
|
||||
":thread_timer",
|
||||
@@ -433,7 +431,6 @@ cc_test(
|
||||
srcs = ["paired_key_verification_runner_test.cc"],
|
||||
deps = [
|
||||
":incoming_frame_reader",
|
||||
":nearby_sharing_decoder_impl",
|
||||
":paired_key_verification_runner",
|
||||
":test_support",
|
||||
":types",
|
||||
@@ -480,7 +477,6 @@ cc_test(
|
||||
deps = [
|
||||
":incoming_frame_reader",
|
||||
":nearby_connection_impl",
|
||||
":nearby_sharing_decoder_impl",
|
||||
":test_support",
|
||||
"//internal/platform/implementation/g3", # fixdeps: keep
|
||||
"//internal/test",
|
||||
@@ -499,7 +495,6 @@ cc_test(
|
||||
deps = [
|
||||
":incoming_frame_reader",
|
||||
":nearby_connection_impl",
|
||||
":nearby_sharing_decoder_impl",
|
||||
":test_support",
|
||||
"//internal/platform/implementation/g3", # fixdeps: keep
|
||||
"//internal/test",
|
||||
@@ -550,6 +545,7 @@ cc_test(
|
||||
":share_session",
|
||||
":test_support",
|
||||
":transfer_metadata",
|
||||
":transfer_metadata_matchers",
|
||||
":types",
|
||||
"//base:casts",
|
||||
"//internal/analytics:mock_event_logger",
|
||||
@@ -557,7 +553,6 @@ cc_test(
|
||||
"//internal/platform/implementation/g3", # fixdeps: keep
|
||||
"//internal/test",
|
||||
"//internal/test:mocks",
|
||||
"//sharing:transfer_metadata_matchers",
|
||||
"//sharing/analytics",
|
||||
"//sharing/certificates",
|
||||
"//sharing/certificates:test_support",
|
||||
@@ -756,7 +751,6 @@ cc_test(
|
||||
name = "share_session_test",
|
||||
srcs = ["share_session_test.cc"],
|
||||
deps = [
|
||||
":nearby_sharing_decoder_impl",
|
||||
":paired_key_verification_runner",
|
||||
":share_session",
|
||||
":test_support",
|
||||
@@ -805,7 +799,6 @@ cc_test(
|
||||
deps = [
|
||||
":attachments",
|
||||
":connection_types",
|
||||
":nearby_sharing_decoder_impl",
|
||||
":paired_key_verification_runner",
|
||||
":share_session",
|
||||
":test_support",
|
||||
@@ -831,7 +824,6 @@ cc_test(
|
||||
":attachment_compare",
|
||||
":attachments",
|
||||
":connection_types",
|
||||
":nearby_sharing_decoder_impl",
|
||||
":paired_key_verification_runner",
|
||||
":share_session",
|
||||
":test_support",
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include "internal/platform/task_runner.h"
|
||||
#include "sharing/internal/public/logging.h"
|
||||
#include "sharing/nearby_connection.h"
|
||||
#include "sharing/nearby_sharing_decoder.h"
|
||||
#include "sharing/proto/wire_format.pb.h"
|
||||
#include "sharing/thread_timer.h"
|
||||
|
||||
@@ -42,13 +41,21 @@ using FrameType = ::nearby::sharing::service::proto::V1Frame_FrameType;
|
||||
using V1Frame = ::nearby::sharing::service::proto::V1Frame;
|
||||
using Frame = ::nearby::sharing::service::proto::Frame;
|
||||
|
||||
std::unique_ptr<Frame> DecodeFrame(absl::Span<const uint8_t> data) {
|
||||
auto frame = std::make_unique<Frame>();
|
||||
|
||||
if (frame->ParseFromArray(data.data(), data.size())) {
|
||||
return frame;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
IncomingFramesReader::IncomingFramesReader(TaskRunner& service_thread,
|
||||
const NearbySharingDecoder& decoder,
|
||||
NearbyConnection* connection)
|
||||
: service_thread_(service_thread),
|
||||
decoder_(decoder),
|
||||
connection_(connection) {
|
||||
NL_DCHECK(connection);
|
||||
}
|
||||
@@ -144,7 +151,7 @@ void IncomingFramesReader::OnDataReadFromConnection(
|
||||
}
|
||||
|
||||
std::unique_ptr<Frame> frame =
|
||||
decoder_.DecodeFrame(absl::MakeSpan(bytes->data(), bytes->size()));
|
||||
DecodeFrame(absl::MakeSpan(bytes->data(), bytes->size()));
|
||||
if (frame == nullptr) {
|
||||
NL_LOG(WARNING)
|
||||
<< __func__
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include "internal/platform/mutex.h"
|
||||
#include "internal/platform/task_runner.h"
|
||||
#include "sharing/nearby_connection.h"
|
||||
#include "sharing/nearby_sharing_decoder.h"
|
||||
#include "sharing/proto/wire_format.pb.h"
|
||||
#include "sharing/thread_timer.h"
|
||||
|
||||
@@ -41,7 +40,6 @@ class IncomingFramesReader
|
||||
: public std::enable_shared_from_this<IncomingFramesReader> {
|
||||
public:
|
||||
IncomingFramesReader(TaskRunner& service_thread,
|
||||
const NearbySharingDecoder& decoder,
|
||||
NearbyConnection* connection);
|
||||
virtual ~IncomingFramesReader();
|
||||
IncomingFramesReader(const IncomingFramesReader&) = delete;
|
||||
@@ -99,7 +97,6 @@ class IncomingFramesReader
|
||||
frame_type) ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
TaskRunner& service_thread_;
|
||||
const NearbySharingDecoder& decoder_;
|
||||
NearbyConnection* const connection_;
|
||||
|
||||
RecursiveMutex mutex_;
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include "sharing/fake_nearby_connections_manager.h"
|
||||
#include "sharing/internal/public/logging.h"
|
||||
#include "sharing/nearby_connection_impl.h"
|
||||
#include "sharing/nearby_sharing_decoder_impl.h"
|
||||
#include "sharing/proto/wire_format.pb.h"
|
||||
|
||||
namespace nearby {
|
||||
@@ -92,7 +91,7 @@ class IncomingFramesReaderTest : public testing::Test {
|
||||
void SetUp() override {
|
||||
FakeTaskRunner::ResetPendingTasksCount();
|
||||
frames_reader_ = std::make_shared<IncomingFramesReader>(
|
||||
fake_task_runner_, nearby_sharing_decoder_, nearby_connection_.get());
|
||||
fake_task_runner_, nearby_connection_.get());
|
||||
}
|
||||
|
||||
NearbyConnectionImpl& connection() {
|
||||
@@ -121,7 +120,6 @@ class IncomingFramesReaderTest : public testing::Test {
|
||||
FakeDeviceInfo fake_device_info_;
|
||||
FakeNearbyConnectionsManager fake_nearby_connections_manager_;
|
||||
std::unique_ptr<NearbyConnectionImpl> nearby_connection_;
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder_;
|
||||
std::shared_ptr<IncomingFramesReader> frames_reader_ = nullptr;
|
||||
};
|
||||
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
#include "sharing/file_attachment.h"
|
||||
#include "sharing/internal/public/logging.h"
|
||||
#include "sharing/nearby_connections_types.h"
|
||||
#include "sharing/nearby_sharing_decoder_impl.h"
|
||||
#include "sharing/paired_key_verification_runner.h"
|
||||
#include "sharing/proto/analytics/nearby_sharing_log.pb.h"
|
||||
#include "sharing/proto/wire_format.pb.h"
|
||||
@@ -70,7 +69,6 @@ using ::nearby::sharing::service::proto::ConnectionResponseFrame;
|
||||
using ::nearby::sharing::service::proto::FileMetadata;
|
||||
using ::nearby::sharing::service::proto::Frame;
|
||||
using ::nearby::sharing::service::proto::IntroductionFrame;
|
||||
using ::nearby::sharing::service::proto::ProgressUpdateFrame;
|
||||
using ::nearby::sharing::service::proto::TextMetadata;
|
||||
using ::nearby::sharing::service::proto::V1Frame;
|
||||
using ::nearby::sharing::service::proto::WifiCredentials;
|
||||
@@ -179,15 +177,14 @@ class IncomingShareSessionTest : public ::testing::Test {
|
||||
MockFunction<void(const IncomingShareSession&, const TransferMetadata&)>
|
||||
transfer_metadata_callback_;
|
||||
FakeNearbyConnectionsManager connections_manager_;
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder_;
|
||||
FakeNearbyConnection connection_;
|
||||
IncomingShareSession session_;
|
||||
IntroductionFrame introduction_frame_;
|
||||
};
|
||||
|
||||
TEST_F(IncomingShareSessionTest, ProcessIntroductionNoSupportedPayload) {
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_));
|
||||
IntroductionFrame frame;
|
||||
|
||||
EXPECT_THAT(session_.ProcessIntroduction(frame),
|
||||
@@ -196,8 +193,8 @@ TEST_F(IncomingShareSessionTest, ProcessIntroductionNoSupportedPayload) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, ProcessIntroductionEmptyFile) {
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_));
|
||||
IntroductionFrame frame;
|
||||
frame.mutable_file_metadata();
|
||||
|
||||
@@ -207,8 +204,8 @@ TEST_F(IncomingShareSessionTest, ProcessIntroductionEmptyFile) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, ProcessIntroductionFilesTooLarge) {
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_));
|
||||
IntroductionFrame frame;
|
||||
FileMetadata file1;
|
||||
FileMetadata file2;
|
||||
@@ -223,8 +220,8 @@ TEST_F(IncomingShareSessionTest, ProcessIntroductionFilesTooLarge) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, ProcessIntroductionEmptyText) {
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_));
|
||||
IntroductionFrame frame;
|
||||
frame.mutable_text_metadata();
|
||||
|
||||
@@ -234,8 +231,8 @@ TEST_F(IncomingShareSessionTest, ProcessIntroductionEmptyText) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, ProcessIntroductionSuccess) {
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_));
|
||||
FileMetadata filemeta1 = introduction_frame_.file_metadata(0);
|
||||
FileAttachment file1(filemeta1.id(), filemeta1.size(), filemeta1.name(),
|
||||
filemeta1.mime_type(), filemeta1.type(),
|
||||
@@ -284,8 +281,8 @@ TEST_F(IncomingShareSessionTest, ProcessIntroductionSuccess) {
|
||||
|
||||
TEST_F(IncomingShareSessionTest,
|
||||
PayloadTransferUpdateCompleteWithWrongPayloadType) {
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_));
|
||||
EXPECT_THAT(session_.ProcessIntroduction(introduction_frame_),
|
||||
Eq(std::nullopt));
|
||||
int64_t payload_id1 = introduction_frame_.file_metadata(0).payload_id();
|
||||
@@ -341,8 +338,8 @@ TEST_F(IncomingShareSessionTest,
|
||||
|
||||
TEST_F(IncomingShareSessionTest,
|
||||
PayloadTransferUpdateCompleteWithMissingFilePayloads) {
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_));
|
||||
EXPECT_THAT(session_.ProcessIntroduction(introduction_frame_),
|
||||
Eq(std::nullopt));
|
||||
std::filesystem::path file1_path = "/usr/tmp/file1";
|
||||
@@ -415,8 +412,8 @@ TEST_F(IncomingShareSessionTest,
|
||||
|
||||
TEST_F(IncomingShareSessionTest,
|
||||
PayloadTransferUpdateCompleteWithMissingTextPayloads) {
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_));
|
||||
EXPECT_THAT(session_.ProcessIntroduction(introduction_frame_),
|
||||
Eq(std::nullopt));
|
||||
std::filesystem::path file1_path = "/usr/tmp/file1";
|
||||
@@ -486,8 +483,8 @@ TEST_F(IncomingShareSessionTest,
|
||||
|
||||
TEST_F(IncomingShareSessionTest,
|
||||
PayloadTransferUpdateCompleteWithMissingWifiPayloads) {
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_));
|
||||
EXPECT_THAT(session_.ProcessIntroduction(introduction_frame_),
|
||||
Eq(std::nullopt));
|
||||
std::filesystem::path file1_path = "/usr/tmp/file1";
|
||||
@@ -555,8 +552,8 @@ TEST_F(IncomingShareSessionTest,
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, GetPayloadFilePaths) {
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_));
|
||||
IntroductionFrame introduction_frame;
|
||||
FileMetadata file1;
|
||||
FileMetadata file2;
|
||||
@@ -595,8 +592,8 @@ TEST_F(IncomingShareSessionTest, GetPayloadFilePaths) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, PayloadTransferUpdateCompleteWithSuccess) {
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_));
|
||||
EXPECT_THAT(session_.ProcessIntroduction(introduction_frame_),
|
||||
Eq(std::nullopt));
|
||||
std::filesystem::path file1_path = "/usr/tmp/file1";
|
||||
@@ -673,8 +670,8 @@ TEST_F(IncomingShareSessionTest, PayloadTransferUpdateCompleteWithSuccess) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, PayloadTransferUpdateCancelled) {
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_));
|
||||
EXPECT_THAT(session_.ProcessIntroduction(introduction_frame_),
|
||||
Eq(std::nullopt));
|
||||
std::filesystem::path file1_path = "/usr/tmp/file1";
|
||||
@@ -729,8 +726,8 @@ TEST_F(IncomingShareSessionTest, PayloadTransferUpdateCancelled) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, PayloadTransferUpdateFailed) {
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_));
|
||||
EXPECT_THAT(session_.ProcessIntroduction(introduction_frame_),
|
||||
Eq(std::nullopt));
|
||||
std::filesystem::path file1_path = "/usr/tmp/file1";
|
||||
@@ -778,8 +775,8 @@ TEST_F(IncomingShareSessionTest, PayloadTransferUpdateFailed) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, PayloadTransferUpdateInProgress) {
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_));
|
||||
EXPECT_THAT(session_.ProcessIntroduction(introduction_frame_),
|
||||
Eq(std::nullopt));
|
||||
std::filesystem::path file1_path = "/usr/tmp/file1";
|
||||
@@ -838,8 +835,8 @@ TEST_F(IncomingShareSessionTest, ReadyForTransferNotConnected) {
|
||||
|
||||
TEST_F(IncomingShareSessionTest, ReadyForTransferNotSelfShare) {
|
||||
session_.set_session_id(1234);
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_));
|
||||
EXPECT_CALL(
|
||||
transfer_metadata_callback_,
|
||||
Call(_, HasStatus(TransferMetadata::Status::kAwaitingLocalConfirmation)));
|
||||
@@ -856,8 +853,8 @@ TEST_F(IncomingShareSessionTest, ReadyForTransferSelfShare) {
|
||||
std::string("XYCA"), share_target,
|
||||
transfer_metadata_callback_.AsStdFunction());
|
||||
session.set_session_id(1234);
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_TRUE(
|
||||
session.OnConnected(absl::Now(), &connections_manager_, &connection_));
|
||||
EXPECT_CALL(
|
||||
transfer_metadata_callback_,
|
||||
Call(_, HasStatus(TransferMetadata::Status::kAwaitingLocalConfirmation)))
|
||||
@@ -870,8 +867,8 @@ TEST_F(IncomingShareSessionTest, ReadyForTransferSelfShare) {
|
||||
|
||||
TEST_F(IncomingShareSessionTest, ReadyForTransferTimeout) {
|
||||
session_.set_session_id(1234);
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_));
|
||||
EXPECT_CALL(
|
||||
transfer_metadata_callback_,
|
||||
Call(_, HasStatus(TransferMetadata::Status::kAwaitingLocalConfirmation)));
|
||||
@@ -889,14 +886,13 @@ TEST_F(IncomingShareSessionTest, ReadyForTransferTimeout) {
|
||||
|
||||
TEST_F(IncomingShareSessionTest, ReadyForTransferTimeoutCancelled) {
|
||||
session_.set_session_id(1234);
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_));
|
||||
EXPECT_CALL(
|
||||
transfer_metadata_callback_,
|
||||
Call(_, HasStatus(TransferMetadata::Status::kAwaitingLocalConfirmation)));
|
||||
EXPECT_CALL(
|
||||
transfer_metadata_callback_,
|
||||
Call(_, HasStatus(TransferMetadata::Status::kInProgress)));
|
||||
EXPECT_CALL(transfer_metadata_callback_,
|
||||
Call(_, HasStatus(TransferMetadata::Status::kInProgress)));
|
||||
bool accept_timeout_called = false;
|
||||
|
||||
EXPECT_THAT(session_.ReadyForTransfer(
|
||||
@@ -925,8 +921,8 @@ TEST_F(IncomingShareSessionTest, AcceptTransferNotConnected) {
|
||||
|
||||
TEST_F(IncomingShareSessionTest, AcceptTransferNotReady) {
|
||||
session_.set_session_id(1234);
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_));
|
||||
EXPECT_THAT(session_.ProcessIntroduction(introduction_frame_),
|
||||
Eq(std::nullopt));
|
||||
|
||||
@@ -937,8 +933,8 @@ TEST_F(IncomingShareSessionTest, AcceptTransferNotReady) {
|
||||
|
||||
TEST_F(IncomingShareSessionTest, AcceptTransferSuccess) {
|
||||
session_.set_session_id(1234);
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_));
|
||||
EXPECT_THAT(session_.ProcessIntroduction(introduction_frame_),
|
||||
Eq(std::nullopt));
|
||||
EXPECT_THAT(
|
||||
@@ -982,8 +978,7 @@ TEST_F(IncomingShareSessionTest, AcceptTransferSuccess) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, ProcessKeyVerificationResultSuccess) {
|
||||
session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_);
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_);
|
||||
session_.SetTokenForTests("1234");
|
||||
|
||||
bool introduction_received = false;
|
||||
@@ -1017,8 +1012,7 @@ TEST_F(IncomingShareSessionTest, ProcessKeyVerificationResultSuccess) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, ProcessKeyVerificationResultFail) {
|
||||
session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_);
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_);
|
||||
session_.SetTokenForTests("1234");
|
||||
|
||||
bool introduction_received = false;
|
||||
@@ -1051,8 +1045,7 @@ TEST_F(IncomingShareSessionTest, ProcessKeyVerificationResultFail) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, ProcessKeyVerificationResultUnable) {
|
||||
session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_);
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_);
|
||||
session_.SetTokenForTests("1234");
|
||||
|
||||
bool introduction_received = false;
|
||||
@@ -1085,8 +1078,7 @@ TEST_F(IncomingShareSessionTest, ProcessKeyVerificationResultUnable) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, ProcessKeyVerificationResultUnknown) {
|
||||
session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_);
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_);
|
||||
session_.SetTokenForTests("1234");
|
||||
|
||||
bool introduction_received = false;
|
||||
@@ -1119,8 +1111,7 @@ TEST_F(IncomingShareSessionTest, ProcessKeyVerificationResultUnknown) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, TryUpgradeBandwidthNotNeeded) {
|
||||
session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_);
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_);
|
||||
|
||||
EXPECT_THAT(session_.TryUpgradeBandwidth(), IsFalse());
|
||||
EXPECT_THAT(connections_manager_.DidUpgradeBandwidth(kEndpointId), IsFalse());
|
||||
@@ -1150,8 +1141,7 @@ TEST_F(IncomingShareSessionTest, TryUpgradeBandwidthNeeded) {
|
||||
}
|
||||
)pb",
|
||||
&introduction_frame));
|
||||
session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_);
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_);
|
||||
EXPECT_THAT(session_.ProcessIntroduction(introduction_frame),
|
||||
Eq(std::nullopt));
|
||||
|
||||
@@ -1167,8 +1157,7 @@ TEST_F(IncomingShareSessionTest, SendFailureResponseNotConnected) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, SendFailureResponseConnected) {
|
||||
session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_);
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection_);
|
||||
EXPECT_CALL(transfer_metadata_callback_,
|
||||
Call(_, HasStatus(TransferMetadata::Status::kNotEnoughSpace)));
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include "internal/test/fake_task_runner.h"
|
||||
#include "sharing/fake_nearby_connections_manager.h"
|
||||
#include "sharing/incoming_frames_reader.h"
|
||||
#include "sharing/nearby_sharing_decoder_impl.h"
|
||||
#include "sharing/proto/wire_format.pb.h"
|
||||
|
||||
namespace nearby {
|
||||
@@ -38,13 +37,12 @@ TEST(NearbyConnectionImpl, DestructorBeforeReaderDestructor) {
|
||||
FakeClock fake_clock;
|
||||
FakeTaskRunner fake_task_runner(&fake_clock, 1);
|
||||
FakeDeviceInfo device_info;
|
||||
NearbySharingDecoderImpl decoder;
|
||||
bool called = false;
|
||||
|
||||
auto connection = std::make_unique<NearbyConnectionImpl>(
|
||||
device_info, &connection_manager, "test");
|
||||
auto frames_reader = std::make_shared<IncomingFramesReader>(
|
||||
fake_task_runner, decoder, connection.get());
|
||||
auto frames_reader = std::make_shared<IncomingFramesReader>(fake_task_runner,
|
||||
connection.get());
|
||||
|
||||
absl::Notification notification;
|
||||
frames_reader->ReadFrame(
|
||||
@@ -64,13 +62,12 @@ TEST(NearbyConnectionImpl, DestructorAfterReaderDestructor) {
|
||||
FakeClock fake_clock;
|
||||
FakeTaskRunner fake_task_runner(&fake_clock, 1);
|
||||
FakeDeviceInfo device_info;
|
||||
NearbySharingDecoderImpl decoder;
|
||||
std::optional<nearby::sharing::service::proto::V1Frame> frame_result;
|
||||
|
||||
auto connection = std::make_unique<NearbyConnectionImpl>(
|
||||
device_info, &connection_manager, "test");
|
||||
auto frames_reader = std::make_shared<IncomingFramesReader>(
|
||||
fake_task_runner, decoder, connection.get());
|
||||
auto frames_reader = std::make_shared<IncomingFramesReader>(fake_task_runner,
|
||||
connection.get());
|
||||
|
||||
absl::Notification notification;
|
||||
frames_reader->ReadFrame(
|
||||
|
||||
@@ -23,20 +23,13 @@
|
||||
#include "sharing/advertisement.h"
|
||||
#include "sharing/proto/wire_format.pb.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace sharing {
|
||||
namespace nearby::sharing {
|
||||
|
||||
class NearbySharingDecoder {
|
||||
public:
|
||||
virtual ~NearbySharingDecoder() = default;
|
||||
inline std::unique_ptr<Advertisement> DecodeAdvertisement(
|
||||
absl::Span<const uint8_t> data) {
|
||||
return Advertisement::FromEndpointInfo(data);
|
||||
}
|
||||
|
||||
virtual std::unique_ptr<Advertisement> DecodeAdvertisement(
|
||||
absl::Span<const uint8_t> data) const = 0;
|
||||
virtual std::unique_ptr<nearby::sharing::service::proto::Frame> DecodeFrame(
|
||||
absl::Span<const uint8_t> data) const = 0;
|
||||
};
|
||||
|
||||
} // namespace sharing
|
||||
} // namespace nearby
|
||||
} // namespace nearby::sharing
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_SHARING_NEARBY_SHARING_DECODER_H_
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
// Copyright 2022 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "sharing/nearby_sharing_decoder_impl.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "absl/types/span.h"
|
||||
#include "sharing/advertisement.h"
|
||||
#include "sharing/proto/wire_format.pb.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace sharing {
|
||||
|
||||
using Frame = ::nearby::sharing::service::proto::Frame;
|
||||
|
||||
std::unique_ptr<Advertisement> NearbySharingDecoderImpl::DecodeAdvertisement(
|
||||
absl::Span<const uint8_t> data) const {
|
||||
return Advertisement::FromEndpointInfo(data);
|
||||
}
|
||||
|
||||
std::unique_ptr<Frame> NearbySharingDecoderImpl::DecodeFrame(
|
||||
absl::Span<const uint8_t> data) const {
|
||||
auto frame = std::make_unique<Frame>();
|
||||
|
||||
if (frame->ParseFromArray(data.data(), data.size())) {
|
||||
return frame;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sharing
|
||||
} // namespace nearby
|
||||
@@ -1,41 +0,0 @@
|
||||
// Copyright 2022 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef THIRD_PARTY_NEARBY_SHARING_NEARBY_SHARING_DECODER_IMPL_H_
|
||||
#define THIRD_PARTY_NEARBY_SHARING_NEARBY_SHARING_DECODER_IMPL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "absl/types/span.h"
|
||||
#include "sharing/advertisement.h"
|
||||
#include "sharing/nearby_sharing_decoder.h"
|
||||
#include "sharing/proto/wire_format.pb.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace sharing {
|
||||
|
||||
class NearbySharingDecoderImpl : public NearbySharingDecoder {
|
||||
public:
|
||||
std::unique_ptr<Advertisement> DecodeAdvertisement(
|
||||
absl::Span<const uint8_t> data) const override;
|
||||
std::unique_ptr<nearby::sharing::service::proto::Frame> DecodeFrame(
|
||||
absl::Span<const uint8_t> data) const override;
|
||||
};
|
||||
|
||||
} // namespace sharing
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_SHARING_NEARBY_SHARING_DECODER_IMPL_H_
|
||||
@@ -23,7 +23,6 @@
|
||||
#include "sharing/internal/api/sharing_platform.h"
|
||||
#include "sharing/internal/public/context_impl.h"
|
||||
#include "sharing/nearby_connections_manager_factory.h"
|
||||
#include "sharing/nearby_sharing_decoder_impl.h"
|
||||
#include "sharing/nearby_sharing_service.h"
|
||||
#include "sharing/nearby_sharing_service_impl.h"
|
||||
|
||||
@@ -47,7 +46,6 @@ NearbySharingService* NearbySharingServiceFactory::CreateSharingService(
|
||||
context_ =
|
||||
std::make_unique<ContextImpl>(sharing_platform);
|
||||
event_logger_ = event_logger;
|
||||
decoder_ = std::make_unique<NearbySharingDecoderImpl>();
|
||||
std::unique_ptr<TaskRunner> service_thread =
|
||||
context_->CreateSequencedTaskRunner();
|
||||
auto nearby_connections_manager =
|
||||
@@ -56,9 +54,7 @@ NearbySharingService* NearbySharingServiceFactory::CreateSharingService(
|
||||
sharing_platform.GetDeviceInfo(), event_logger_);
|
||||
|
||||
nearby_sharing_service_ = std::make_unique<NearbySharingServiceImpl>(
|
||||
vendor_id,
|
||||
std::move(service_thread),
|
||||
context_.get(), sharing_platform, decoder_.get(),
|
||||
vendor_id, std::move(service_thread), context_.get(), sharing_platform,
|
||||
std::move(nearby_connections_manager), event_logger_);
|
||||
|
||||
return nearby_sharing_service_.get();
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "internal/analytics/event_logger.h"
|
||||
#include "sharing/internal/api/sharing_platform.h"
|
||||
#include "sharing/internal/public/context.h"
|
||||
#include "sharing/nearby_sharing_decoder.h"
|
||||
#include "sharing/nearby_sharing_service.h"
|
||||
|
||||
namespace nearby::sharing {
|
||||
@@ -41,7 +40,6 @@ class NearbySharingServiceFactory {
|
||||
|
||||
std::unique_ptr<Context> context_;
|
||||
::nearby::analytics::EventLogger* event_logger_ = nullptr;
|
||||
std::unique_ptr<NearbySharingDecoder> decoder_;
|
||||
std::unique_ptr<NearbySharingService> nearby_sharing_service_;
|
||||
};
|
||||
|
||||
|
||||
@@ -193,7 +193,6 @@ OSType ToProtoOsType(::nearby::api::DeviceInfo::OsType os_type) {
|
||||
NearbySharingServiceImpl::NearbySharingServiceImpl(
|
||||
int32_t vendor_id, std::unique_ptr<TaskRunner> service_thread,
|
||||
Context* context, SharingPlatform& sharing_platform,
|
||||
NearbySharingDecoder* decoder,
|
||||
std::unique_ptr<NearbyConnectionsManager> nearby_connections_manager,
|
||||
nearby::analytics::EventLogger* event_logger)
|
||||
: service_thread_(std::move(service_thread)),
|
||||
@@ -201,7 +200,6 @@ NearbySharingServiceImpl::NearbySharingServiceImpl(
|
||||
device_info_(sharing_platform.GetDeviceInfo()),
|
||||
preference_manager_(sharing_platform.GetPreferenceManager()),
|
||||
account_manager_(sharing_platform.GetAccountManager()),
|
||||
decoder_(decoder),
|
||||
nearby_connections_manager_(std::move(nearby_connections_manager)),
|
||||
analytics_recorder_(std::make_unique<analytics::AnalyticsRecorder>(
|
||||
vendor_id, event_logger)),
|
||||
@@ -229,7 +227,6 @@ NearbySharingServiceImpl::NearbySharingServiceImpl(
|
||||
context_, settings_.get())),
|
||||
file_handler_(sharing_platform),
|
||||
app_info_(sharing_platform.CreateAppInfo()) {
|
||||
NL_DCHECK(decoder_);
|
||||
NL_DCHECK(nearby_connections_manager_);
|
||||
|
||||
is_shutting_down_ = std::make_unique<bool>(false);
|
||||
@@ -1100,14 +1097,14 @@ void NearbySharingServiceImpl::OnIncomingConnection(
|
||||
IncomingShareSession& session = CreateIncomingShareSession(
|
||||
placeholder_share_target, endpoint_id, /*certificate=*/std::nullopt);
|
||||
session.set_session_id(analytics_recorder_->GenerateNextId());
|
||||
session.OnConnected(*decoder_, context_->GetClock()->Now(),
|
||||
session.OnConnected(context_->GetClock()->Now(),
|
||||
nearby_connections_manager_.get(), connection);
|
||||
connection->SetDisconnectionListener([this, placeholder_share_target_id]() {
|
||||
OnConnectionDisconnected(placeholder_share_target_id);
|
||||
});
|
||||
|
||||
std::unique_ptr<Advertisement> advertisement =
|
||||
decoder_->DecodeAdvertisement(endpoint_info);
|
||||
DecodeAdvertisement(endpoint_info);
|
||||
OnIncomingAdvertisementDecoded(endpoint_id, session,
|
||||
std::move(advertisement));
|
||||
}
|
||||
@@ -1699,7 +1696,7 @@ void NearbySharingServiceImpl::HandleEndpointDiscovered(
|
||||
}
|
||||
|
||||
std::unique_ptr<Advertisement> advertisement =
|
||||
decoder_->DecodeAdvertisement(endpoint_info);
|
||||
DecodeAdvertisement(endpoint_info);
|
||||
OnOutgoingAdvertisementDecoded(endpoint_id, endpoint_info,
|
||||
std::move(advertisement));
|
||||
}
|
||||
@@ -2461,7 +2458,7 @@ void NearbySharingServiceImpl::OnOutgoingConnection(
|
||||
absl::Time connect_start_time, NearbyConnection* connection,
|
||||
OutgoingShareSession& session) {
|
||||
int64_t share_target_id = session.share_target().id;
|
||||
if (!session.OnConnected(*decoder_, connect_start_time,
|
||||
if (!session.OnConnected(connect_start_time,
|
||||
nearby_connections_manager_.get(), connection)) {
|
||||
session.Abort(session.disconnect_status());
|
||||
return;
|
||||
@@ -2828,7 +2825,7 @@ void NearbySharingServiceImpl::OnIncomingDecryptedCertificate(
|
||||
*share_target, endpoint_id, std::move(certificate));
|
||||
// Copy session id from placeholder session to actual session.
|
||||
session.set_session_id(session_id);
|
||||
session.OnConnected(*decoder_, context_->GetClock()->Now(),
|
||||
session.OnConnected(context_->GetClock()->Now(),
|
||||
nearby_connections_manager_.get(), connection);
|
||||
// Need to rebind the disconnect listener to the new share target id.
|
||||
connection->SetDisconnectionListener(
|
||||
|
||||
@@ -64,7 +64,6 @@
|
||||
#include "sharing/nearby_connections_manager.h"
|
||||
#include "sharing/nearby_connections_types.h"
|
||||
#include "sharing/nearby_file_handler.h"
|
||||
#include "sharing/nearby_sharing_decoder.h"
|
||||
#include "sharing/nearby_sharing_service.h"
|
||||
#include "sharing/nearby_sharing_service_extension.h"
|
||||
#include "sharing/nearby_sharing_settings.h"
|
||||
@@ -109,7 +108,6 @@ class NearbySharingServiceImpl
|
||||
NearbySharingServiceImpl(
|
||||
int32_t vendor_id, std::unique_ptr<nearby::TaskRunner> service_thread,
|
||||
Context* context, nearby::sharing::api::SharingPlatform& sharing_platform,
|
||||
NearbySharingDecoder* decoder,
|
||||
std::unique_ptr<NearbyConnectionsManager> nearby_connections_manager,
|
||||
nearby::analytics::EventLogger* event_logger = nullptr);
|
||||
~NearbySharingServiceImpl() override;
|
||||
@@ -455,7 +453,6 @@ class NearbySharingServiceImpl
|
||||
nearby::DeviceInfo& device_info_;
|
||||
nearby::sharing::api::PreferenceManager& preference_manager_;
|
||||
AccountManager& account_manager_;
|
||||
NearbySharingDecoder* const decoder_;
|
||||
|
||||
std::unique_ptr<NearbyConnectionsManager> nearby_connections_manager_;
|
||||
// Used to create analytics events.
|
||||
|
||||
@@ -79,7 +79,6 @@
|
||||
#include "sharing/local_device_data/nearby_share_local_device_data_manager_impl.h"
|
||||
#include "sharing/nearby_connections_manager.h"
|
||||
#include "sharing/nearby_connections_types.h"
|
||||
#include "sharing/nearby_sharing_decoder.h"
|
||||
#include "sharing/nearby_sharing_service.h"
|
||||
#include "sharing/nearby_sharing_settings.h"
|
||||
#include "sharing/proto/enums.pb.h"
|
||||
@@ -143,16 +142,6 @@ class MockShareTargetDiscoveredCallback : public ShareTargetDiscoveredCallback {
|
||||
(override));
|
||||
};
|
||||
|
||||
class MockNearbySharingDecoder : public NearbySharingDecoder {
|
||||
public:
|
||||
~MockNearbySharingDecoder() override = default;
|
||||
|
||||
MOCK_METHOD(std::unique_ptr<Advertisement>, DecodeAdvertisement,
|
||||
(absl::Span<const uint8_t> data), (const, override));
|
||||
MOCK_METHOD(std::unique_ptr<Frame>, DecodeFrame,
|
||||
(absl::Span<const uint8_t> data), (const, override));
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace NearbySharingServiceUnitTests {
|
||||
@@ -174,17 +163,6 @@ constexpr uint8_t kVendorId = 0;
|
||||
|
||||
constexpr int64_t kFreeDiskSpace = 10000;
|
||||
|
||||
std::vector<uint8_t> GetValidV1EndpointInfoWithVendor(uint8_t vendor_id) {
|
||||
auto advertisement = Advertisement::NewInstance(
|
||||
{0, 0}, std::vector<uint8_t>(14, 0), ShareTargetType::kPhone,
|
||||
"deviceName", vendor_id);
|
||||
return advertisement->ToEndpointInfo();
|
||||
}
|
||||
|
||||
std::vector<uint8_t> GetValidV1EndpointInfo() {
|
||||
return GetValidV1EndpointInfoWithVendor(kVendorId);
|
||||
}
|
||||
|
||||
const std::vector<uint8_t>& GetToken() {
|
||||
static std::vector<uint8_t>* token = new std::vector<uint8_t>({0, 1, 2});
|
||||
return *token;
|
||||
@@ -428,7 +406,7 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
fake_nearby_connections_manager_ = new FakeNearbyConnectionsManager();
|
||||
return std::make_unique<NearbySharingServiceImpl>(
|
||||
/*vendor_id=*/0, std::move(task_runner), &fake_context_,
|
||||
mock_sharing_platform_, &fake_decoder_,
|
||||
mock_sharing_platform_,
|
||||
absl::WrapUnique(fake_nearby_connections_manager_));
|
||||
}
|
||||
|
||||
@@ -638,121 +616,80 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS);
|
||||
local_device_data_manager()->SetDeviceName(kDeviceName);
|
||||
|
||||
std::string encryption_frame = "test_encryption_frame";
|
||||
std::vector<uint8_t> encryption_bytes(encryption_frame.begin(),
|
||||
encryption_frame.end());
|
||||
|
||||
EXPECT_CALL(fake_decoder_, DecodeFrame(testing::Eq(encryption_bytes)))
|
||||
.WillOnce(testing::Invoke([=](absl::Span<const uint8_t> data) {
|
||||
V1Frame* v1_frame = V1Frame::default_instance().New();
|
||||
v1_frame->set_type(V1Frame::PAIRED_KEY_ENCRYPTION);
|
||||
nearby::sharing::service::proto::PairedKeyEncryptionFrame*
|
||||
paired_key_encryption_frame =
|
||||
nearby::sharing::service::proto::PairedKeyEncryptionFrame::
|
||||
default_instance()
|
||||
.New();
|
||||
paired_key_encryption_frame->set_signed_data(
|
||||
is_incoming
|
||||
? std::string(GetIncomingConnectionSignedData().begin(),
|
||||
GetIncomingConnectionSignedData().end())
|
||||
: std::string(GetOutgoingConnectionSignedData().begin(),
|
||||
GetOutgoingConnectionSignedData().end()));
|
||||
paired_key_encryption_frame->set_secret_id_hash(
|
||||
std::string(GetPrivateCertificateHashAuthToken().begin(),
|
||||
GetPrivateCertificateHashAuthToken().end()));
|
||||
v1_frame->set_allocated_paired_key_encryption(
|
||||
paired_key_encryption_frame);
|
||||
Frame* frame = Frame::default_instance().New();
|
||||
frame->set_version(Frame::V1);
|
||||
frame->set_allocated_v1(v1_frame);
|
||||
return std::unique_ptr<Frame>(frame);
|
||||
}));
|
||||
Frame frame;
|
||||
frame.set_version(Frame::V1);
|
||||
V1Frame* v1_frame = frame.mutable_v1();
|
||||
v1_frame->set_type(V1Frame::PAIRED_KEY_ENCRYPTION);
|
||||
nearby::sharing::service::proto::PairedKeyEncryptionFrame*
|
||||
paired_key_encryption_frame =
|
||||
nearby::sharing::service::proto::PairedKeyEncryptionFrame::
|
||||
default_instance()
|
||||
.New();
|
||||
paired_key_encryption_frame->set_signed_data(
|
||||
is_incoming
|
||||
? std::string(GetIncomingConnectionSignedData().begin(),
|
||||
GetIncomingConnectionSignedData().end())
|
||||
: std::string(GetOutgoingConnectionSignedData().begin(),
|
||||
GetOutgoingConnectionSignedData().end()));
|
||||
paired_key_encryption_frame->set_secret_id_hash(
|
||||
std::string(GetPrivateCertificateHashAuthToken().begin(),
|
||||
GetPrivateCertificateHashAuthToken().end()));
|
||||
v1_frame->set_allocated_paired_key_encryption(
|
||||
paired_key_encryption_frame);
|
||||
std::vector<uint8_t> encryption_bytes(frame.ByteSizeLong());
|
||||
frame.SerializeToArray(encryption_bytes.data(), encryption_bytes.size());
|
||||
|
||||
connection_->AppendReadableData(encryption_bytes);
|
||||
FlushTesting();
|
||||
|
||||
std::string encryption_result = "test_encryption_result";
|
||||
std::vector<uint8_t> result_bytes(encryption_result.begin(),
|
||||
encryption_result.end());
|
||||
|
||||
EXPECT_CALL(fake_decoder_, DecodeFrame(testing::Eq(result_bytes)))
|
||||
.WillOnce(testing::Invoke([=](absl::Span<const uint8_t> data) {
|
||||
V1Frame* v1_frame = V1Frame::default_instance().New();
|
||||
v1_frame->set_type(V1Frame::PAIRED_KEY_RESULT);
|
||||
PairedKeyResultFrame* paired_key_result_frame =
|
||||
PairedKeyResultFrame::default_instance().New();
|
||||
paired_key_result_frame->set_status(status);
|
||||
v1_frame->set_allocated_paired_key_result(paired_key_result_frame);
|
||||
|
||||
Frame* frame = Frame::default_instance().New();
|
||||
frame->set_version(Frame::V1);
|
||||
frame->set_allocated_v1(v1_frame);
|
||||
return std::unique_ptr<Frame>(frame);
|
||||
}));
|
||||
Frame result_frame;
|
||||
result_frame.set_version(Frame::V1);
|
||||
V1Frame* result_v1_frame = result_frame.mutable_v1();
|
||||
result_v1_frame->set_type(V1Frame::PAIRED_KEY_RESULT);
|
||||
PairedKeyResultFrame* paired_key_result_frame =
|
||||
result_v1_frame->mutable_paired_key_result();
|
||||
paired_key_result_frame->set_status(status);
|
||||
std::vector<uint8_t> result_bytes(result_frame.ByteSizeLong());
|
||||
result_frame.SerializeToArray(result_bytes.data(), result_bytes.size());
|
||||
|
||||
connection_->AppendReadableData(result_bytes);
|
||||
FlushTesting();
|
||||
}
|
||||
|
||||
void SetUpAdvertisementDecoder(const std::vector<uint8_t>& endpoint_info,
|
||||
bool return_empty_advertisement,
|
||||
bool return_empty_device_name,
|
||||
size_t expected_number_of_calls) {
|
||||
EXPECT_CALL(fake_decoder_, DecodeAdvertisement(testing::Eq(endpoint_info)))
|
||||
.Times(expected_number_of_calls)
|
||||
.WillRepeatedly(testing::Invoke([this, return_empty_advertisement,
|
||||
return_empty_device_name](
|
||||
absl::Span<const uint8_t> data) {
|
||||
if (return_empty_advertisement) {
|
||||
connection_->AppendReadableData({});
|
||||
FlushTesting();
|
||||
return std::unique_ptr<Advertisement>(nullptr);
|
||||
}
|
||||
|
||||
std::optional<std::string> device_name;
|
||||
if (!return_empty_device_name) device_name = kDeviceName;
|
||||
|
||||
return Advertisement::NewInstance(
|
||||
GetNearbyShareTestEncryptedMetadataKey().salt(),
|
||||
GetNearbyShareTestEncryptedMetadataKey().encrypted_key(),
|
||||
kDeviceType, device_name, kVendorId);
|
||||
}));
|
||||
std::vector<uint8_t> CreateTestEndpointInfo(uint8_t vendor_id = kVendorId) {
|
||||
std::unique_ptr<Advertisement> advertisement = Advertisement::NewInstance(
|
||||
GetNearbyShareTestEncryptedMetadataKey().salt(),
|
||||
GetNearbyShareTestEncryptedMetadataKey().encrypted_key(), kDeviceType,
|
||||
kDeviceName, vendor_id);
|
||||
return advertisement->ToEndpointInfo();
|
||||
}
|
||||
|
||||
void SetUpIntroductionFrameDecoder(bool return_empty_introduction_frame) {
|
||||
std::string intro = "introduction_frame";
|
||||
std::vector<uint8_t> bytes(intro.begin(), intro.end());
|
||||
|
||||
EXPECT_CALL(fake_decoder_, DecodeFrame(testing::Eq(bytes)))
|
||||
.WillOnce(testing::Invoke([=](absl::Span<const uint8_t> data) {
|
||||
if (return_empty_introduction_frame) {
|
||||
return GetEmptyIntroductionFrame();
|
||||
}
|
||||
|
||||
return GetValidIntroductionFrame();
|
||||
}));
|
||||
std::unique_ptr<Frame> frame;
|
||||
if (return_empty_introduction_frame) {
|
||||
frame = GetEmptyIntroductionFrame();
|
||||
} else {
|
||||
frame = GetValidIntroductionFrame();
|
||||
}
|
||||
std::vector<uint8_t> bytes(frame->ByteSizeLong());
|
||||
frame->SerializeToArray(bytes.data(), bytes.size());
|
||||
|
||||
connection_->AppendReadableData(bytes);
|
||||
FlushTesting();
|
||||
}
|
||||
|
||||
void SendConnectionResponse(ConnectionResponseFrame::Status status) {
|
||||
std::string intro = "connection_result_frame";
|
||||
std::vector<uint8_t> bytes(intro.begin(), intro.end());
|
||||
EXPECT_CALL(fake_decoder_, DecodeFrame(testing::Eq(bytes)))
|
||||
.WillOnce(testing::Invoke([=](absl::Span<const uint8_t> data) {
|
||||
return GetConnectionResponseFrame(status);
|
||||
}));
|
||||
std::unique_ptr<Frame> frame = GetConnectionResponseFrame(status);
|
||||
std::vector<uint8_t> bytes(frame->ByteSizeLong());
|
||||
frame->SerializeToArray(bytes.data(), bytes.size());
|
||||
connection_->AppendReadableData(bytes);
|
||||
FlushTesting();
|
||||
}
|
||||
|
||||
void SendCancel() {
|
||||
std::string intro = "cancel_frame";
|
||||
std::vector<uint8_t> bytes(intro.begin(), intro.end());
|
||||
EXPECT_CALL(fake_decoder_, DecodeFrame(testing::Eq(bytes)))
|
||||
.WillOnce(testing::Invoke(
|
||||
[=](absl::Span<const uint8_t> data) { return GetCancelFrame(); }));
|
||||
std::unique_ptr<Frame> frame = GetCancelFrame();
|
||||
std::vector<uint8_t> bytes(frame->ByteSizeLong());
|
||||
frame->SerializeToArray(bytes.data(), bytes.size());
|
||||
connection_->AppendReadableData(bytes);
|
||||
FlushTesting();
|
||||
}
|
||||
@@ -762,10 +699,6 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
bool for_self_share = false) {
|
||||
fake_nearby_connections_manager_->SetRawAuthenticationToken(kEndpointId,
|
||||
GetToken());
|
||||
SetUpAdvertisementDecoder(GetValidV1EndpointInfo(),
|
||||
/*return_empty_advertisement=*/false,
|
||||
/*return_empty_device_name=*/false,
|
||||
/*expected_number_of_calls=*/1u);
|
||||
|
||||
SetUpIntroductionFrameDecoder(/*return_empty_introduction_frame=*/false);
|
||||
|
||||
@@ -800,7 +733,7 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
SetUpBackgroundReceiveSurface(callback);
|
||||
}
|
||||
EXPECT_CALL(*mock_app_info_, SetActiveFlag());
|
||||
service_->OnIncomingConnection(kEndpointId, GetValidV1EndpointInfo(),
|
||||
service_->OnIncomingConnection(kEndpointId, CreateTestEndpointInfo(),
|
||||
connection_.get());
|
||||
ProcessLatestPublicCertificateDecryption(/*expected_num_calls=*/1,
|
||||
/*success=*/true, for_self_share);
|
||||
@@ -850,12 +783,6 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
MockShareTargetDiscoveredCallback& discovery_callback) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
|
||||
// Ensure decoder parses a valid endpoint advertisement.
|
||||
SetUpAdvertisementDecoder(GetValidV1EndpointInfo(),
|
||||
/*return_empty_advertisement=*/false,
|
||||
/*return_empty_device_name=*/false,
|
||||
/*expected_number_of_calls=*/1u);
|
||||
|
||||
// Start discovering, to ensure a discovery listener is registered.
|
||||
EXPECT_EQ(RegisterSendSurface(&transfer_callback, &discovery_callback,
|
||||
SendSurfaceState::kForeground),
|
||||
@@ -870,7 +797,7 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
});
|
||||
|
||||
auto endpoint_info = std::make_unique<DiscoveredEndpointInfo>(
|
||||
GetValidV1EndpointInfo(), kServiceId);
|
||||
CreateTestEndpointInfo(), kServiceId);
|
||||
fake_nearby_connections_manager_->OnEndpointFound(kEndpointId,
|
||||
std::move(endpoint_info));
|
||||
FlushTesting();
|
||||
@@ -1080,6 +1007,21 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
*fake_nearby_connections_manager_->advertising_endpoint_info()));
|
||||
}
|
||||
|
||||
std::vector<uint8_t> CreateInvalidTestEndpointInfo() {
|
||||
std::unique_ptr<Advertisement> advertisement = Advertisement::NewInstance(
|
||||
GetNearbyShareTestEncryptedMetadataKey().salt(),
|
||||
GetNearbyShareTestEncryptedMetadataKey().encrypted_key(), kDeviceType,
|
||||
std::nullopt, kVendorId);
|
||||
return advertisement->ToEndpointInfo();
|
||||
}
|
||||
|
||||
void FindInvalidEndpoint(absl::string_view endpoint_id) {
|
||||
fake_nearby_connections_manager_->OnEndpointFound(
|
||||
endpoint_id, std::make_unique<DiscoveredEndpointInfo>(
|
||||
CreateInvalidTestEndpointInfo(), kServiceId));
|
||||
FlushTesting();
|
||||
}
|
||||
|
||||
void FindEndpoint(absl::string_view endpoint_id) {
|
||||
FindEndpointWithVendorId(endpoint_id, kVendorId);
|
||||
}
|
||||
@@ -1087,9 +1029,8 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
void FindEndpointWithVendorId(absl::string_view endpoint_id,
|
||||
uint8_t vendor_id) {
|
||||
fake_nearby_connections_manager_->OnEndpointFound(
|
||||
endpoint_id,
|
||||
std::make_unique<DiscoveredEndpointInfo>(
|
||||
GetValidV1EndpointInfoWithVendor(vendor_id), kServiceId));
|
||||
endpoint_id, std::make_unique<DiscoveredEndpointInfo>(
|
||||
CreateTestEndpointInfo(vendor_id), kServiceId));
|
||||
FlushTesting();
|
||||
}
|
||||
|
||||
@@ -1260,7 +1201,6 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
std::unique_ptr<FakeNearbyFastInitiation::Factory>
|
||||
nearby_fast_initiation_factory_;
|
||||
std::unique_ptr<FakeNearbyConnection> connection_;
|
||||
MockNearbySharingDecoder fake_decoder_;
|
||||
StrictMock<MockAppInfo>* mock_app_info_ = nullptr;
|
||||
std::unique_ptr<NearbySharingServiceImpl> service_;
|
||||
int expect_transfer_updates_count_ = 0;
|
||||
@@ -1635,12 +1575,6 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
RegisterSendSurfaceEndpointFoundDiscoveryCallbackNotified) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
|
||||
// Ensure decoder parses a valid endpoint advertisement.
|
||||
SetUpAdvertisementDecoder(GetValidV1EndpointInfo(),
|
||||
/*return_empty_advertisement=*/false,
|
||||
/*return_empty_device_name=*/false,
|
||||
/*expected_number_of_calls=*/1u);
|
||||
|
||||
// Start discovering, to ensure a discovery listener is registered.
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
NiceMock<MockShareTargetDiscoveredCallback> discovery_callback;
|
||||
@@ -1662,7 +1596,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
});
|
||||
fake_nearby_connections_manager_->OnEndpointFound(
|
||||
kEndpointId, std::make_unique<DiscoveredEndpointInfo>(
|
||||
GetValidV1EndpointInfo(), kServiceId));
|
||||
CreateTestEndpointInfo(), kServiceId));
|
||||
FlushTesting();
|
||||
ProcessLatestPublicCertificateDecryption(/*expected_num_calls=*/1,
|
||||
/*success=*/true);
|
||||
@@ -1688,12 +1622,6 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
TEST_F(NearbySharingServiceImplTest, RegisterSendSurfaceEmptyCertificate) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
|
||||
// Ensure decoder parses a valid endpoint advertisement.
|
||||
SetUpAdvertisementDecoder(GetValidV1EndpointInfo(),
|
||||
/*return_empty_advertisement=*/false,
|
||||
/*return_empty_device_name=*/false,
|
||||
/*expected_number_of_calls=*/1u);
|
||||
|
||||
// Start discovering, to ensure a discovery listener is registered.
|
||||
MockTransferUpdateCallback transfer_callback;
|
||||
NiceMock<MockShareTargetDiscoveredCallback> discovery_callback;
|
||||
@@ -1716,7 +1644,7 @@ TEST_F(NearbySharingServiceImplTest, RegisterSendSurfaceEmptyCertificate) {
|
||||
});
|
||||
fake_nearby_connections_manager_->OnEndpointFound(
|
||||
kEndpointId, std::make_unique<DiscoveredEndpointInfo>(
|
||||
GetValidV1EndpointInfo(), kServiceId));
|
||||
CreateTestEndpointInfo(), kServiceId));
|
||||
FlushTesting();
|
||||
ProcessLatestPublicCertificateDecryption(/*expected_num_calls=*/1,
|
||||
/*success=*/false);
|
||||
@@ -2387,10 +2315,6 @@ TEST_F(NearbySharingServiceImplTest, UnregisterReceiveSurfaceNeverRegistered) {
|
||||
TEST_F(NearbySharingServiceImplTest, IncomingConnectionClosedAfterShutdown) {
|
||||
fake_nearby_connections_manager_->SetRawAuthenticationToken(kEndpointId,
|
||||
GetToken());
|
||||
SetUpAdvertisementDecoder(GetValidV1EndpointInfo(),
|
||||
/*return_empty_advertisement=*/false,
|
||||
/*return_empty_device_name=*/false,
|
||||
/*expected_number_of_calls=*/1u);
|
||||
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
@@ -2402,7 +2326,7 @@ TEST_F(NearbySharingServiceImplTest, IncomingConnectionClosedAfterShutdown) {
|
||||
EXPECT_CALL(*mock_app_info_, SetActiveFlag());
|
||||
Shutdown();
|
||||
|
||||
service_->OnIncomingConnection(kEndpointId, GetValidV1EndpointInfo(),
|
||||
service_->OnIncomingConnection(kEndpointId, CreateTestEndpointInfo(),
|
||||
connection_.get());
|
||||
|
||||
sharing_service_task_runner_->SyncWithTimeout(kTaskWaitTimeout);
|
||||
@@ -2413,10 +2337,6 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
IncomingConnectionClosedBeforeCertDecryption) {
|
||||
fake_nearby_connections_manager_->SetRawAuthenticationToken(kEndpointId,
|
||||
GetToken());
|
||||
SetUpAdvertisementDecoder(GetValidV1EndpointInfo(),
|
||||
/*return_empty_advertisement=*/false,
|
||||
/*return_empty_device_name=*/false,
|
||||
/*expected_number_of_calls=*/1u);
|
||||
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS);
|
||||
@@ -2432,7 +2352,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
SetUpForegroundReceiveSurface(callback);
|
||||
EXPECT_CALL(*mock_app_info_, SetActiveFlag());
|
||||
service_->OnIncomingConnection(kEndpointId, GetValidV1EndpointInfo(),
|
||||
service_->OnIncomingConnection(kEndpointId, CreateTestEndpointInfo(),
|
||||
connection_.get());
|
||||
sharing_service_task_runner_->PostTask([this]() { connection_->Close(); });
|
||||
sharing_service_task_runner_->SyncWithTimeout(kTaskWaitTimeout);
|
||||
@@ -2445,10 +2365,6 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
IncomingConnectionClosedReadingIntroduction) {
|
||||
fake_nearby_connections_manager_->SetRawAuthenticationToken(kEndpointId,
|
||||
GetToken());
|
||||
SetUpAdvertisementDecoder(GetValidV1EndpointInfo(),
|
||||
/*return_empty_advertisement=*/false,
|
||||
/*return_empty_device_name=*/false,
|
||||
/*expected_number_of_calls=*/1u);
|
||||
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
@@ -2459,7 +2375,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
service::proto::PairedKeyResultFrame::SUCCESS);
|
||||
SetUpForegroundReceiveSurface(callback);
|
||||
EXPECT_CALL(*mock_app_info_, SetActiveFlag());
|
||||
service_->OnIncomingConnection(kEndpointId, GetValidV1EndpointInfo(),
|
||||
service_->OnIncomingConnection(kEndpointId, CreateTestEndpointInfo(),
|
||||
connection_.get());
|
||||
ProcessLatestPublicCertificateDecryption(/*expected_num_calls=*/1,
|
||||
/*success=*/true);
|
||||
@@ -2471,10 +2387,6 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
TEST_F(NearbySharingServiceImplTest, IncomingConnectionEmptyIntroductionFrame) {
|
||||
fake_nearby_connections_manager_->SetRawAuthenticationToken(kEndpointId,
|
||||
GetToken());
|
||||
SetUpAdvertisementDecoder(GetValidV1EndpointInfo(),
|
||||
/*return_empty_advertisement=*/false,
|
||||
/*return_empty_device_name=*/false,
|
||||
/*expected_number_of_calls=*/1u);
|
||||
SetUpIntroductionFrameDecoder(/*return_empty_introduction_frame=*/true);
|
||||
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
@@ -2500,7 +2412,7 @@ TEST_F(NearbySharingServiceImplTest, IncomingConnectionEmptyIntroductionFrame) {
|
||||
service::proto::PairedKeyResultFrame::SUCCESS);
|
||||
SetUpForegroundReceiveSurface(callback);
|
||||
EXPECT_CALL(*mock_app_info_, SetActiveFlag());
|
||||
service_->OnIncomingConnection(kEndpointId, GetValidV1EndpointInfo(),
|
||||
service_->OnIncomingConnection(kEndpointId, CreateTestEndpointInfo(),
|
||||
connection_.get());
|
||||
ProcessLatestPublicCertificateDecryption(/*expected_num_calls=*/1,
|
||||
/*success=*/true);
|
||||
@@ -2518,10 +2430,6 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
IncomingConnectionValidIntroductionFrameInvalidCertificate) {
|
||||
fake_nearby_connections_manager_->SetRawAuthenticationToken(kEndpointId,
|
||||
GetToken());
|
||||
SetUpAdvertisementDecoder(GetValidV1EndpointInfo(),
|
||||
/*return_empty_advertisement=*/false,
|
||||
/*return_empty_device_name=*/false,
|
||||
/*expected_number_of_calls=*/1u);
|
||||
SetUpIntroductionFrameDecoder(/*return_empty_introduction_frame=*/false);
|
||||
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
@@ -2550,7 +2458,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
service::proto::PairedKeyResultFrame::SUCCESS);
|
||||
SetUpForegroundReceiveSurface(callback);
|
||||
EXPECT_CALL(*mock_app_info_, SetActiveFlag());
|
||||
service_->OnIncomingConnection(kEndpointId, GetValidV1EndpointInfo(),
|
||||
service_->OnIncomingConnection(kEndpointId, CreateTestEndpointInfo(),
|
||||
connection_.get());
|
||||
ProcessLatestPublicCertificateDecryption(/*expected_num_calls=*/1,
|
||||
/*success=*/false);
|
||||
@@ -2608,40 +2516,24 @@ TEST_F(NearbySharingServiceImplTest, IncomingConnectionOutOfStorage) {
|
||||
GetCompatibleU8String(fake_device_info_.GetDownloadPath().u8string()));
|
||||
fake_nearby_connections_manager_->SetRawAuthenticationToken(kEndpointId,
|
||||
GetToken());
|
||||
SetUpAdvertisementDecoder(GetValidV1EndpointInfo(),
|
||||
/*return_empty_advertisement=*/false,
|
||||
/*return_empty_device_name=*/false,
|
||||
/*expected_number_of_calls=*/1u);
|
||||
|
||||
// Set a huge file size in introduction frame to go out of storage.
|
||||
std::string intro = "introduction_frame";
|
||||
std::vector<uint8_t> bytes(intro.begin(), intro.end());
|
||||
EXPECT_CALL(fake_decoder_, DecodeFrame(testing::Eq(bytes)))
|
||||
.WillOnce(testing::Invoke([=](absl::Span<const uint8_t> data) {
|
||||
IntroductionFrame* introduction_frame =
|
||||
IntroductionFrame::default_instance().New();
|
||||
auto file_metadatas = introduction_frame->mutable_file_metadata();
|
||||
nearby::sharing::service::proto::FileMetadata* file_metadata =
|
||||
nearby::sharing::service::proto::FileMetadata::default_instance()
|
||||
.New();
|
||||
file_metadata->set_name("name");
|
||||
file_metadata->set_type(
|
||||
nearby::sharing::service::proto::FileMetadata::AUDIO);
|
||||
file_metadata->set_payload_id(1);
|
||||
file_metadata->set_size(kFreeDiskSpace + 1);
|
||||
file_metadata->set_mime_type("mime type");
|
||||
file_metadata->set_id(123);
|
||||
file_metadatas->AddAllocated(file_metadata);
|
||||
|
||||
V1Frame* v1_frame = V1Frame::default_instance().New();
|
||||
v1_frame->set_type(V1Frame::INTRODUCTION);
|
||||
v1_frame->set_allocated_introduction(introduction_frame);
|
||||
|
||||
Frame* frame = Frame::default_instance().New();
|
||||
frame->set_version(Frame::V1);
|
||||
frame->set_allocated_v1(v1_frame);
|
||||
return std::unique_ptr<Frame>(frame);
|
||||
}));
|
||||
Frame frame;
|
||||
frame.set_version(Frame::V1);
|
||||
V1Frame* v1_frame = frame.mutable_v1();
|
||||
v1_frame->set_type(V1Frame::INTRODUCTION);
|
||||
IntroductionFrame* introduction_frame = v1_frame->mutable_introduction();
|
||||
nearby::sharing::service::proto::FileMetadata* file_metadata =
|
||||
introduction_frame->add_file_metadata();
|
||||
file_metadata->set_name("name");
|
||||
file_metadata->set_type(
|
||||
nearby::sharing::service::proto::FileMetadata::AUDIO);
|
||||
file_metadata->set_payload_id(1);
|
||||
file_metadata->set_size(kFreeDiskSpace + 1);
|
||||
file_metadata->set_mime_type("mime type");
|
||||
file_metadata->set_id(123);
|
||||
std::vector<uint8_t> bytes(frame.ByteSizeLong());
|
||||
frame.SerializeToArray(bytes.data(), bytes.size());
|
||||
connection_->AppendReadableData(std::move(bytes));
|
||||
FlushTesting();
|
||||
|
||||
@@ -2668,7 +2560,7 @@ TEST_F(NearbySharingServiceImplTest, IncomingConnectionOutOfStorage) {
|
||||
/*is_incoming=*/true, PairedKeyResultFrame::SUCCESS);
|
||||
SetUpForegroundReceiveSurface(callback);
|
||||
EXPECT_CALL(*mock_app_info_, SetActiveFlag());
|
||||
service_->OnIncomingConnection(kEndpointId, GetValidV1EndpointInfo(),
|
||||
service_->OnIncomingConnection(kEndpointId, CreateTestEndpointInfo(),
|
||||
connection_.get());
|
||||
ProcessLatestPublicCertificateDecryption(/*expected_num_calls=*/1,
|
||||
/*success=*/true);
|
||||
@@ -2680,51 +2572,33 @@ TEST_F(NearbySharingServiceImplTest, IncomingConnectionOutOfStorage) {
|
||||
TEST_F(NearbySharingServiceImplTest, IncomingConnectionFileSizeOverflow) {
|
||||
fake_nearby_connections_manager_->SetRawAuthenticationToken(kEndpointId,
|
||||
GetToken());
|
||||
SetUpAdvertisementDecoder(GetValidV1EndpointInfo(),
|
||||
/*return_empty_advertisement=*/false,
|
||||
/*return_empty_device_name=*/false,
|
||||
/*expected_number_of_calls=*/1u);
|
||||
|
||||
// Set file size sum huge to check for overflow.
|
||||
std::string intro = "introduction_frame";
|
||||
std::vector<uint8_t> bytes(intro.begin(), intro.end());
|
||||
EXPECT_CALL(fake_decoder_, DecodeFrame(testing::Eq(bytes)))
|
||||
.WillOnce(testing::Invoke([=](absl::Span<const uint8_t> data) {
|
||||
IntroductionFrame* introduction_frame =
|
||||
IntroductionFrame::default_instance().New();
|
||||
auto file_metadatas = introduction_frame->mutable_file_metadata();
|
||||
nearby::sharing::service::proto::FileMetadata* file_metadata =
|
||||
nearby::sharing::service::proto::FileMetadata::default_instance()
|
||||
.New();
|
||||
file_metadata->set_name("name_1");
|
||||
file_metadata->set_type(
|
||||
nearby::sharing::service::proto::FileMetadata::AUDIO);
|
||||
file_metadata->set_payload_id(1);
|
||||
file_metadata->set_size(std::numeric_limits<int64_t>::max());
|
||||
file_metadata->set_mime_type("mime type");
|
||||
file_metadata->set_id(123);
|
||||
file_metadatas->AddAllocated(file_metadata);
|
||||
nearby::sharing::service::proto::FileMetadata* file2_metadata =
|
||||
nearby::sharing::service::proto::FileMetadata::default_instance()
|
||||
.New();
|
||||
file2_metadata->set_name("name_2");
|
||||
file2_metadata->set_type(
|
||||
nearby::sharing::service::proto::FileMetadata::VIDEO);
|
||||
file2_metadata->set_payload_id(2);
|
||||
file2_metadata->set_size(100);
|
||||
file2_metadata->set_mime_type("mime type");
|
||||
file2_metadata->set_id(124);
|
||||
file_metadatas->AddAllocated(file2_metadata);
|
||||
|
||||
V1Frame* v1_frame = V1Frame::default_instance().New();
|
||||
v1_frame->set_type(V1Frame::INTRODUCTION);
|
||||
v1_frame->set_allocated_introduction(introduction_frame);
|
||||
|
||||
Frame* frame = Frame::default_instance().New();
|
||||
frame->set_version(Frame::V1);
|
||||
frame->set_allocated_v1(v1_frame);
|
||||
return std::unique_ptr<Frame>(frame);
|
||||
}));
|
||||
Frame frame;
|
||||
frame.set_version(Frame::V1);
|
||||
V1Frame* v1_frame = frame.mutable_v1();
|
||||
v1_frame->set_type(V1Frame::INTRODUCTION);
|
||||
IntroductionFrame* introduction_frame = v1_frame->mutable_introduction();
|
||||
nearby::sharing::service::proto::FileMetadata* file_metadata =
|
||||
introduction_frame->add_file_metadata();
|
||||
file_metadata->set_name("name_1");
|
||||
file_metadata->set_type(
|
||||
nearby::sharing::service::proto::FileMetadata::AUDIO);
|
||||
file_metadata->set_payload_id(1);
|
||||
file_metadata->set_size(std::numeric_limits<int64_t>::max());
|
||||
file_metadata->set_mime_type("mime type");
|
||||
file_metadata->set_id(123);
|
||||
nearby::sharing::service::proto::FileMetadata* file2_metadata =
|
||||
introduction_frame->add_file_metadata();
|
||||
file2_metadata->set_name("name_2");
|
||||
file2_metadata->set_type(
|
||||
nearby::sharing::service::proto::FileMetadata::VIDEO);
|
||||
file2_metadata->set_payload_id(2);
|
||||
file2_metadata->set_size(100);
|
||||
file2_metadata->set_mime_type("mime type");
|
||||
file2_metadata->set_id(124);
|
||||
std::vector<uint8_t> bytes(frame.ByteSizeLong());
|
||||
frame.SerializeToArray(bytes.data(), bytes.size());
|
||||
connection_->AppendReadableData(std::move(bytes));
|
||||
FlushTesting();
|
||||
|
||||
@@ -2749,7 +2623,7 @@ TEST_F(NearbySharingServiceImplTest, IncomingConnectionFileSizeOverflow) {
|
||||
/*is_incoming=*/true, PairedKeyResultFrame::SUCCESS);
|
||||
SetUpForegroundReceiveSurface(callback);
|
||||
EXPECT_CALL(*mock_app_info_, SetActiveFlag());
|
||||
service_->OnIncomingConnection(kEndpointId, GetValidV1EndpointInfo(),
|
||||
service_->OnIncomingConnection(kEndpointId, CreateTestEndpointInfo(),
|
||||
connection_.get());
|
||||
ProcessLatestPublicCertificateDecryption(/*expected_num_calls=*/1,
|
||||
/*success=*/true);
|
||||
@@ -2761,10 +2635,6 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
IncomingConnectionValidIntroductionFrameValidCertificate) {
|
||||
fake_nearby_connections_manager_->SetRawAuthenticationToken(kEndpointId,
|
||||
GetToken());
|
||||
SetUpAdvertisementDecoder(GetValidV1EndpointInfo(),
|
||||
/*return_empty_advertisement=*/false,
|
||||
/*return_empty_device_name=*/false,
|
||||
/*expected_number_of_calls=*/1u);
|
||||
SetUpIntroductionFrameDecoder(/*return_empty_introduction_frame=*/false);
|
||||
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
@@ -2797,7 +2667,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
SetUpKeyVerification(/*is_incoming=*/true, PairedKeyResultFrame::SUCCESS);
|
||||
SetUpForegroundReceiveSurface(callback);
|
||||
EXPECT_CALL(*mock_app_info_, SetActiveFlag());
|
||||
service_->OnIncomingConnection(kEndpointId, GetValidV1EndpointInfo(),
|
||||
service_->OnIncomingConnection(kEndpointId, CreateTestEndpointInfo(),
|
||||
connection_.get());
|
||||
ProcessLatestPublicCertificateDecryption(/*expected_num_calls=*/1,
|
||||
/*success=*/true);
|
||||
@@ -3081,10 +2951,6 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
IncomingConnectionKeyVerificationRunnerStatusUnable) {
|
||||
fake_nearby_connections_manager_->SetRawAuthenticationToken(kEndpointId,
|
||||
GetToken());
|
||||
SetUpAdvertisementDecoder(GetValidV1EndpointInfo(),
|
||||
/*return_empty_advertisement=*/false,
|
||||
/*return_empty_device_name=*/false,
|
||||
/*expected_number_of_calls=*/1u);
|
||||
SetUpIntroductionFrameDecoder(/*return_empty_introduction_frame=*/false);
|
||||
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
@@ -3115,7 +2981,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
SetUpForegroundReceiveSurface(callback);
|
||||
EXPECT_CALL(*mock_app_info_, SetActiveFlag());
|
||||
|
||||
service_->OnIncomingConnection(kEndpointId, GetValidV1EndpointInfo(),
|
||||
service_->OnIncomingConnection(kEndpointId, CreateTestEndpointInfo(),
|
||||
connection_.get());
|
||||
ProcessLatestPublicCertificateDecryption(/*expected_num_calls=*/1,
|
||||
/*success=*/true);
|
||||
@@ -3131,10 +2997,6 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
IncomingConnectionKeyVerificationRunnerStatusUnableLowPower) {
|
||||
fake_nearby_connections_manager_->SetRawAuthenticationToken(kEndpointId,
|
||||
GetToken());
|
||||
SetUpAdvertisementDecoder(GetValidV1EndpointInfo(),
|
||||
/*return_empty_advertisement=*/false,
|
||||
/*return_empty_device_name=*/false,
|
||||
/*expected_number_of_calls=*/1u);
|
||||
SetUpIntroductionFrameDecoder(/*return_empty_introduction_frame=*/false);
|
||||
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
@@ -3170,7 +3032,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
EXPECT_TRUE(fake_nearby_connections_manager_->IsAdvertising());
|
||||
EXPECT_CALL(*mock_app_info_, SetActiveFlag());
|
||||
|
||||
service_->OnIncomingConnection(kEndpointId, GetValidV1EndpointInfo(),
|
||||
service_->OnIncomingConnection(kEndpointId, CreateTestEndpointInfo(),
|
||||
connection_.get());
|
||||
ProcessLatestPublicCertificateDecryption(/*expected_num_calls=*/1,
|
||||
/*success=*/true);
|
||||
@@ -3186,10 +3048,6 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
IncomingConnectionKeyVerificationRunnerStatusFail) {
|
||||
fake_nearby_connections_manager_->SetRawAuthenticationToken(kEndpointId,
|
||||
GetToken());
|
||||
SetUpAdvertisementDecoder(GetValidV1EndpointInfo(),
|
||||
/*return_empty_advertisement=*/false,
|
||||
/*return_empty_device_name=*/false,
|
||||
/*expected_number_of_calls=*/1u);
|
||||
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
@@ -3200,7 +3058,6 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
// Ensures that introduction is never received for failed key verification.
|
||||
std::string intro = "introduction_frame";
|
||||
std::vector<uint8_t> bytes(intro.begin(), intro.end());
|
||||
EXPECT_CALL(fake_decoder_, DecodeFrame(testing::Eq(bytes))).Times(0);
|
||||
connection_->AppendReadableData(bytes);
|
||||
FlushTesting();
|
||||
EXPECT_CALL(*mock_app_info_, SetActiveFlag());
|
||||
@@ -3210,7 +3067,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
nearby::sharing::HasStatus(
|
||||
TransferMetadata::Status::kPairedKeyVerificationFailed)));
|
||||
|
||||
service_->OnIncomingConnection(kEndpointId, GetValidV1EndpointInfo(),
|
||||
service_->OnIncomingConnection(kEndpointId, CreateTestEndpointInfo(),
|
||||
connection_.get());
|
||||
ProcessLatestPublicCertificateDecryption(/*expected_num_calls=*/1,
|
||||
/*success=*/true);
|
||||
@@ -3227,11 +3084,6 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
IncomingConnectionEmptyAuthTokenKeyVerificationRunnerStatusFail) {
|
||||
SetUpAdvertisementDecoder(GetValidV1EndpointInfo(),
|
||||
/*return_empty_advertisement=*/false,
|
||||
/*return_empty_device_name=*/false,
|
||||
/*expected_number_of_calls=*/1u);
|
||||
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_EVERYONE);
|
||||
NiceMock<MockTransferUpdateCallback> callback;
|
||||
@@ -3241,12 +3093,11 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
// Ensures that introduction is never received for empty auth token.
|
||||
std::string intro = "introduction_frame";
|
||||
std::vector<uint8_t> bytes(intro.begin(), intro.end());
|
||||
EXPECT_CALL(fake_decoder_, DecodeFrame(testing::Eq(bytes))).Times(0);
|
||||
connection_->AppendReadableData(bytes);
|
||||
FlushTesting();
|
||||
EXPECT_CALL(*mock_app_info_, SetActiveFlag());
|
||||
|
||||
service_->OnIncomingConnection(kEndpointId, GetValidV1EndpointInfo(),
|
||||
service_->OnIncomingConnection(kEndpointId, CreateTestEndpointInfo(),
|
||||
connection_.get());
|
||||
ProcessLatestPublicCertificateDecryption(/*expected_num_calls=*/1,
|
||||
/*success=*/true);
|
||||
@@ -4104,12 +3955,6 @@ TEST_F(NearbySharingServiceImplTest, OrderedEndpointDiscoveryEvents) {
|
||||
// - Nearby Connections loses endpoint 3
|
||||
// - Nearby Connections loses endpoint 2
|
||||
// - Nearby Share processes these four events in order.
|
||||
|
||||
// Expect the advertisement decoder to be invoked once for each discovery.
|
||||
SetUpAdvertisementDecoder(GetValidV1EndpointInfo(),
|
||||
/*return_empty_advertisement=*/false,
|
||||
/*return_empty_device_name=*/false,
|
||||
/*expected_number_of_calls=*/3u);
|
||||
{
|
||||
absl::Notification notification;
|
||||
FindEndpoint(/*endpoint_id=*/"1");
|
||||
@@ -4172,10 +4017,6 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
EXPECT_EQ(certificate_manager()->num_download_public_certificates_calls(),
|
||||
1u);
|
||||
EXPECT_TRUE(fake_nearby_connections_manager_->IsDiscovering());
|
||||
SetUpAdvertisementDecoder(GetValidV1EndpointInfo(),
|
||||
/*return_empty_advertisement=*/false,
|
||||
/*return_empty_device_name=*/true,
|
||||
/*expected_number_of_calls=*/1u);
|
||||
// Order of events:
|
||||
// - Discover endpoint 1 --> decrypts public certificate
|
||||
// - Fire certificate download timer --> no download because no cached
|
||||
@@ -4210,10 +4051,6 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
EXPECT_EQ(certificate_manager()->num_download_public_certificates_calls(),
|
||||
1u);
|
||||
EXPECT_TRUE(fake_nearby_connections_manager_->IsDiscovering());
|
||||
SetUpAdvertisementDecoder(GetValidV1EndpointInfo(),
|
||||
/*return_empty_advertisement=*/false,
|
||||
/*return_empty_device_name=*/true,
|
||||
/*expected_number_of_calls=*/6u);
|
||||
// Order of events:
|
||||
// - Discover endpoint 1 --> decrypts public certificate
|
||||
// - Discover endpoint 2 --> cannot decrypt public certificate
|
||||
@@ -4224,10 +4061,10 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
// - (Re)discover endpoints 2 and 4
|
||||
{
|
||||
absl::Notification notification;
|
||||
FindEndpoint(/*endpoint_id=*/"1");
|
||||
FindEndpoint(/*endpoint_id=*/"2");
|
||||
FindEndpoint(/*endpoint_id=*/"3");
|
||||
FindEndpoint(/*endpoint_id=*/"4");
|
||||
FindInvalidEndpoint(/*endpoint_id=*/"1");
|
||||
FindInvalidEndpoint(/*endpoint_id=*/"2");
|
||||
FindInvalidEndpoint(/*endpoint_id=*/"3");
|
||||
FindInvalidEndpoint(/*endpoint_id=*/"4");
|
||||
LoseEndpoint(/*endpoint_id=*/"3");
|
||||
::testing::InSequence s;
|
||||
EXPECT_CALL(discovery_callback, OnShareTargetDiscovered).Times(2);
|
||||
@@ -4276,10 +4113,6 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
EXPECT_EQ(certificate_manager()->num_download_public_certificates_calls(),
|
||||
1u);
|
||||
EXPECT_TRUE(fake_nearby_connections_manager_->IsDiscovering());
|
||||
SetUpAdvertisementDecoder(GetValidV1EndpointInfo(),
|
||||
/*return_empty_advertisement=*/false,
|
||||
/*return_empty_device_name=*/true,
|
||||
/*expected_number_of_calls=*/1u);
|
||||
// Order of events:
|
||||
// - Discover endpoint 1 --> cannot decrypt public certificate
|
||||
// - Stop discovery
|
||||
@@ -4287,7 +4120,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
// - Start discovery
|
||||
// - Fire certificate download timer --> certificates not downloaded; cached
|
||||
// advertisement map has been cleared
|
||||
FindEndpoint(/*endpoint_id=*/"1");
|
||||
FindInvalidEndpoint(/*endpoint_id=*/"1");
|
||||
InSequence s;
|
||||
EXPECT_CALL(discovery_callback, OnShareTargetDiscovered).Times(0);
|
||||
EXPECT_CALL(discovery_callback, OnShareTargetLost).Times(0);
|
||||
@@ -4322,11 +4155,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
EXPECT_EQ(certificate_manager()->num_download_public_certificates_calls(),
|
||||
1u);
|
||||
EXPECT_TRUE(fake_nearby_connections_manager_->IsDiscovering());
|
||||
SetUpAdvertisementDecoder(GetValidV1EndpointInfo(),
|
||||
/*return_empty_advertisement=*/false,
|
||||
/*return_empty_device_name=*/true,
|
||||
/*expected_number_of_calls=*/3u);
|
||||
FindEndpoint(/*endpoint_id=*/"1");
|
||||
FindInvalidEndpoint(/*endpoint_id=*/"1");
|
||||
|
||||
ProcessLatestPublicCertificateDecryption(/*expected_num_calls=*/1,
|
||||
/*success=*/false);
|
||||
@@ -4346,7 +4175,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
FlushTesting();
|
||||
// Don't download public certificates in case of the endpoint is discovered
|
||||
// again.
|
||||
FindEndpoint(/*endpoint_id=*/"1");
|
||||
FindInvalidEndpoint(/*endpoint_id=*/"1");
|
||||
ProcessLatestPublicCertificateDecryption(/*expected_num_calls=*/2,
|
||||
/*success=*/false);
|
||||
EXPECT_EQ(certificate_manager()->num_download_public_certificates_calls(),
|
||||
@@ -4365,11 +4194,6 @@ TEST_F(NearbySharingServiceImplTest, RetryDiscoveredEndpointsDownloadLimit) {
|
||||
EXPECT_EQ(certificate_manager()->num_download_public_certificates_calls(),
|
||||
1u);
|
||||
EXPECT_TRUE(fake_nearby_connections_manager_->IsDiscovering());
|
||||
SetUpAdvertisementDecoder(GetValidV1EndpointInfo(),
|
||||
/*return_empty_advertisement=*/false,
|
||||
/*return_empty_device_name=*/true,
|
||||
/*expected_number_of_calls=*/2u +
|
||||
kMaxCertificateDownloadsDuringDiscovery);
|
||||
// Order of events:
|
||||
// - x3:
|
||||
// - (Re)discover endpoint 1 --> cannot decrypt public certificate
|
||||
@@ -4378,7 +4202,7 @@ TEST_F(NearbySharingServiceImplTest, RetryDiscoveredEndpointsDownloadLimit) {
|
||||
// - Fire certificate download timer --> no download; limit reached
|
||||
// - Restart discovery which resets limit counter
|
||||
for (size_t i = 1; i <= kMaxCertificateDownloadsDuringDiscovery; ++i) {
|
||||
FindEndpoint(/*endpoint_id=*/absl::StrCat(i));
|
||||
FindInvalidEndpoint(/*endpoint_id=*/absl::StrCat(i));
|
||||
}
|
||||
|
||||
for (size_t i = 1; i <= kMaxCertificateDownloadsDuringDiscovery; ++i) {
|
||||
@@ -4401,7 +4225,7 @@ TEST_F(NearbySharingServiceImplTest, RetryDiscoveredEndpointsDownloadLimit) {
|
||||
// is not related to the retry timer.
|
||||
EXPECT_EQ(certificate_manager()->num_download_public_certificates_calls(),
|
||||
2u + kMaxCertificateDownloadsDuringDiscovery);
|
||||
FindEndpoint(/*endpoint_id=*/"1");
|
||||
FindInvalidEndpoint(/*endpoint_id=*/"1");
|
||||
ProcessLatestPublicCertificateDecryption(
|
||||
/*expected_num_calls=*/1u + kMaxCertificateDownloadsDuringDiscovery,
|
||||
/*success=*/false);
|
||||
@@ -4458,15 +4282,6 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, BlockTargetWithSameVendorId) {
|
||||
InSequence s;
|
||||
// Set up advertisement decoder.
|
||||
EXPECT_CALL(fake_decoder_, DecodeAdvertisement(testing::_))
|
||||
.WillRepeatedly(testing::Invoke([=](absl::Span<const uint8_t> data) {
|
||||
return Advertisement::NewInstance(
|
||||
GetNearbyShareTestEncryptedMetadataKey().salt(),
|
||||
GetNearbyShareTestEncryptedMetadataKey().encrypted_key(),
|
||||
kDeviceType, kDeviceName,
|
||||
static_cast<uint8_t>(Advertisement::BlockedVendorId::kSamsung));
|
||||
}));
|
||||
// Register send surface with vendor ID 1 that requests blocking.
|
||||
MockTransferUpdateCallback callback;
|
||||
MockShareTargetDiscoveredCallback discovery_callback;
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
#include "sharing/nearby_connections_manager.h"
|
||||
#include "sharing/nearby_connections_types.h"
|
||||
#include "sharing/nearby_file_handler.h"
|
||||
#include "sharing/nearby_sharing_decoder_impl.h"
|
||||
#include "sharing/paired_key_verification_runner.h"
|
||||
#include "sharing/proto/wire_format.pb.h"
|
||||
#include "sharing/share_target.h"
|
||||
@@ -102,11 +101,10 @@ class OutgoingShareSessionTest : public ::testing::Test {
|
||||
|
||||
protected:
|
||||
FakeClock fake_clock_;
|
||||
FakeTaskRunner fake_task_runner_ {&fake_clock_, 1};
|
||||
FakeTaskRunner fake_task_runner_{&fake_clock_, 1};
|
||||
nearby::analytics::MockEventLogger mock_event_logger_;
|
||||
analytics::AnalyticsRecorder analytics_recorder_{/*vendor_id=*/0,
|
||||
&mock_event_logger_};
|
||||
NearbySharingDecoderImpl decoder_;
|
||||
ShareTarget share_target_;
|
||||
MockFunction<void(OutgoingShareSession&, const TransferMetadata&)>
|
||||
transfer_metadata_callback_;
|
||||
@@ -252,8 +250,7 @@ TEST_F(OutgoingShareSessionTest, SendIntroductionWithoutPayloads) {
|
||||
TEST_F(OutgoingShareSessionTest, SendIntroductionSuccess) {
|
||||
session_.set_session_id(1234);
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder_, absl::Now(), &connections_manager_,
|
||||
&connection);
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection);
|
||||
std::vector<NearbyFileHandler::FileInfo> file_infos;
|
||||
file_infos.push_back({
|
||||
.size = 12355L,
|
||||
@@ -321,13 +318,11 @@ TEST_F(OutgoingShareSessionTest, SendIntroductionSuccess) {
|
||||
}
|
||||
|
||||
TEST_F(OutgoingShareSessionTest, SendIntroductionTimeout) {
|
||||
AttachmentContainer container(
|
||||
std::vector<TextAttachment>{text1_}, {}, {});
|
||||
AttachmentContainer container(std::vector<TextAttachment>{text1_}, {}, {});
|
||||
session_.SetAttachmentContainer(std::move(container));
|
||||
session_.set_session_id(1234);
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder_, absl::Now(), &connections_manager_,
|
||||
&connection);
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection);
|
||||
session_.CreateTextPayloads();
|
||||
EXPECT_CALL(
|
||||
mock_event_logger_,
|
||||
@@ -348,13 +343,11 @@ TEST_F(OutgoingShareSessionTest, SendIntroductionTimeout) {
|
||||
}
|
||||
|
||||
TEST_F(OutgoingShareSessionTest, SendIntroductionTimeoutCancelled) {
|
||||
AttachmentContainer container(
|
||||
std::vector<TextAttachment>{text1_}, {}, {});
|
||||
AttachmentContainer container(std::vector<TextAttachment>{text1_}, {}, {});
|
||||
session_.SetAttachmentContainer(std::move(container));
|
||||
session_.set_session_id(1234);
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder_, absl::Now(), &connections_manager_,
|
||||
&connection);
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection);
|
||||
session_.CreateTextPayloads();
|
||||
EXPECT_CALL(
|
||||
mock_event_logger_,
|
||||
@@ -391,8 +384,7 @@ TEST_F(OutgoingShareSessionTest, AcceptTransferNotConnected) {
|
||||
TEST_F(OutgoingShareSessionTest, AcceptTransferNotReady) {
|
||||
session_.set_session_id(1234);
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder_, absl::Now(), &connections_manager_,
|
||||
&connection);
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection);
|
||||
|
||||
EXPECT_THAT(
|
||||
session_.AcceptTransfer([](std::optional<ConnectionResponseFrame>) {}),
|
||||
@@ -400,13 +392,11 @@ TEST_F(OutgoingShareSessionTest, AcceptTransferNotReady) {
|
||||
}
|
||||
|
||||
TEST_F(OutgoingShareSessionTest, AcceptTransferSuccess) {
|
||||
AttachmentContainer container(
|
||||
std::vector<TextAttachment>{text1_}, {}, {});
|
||||
AttachmentContainer container(std::vector<TextAttachment>{text1_}, {}, {});
|
||||
session_.SetAttachmentContainer(std::move(container));
|
||||
session_.set_session_id(1234);
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder_, absl::Now(), &connections_manager_,
|
||||
&connection);
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection);
|
||||
session_.CreateTextPayloads();
|
||||
EXPECT_CALL(mock_event_logger_,
|
||||
Log(Matcher<const SharingLog&>(
|
||||
@@ -497,8 +487,7 @@ TEST_F(OutgoingShareSessionTest, HandleConnectionResponseAcceptResponse) {
|
||||
ConnectionResponseFrame response;
|
||||
response.set_status(ConnectionResponseFrame::ACCEPT);
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder_, absl::Now(), &connections_manager_,
|
||||
&connection);
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection);
|
||||
EXPECT_CALL(transfer_metadata_callback_,
|
||||
Call(_, HasStatus(TransferMetadata::Status::kInProgress)));
|
||||
|
||||
@@ -551,8 +540,7 @@ TEST_F(OutgoingShareSessionTest, SendPayloadsDisableCancellationOptimization) {
|
||||
Property(&SharingLog::send_attachments_start,
|
||||
HasSessionId(1234)))))));
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder_, absl::Now(), &connections_manager_,
|
||||
&connection);
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection);
|
||||
|
||||
session_.SendPayloads(
|
||||
/*enable_transfer_cancellation_optimization=*/
|
||||
@@ -594,8 +582,7 @@ TEST_F(OutgoingShareSessionTest, SendPayloadsEnableCancellationOptimization) {
|
||||
Property(&SharingLog::send_attachments_start,
|
||||
HasSessionId(1234)))))));
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder_, absl::Now(), &connections_manager_,
|
||||
&connection);
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection);
|
||||
|
||||
session_.SendPayloads(
|
||||
/*enable_transfer_cancellation_optimization=*/
|
||||
@@ -638,8 +625,7 @@ TEST_F(OutgoingShareSessionTest, SendNextPayload) {
|
||||
Property(&SharingLog::send_attachments_start,
|
||||
HasSessionId(1234)))))));
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder_, absl::Now(), &connections_manager_,
|
||||
&connection);
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection);
|
||||
|
||||
session_.SendPayloads(
|
||||
/*enable_transfer_cancellation_optimization=*/
|
||||
@@ -667,8 +653,7 @@ TEST_F(OutgoingShareSessionTest, SendNextPayload) {
|
||||
|
||||
TEST_F(OutgoingShareSessionTest, ProcessKeyVerificationResultFail) {
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder_, absl::Now(), &connections_manager_,
|
||||
&connection);
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection);
|
||||
session_.SetTokenForTests("1234");
|
||||
|
||||
EXPECT_THAT(
|
||||
@@ -683,8 +668,7 @@ TEST_F(OutgoingShareSessionTest, ProcessKeyVerificationResultFail) {
|
||||
|
||||
TEST_F(OutgoingShareSessionTest, ProcessKeyVerificationResultSuccess) {
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder_, absl::Now(), &connections_manager_,
|
||||
&connection);
|
||||
session_.OnConnected(absl::Now(), &connections_manager_, &connection);
|
||||
session_.SetTokenForTests("1234");
|
||||
|
||||
EXPECT_THAT(
|
||||
|
||||
@@ -39,8 +39,6 @@
|
||||
#include "sharing/incoming_frames_reader.h"
|
||||
#include "sharing/internal/public/logging.h"
|
||||
#include "sharing/nearby_connection.h"
|
||||
#include "sharing/nearby_sharing_decoder.h"
|
||||
#include "sharing/nearby_sharing_decoder_impl.h"
|
||||
#include "sharing/proto/enums.pb.h"
|
||||
#include "sharing/proto/rpc_resources.pb.h"
|
||||
#include "sharing/proto/wire_format.pb.h"
|
||||
@@ -137,9 +135,8 @@ const absl::Duration kTimeout = absl::Seconds(1);
|
||||
class MockIncomingFramesReader : public IncomingFramesReader {
|
||||
public:
|
||||
MockIncomingFramesReader(TaskRunner& service_thread,
|
||||
const NearbySharingDecoder& decoder,
|
||||
NearbyConnection* connection)
|
||||
: IncomingFramesReader(service_thread, decoder, connection) {}
|
||||
: IncomingFramesReader(service_thread, connection) {}
|
||||
|
||||
MOCK_METHOD(void, ReadFrame,
|
||||
(std::function<void(std::optional<V1Frame>)> callback),
|
||||
@@ -186,7 +183,7 @@ class PairedKeyVerificationRunnerTest : public testing::Test {
|
||||
};
|
||||
|
||||
PairedKeyVerificationRunnerTest()
|
||||
: frames_reader_(fake_task_runner_, decoder_, &connection_) {}
|
||||
: frames_reader_(fake_task_runner_, &connection_) {}
|
||||
|
||||
void SetUp() override {
|
||||
GetFakeClock()->FastForward(absl::Minutes(15));
|
||||
@@ -326,7 +323,6 @@ class PairedKeyVerificationRunnerTest : public testing::Test {
|
||||
FakeClock fake_clock_;
|
||||
FakeTaskRunner fake_task_runner_ {&fake_clock_, 1};
|
||||
FakeNearbyConnection connection_;
|
||||
NearbySharingDecoderImpl decoder_;
|
||||
testing::NiceMock<MockIncomingFramesReader> frames_reader_;
|
||||
FakeNearbyShareCertificateManager certificate_manager_;
|
||||
};
|
||||
|
||||
@@ -857,6 +857,8 @@ message SharingLog {
|
||||
message SetupWizard {
|
||||
// The new visibility of the device.
|
||||
optional location.nearby.proto.sharing.Visibility visibility = 1;
|
||||
// The previous visibility of the device.
|
||||
optional location.nearby.proto.sharing.Visibility previous_visibility = 2;
|
||||
}
|
||||
|
||||
message SendDesktopNotification {
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
#include "sharing/internal/public/logging.h"
|
||||
#include "sharing/nearby_connection.h"
|
||||
#include "sharing/nearby_connections_manager.h"
|
||||
#include "sharing/nearby_sharing_decoder.h"
|
||||
#include "sharing/paired_key_verification_runner.h"
|
||||
#include "sharing/proto/wire_format.pb.h"
|
||||
#include "sharing/share_target.h"
|
||||
@@ -115,8 +114,7 @@ void ShareSession::set_disconnect_status(
|
||||
}
|
||||
}
|
||||
|
||||
bool ShareSession::OnConnected(const NearbySharingDecoder& decoder,
|
||||
absl::Time connect_start_time,
|
||||
bool ShareSession::OnConnected(absl::Time connect_start_time,
|
||||
NearbyConnectionsManager* connections_manager,
|
||||
NearbyConnection* connection) {
|
||||
NL_DCHECK(connections_manager) << "Connections manager must not be null";
|
||||
@@ -126,8 +124,8 @@ bool ShareSession::OnConnected(const NearbySharingDecoder& decoder,
|
||||
}
|
||||
connection_start_time_ = connect_start_time;
|
||||
connection_ = connection;
|
||||
frames_reader_ = std::make_shared<IncomingFramesReader>(service_thread_,
|
||||
decoder, connection_);
|
||||
frames_reader_ =
|
||||
std::make_shared<IncomingFramesReader>(service_thread_, connection_);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
#include "sharing/incoming_frames_reader.h"
|
||||
#include "sharing/nearby_connection.h"
|
||||
#include "sharing/nearby_connections_manager.h"
|
||||
#include "sharing/nearby_sharing_decoder.h"
|
||||
#include "sharing/paired_key_verification_runner.h"
|
||||
#include "sharing/payload_tracker.h"
|
||||
#include "sharing/proto/wire_format.pb.h"
|
||||
@@ -104,8 +103,7 @@ class ShareSession {
|
||||
}
|
||||
// Notifies the ShareTargetInfo that the connection has been established.
|
||||
// Returns true if the connection was successfully established.
|
||||
bool OnConnected(const NearbySharingDecoder& decoder,
|
||||
absl::Time connect_start_time,
|
||||
bool OnConnected(absl::Time connect_start_time,
|
||||
NearbyConnectionsManager* connections_manager,
|
||||
NearbyConnection* connection);
|
||||
|
||||
|
||||
@@ -34,12 +34,11 @@
|
||||
#include "sharing/fake_nearby_connection.h"
|
||||
#include "sharing/fake_nearby_connections_manager.h"
|
||||
#include "sharing/nearby_connection.h"
|
||||
#include "sharing/nearby_sharing_decoder_impl.h"
|
||||
#include "sharing/paired_key_verification_runner.h"
|
||||
#include "sharing/share_target.h"
|
||||
#include "sharing/transfer_metadata.h"
|
||||
#include "sharing/transfer_metadata_matchers.h"
|
||||
#include "sharing/transfer_metadata_builder.h"
|
||||
#include "sharing/transfer_metadata_matchers.h"
|
||||
|
||||
namespace nearby::sharing {
|
||||
namespace {
|
||||
@@ -88,7 +87,7 @@ class TestShareSession : public ShareSession {
|
||||
|
||||
private:
|
||||
FakeClock fake_clock_;
|
||||
FakeTaskRunner fake_task_runner_ {&fake_clock_, 1};
|
||||
FakeTaskRunner fake_task_runner_{&fake_clock_, 1};
|
||||
nearby::analytics::MockEventLogger mock_event_logger_;
|
||||
analytics::AnalyticsRecorder analytics_recorder_{/*vendor_id=*/0,
|
||||
&mock_event_logger_};
|
||||
@@ -140,27 +139,24 @@ TEST(ShareSessionTest, SetDisconnectStatus) {
|
||||
|
||||
TEST(ShareSessionTest, OnConnectedFails) {
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder;
|
||||
ShareTarget share_target;
|
||||
TestShareSession session(std::string(kEndpointId), share_target);
|
||||
session.SetOnNewConnectionResult(false);
|
||||
|
||||
EXPECT_FALSE(session.OnConnected(nearby_sharing_decoder, absl::Now(),
|
||||
&connections_manager,
|
||||
EXPECT_FALSE(session.OnConnected(absl::Now(), &connections_manager,
|
||||
/*connection=*/nullptr));
|
||||
}
|
||||
|
||||
TEST(ShareSessionTest, OnConnectedSucceeds) {
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder;
|
||||
ShareTarget share_target;
|
||||
TestShareSession session(std::string(kEndpointId), share_target);
|
||||
FakeNearbyConnection connection;
|
||||
session.SetOnNewConnectionResult(true);
|
||||
absl::Time connect_start_time = absl::Now();
|
||||
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder, connect_start_time,
|
||||
&connections_manager, &connection));
|
||||
EXPECT_TRUE(session.OnConnected(connect_start_time, &connections_manager,
|
||||
&connection));
|
||||
EXPECT_EQ(session.connection_start_time(), connect_start_time);
|
||||
EXPECT_EQ(session.connection(), &connection);
|
||||
}
|
||||
@@ -168,7 +164,6 @@ TEST(ShareSessionTest, OnConnectedSucceeds) {
|
||||
TEST(ShareSessionTest, IncomingRunPairedKeyVerificationSuccess) {
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
FakeClock fake_clock;
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder;
|
||||
FakeNearbyShareCertificateManager certificate_manager;
|
||||
FakeNearbyConnection connection;
|
||||
std::vector<uint8_t> token = {0, 1, 2, 3, 4, 5};
|
||||
@@ -177,8 +172,8 @@ TEST(ShareSessionTest, IncomingRunPairedKeyVerificationSuccess) {
|
||||
TestShareSession session(std::string(kEndpointId), share_target);
|
||||
session.SetOnNewConnectionResult(true);
|
||||
absl::Time connect_start_time = absl::Now();
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder, connect_start_time,
|
||||
&connections_manager, &connection));
|
||||
EXPECT_TRUE(session.OnConnected(connect_start_time, &connections_manager,
|
||||
&connection));
|
||||
absl::Notification notification;
|
||||
PairedKeyVerificationRunner::PairedKeyVerificationResult verification_result;
|
||||
|
||||
@@ -249,12 +244,11 @@ TEST(ShareSessionTest, OnDisconnect) {
|
||||
|
||||
TEST(ShareSessionTest, CancelPayloads) {
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder;
|
||||
FakeNearbyConnection connection;
|
||||
ShareTarget share_target;
|
||||
TestShareSession session(std::string(kEndpointId), share_target);
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder, absl::Now(),
|
||||
&connections_manager, &connection));
|
||||
EXPECT_TRUE(
|
||||
session.OnConnected(absl::Now(), &connections_manager, &connection));
|
||||
session.SetAttachmentPayloadId(1, 2);
|
||||
session.SetAttachmentPayloadId(3, 4);
|
||||
|
||||
@@ -266,12 +260,11 @@ TEST(ShareSessionTest, CancelPayloads) {
|
||||
|
||||
TEST(ShareSessionTest, WriteResponseFrame) {
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder;
|
||||
ShareTarget share_target;
|
||||
TestShareSession session(std::string(kEndpointId), share_target);
|
||||
FakeNearbyConnection connection;
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder, absl::Now(),
|
||||
&connections_manager, &connection));
|
||||
EXPECT_TRUE(
|
||||
session.OnConnected(absl::Now(), &connections_manager, &connection));
|
||||
|
||||
session.WriteResponseFrame(ConnectionResponseFrame::REJECT);
|
||||
|
||||
@@ -286,12 +279,11 @@ TEST(ShareSessionTest, WriteResponseFrame) {
|
||||
|
||||
TEST(ShareSessionTest, WriteCancelFrame) {
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder;
|
||||
ShareTarget share_target;
|
||||
TestShareSession session(std::string(kEndpointId), share_target);
|
||||
FakeNearbyConnection connection;
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder, absl::Now(),
|
||||
&connections_manager, &connection));
|
||||
EXPECT_TRUE(
|
||||
session.OnConnected(absl::Now(), &connections_manager, &connection));
|
||||
|
||||
session.WriteCancelFrame();
|
||||
|
||||
@@ -304,12 +296,11 @@ TEST(ShareSessionTest, WriteCancelFrame) {
|
||||
|
||||
TEST(ShareSessionTest, HandleKeyVerificationResultFail) {
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder;
|
||||
ShareTarget share_target;
|
||||
TestShareSession session(std::string(kEndpointId), share_target);
|
||||
FakeNearbyConnection connection;
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder, absl::Now(),
|
||||
&connections_manager, &connection));
|
||||
EXPECT_TRUE(
|
||||
session.OnConnected(absl::Now(), &connections_manager, &connection));
|
||||
session.SetTokenForTests("9876");
|
||||
|
||||
EXPECT_FALSE(session.HandleKeyVerificationResult(
|
||||
@@ -321,13 +312,12 @@ TEST(ShareSessionTest, HandleKeyVerificationResultFail) {
|
||||
|
||||
TEST(ShareSessionTest, HandleKeyVerificationResultSelfShareSuccess) {
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder;
|
||||
ShareTarget share_target;
|
||||
share_target.for_self_share = true;
|
||||
TestShareSession session(std::string(kEndpointId), share_target);
|
||||
FakeNearbyConnection connection;
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder, absl::Now(),
|
||||
&connections_manager, &connection));
|
||||
EXPECT_TRUE(
|
||||
session.OnConnected(absl::Now(), &connections_manager, &connection));
|
||||
session.SetTokenForTests("9876");
|
||||
|
||||
EXPECT_TRUE(session.HandleKeyVerificationResult(
|
||||
@@ -340,12 +330,11 @@ TEST(ShareSessionTest, HandleKeyVerificationResultSelfShareSuccess) {
|
||||
|
||||
TEST(ShareSessionTest, HandleKeyVerificationResultNotSelfShareSuccess) {
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder;
|
||||
ShareTarget share_target;
|
||||
TestShareSession session(std::string(kEndpointId), share_target);
|
||||
FakeNearbyConnection connection;
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder, absl::Now(),
|
||||
&connections_manager, &connection));
|
||||
EXPECT_TRUE(
|
||||
session.OnConnected(absl::Now(), &connections_manager, &connection));
|
||||
session.SetTokenForTests("9876");
|
||||
|
||||
EXPECT_TRUE(session.HandleKeyVerificationResult(
|
||||
@@ -359,13 +348,12 @@ TEST(ShareSessionTest, HandleKeyVerificationResultNotSelfShareSuccess) {
|
||||
|
||||
TEST(ShareSessionTest, HandleKeyVerificationResultSelfShareUnable) {
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder;
|
||||
ShareTarget share_target;
|
||||
share_target.for_self_share = true;
|
||||
TestShareSession session(std::string(kEndpointId), share_target);
|
||||
FakeNearbyConnection connection;
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder, absl::Now(),
|
||||
&connections_manager, &connection));
|
||||
EXPECT_TRUE(
|
||||
session.OnConnected(absl::Now(), &connections_manager, &connection));
|
||||
session.SetTokenForTests("9876");
|
||||
|
||||
EXPECT_TRUE(session.HandleKeyVerificationResult(
|
||||
@@ -378,12 +366,11 @@ TEST(ShareSessionTest, HandleKeyVerificationResultSelfShareUnable) {
|
||||
|
||||
TEST(ShareSessionTest, HandleKeyVerificationResultNotSelfShareUnable) {
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder;
|
||||
ShareTarget share_target;
|
||||
TestShareSession session(std::string(kEndpointId), share_target);
|
||||
FakeNearbyConnection connection;
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder, absl::Now(),
|
||||
&connections_manager, &connection));
|
||||
EXPECT_TRUE(
|
||||
session.OnConnected(absl::Now(), &connections_manager, &connection));
|
||||
session.SetTokenForTests("9876");
|
||||
|
||||
EXPECT_TRUE(session.HandleKeyVerificationResult(
|
||||
@@ -396,12 +383,11 @@ TEST(ShareSessionTest, HandleKeyVerificationResultNotSelfShareUnable) {
|
||||
|
||||
TEST(ShareSessionTest, HandleKeyVerificationResultUnknown) {
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder;
|
||||
ShareTarget share_target;
|
||||
TestShareSession session(std::string(kEndpointId), share_target);
|
||||
FakeNearbyConnection connection;
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder, absl::Now(),
|
||||
&connections_manager, &connection));
|
||||
EXPECT_TRUE(
|
||||
session.OnConnected(absl::Now(), &connections_manager, &connection));
|
||||
session.SetTokenForTests("9876");
|
||||
|
||||
EXPECT_FALSE(session.HandleKeyVerificationResult(
|
||||
@@ -423,15 +409,14 @@ TEST(ShareSessionTest, AbortNotConnected) {
|
||||
|
||||
TEST(ShareSessionTest, AbortConnected) {
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder;
|
||||
ShareTarget share_target;
|
||||
TestShareSession session(std::string(kEndpointId), share_target);
|
||||
FakeNearbyConnection connection;
|
||||
bool disconnected = false;
|
||||
connection.SetDisconnectionListener(
|
||||
[&disconnected]() { disconnected = true; });
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder, absl::Now(),
|
||||
&connections_manager, &connection));
|
||||
EXPECT_TRUE(
|
||||
session.OnConnected(absl::Now(), &connections_manager, &connection));
|
||||
EXPECT_CALL(session, InvokeTransferUpdateCallback(AllOf(
|
||||
HasStatus(TransferMetadata::Status::kNotEnoughSpace),
|
||||
IsFinalStatus())));
|
||||
@@ -443,15 +428,14 @@ TEST(ShareSessionTest, AbortConnected) {
|
||||
|
||||
TEST(ShareSessionTest, Disconnect) {
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder;
|
||||
ShareTarget share_target;
|
||||
TestShareSession session(std::string(kEndpointId), share_target);
|
||||
FakeNearbyConnection connection;
|
||||
bool disconnected = false;
|
||||
connection.SetDisconnectionListener(
|
||||
[&disconnected]() { disconnected = true; });
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder, absl::Now(),
|
||||
&connections_manager, &connection));
|
||||
EXPECT_TRUE(
|
||||
session.OnConnected(absl::Now(), &connections_manager, &connection));
|
||||
|
||||
session.Disconnect();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user