mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Pass NearbyConnectionsManager into ShareSession.
PiperOrigin-RevId: 656651595
This commit is contained in:
committed by
Copybara-Service
parent
a5b377c770
commit
0074ffb990
@@ -212,7 +212,7 @@ bool IncomingShareSession::ReadyForTransfer(
|
||||
}
|
||||
|
||||
bool IncomingShareSession::AcceptTransfer(
|
||||
Clock* clock, NearbyConnectionsManager& connections_manager,
|
||||
Clock* clock,
|
||||
std::function<void(int64_t, TransferMetadata)> update_callback) {
|
||||
if (!ready_for_accept_ || !IsConnected()) {
|
||||
NL_LOG(WARNING) << __func__ << ": out of order API call.";
|
||||
@@ -235,8 +235,8 @@ bool IncomingShareSession::AcceptTransfer(
|
||||
<< ": Started listening for progress on payload: " << it->second
|
||||
<< " for attachment: " << it->first;
|
||||
|
||||
connections_manager.RegisterPayloadStatusListener(it->second,
|
||||
payload_tracker());
|
||||
connections_manager()->RegisterPayloadStatusListener(it->second,
|
||||
payload_tracker());
|
||||
|
||||
NL_VLOG(1) << __func__ << ": Accepted incoming files from share target - "
|
||||
<< share_target().id;
|
||||
@@ -253,7 +253,7 @@ bool IncomingShareSession::AcceptTransfer(
|
||||
.set_token(token())
|
||||
.build());
|
||||
|
||||
if (TryUpgradeBandwidth(connections_manager)) {
|
||||
if (TryUpgradeBandwidth()) {
|
||||
// Upgrade bandwidth regardless of advertising visibility because either
|
||||
// the system or the user has verified the sender's identity; the
|
||||
// stable identifiers potentially exposed by performing a bandwidth
|
||||
@@ -267,7 +267,6 @@ bool IncomingShareSession::AcceptTransfer(
|
||||
}
|
||||
|
||||
void IncomingShareSession::HandleProgressUpdate(
|
||||
NearbyConnectionsManager& connections_manager,
|
||||
const ProgressUpdateFrame& progress_update) {
|
||||
if (!IsConnected()) {
|
||||
NL_LOG(ERROR) << "Received ProgressUpdate Frame on disconnected session";
|
||||
@@ -280,7 +279,7 @@ void IncomingShareSession::HandleProgressUpdate(
|
||||
<< share_target().id;
|
||||
// TODO(b/338468927): Check if this is actually needed.
|
||||
// Bandwidth upgrade was already requested in Accept.
|
||||
if (TryUpgradeBandwidth(connections_manager)) {
|
||||
if (TryUpgradeBandwidth()) {
|
||||
NL_LOG(INFO)
|
||||
<< __func__
|
||||
<< ": Upgrade bandwidth when receiving progress update frame "
|
||||
@@ -295,8 +294,7 @@ void IncomingShareSession::HandleProgressUpdate(
|
||||
}
|
||||
}
|
||||
|
||||
bool IncomingShareSession::UpdateFilePayloadPaths(
|
||||
const NearbyConnectionsManager& connections_manager) {
|
||||
bool IncomingShareSession::UpdateFilePayloadPaths() {
|
||||
AttachmentContainer& container = mutable_attachment_container();
|
||||
bool result = true;
|
||||
for (int i = 0; i < container.GetFileAttachments().size(); ++i) {
|
||||
@@ -314,7 +312,7 @@ bool IncomingShareSession::UpdateFilePayloadPaths(
|
||||
}
|
||||
|
||||
const Payload* incoming_payload =
|
||||
connections_manager.GetIncomingPayload(it->second);
|
||||
connections_manager()->GetIncomingPayload(it->second);
|
||||
if (!incoming_payload || !incoming_payload->content.is_file()) {
|
||||
NL_LOG(WARNING) << __func__ << ": No payload found for file - "
|
||||
<< file.id();
|
||||
@@ -330,9 +328,8 @@ bool IncomingShareSession::UpdateFilePayloadPaths(
|
||||
return result;
|
||||
}
|
||||
|
||||
bool IncomingShareSession::UpdatePayloadContents(
|
||||
const NearbyConnectionsManager& connections_manager) {
|
||||
if (!UpdateFilePayloadPaths(connections_manager)) {
|
||||
bool IncomingShareSession::UpdatePayloadContents() {
|
||||
if (!UpdateFilePayloadPaths()) {
|
||||
return false;
|
||||
}
|
||||
AttachmentContainer& container = mutable_attachment_container();
|
||||
@@ -347,7 +344,7 @@ bool IncomingShareSession::UpdatePayloadContents(
|
||||
return false;
|
||||
}
|
||||
const Payload* incoming_payload =
|
||||
connections_manager.GetIncomingPayload(it->second);
|
||||
connections_manager()->GetIncomingPayload(it->second);
|
||||
if (!incoming_payload || !incoming_payload->content.is_bytes()) {
|
||||
NL_LOG(WARNING) << __func__ << ": No payload found for text - "
|
||||
<< text.id();
|
||||
@@ -382,7 +379,7 @@ bool IncomingShareSession::UpdatePayloadContents(
|
||||
}
|
||||
|
||||
const Payload* incoming_payload =
|
||||
connections_manager.GetIncomingPayload(it->second);
|
||||
connections_manager()->GetIncomingPayload(it->second);
|
||||
if (!incoming_payload || !incoming_payload->content.is_bytes()) {
|
||||
NL_LOG(WARNING) << __func__
|
||||
<< ": No payload found for WiFi credentials - "
|
||||
@@ -414,9 +411,8 @@ bool IncomingShareSession::UpdatePayloadContents(
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IncomingShareSession::FinalizePayloads(
|
||||
const NearbyConnectionsManager& connections_manager) {
|
||||
if (!UpdatePayloadContents(connections_manager)) {
|
||||
bool IncomingShareSession::FinalizePayloads() {
|
||||
if (!UpdatePayloadContents()) {
|
||||
mutable_attachment_container().ClearAttachments();
|
||||
return false;
|
||||
}
|
||||
@@ -442,12 +438,11 @@ std::vector<std::filesystem::path> IncomingShareSession::GetPayloadFilePaths()
|
||||
return file_paths;
|
||||
}
|
||||
|
||||
bool IncomingShareSession::TryUpgradeBandwidth(
|
||||
NearbyConnectionsManager& connections_manager) {
|
||||
bool IncomingShareSession::TryUpgradeBandwidth() {
|
||||
if (!bandwidth_upgrade_requested_ &&
|
||||
attachment_container().GetTotalAttachmentsSize() >=
|
||||
kAttachmentsSizeThresholdOverHighQualityMedium) {
|
||||
connections_manager.UpgradeBandwidth(endpoint_id());
|
||||
connections_manager()->UpgradeBandwidth(endpoint_id());
|
||||
bandwidth_upgrade_requested_ = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include "internal/platform/task_runner.h"
|
||||
#include "sharing/analytics/analytics_recorder.h"
|
||||
#include "sharing/nearby_connection.h"
|
||||
#include "sharing/nearby_connections_manager.h"
|
||||
#include "sharing/paired_key_verification_runner.h"
|
||||
#include "sharing/proto/wire_format.pb.h"
|
||||
#include "sharing/share_session.h"
|
||||
@@ -71,8 +70,7 @@ class IncomingShareSession : public ShareSession {
|
||||
introduction_callback);
|
||||
|
||||
// Update file attachment paths with payload paths.
|
||||
bool UpdateFilePayloadPaths(
|
||||
const NearbyConnectionsManager& connections_manager);
|
||||
bool UpdateFilePayloadPaths();
|
||||
|
||||
// Returns true if the transfer can begin and AcceptTransfer should be called
|
||||
// immediately.
|
||||
@@ -86,25 +84,24 @@ class IncomingShareSession : public ShareSession {
|
||||
// Accept the transfer and begin listening for payload transfer updates.
|
||||
// Returns false if session is not in a state to accept the transfer.
|
||||
bool AcceptTransfer(
|
||||
Clock* clock, NearbyConnectionsManager& connections_manager,
|
||||
Clock* clock,
|
||||
std::function<void(int64_t, TransferMetadata)> update_callback);
|
||||
|
||||
void HandleProgressUpdate(
|
||||
NearbyConnectionsManager& connections_manager,
|
||||
const nearby::sharing::service::proto::ProgressUpdateFrame&
|
||||
progress_update);
|
||||
|
||||
// Once transfer has completed, make payload content available in the
|
||||
// corresponding Attachment.
|
||||
// Returns true if all payloads were successfully finalized.
|
||||
bool FinalizePayloads(const NearbyConnectionsManager& connections_manager);
|
||||
bool FinalizePayloads();
|
||||
|
||||
// Returns the file paths of all file payloads.
|
||||
std::vector<std::filesystem::path> GetPayloadFilePaths() const;
|
||||
|
||||
// Upgrade bandwidth if it is needed.
|
||||
// Returns true if bandwidth upgrade was requested.
|
||||
bool TryUpgradeBandwidth(NearbyConnectionsManager& connections_manager);
|
||||
bool TryUpgradeBandwidth();
|
||||
|
||||
// Send TransferMetadataUpdate with the final |status|.
|
||||
// Map |status| to corresponding ConnectionResponseFrame::Status and send
|
||||
@@ -117,8 +114,7 @@ class IncomingShareSession : public ShareSession {
|
||||
|
||||
private:
|
||||
// Copy payload contents from the NearbyConnection to the Attachment.
|
||||
bool UpdatePayloadContents(
|
||||
const NearbyConnectionsManager& connections_manager);
|
||||
bool UpdatePayloadContents();
|
||||
|
||||
std::function<void(const IncomingShareSession&, const TransferMetadata&)>
|
||||
transfer_update_callback_;
|
||||
|
||||
@@ -76,7 +76,6 @@ using ::nearby::sharing::service::proto::WifiCredentialsMetadata;
|
||||
using ::testing::_;
|
||||
using ::testing::AllOf;
|
||||
using ::testing::Eq;
|
||||
using ::testing::Invoke;
|
||||
using ::testing::IsEmpty;
|
||||
using ::testing::IsFalse;
|
||||
using ::testing::IsTrue;
|
||||
@@ -177,11 +176,16 @@ class IncomingShareSessionTest : public ::testing::Test {
|
||||
ShareTarget share_target_;
|
||||
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_));
|
||||
IntroductionFrame frame;
|
||||
|
||||
EXPECT_THAT(session_.ProcessIntroduction(frame),
|
||||
@@ -190,6 +194,8 @@ TEST_F(IncomingShareSessionTest, ProcessIntroductionNoSupportedPayload) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, ProcessIntroductionEmptyFile) {
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
IntroductionFrame frame;
|
||||
frame.mutable_file_metadata();
|
||||
|
||||
@@ -199,6 +205,8 @@ TEST_F(IncomingShareSessionTest, ProcessIntroductionEmptyFile) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, ProcessIntroductionFilesTooLarge) {
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
IntroductionFrame frame;
|
||||
FileMetadata file1;
|
||||
FileMetadata file2;
|
||||
@@ -213,6 +221,8 @@ TEST_F(IncomingShareSessionTest, ProcessIntroductionFilesTooLarge) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, ProcessIntroductionEmptyText) {
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
IntroductionFrame frame;
|
||||
frame.mutable_text_metadata();
|
||||
|
||||
@@ -222,6 +232,8 @@ TEST_F(IncomingShareSessionTest, ProcessIntroductionEmptyText) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, ProcessIntroductionSuccess) {
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, 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(),
|
||||
@@ -269,20 +281,21 @@ TEST_F(IncomingShareSessionTest, ProcessIntroductionSuccess) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, UpdateFilePayloadPathsSuccess) {
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_THAT(session_.ProcessIntroduction(introduction_frame_),
|
||||
Eq(std::nullopt));
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
std::filesystem::path file1_path = "/usr/tmp/file1";
|
||||
int64_t payload_id1 = introduction_frame_.file_metadata(0).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
payload_id1, CreateFilePayload(payload_id1, file1_path));
|
||||
|
||||
std::filesystem::path file2_path = "/usr/tmp/file2";
|
||||
int64_t payload_id2 = introduction_frame_.file_metadata(1).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
payload_id2, CreateFilePayload(payload_id2, file2_path));
|
||||
|
||||
EXPECT_THAT(session_.UpdateFilePayloadPaths(connections_manager), IsTrue());
|
||||
EXPECT_THAT(session_.UpdateFilePayloadPaths(), IsTrue());
|
||||
EXPECT_THAT(
|
||||
session_.attachment_container().GetFileAttachments()[0].file_path(),
|
||||
Eq(file1_path));
|
||||
@@ -292,35 +305,37 @@ TEST_F(IncomingShareSessionTest, UpdateFilePayloadPathsSuccess) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, UpdateFilePayloadPathsWrongType) {
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_THAT(session_.ProcessIntroduction(introduction_frame_),
|
||||
Eq(std::nullopt));
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
int64_t payload_id1 = introduction_frame_.file_metadata(0).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
payload_id1, CreateTextPayload(payload_id1, "text1"));
|
||||
|
||||
std::filesystem::path file2_path = "/usr/tmp/file2";
|
||||
int64_t payload_id2 = introduction_frame_.file_metadata(1).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
payload_id2, CreateFilePayload(payload_id2, file2_path));
|
||||
|
||||
EXPECT_THAT(session_.UpdateFilePayloadPaths(connections_manager), IsFalse());
|
||||
EXPECT_THAT(session_.UpdateFilePayloadPaths(), IsFalse());
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, GetPayloadFilePaths) {
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_THAT(session_.ProcessIntroduction(introduction_frame_),
|
||||
Eq(std::nullopt));
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
std::filesystem::path file1_path = "/usr/tmp/file1";
|
||||
int64_t payload_id1 = introduction_frame_.file_metadata(0).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
payload_id1, CreateFilePayload(payload_id1, file1_path));
|
||||
|
||||
std::filesystem::path file2_path = "/usr/tmp/file2";
|
||||
int64_t payload_id2 = introduction_frame_.file_metadata(1).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
payload_id2, CreateFilePayload(payload_id2, file2_path));
|
||||
EXPECT_THAT(session_.UpdateFilePayloadPaths(connections_manager), IsTrue());
|
||||
EXPECT_THAT(session_.UpdateFilePayloadPaths(), IsTrue());
|
||||
|
||||
std::vector<std::filesystem::path> file_paths =
|
||||
session_.GetPayloadFilePaths();
|
||||
@@ -329,43 +344,44 @@ TEST_F(IncomingShareSessionTest, GetPayloadFilePaths) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, FinalizePayloadsSuccess) {
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_THAT(session_.ProcessIntroduction(introduction_frame_),
|
||||
Eq(std::nullopt));
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
std::filesystem::path file1_path = "/usr/tmp/file1";
|
||||
int64_t payload_id1 = introduction_frame_.file_metadata(0).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
payload_id1, CreateFilePayload(payload_id1, file1_path));
|
||||
|
||||
std::filesystem::path file2_path = "/usr/tmp/file2";
|
||||
int64_t payload_id2 = introduction_frame_.file_metadata(1).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
payload_id2, CreateFilePayload(payload_id2, file2_path));
|
||||
EXPECT_THAT(session_.UpdateFilePayloadPaths(connections_manager), IsTrue());
|
||||
EXPECT_THAT(session_.UpdateFilePayloadPaths(), IsTrue());
|
||||
|
||||
std::string text_content1 = "text1";
|
||||
int64_t text_payload_id1 = introduction_frame_.text_metadata(0).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
text_payload_id1, CreateTextPayload(text_payload_id1, text_content1));
|
||||
|
||||
std::string text_content2 = "text2";
|
||||
int64_t text_payload_id2 = introduction_frame_.text_metadata(1).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
text_payload_id2, CreateTextPayload(text_payload_id2, text_content2));
|
||||
|
||||
int64_t wifi_payload_id1 =
|
||||
introduction_frame_.wifi_credentials_metadata(0).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
wifi_payload_id1,
|
||||
CreateWifiCredentialsPayload(wifi_payload_id1, "password1", false));
|
||||
|
||||
int64_t wifi_payload_id2 =
|
||||
introduction_frame_.wifi_credentials_metadata(1).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
wifi_payload_id2,
|
||||
CreateWifiCredentialsPayload(wifi_payload_id2, "password2", true));
|
||||
|
||||
EXPECT_THAT(session_.FinalizePayloads(connections_manager), IsTrue());
|
||||
EXPECT_THAT(session_.FinalizePayloads(), IsTrue());
|
||||
EXPECT_THAT(
|
||||
session_.attachment_container().GetFileAttachments()[0].file_path(),
|
||||
Eq(file1_path));
|
||||
@@ -397,38 +413,39 @@ TEST_F(IncomingShareSessionTest, FinalizePayloadsSuccess) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, FinalizePayloadsMissingFilePayloads) {
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_THAT(session_.ProcessIntroduction(introduction_frame_),
|
||||
Eq(std::nullopt));
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
std::filesystem::path file1_path = "/usr/tmp/file1";
|
||||
int64_t payload_id1 = introduction_frame_.file_metadata(0).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
payload_id1, CreateFilePayload(payload_id1, file1_path));
|
||||
EXPECT_THAT(session_.UpdateFilePayloadPaths(connections_manager), IsFalse());
|
||||
EXPECT_THAT(session_.UpdateFilePayloadPaths(), IsFalse());
|
||||
|
||||
std::string text_content1 = "text1";
|
||||
int64_t text_payload_id1 = introduction_frame_.text_metadata(0).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
text_payload_id1, CreateTextPayload(text_payload_id1, text_content1));
|
||||
|
||||
std::string text_content2 = "text2";
|
||||
int64_t text_payload_id2 = introduction_frame_.text_metadata(1).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
text_payload_id2, CreateTextPayload(text_payload_id2, text_content2));
|
||||
|
||||
int64_t wifi_payload_id1 =
|
||||
introduction_frame_.wifi_credentials_metadata(0).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
wifi_payload_id1,
|
||||
CreateWifiCredentialsPayload(wifi_payload_id1, "password1", false));
|
||||
|
||||
int64_t wifi_payload_id2 =
|
||||
introduction_frame_.wifi_credentials_metadata(1).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
wifi_payload_id2,
|
||||
CreateWifiCredentialsPayload(wifi_payload_id2, "password2", true));
|
||||
|
||||
EXPECT_THAT(session_.FinalizePayloads(connections_manager), IsFalse());
|
||||
EXPECT_THAT(session_.FinalizePayloads(), IsFalse());
|
||||
|
||||
// Verify that attachments are cleared out
|
||||
EXPECT_THAT(
|
||||
@@ -462,39 +479,40 @@ TEST_F(IncomingShareSessionTest, FinalizePayloadsMissingFilePayloads) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, FinalizePayloadsMissingTextPayloads) {
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_THAT(session_.ProcessIntroduction(introduction_frame_),
|
||||
Eq(std::nullopt));
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
std::filesystem::path file1_path = "/usr/tmp/file1";
|
||||
int64_t payload_id1 = introduction_frame_.file_metadata(0).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
payload_id1, CreateFilePayload(payload_id1, file1_path));
|
||||
EXPECT_THAT(session_.UpdateFilePayloadPaths(connections_manager), IsFalse());
|
||||
EXPECT_THAT(session_.UpdateFilePayloadPaths(), IsFalse());
|
||||
|
||||
std::filesystem::path file2_path = "/usr/tmp/file2";
|
||||
int64_t payload_id2 = introduction_frame_.file_metadata(1).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
payload_id2, CreateFilePayload(payload_id2, file2_path));
|
||||
EXPECT_THAT(session_.UpdateFilePayloadPaths(connections_manager), IsTrue());
|
||||
EXPECT_THAT(session_.UpdateFilePayloadPaths(), IsTrue());
|
||||
|
||||
std::string text_content1 = "text1";
|
||||
int64_t text_payload_id1 = introduction_frame_.text_metadata(0).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
text_payload_id1, CreateTextPayload(text_payload_id1, text_content1));
|
||||
|
||||
int64_t wifi_payload_id1 =
|
||||
introduction_frame_.wifi_credentials_metadata(0).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
wifi_payload_id1,
|
||||
CreateWifiCredentialsPayload(wifi_payload_id1, "password1", false));
|
||||
|
||||
int64_t wifi_payload_id2 =
|
||||
introduction_frame_.wifi_credentials_metadata(1).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
wifi_payload_id2,
|
||||
CreateWifiCredentialsPayload(wifi_payload_id2, "password2", true));
|
||||
|
||||
EXPECT_THAT(session_.FinalizePayloads(connections_manager), IsFalse());
|
||||
EXPECT_THAT(session_.FinalizePayloads(), IsFalse());
|
||||
|
||||
// Verify that attachments are cleared out
|
||||
EXPECT_THAT(
|
||||
@@ -528,38 +546,39 @@ TEST_F(IncomingShareSessionTest, FinalizePayloadsMissingTextPayloads) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, FinalizePayloadsMissingWifiPayloads) {
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_THAT(session_.ProcessIntroduction(introduction_frame_),
|
||||
Eq(std::nullopt));
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
std::filesystem::path file1_path = "/usr/tmp/file1";
|
||||
int64_t payload_id1 = introduction_frame_.file_metadata(0).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
payload_id1, CreateFilePayload(payload_id1, file1_path));
|
||||
EXPECT_THAT(session_.UpdateFilePayloadPaths(connections_manager), IsFalse());
|
||||
EXPECT_THAT(session_.UpdateFilePayloadPaths(), IsFalse());
|
||||
|
||||
std::filesystem::path file2_path = "/usr/tmp/file2";
|
||||
int64_t payload_id2 = introduction_frame_.file_metadata(1).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
payload_id2, CreateFilePayload(payload_id2, file2_path));
|
||||
EXPECT_THAT(session_.UpdateFilePayloadPaths(connections_manager), IsTrue());
|
||||
EXPECT_THAT(session_.UpdateFilePayloadPaths(), IsTrue());
|
||||
|
||||
std::string text_content1 = "text1";
|
||||
int64_t text_payload_id1 = introduction_frame_.text_metadata(0).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
text_payload_id1, CreateTextPayload(text_payload_id1, text_content1));
|
||||
|
||||
std::string text_content2 = "text2";
|
||||
int64_t text_payload_id2 = introduction_frame_.text_metadata(1).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
text_payload_id2, CreateTextPayload(text_payload_id2, text_content2));
|
||||
|
||||
int64_t wifi_payload_id1 =
|
||||
introduction_frame_.wifi_credentials_metadata(0).payload_id();
|
||||
connections_manager.SetIncomingPayload(
|
||||
connections_manager_.SetIncomingPayload(
|
||||
wifi_payload_id1,
|
||||
CreateWifiCredentialsPayload(wifi_payload_id1, "password1", false));
|
||||
|
||||
EXPECT_THAT(session_.FinalizePayloads(connections_manager), IsFalse());
|
||||
EXPECT_THAT(session_.FinalizePayloads(), IsFalse());
|
||||
|
||||
// Verify that attachments are cleared out
|
||||
EXPECT_THAT(
|
||||
@@ -595,7 +614,6 @@ TEST_F(IncomingShareSessionTest, FinalizePayloadsMissingWifiPayloads) {
|
||||
TEST_F(IncomingShareSessionTest, ReadyForTransferNotConnected) {
|
||||
session_.set_session_id(1234);
|
||||
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
FakeClock clock;
|
||||
EXPECT_THAT(
|
||||
session_.ReadyForTransfer([]() {}, [](std::optional<V1Frame> frame) {}),
|
||||
@@ -603,11 +621,9 @@ TEST_F(IncomingShareSessionTest, ReadyForTransferNotConnected) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, ReadyForTransferNotSelfShare) {
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder;
|
||||
FakeNearbyConnection connection;
|
||||
session_.set_session_id(1234);
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(nearby_sharing_decoder, absl::Now(), &connection));
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_CALL(
|
||||
transfer_metadata_callback_,
|
||||
Call(_, HasStatus(TransferMetadata::Status::kAwaitingLocalConfirmation)));
|
||||
@@ -623,11 +639,9 @@ TEST_F(IncomingShareSessionTest, ReadyForTransferSelfShare) {
|
||||
IncomingShareSession session(task_runner_, analytics_recorder_,
|
||||
std::string("XYCA"), share_target,
|
||||
transfer_metadata_callback_.AsStdFunction());
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder;
|
||||
FakeNearbyConnection connection;
|
||||
session.set_session_id(1234);
|
||||
EXPECT_TRUE(
|
||||
session.OnConnected(nearby_sharing_decoder, absl::Now(), &connection));
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_CALL(
|
||||
transfer_metadata_callback_,
|
||||
Call(_, HasStatus(TransferMetadata::Status::kAwaitingLocalConfirmation)))
|
||||
@@ -639,11 +653,9 @@ TEST_F(IncomingShareSessionTest, ReadyForTransferSelfShare) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, ReadyForTransferTimeout) {
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder;
|
||||
FakeNearbyConnection connection;
|
||||
session_.set_session_id(1234);
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(nearby_sharing_decoder, absl::Now(), &connection));
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_CALL(
|
||||
transfer_metadata_callback_,
|
||||
Call(_, HasStatus(TransferMetadata::Status::kAwaitingLocalConfirmation)));
|
||||
@@ -660,11 +672,9 @@ TEST_F(IncomingShareSessionTest, ReadyForTransferTimeout) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, ReadyForTransferTimeoutCancelled) {
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder;
|
||||
FakeNearbyConnection connection;
|
||||
session_.set_session_id(1234);
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(nearby_sharing_decoder, absl::Now(), &connection));
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_CALL(
|
||||
transfer_metadata_callback_,
|
||||
Call(_, HasStatus(TransferMetadata::Status::kAwaitingLocalConfirmation)));
|
||||
@@ -674,10 +684,9 @@ TEST_F(IncomingShareSessionTest, ReadyForTransferTimeoutCancelled) {
|
||||
[&accept_timeout_called]() { accept_timeout_called = true; },
|
||||
[](std::optional<V1Frame> frame) {}),
|
||||
IsFalse());
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
ProgressUpdateFrame progress_update_frame;
|
||||
progress_update_frame.set_start_transfer(true);
|
||||
session_.HandleProgressUpdate(connections_manager, progress_update_frame);
|
||||
session_.HandleProgressUpdate(progress_update_frame);
|
||||
clock_.FastForward(absl::Seconds(60));
|
||||
task_runner_.SyncWithTimeout(absl::Milliseconds(100));
|
||||
|
||||
@@ -685,12 +694,13 @@ TEST_F(IncomingShareSessionTest, ReadyForTransferTimeoutCancelled) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, HandleProgressUpdateNotConnected) {
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
ProgressUpdateFrame progress_update_frame;
|
||||
progress_update_frame.set_start_transfer(true);
|
||||
session_.HandleProgressUpdate(connections_manager, progress_update_frame);
|
||||
session_.HandleProgressUpdate(progress_update_frame);
|
||||
|
||||
EXPECT_THAT(connections_manager.DidUpgradeBandwidth(kEndpointId), IsFalse());
|
||||
EXPECT_THAT(connections_manager_.DidUpgradeBandwidth(kEndpointId), IsFalse());
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, HandleProgressUpdateTryUpgradeBandwidth) {
|
||||
@@ -708,53 +718,42 @@ TEST_F(IncomingShareSessionTest, HandleProgressUpdateTryUpgradeBandwidth) {
|
||||
}
|
||||
)pb",
|
||||
&introduction_frame));
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder;
|
||||
FakeNearbyConnection connection;
|
||||
session_.set_session_id(1234);
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(nearby_sharing_decoder, absl::Now(), &connection));
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_THAT(session_.ProcessIntroduction(introduction_frame),
|
||||
Eq(std::nullopt));
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
ProgressUpdateFrame progress_update_frame;
|
||||
progress_update_frame.set_start_transfer(true);
|
||||
session_.HandleProgressUpdate(connections_manager, progress_update_frame);
|
||||
session_.HandleProgressUpdate(progress_update_frame);
|
||||
|
||||
EXPECT_THAT(connections_manager.DidUpgradeBandwidth(kEndpointId), IsTrue());
|
||||
EXPECT_THAT(connections_manager_.DidUpgradeBandwidth(kEndpointId), IsTrue());
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, AcceptTransferNotConnected) {
|
||||
session_.set_session_id(1234);
|
||||
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
FakeClock clock;
|
||||
EXPECT_THAT(session_.AcceptTransfer(&clock, connections_manager,
|
||||
[](int64_t, TransferMetadata) {}),
|
||||
EXPECT_THAT(session_.AcceptTransfer(&clock, [](int64_t, TransferMetadata) {}),
|
||||
IsFalse());
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, AcceptTransferNotReady) {
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder;
|
||||
FakeNearbyConnection connection;
|
||||
session_.set_session_id(1234);
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(nearby_sharing_decoder, absl::Now(), &connection));
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_THAT(session_.ProcessIntroduction(introduction_frame_),
|
||||
Eq(std::nullopt));
|
||||
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
FakeClock clock;
|
||||
EXPECT_THAT(session_.AcceptTransfer(&clock, connections_manager,
|
||||
[](int64_t, TransferMetadata) {}),
|
||||
EXPECT_THAT(session_.AcceptTransfer(&clock, [](int64_t, TransferMetadata) {}),
|
||||
IsFalse());
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, AcceptTransferSuccess) {
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder;
|
||||
FakeNearbyConnection connection;
|
||||
session_.set_session_id(1234);
|
||||
EXPECT_TRUE(
|
||||
session_.OnConnected(nearby_sharing_decoder, absl::Now(), &connection));
|
||||
EXPECT_TRUE(session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_));
|
||||
EXPECT_THAT(session_.ProcessIntroduction(introduction_frame_),
|
||||
Eq(std::nullopt));
|
||||
EXPECT_THAT(
|
||||
@@ -778,19 +777,17 @@ TEST_F(IncomingShareSessionTest, AcceptTransferSuccess) {
|
||||
Property(&SharingLog::receive_attachments_start,
|
||||
HasSessionId(1234)))))));
|
||||
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
FakeClock clock;
|
||||
EXPECT_THAT(session_.AcceptTransfer(&clock, connections_manager,
|
||||
[](int64_t, TransferMetadata) {}),
|
||||
EXPECT_THAT(session_.AcceptTransfer(&clock, [](int64_t, TransferMetadata) {}),
|
||||
IsTrue());
|
||||
|
||||
for (auto it : session_.attachment_payload_map()) {
|
||||
EXPECT_THAT(
|
||||
connections_manager.GetRegisteredPayloadStatusListener(it.second)
|
||||
connections_manager_.GetRegisteredPayloadStatusListener(it.second)
|
||||
.lock(),
|
||||
Eq(session_.payload_tracker().lock()));
|
||||
}
|
||||
std::vector<uint8_t> frame_data = connection.GetWrittenData();
|
||||
std::vector<uint8_t> frame_data = connection_.GetWrittenData();
|
||||
Frame frame;
|
||||
ASSERT_TRUE(frame.ParseFromArray(frame_data.data(), frame_data.size()));
|
||||
ASSERT_EQ(frame.version(), Frame::V1);
|
||||
@@ -800,9 +797,8 @@ TEST_F(IncomingShareSessionTest, AcceptTransferSuccess) {
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, ProcessKeyVerificationResultSuccess) {
|
||||
NearbySharingDecoderImpl decoder;
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder, absl::Now(), &connection);
|
||||
session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_);
|
||||
session_.SetTokenForTests("1234");
|
||||
|
||||
bool introduction_received = false;
|
||||
@@ -830,15 +826,14 @@ TEST_F(IncomingShareSessionTest, ProcessKeyVerificationResultSuccess) {
|
||||
std::vector<uint8_t> data;
|
||||
data.resize(frame.ByteSizeLong());
|
||||
EXPECT_THAT(frame.SerializeToArray(data.data(), data.size()), IsTrue());
|
||||
connection.AppendReadableData(std::move(data));
|
||||
connection_.AppendReadableData(std::move(data));
|
||||
|
||||
EXPECT_THAT(introduction_received, IsTrue());
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, ProcessKeyVerificationResultFail) {
|
||||
NearbySharingDecoderImpl decoder;
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder, absl::Now(), &connection);
|
||||
session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_);
|
||||
session_.SetTokenForTests("1234");
|
||||
|
||||
bool introduction_received = false;
|
||||
@@ -865,15 +860,14 @@ TEST_F(IncomingShareSessionTest, ProcessKeyVerificationResultFail) {
|
||||
std::vector<uint8_t> data;
|
||||
data.resize(frame.ByteSizeLong());
|
||||
EXPECT_THAT(frame.SerializeToArray(data.data(), data.size()), IsTrue());
|
||||
connection.AppendReadableData(std::move(data));
|
||||
connection_.AppendReadableData(std::move(data));
|
||||
|
||||
EXPECT_THAT(introduction_received, IsFalse());
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, ProcessKeyVerificationResultUnable) {
|
||||
NearbySharingDecoderImpl decoder;
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder, absl::Now(), &connection);
|
||||
session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_);
|
||||
session_.SetTokenForTests("1234");
|
||||
|
||||
bool introduction_received = false;
|
||||
@@ -900,15 +894,14 @@ TEST_F(IncomingShareSessionTest, ProcessKeyVerificationResultUnable) {
|
||||
std::vector<uint8_t> data;
|
||||
data.resize(frame.ByteSizeLong());
|
||||
EXPECT_THAT(frame.SerializeToArray(data.data(), data.size()), IsTrue());
|
||||
connection.AppendReadableData(std::move(data));
|
||||
connection_.AppendReadableData(std::move(data));
|
||||
|
||||
EXPECT_THAT(introduction_received, IsTrue());
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, ProcessKeyVerificationResultUnknown) {
|
||||
NearbySharingDecoderImpl decoder;
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder, absl::Now(), &connection);
|
||||
session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_);
|
||||
session_.SetTokenForTests("1234");
|
||||
|
||||
bool introduction_received = false;
|
||||
@@ -935,19 +928,17 @@ TEST_F(IncomingShareSessionTest, ProcessKeyVerificationResultUnknown) {
|
||||
std::vector<uint8_t> data;
|
||||
data.resize(frame.ByteSizeLong());
|
||||
EXPECT_THAT(frame.SerializeToArray(data.data(), data.size()), IsTrue());
|
||||
connection.AppendReadableData(std::move(data));
|
||||
connection_.AppendReadableData(std::move(data));
|
||||
|
||||
EXPECT_THAT(introduction_received, IsFalse());
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, TryUpgradeBandwidthNotNeeded) {
|
||||
NearbySharingDecoderImpl decoder;
|
||||
FakeNearbyConnection connection;
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
session_.OnConnected(decoder, absl::Now(), &connection);
|
||||
session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_);
|
||||
|
||||
EXPECT_THAT(session_.TryUpgradeBandwidth(connections_manager), IsFalse());
|
||||
EXPECT_THAT(connections_manager.DidUpgradeBandwidth(kEndpointId), IsFalse());
|
||||
EXPECT_THAT(session_.TryUpgradeBandwidth(), IsFalse());
|
||||
EXPECT_THAT(connections_manager_.DidUpgradeBandwidth(kEndpointId), IsFalse());
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, TryUpgradeBandwidthNeeded) {
|
||||
@@ -974,36 +965,31 @@ TEST_F(IncomingShareSessionTest, TryUpgradeBandwidthNeeded) {
|
||||
}
|
||||
)pb",
|
||||
&introduction_frame));
|
||||
NearbySharingDecoderImpl decoder;
|
||||
FakeNearbyConnection connection;
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
session_.OnConnected(decoder, absl::Now(), &connection);
|
||||
session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_);
|
||||
EXPECT_THAT(session_.ProcessIntroduction(introduction_frame),
|
||||
Eq(std::nullopt));
|
||||
|
||||
EXPECT_THAT(session_.TryUpgradeBandwidth(connections_manager), IsTrue());
|
||||
EXPECT_THAT(connections_manager.DidUpgradeBandwidth(kEndpointId), IsTrue());
|
||||
EXPECT_THAT(session_.TryUpgradeBandwidth(), IsTrue());
|
||||
EXPECT_THAT(connections_manager_.DidUpgradeBandwidth(kEndpointId), IsTrue());
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, SendFailureResponseNotConnected) {
|
||||
EXPECT_CALL(
|
||||
transfer_metadata_callback_,
|
||||
Call(_, HasStatus(TransferMetadata::Status::kNotEnoughSpace)));
|
||||
EXPECT_CALL(transfer_metadata_callback_,
|
||||
Call(_, HasStatus(TransferMetadata::Status::kNotEnoughSpace)));
|
||||
|
||||
session_.SendFailureResponse(TransferMetadata::Status::kNotEnoughSpace);
|
||||
}
|
||||
|
||||
TEST_F(IncomingShareSessionTest, SendFailureResponseConnected) {
|
||||
NearbySharingDecoderImpl decoder;
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder, absl::Now(), &connection);
|
||||
EXPECT_CALL(
|
||||
transfer_metadata_callback_,
|
||||
Call(_, HasStatus(TransferMetadata::Status::kNotEnoughSpace)));
|
||||
session_.OnConnected(nearby_sharing_decoder_, absl::Now(),
|
||||
&connections_manager_, &connection_);
|
||||
EXPECT_CALL(transfer_metadata_callback_,
|
||||
Call(_, HasStatus(TransferMetadata::Status::kNotEnoughSpace)));
|
||||
|
||||
session_.SendFailureResponse(TransferMetadata::Status::kNotEnoughSpace);
|
||||
|
||||
std::vector<uint8_t> frame_data = connection.GetWrittenData();
|
||||
std::vector<uint8_t> frame_data = connection_.GetWrittenData();
|
||||
Frame frame;
|
||||
ASSERT_TRUE(frame.ParseFromArray(frame_data.data(), frame_data.size()));
|
||||
ASSERT_EQ(frame.version(), Frame::V1);
|
||||
|
||||
@@ -597,18 +597,16 @@ void NearbySharingServiceImpl::RegisterReceiveSurface(
|
||||
std::move(status_codes_callback)(StatusCodes::kOk);
|
||||
return;
|
||||
}
|
||||
if (foreground_receive_callbacks_map_.contains(
|
||||
transfer_callback) ||
|
||||
background_receive_callbacks_map_.contains(
|
||||
transfer_callback)) {
|
||||
if (foreground_receive_callbacks_map_.contains(transfer_callback) ||
|
||||
background_receive_callbacks_map_.contains(transfer_callback)) {
|
||||
NL_LOG(ERROR) << __func__
|
||||
<< ": transfer callback already registered but for a "
|
||||
"different state.";
|
||||
std::move(status_codes_callback)(StatusCodes::kInvalidArgument);
|
||||
return;
|
||||
}
|
||||
if (ShouldBlockSurfaceRegistration(
|
||||
vendor_id, before_registration_vendor_id)) {
|
||||
if (ShouldBlockSurfaceRegistration(vendor_id,
|
||||
before_registration_vendor_id)) {
|
||||
// Block alternate vendor ID registration.
|
||||
NL_LOG(ERROR) << __func__
|
||||
<< ": disallowing registration of a receive surface "
|
||||
@@ -831,7 +829,7 @@ void NearbySharingServiceImpl::Accept(
|
||||
if (incoming_session != nullptr) {
|
||||
// Incoming session.
|
||||
bool accept_success = incoming_session->AcceptTransfer(
|
||||
context_->GetClock(), *nearby_connections_manager_,
|
||||
context_->GetClock(),
|
||||
absl::bind_front(
|
||||
&NearbySharingServiceImpl::OnPayloadTransferUpdate, this));
|
||||
std::move(status_codes_callback)(
|
||||
@@ -940,7 +938,7 @@ void NearbySharingServiceImpl::DoCancel(
|
||||
// cancellation signals. Also, note that there might not be any ongoing
|
||||
// payload transfer, for example, if a connection has not been established
|
||||
// yet.
|
||||
session->CancelPayloads(*nearby_connections_manager_);
|
||||
session->CancelPayloads();
|
||||
|
||||
// Inform the user that the transfer has been cancelled before disconnecting
|
||||
// because subsequent disconnections might be interpreted as failure.
|
||||
@@ -1008,8 +1006,8 @@ void NearbySharingServiceImpl::Open(
|
||||
NL_LOG(INFO) << __func__ << ": Open is called for share_target: "
|
||||
<< share_target.ToString();
|
||||
// Log analytics event of opening received attachments.
|
||||
analytics_recorder_->NewOpenReceivedAttachments(
|
||||
*attachment_container, /*session_id=*/0);
|
||||
analytics_recorder_->NewOpenReceivedAttachments(*attachment_container,
|
||||
/*session_id=*/0);
|
||||
status_codes_callback(service_extension_->Open(*attachment_container));
|
||||
});
|
||||
}
|
||||
@@ -1112,7 +1110,8 @@ 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(), connection);
|
||||
session.OnConnected(*decoder_, context_->GetClock()->Now(),
|
||||
nearby_connections_manager_.get(), connection);
|
||||
connection->SetDisconnectionListener([this, placeholder_share_target_id]() {
|
||||
OnConnectionDisconnected(placeholder_share_target_id);
|
||||
});
|
||||
@@ -2429,7 +2428,8 @@ 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, connection)) {
|
||||
if (!session.OnConnected(*decoder_, connect_start_time,
|
||||
nearby_connections_manager_.get(), connection)) {
|
||||
session.Abort(session.disconnect_status());
|
||||
return;
|
||||
}
|
||||
@@ -2722,7 +2722,7 @@ void NearbySharingServiceImpl::OnOutgoingTransferUpdate(
|
||||
metadata.in_progress_attachment_total_bytes().has_value() &&
|
||||
*metadata.in_progress_attachment_transferred_bytes() ==
|
||||
*metadata.in_progress_attachment_total_bytes()) {
|
||||
session.SendNextPayload(*nearby_connections_manager_);
|
||||
session.SendNextPayload();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2788,7 +2788,8 @@ 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(), connection);
|
||||
session.OnConnected(*decoder_, context_->GetClock()->Now(),
|
||||
nearby_connections_manager_.get(), connection);
|
||||
// Need to rebind the disconnect listener to the new share target id.
|
||||
connection->SetDisconnectionListener(
|
||||
[this, share_target_id]() { OnConnectionDisconnected(share_target_id); });
|
||||
@@ -2914,7 +2915,7 @@ void NearbySharingServiceImpl::OnReceivedIntroduction(
|
||||
sharing::config_package_nearby::nearby_sharing_feature::
|
||||
kUpgradeBandwidthAfterAccept)) {
|
||||
if (frame->has_start_transfer() && frame->start_transfer()) {
|
||||
if (session->TryUpgradeBandwidth(*nearby_connections_manager_)) {
|
||||
if (session->TryUpgradeBandwidth()) {
|
||||
NL_LOG(INFO)
|
||||
<< __func__
|
||||
<< ": Upgrade bandwidth when receiving an introduction frame.";
|
||||
@@ -2955,7 +2956,7 @@ void NearbySharingServiceImpl::OnReceiveConnectionResponse(
|
||||
NearbyFlags::GetInstance().GetBoolFlag(
|
||||
config_package_nearby::nearby_sharing_feature::
|
||||
kEnableTransferCancellationOptimization),
|
||||
context_->GetClock(), *nearby_connections_manager_,
|
||||
context_->GetClock(),
|
||||
[this, share_target_id](
|
||||
std::optional<nearby::sharing::service::proto::V1Frame> frame) {
|
||||
OnFrameRead(share_target_id, std::move(frame));
|
||||
@@ -2984,7 +2985,7 @@ void NearbySharingServiceImpl::OnStorageCheckCompleted(
|
||||
// Don't need to wait for user to accept for Self share.
|
||||
NL_LOG(INFO) << __func__ << ": Auto-accepting self share.";
|
||||
session.AcceptTransfer(
|
||||
context_->GetClock(), *nearby_connections_manager_,
|
||||
context_->GetClock(),
|
||||
absl::bind_front(&NearbySharingServiceImpl::OnPayloadTransferUpdate,
|
||||
this));
|
||||
OnTransferStarted(/*is_incoming=*/true);
|
||||
@@ -3047,8 +3048,7 @@ void NearbySharingServiceImpl::HandleProgressUpdateFrame(
|
||||
NL_LOG(ERROR) << "Received ProgressUpdate Frame on unknown session";
|
||||
return;
|
||||
}
|
||||
session->HandleProgressUpdate(*nearby_connections_manager_,
|
||||
progress_update_frame);
|
||||
session->HandleProgressUpdate(progress_update_frame);
|
||||
}
|
||||
|
||||
void NearbySharingServiceImpl::OnConnectionDisconnected(
|
||||
@@ -3143,11 +3143,11 @@ void NearbySharingServiceImpl::OnPayloadTransferUpdate(
|
||||
// TODO: b/289290115 - Revisit UpdateFilePath to enhance transfer speed for
|
||||
// MacOS.
|
||||
if (update_file_paths_in_progress_) {
|
||||
incoming_session->UpdateFilePayloadPaths(*nearby_connections_manager_);
|
||||
incoming_session->UpdateFilePayloadPaths();
|
||||
}
|
||||
|
||||
if (metadata.status() == TransferMetadata::Status::kComplete) {
|
||||
if (!incoming_session->FinalizePayloads(*nearby_connections_manager_)) {
|
||||
if (!incoming_session->FinalizePayloads()) {
|
||||
payload_incomplete = true;
|
||||
}
|
||||
|
||||
@@ -3160,7 +3160,7 @@ void NearbySharingServiceImpl::OnPayloadTransferUpdate(
|
||||
} else if (metadata.status() == TransferMetadata::Status::kCancelled) {
|
||||
NL_VLOG(1) << __func__ << ": Update file paths for cancelled transfer";
|
||||
if (!update_file_paths_in_progress_) {
|
||||
incoming_session->UpdateFilePayloadPaths(*nearby_connections_manager_);
|
||||
incoming_session->UpdateFilePayloadPaths();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3248,8 +3248,7 @@ void NearbySharingServiceImpl::Disconnect(int64_t share_target_id,
|
||||
// Disconnect after a timeout to make sure any pending payloads are sent.
|
||||
auto timer = std::make_unique<ThreadTimer>(
|
||||
*service_thread_, "disconnection_timeout_alarm",
|
||||
kOutgoingDisconnectionDelay,
|
||||
[this, endpoint_id]() {
|
||||
kOutgoingDisconnectionDelay, [this, endpoint_id]() {
|
||||
disconnection_timeout_alarms_.erase(endpoint_id);
|
||||
nearby_connections_manager_->Disconnect(endpoint_id);
|
||||
});
|
||||
|
||||
@@ -267,7 +267,6 @@ bool OutgoingShareSession::AcceptTransfer(
|
||||
|
||||
void OutgoingShareSession::SendPayloads(
|
||||
bool enable_transfer_cancellation_optimization, Clock* clock,
|
||||
NearbyConnectionsManager& connection_manager,
|
||||
std::function<
|
||||
void(std::optional<nearby::sharing::service::proto::V1Frame> frame)>
|
||||
frame_read_callback,
|
||||
@@ -287,44 +286,43 @@ void OutgoingShareSession::SendPayloads(
|
||||
NL_VLOG(1) << __func__
|
||||
<< ": The connection was accepted. Payloads are now being sent.";
|
||||
if (enable_transfer_cancellation_optimization) {
|
||||
InitSendPayload(clock, connection_manager, std::move(update_callback));
|
||||
SendNextPayload(connection_manager);
|
||||
InitSendPayload(clock, std::move(update_callback));
|
||||
SendNextPayload();
|
||||
} else {
|
||||
SendAllPayloads(clock, connection_manager, std::move(update_callback));
|
||||
SendAllPayloads(clock, std::move(update_callback));
|
||||
}
|
||||
}
|
||||
|
||||
void OutgoingShareSession::SendAllPayloads(
|
||||
Clock* clock, NearbyConnectionsManager& connection_manager,
|
||||
Clock* clock,
|
||||
std::function<void(int64_t, TransferMetadata)> update_callback) {
|
||||
set_payload_tracker(std::make_unique<PayloadTracker>(
|
||||
clock, share_target().id, attachment_container(),
|
||||
attachment_payload_map(), std::move(update_callback)));
|
||||
for (auto& payload : ExtractTextPayloads()) {
|
||||
connection_manager.Send(endpoint_id(), std::make_unique<Payload>(payload),
|
||||
payload_tracker());
|
||||
connections_manager()->Send(
|
||||
endpoint_id(), std::make_unique<Payload>(payload), payload_tracker());
|
||||
}
|
||||
for (auto& payload : ExtractFilePayloads()) {
|
||||
connection_manager.Send(endpoint_id(), std::make_unique<Payload>(payload),
|
||||
payload_tracker());
|
||||
connections_manager()->Send(
|
||||
endpoint_id(), std::make_unique<Payload>(payload), payload_tracker());
|
||||
}
|
||||
}
|
||||
|
||||
void OutgoingShareSession::InitSendPayload(
|
||||
Clock* clock, NearbyConnectionsManager& connection_manager,
|
||||
Clock* clock,
|
||||
std::function<void(int64_t, TransferMetadata)> update_callback) {
|
||||
set_payload_tracker(std::make_unique<PayloadTracker>(
|
||||
clock, share_target().id, attachment_container(),
|
||||
attachment_payload_map(), std::move(update_callback)));
|
||||
}
|
||||
|
||||
void OutgoingShareSession::SendNextPayload(
|
||||
NearbyConnectionsManager& connection_manager) {
|
||||
void OutgoingShareSession::SendNextPayload() {
|
||||
std::optional<Payload> payload = ExtractNextPayload();
|
||||
if (payload.has_value()) {
|
||||
NL_LOG(INFO) << __func__ << ": Send payload " << payload->id;
|
||||
connection_manager.Send(endpoint_id(), std::make_unique<Payload>(*payload),
|
||||
payload_tracker());
|
||||
connections_manager()->Send(
|
||||
endpoint_id(), std::make_unique<Payload>(*payload), payload_tracker());
|
||||
} else {
|
||||
NL_LOG(WARNING) << __func__ << ": There is no paylaods to send.";
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include "internal/platform/task_runner.h"
|
||||
#include "sharing/analytics/analytics_recorder.h"
|
||||
#include "sharing/nearby_connection.h"
|
||||
#include "sharing/nearby_connections_manager.h"
|
||||
#include "sharing/nearby_connections_types.h"
|
||||
#include "sharing/nearby_file_handler.h"
|
||||
#include "sharing/paired_key_verification_runner.h"
|
||||
@@ -117,14 +116,13 @@ class OutgoingShareSession : public ShareSession {
|
||||
// Any other frames received will be passed to `frame_read_callback`.
|
||||
void SendPayloads(
|
||||
bool enable_transfer_cancellation_optimization, Clock* clock,
|
||||
NearbyConnectionsManager& connection_manager,
|
||||
std::function<
|
||||
void(std::optional<nearby::sharing::service::proto::V1Frame> frame)>
|
||||
frame_read_callback,
|
||||
std::function<void(int64_t, TransferMetadata)> update_callback);
|
||||
// Send the next payload to NearbyConnectionManager.
|
||||
// Used only if enable_transfer_cancellation_optimization is true.
|
||||
void SendNextPayload(NearbyConnectionsManager& connection_manager);
|
||||
void SendNextPayload();
|
||||
|
||||
protected:
|
||||
void InvokeTransferUpdateCallback(const TransferMetadata& metadata) override;
|
||||
@@ -136,13 +134,13 @@ class OutgoingShareSession : public ShareSession {
|
||||
// Create a payload status listener to send status change to
|
||||
// `update_callback`. Send all payloads to NearbyConnectionManager.
|
||||
void SendAllPayloads(
|
||||
Clock* clock, NearbyConnectionsManager& connection_manager,
|
||||
Clock* clock,
|
||||
std::function<void(int64_t, TransferMetadata)> update_callback);
|
||||
|
||||
// Create a payload status listener to send status change to
|
||||
// `update_callback`.
|
||||
void InitSendPayload(
|
||||
Clock* clock, NearbyConnectionsManager& connection_manager,
|
||||
Clock* clock,
|
||||
std::function<void(int64_t, TransferMetadata)> update_callback);
|
||||
|
||||
std::vector<Payload> ExtractTextPayloads();
|
||||
|
||||
@@ -112,6 +112,7 @@ class OutgoingShareSessionTest : public ::testing::Test {
|
||||
MockFunction<void(OutgoingShareSession&, const TransferMetadata&)>
|
||||
transfer_metadata_callback_;
|
||||
OutgoingShareSession session_;
|
||||
FakeNearbyConnectionsManager connections_manager_;
|
||||
TextAttachment text1_;
|
||||
TextAttachment text2_;
|
||||
FileAttachment file1_;
|
||||
@@ -252,7 +253,8 @@ TEST_F(OutgoingShareSessionTest, SendIntroductionWithoutPayloads) {
|
||||
TEST_F(OutgoingShareSessionTest, SendIntroductionSuccess) {
|
||||
session_.set_session_id(1234);
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder_, absl::Now(), &connection);
|
||||
session_.OnConnected(decoder_, absl::Now(), &connections_manager_,
|
||||
&connection);
|
||||
std::vector<NearbyFileHandler::FileInfo> file_infos;
|
||||
file_infos.push_back({
|
||||
.size = 12355L,
|
||||
@@ -325,7 +327,8 @@ TEST_F(OutgoingShareSessionTest, SendIntroductionTimeout) {
|
||||
session_.SetAttachmentContainer(std::move(container));
|
||||
session_.set_session_id(1234);
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder_, absl::Now(), &connection);
|
||||
session_.OnConnected(decoder_, absl::Now(), &connections_manager_,
|
||||
&connection);
|
||||
session_.CreateTextPayloads();
|
||||
EXPECT_CALL(
|
||||
mock_event_logger_,
|
||||
@@ -351,7 +354,8 @@ TEST_F(OutgoingShareSessionTest, SendIntroductionTimeoutCancelled) {
|
||||
session_.SetAttachmentContainer(std::move(container));
|
||||
session_.set_session_id(1234);
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder_, absl::Now(), &connection);
|
||||
session_.OnConnected(decoder_, absl::Now(), &connections_manager_,
|
||||
&connection);
|
||||
session_.CreateTextPayloads();
|
||||
EXPECT_CALL(
|
||||
mock_event_logger_,
|
||||
@@ -388,7 +392,8 @@ TEST_F(OutgoingShareSessionTest, AcceptTransferNotConnected) {
|
||||
TEST_F(OutgoingShareSessionTest, AcceptTransferNotReady) {
|
||||
session_.set_session_id(1234);
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder_, absl::Now(), &connection);
|
||||
session_.OnConnected(decoder_, absl::Now(), &connections_manager_,
|
||||
&connection);
|
||||
|
||||
EXPECT_THAT(
|
||||
session_.AcceptTransfer([](std::optional<ConnectionResponseFrame>) {}),
|
||||
@@ -401,7 +406,8 @@ TEST_F(OutgoingShareSessionTest, AcceptTransferSuccess) {
|
||||
session_.SetAttachmentContainer(std::move(container));
|
||||
session_.set_session_id(1234);
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder_, absl::Now(), &connection);
|
||||
session_.OnConnected(decoder_, absl::Now(), &connections_manager_,
|
||||
&connection);
|
||||
session_.CreateTextPayloads();
|
||||
EXPECT_CALL(mock_event_logger_,
|
||||
Log(Matcher<const SharingLog&>(
|
||||
@@ -492,7 +498,8 @@ TEST_F(OutgoingShareSessionTest, HandleConnectionResponseAcceptResponse) {
|
||||
ConnectionResponseFrame response;
|
||||
response.set_status(ConnectionResponseFrame::ACCEPT);
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder_, absl::Now(), &connection);
|
||||
session_.OnConnected(decoder_, absl::Now(), &connections_manager_,
|
||||
&connection);
|
||||
EXPECT_CALL(transfer_metadata_callback_,
|
||||
Call(_, HasStatus(TransferMetadata::Status::kInProgress)));
|
||||
|
||||
@@ -527,8 +534,7 @@ TEST_F(OutgoingShareSessionTest, SendPayloadsDisableCancellationOptimization) {
|
||||
std::unique_ptr<Payload>,
|
||||
std::weak_ptr<NearbyConnectionsManager::PayloadStatusListener>)>>
|
||||
send_payload_callback;
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
connections_manager.set_send_payload_callback(
|
||||
connections_manager_.set_send_payload_callback(
|
||||
send_payload_callback.AsStdFunction());
|
||||
EXPECT_CALL(send_payload_callback, Call(_, _))
|
||||
.WillOnce(Invoke(
|
||||
@@ -556,12 +562,12 @@ TEST_F(OutgoingShareSessionTest, SendPayloadsDisableCancellationOptimization) {
|
||||
Property(&SharingLog::send_attachments_start,
|
||||
HasSessionId(1234)))))));
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder_, absl::Now(), &connection);
|
||||
session_.OnConnected(decoder_, absl::Now(), &connections_manager_,
|
||||
&connection);
|
||||
|
||||
session_.SendPayloads(
|
||||
/*enable_transfer_cancellation_optimization=*/
|
||||
false, &fake_clock_, connections_manager,
|
||||
[](std::optional<V1Frame> frame) {},
|
||||
false, &fake_clock_, [](std::optional<V1Frame> frame) {},
|
||||
transfer_metadata_callback.AsStdFunction());
|
||||
|
||||
auto payload_listener = session_.payload_tracker().lock();
|
||||
@@ -583,8 +589,7 @@ TEST_F(OutgoingShareSessionTest, SendPayloadsEnableCancellationOptimization) {
|
||||
std::unique_ptr<Payload>,
|
||||
std::weak_ptr<NearbyConnectionsManager::PayloadStatusListener>)>>
|
||||
send_payload_callback;
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
connections_manager.set_send_payload_callback(
|
||||
connections_manager_.set_send_payload_callback(
|
||||
send_payload_callback.AsStdFunction());
|
||||
EXPECT_CALL(send_payload_callback, Call(_, _))
|
||||
.WillOnce(Invoke(
|
||||
@@ -600,12 +605,12 @@ TEST_F(OutgoingShareSessionTest, SendPayloadsEnableCancellationOptimization) {
|
||||
Property(&SharingLog::send_attachments_start,
|
||||
HasSessionId(1234)))))));
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder_, absl::Now(), &connection);
|
||||
session_.OnConnected(decoder_, absl::Now(), &connections_manager_,
|
||||
&connection);
|
||||
|
||||
session_.SendPayloads(
|
||||
/*enable_transfer_cancellation_optimization=*/
|
||||
true, &fake_clock_, connections_manager,
|
||||
[](std::optional<V1Frame> frame) {},
|
||||
true, &fake_clock_, [](std::optional<V1Frame> frame) {},
|
||||
transfer_metadata_callback.AsStdFunction());
|
||||
|
||||
auto payload_listener = session_.payload_tracker().lock();
|
||||
@@ -627,8 +632,7 @@ TEST_F(OutgoingShareSessionTest, SendNextPayload) {
|
||||
std::unique_ptr<Payload>,
|
||||
std::weak_ptr<NearbyConnectionsManager::PayloadStatusListener>)>>
|
||||
send_payload_callback;
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
connections_manager.set_send_payload_callback(
|
||||
connections_manager_.set_send_payload_callback(
|
||||
send_payload_callback.AsStdFunction());
|
||||
|
||||
EXPECT_CALL(send_payload_callback, Call(_, _))
|
||||
@@ -645,12 +649,12 @@ TEST_F(OutgoingShareSessionTest, SendNextPayload) {
|
||||
Property(&SharingLog::send_attachments_start,
|
||||
HasSessionId(1234)))))));
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder_, absl::Now(), &connection);
|
||||
session_.OnConnected(decoder_, absl::Now(), &connections_manager_,
|
||||
&connection);
|
||||
|
||||
session_.SendPayloads(
|
||||
/*enable_transfer_cancellation_optimization=*/
|
||||
true, &fake_clock_, connections_manager,
|
||||
[](std::optional<V1Frame> frame) {},
|
||||
true, &fake_clock_, [](std::optional<V1Frame> frame) {},
|
||||
transfer_metadata_callback.AsStdFunction());
|
||||
|
||||
EXPECT_CALL(send_payload_callback, Call(_, _))
|
||||
@@ -660,7 +664,7 @@ TEST_F(OutgoingShareSessionTest, SendNextPayload) {
|
||||
std::weak_ptr<NearbyConnectionsManager::PayloadStatusListener>) {
|
||||
payload->id = session_.attachment_payload_map().at(text1_.id());
|
||||
}));
|
||||
session_.SendNextPayload(connections_manager);
|
||||
session_.SendNextPayload();
|
||||
|
||||
EXPECT_CALL(send_payload_callback, Call(_, _))
|
||||
.WillOnce(Invoke(
|
||||
@@ -669,12 +673,13 @@ TEST_F(OutgoingShareSessionTest, SendNextPayload) {
|
||||
std::weak_ptr<NearbyConnectionsManager::PayloadStatusListener>) {
|
||||
payload->id = session_.attachment_payload_map().at(text2_.id());
|
||||
}));
|
||||
session_.SendNextPayload(connections_manager);
|
||||
session_.SendNextPayload();
|
||||
}
|
||||
|
||||
TEST_F(OutgoingShareSessionTest, ProcessKeyVerificationResultFail) {
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder_, absl::Now(), &connection);
|
||||
session_.OnConnected(decoder_, absl::Now(), &connections_manager_,
|
||||
&connection);
|
||||
session_.SetTokenForTests("1234");
|
||||
|
||||
EXPECT_THAT(
|
||||
@@ -689,7 +694,8 @@ TEST_F(OutgoingShareSessionTest, ProcessKeyVerificationResultFail) {
|
||||
|
||||
TEST_F(OutgoingShareSessionTest, ProcessKeyVerificationResultSuccess) {
|
||||
FakeNearbyConnection connection;
|
||||
session_.OnConnected(decoder_, absl::Now(), &connection);
|
||||
session_.OnConnected(decoder_, absl::Now(), &connections_manager_,
|
||||
&connection);
|
||||
session_.SetTokenForTests("1234");
|
||||
|
||||
EXPECT_THAT(
|
||||
|
||||
@@ -117,7 +117,10 @@ void ShareSession::set_disconnect_status(
|
||||
|
||||
bool ShareSession::OnConnected(const NearbySharingDecoder& decoder,
|
||||
absl::Time connect_start_time,
|
||||
NearbyConnectionsManager* connections_manager,
|
||||
NearbyConnection* connection) {
|
||||
NL_DCHECK(connections_manager) << "Connections manager must not be null";
|
||||
connections_manager_ = connections_manager;
|
||||
if (!OnNewConnection(connection)) {
|
||||
return false;
|
||||
}
|
||||
@@ -175,10 +178,12 @@ void ShareSession::SetAttachmentPayloadId(int64_t attachment_id,
|
||||
attachment_payload_map_[attachment_id] = payload_id;
|
||||
}
|
||||
|
||||
void ShareSession::CancelPayloads(
|
||||
NearbyConnectionsManager& connections_manager) {
|
||||
void ShareSession::CancelPayloads() {
|
||||
if (connections_manager_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
for (const auto& [attachment_id, payload_id] : attachment_payload_map_) {
|
||||
connections_manager.Cancel(payload_id);
|
||||
connections_manager_->Cancel(payload_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,9 @@ 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, NearbyConnection* connection);
|
||||
absl::Time connect_start_time,
|
||||
NearbyConnectionsManager* connections_manager,
|
||||
NearbyConnection* connection);
|
||||
|
||||
// Send TransferMetadataUpdate with the final status.
|
||||
// If connected, also close the connection.
|
||||
@@ -129,7 +131,7 @@ class ShareSession {
|
||||
return attachment_container_;
|
||||
}
|
||||
|
||||
void CancelPayloads(NearbyConnectionsManager& connections_manager);
|
||||
void CancelPayloads();
|
||||
|
||||
const absl::flat_hash_map<int64_t, int64_t>& attachment_payload_map() const {
|
||||
return attachment_payload_map_;
|
||||
@@ -168,11 +170,16 @@ class ShareSession {
|
||||
PairedKeyVerificationRunner::PairedKeyVerificationResult result,
|
||||
location::nearby::proto::sharing::OSType share_target_os_type);
|
||||
|
||||
NearbyConnectionsManager* connections_manager() {
|
||||
return connections_manager_;
|
||||
}
|
||||
|
||||
private:
|
||||
TaskRunner& service_thread_;
|
||||
analytics::AnalyticsRecorder& analytics_recorder_;
|
||||
std::string endpoint_id_;
|
||||
std::optional<NearbyShareDecryptedPublicCertificate> certificate_;
|
||||
NearbyConnectionsManager* connections_manager_ = nullptr;
|
||||
NearbyConnection* connection_ = nullptr;
|
||||
// If not empty, this is the 4 digit token used to verify the connection.
|
||||
// If token is empty, it means self-share and verification is not needed.
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "sharing/share_session.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@@ -140,16 +139,19 @@ 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(), nullptr));
|
||||
EXPECT_FALSE(session.OnConnected(nearby_sharing_decoder, 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);
|
||||
@@ -158,12 +160,13 @@ TEST(ShareSessionTest, OnConnectedSucceeds) {
|
||||
absl::Time connect_start_time = absl::Now();
|
||||
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder, connect_start_time,
|
||||
&connection));
|
||||
&connections_manager, &connection));
|
||||
EXPECT_EQ(session.connection_start_time(), connect_start_time);
|
||||
EXPECT_EQ(session.connection(), &connection);
|
||||
}
|
||||
|
||||
TEST(ShareSessionTest, IncomingRunPairedKeyVerificationSuccess) {
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
FakeClock fake_clock;
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder;
|
||||
FakeNearbyShareCertificateManager certificate_manager;
|
||||
@@ -175,7 +178,7 @@ TEST(ShareSessionTest, IncomingRunPairedKeyVerificationSuccess) {
|
||||
session.SetOnNewConnectionResult(true);
|
||||
absl::Time connect_start_time = absl::Now();
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder, connect_start_time,
|
||||
&connection));
|
||||
&connections_manager, &connection));
|
||||
absl::Notification notification;
|
||||
PairedKeyVerificationRunner::PairedKeyVerificationResult verification_result;
|
||||
|
||||
@@ -245,25 +248,30 @@ 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));
|
||||
session.SetAttachmentPayloadId(1, 2);
|
||||
session.SetAttachmentPayloadId(3, 4);
|
||||
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
session.CancelPayloads(connections_manager);
|
||||
session.CancelPayloads();
|
||||
|
||||
EXPECT_TRUE(connections_manager.WasPayloadCanceled(2));
|
||||
EXPECT_TRUE(connections_manager.WasPayloadCanceled(4));
|
||||
}
|
||||
|
||||
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(), &connection));
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder, absl::Now(),
|
||||
&connections_manager, &connection));
|
||||
|
||||
session.WriteResponseFrame(ConnectionResponseFrame::REJECT);
|
||||
|
||||
@@ -277,12 +285,13 @@ 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(), &connection));
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder, absl::Now(),
|
||||
&connections_manager, &connection));
|
||||
|
||||
session.WriteCancelFrame();
|
||||
|
||||
@@ -294,12 +303,13 @@ 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(), &connection));
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder, absl::Now(),
|
||||
&connections_manager, &connection));
|
||||
session.SetTokenForTests("9876");
|
||||
|
||||
EXPECT_FALSE(session.HandleKeyVerificationResult(
|
||||
@@ -310,13 +320,14 @@ 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(), &connection));
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder, absl::Now(),
|
||||
&connections_manager, &connection));
|
||||
session.SetTokenForTests("9876");
|
||||
|
||||
EXPECT_TRUE(session.HandleKeyVerificationResult(
|
||||
@@ -328,12 +339,13 @@ 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(), &connection));
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder, absl::Now(),
|
||||
&connections_manager, &connection));
|
||||
session.SetTokenForTests("9876");
|
||||
|
||||
EXPECT_TRUE(session.HandleKeyVerificationResult(
|
||||
@@ -346,13 +358,14 @@ 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(), &connection));
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder, absl::Now(),
|
||||
&connections_manager, &connection));
|
||||
session.SetTokenForTests("9876");
|
||||
|
||||
EXPECT_TRUE(session.HandleKeyVerificationResult(
|
||||
@@ -364,12 +377,13 @@ 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(), &connection));
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder, absl::Now(),
|
||||
&connections_manager, &connection));
|
||||
session.SetTokenForTests("9876");
|
||||
|
||||
EXPECT_TRUE(session.HandleKeyVerificationResult(
|
||||
@@ -381,12 +395,13 @@ 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(), &connection));
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder, absl::Now(),
|
||||
&connections_manager, &connection));
|
||||
session.SetTokenForTests("9876");
|
||||
|
||||
EXPECT_FALSE(session.HandleKeyVerificationResult(
|
||||
@@ -407,6 +422,7 @@ TEST(ShareSessionTest, AbortNotConnected) {
|
||||
}
|
||||
|
||||
TEST(ShareSessionTest, AbortConnected) {
|
||||
FakeNearbyConnectionsManager connections_manager;
|
||||
NearbySharingDecoderImpl nearby_sharing_decoder;
|
||||
ShareTarget share_target;
|
||||
TestShareSession session(std::string(kEndpointId), share_target);
|
||||
@@ -414,8 +430,8 @@ TEST(ShareSessionTest, AbortConnected) {
|
||||
bool disconnected = false;
|
||||
connection.SetDisconnectionListener(
|
||||
[&disconnected]() { disconnected = true; });
|
||||
EXPECT_TRUE(
|
||||
session.OnConnected(nearby_sharing_decoder, absl::Now(), &connection));
|
||||
EXPECT_TRUE(session.OnConnected(nearby_sharing_decoder, absl::Now(),
|
||||
&connections_manager, &connection));
|
||||
EXPECT_CALL(session, InvokeTransferUpdateCallback(AllOf(
|
||||
HasStatus(TransferMetadata::Status::kNotEnoughSpace),
|
||||
IsFinalStatus())));
|
||||
|
||||
Reference in New Issue
Block a user