Split frame handler for incoming and outgoing sessions.

PiperOrigin-RevId: 870909627
This commit is contained in:
Francis Tsui
2026-02-16 08:51:41 -08:00
committed by Copybara-Service
parent 80a263efeb
commit 91a06b6a7f
12 changed files with 153 additions and 335 deletions
+4 -6
View File
@@ -159,6 +159,7 @@ void IncomingFramesReader::OnDataReadFromConnection(
{
absl::MutexLock lock(mutex_);
if (read_frame_info_queue_.empty()) {
// Drop the frame if no one is waiting.
return;
}
const ReadFrameInfo& frame_info = read_frame_info_queue_.front();
@@ -210,12 +211,9 @@ void IncomingFramesReader::Done(std::unique_ptr<V1Frame> frame) {
read_frame_info_queue_.pop();
}
if (read_frame_info.timeout != absl::ZeroDuration()) {
ReadFrame(*read_frame_info.frame_type, std::move(read_frame_info.callback),
read_frame_info.timeout);
} else {
ReadFrame(std::move(read_frame_info.callback), read_frame_info.timeout);
}
ProcessReadRequest(read_frame_info.frame_type,
std::move(read_frame_info.callback),
read_frame_info.timeout);
}
std::unique_ptr<V1Frame> IncomingFramesReader::PopCachedFrame(
-24
View File
@@ -192,30 +192,6 @@ IncomingShareSession::ProcessIntroduction(
return std::nullopt;
}
bool IncomingShareSession::ProcessKeyVerificationResult(
PairedKeyVerificationRunner::PairedKeyVerificationResult result,
OSType share_target_os_type,
std::function<void(std::optional<IntroductionFrame>)>
introduction_callback) {
if (!HandleKeyVerificationResult(result, share_target_os_type)) {
return false;
}
LOG(INFO) << ":Waiting for introduction from " << share_target().id;
frames_reader()->ReadFrame(
V1Frame::INTRODUCTION,
[callback = std::move(introduction_callback)](
bool is_timeout, std::optional<V1Frame> frame) {
if (!frame.has_value()) {
callback(std::nullopt);
} else {
callback(frame->introduction());
}
},
kReadFramesTimeout);
return true;
}
bool IncomingShareSession::ReadyForTransfer(
std::function<void()> accept_timeout_callback,
std::function<void(bool is_timeout, std::optional<V1Frame> frame)>
-11
View File
@@ -61,17 +61,6 @@ class IncomingShareSession : public ShareSession {
const nearby::sharing::service::proto::IntroductionFrame&
introduction_frame);
// Processes the PairedKeyVerificationResult.
// Returns true if verification was successful and the session is now waiting
// for the introduction frame. Calls |introduction_callback| when it is
// received.
bool ProcessKeyVerificationResult(
PairedKeyVerificationRunner::PairedKeyVerificationResult result,
location::nearby::proto::sharing::OSType share_target_os_type,
std::function<void(
std::optional<nearby::sharing::service::proto::IntroductionFrame>)>
introduction_callback);
// Returns true if the transfer can begin and AcceptTransfer should be called
// immediately.
// Returns false if user needs to accept the transfer.
-133
View File
@@ -1235,139 +1235,6 @@ TEST_F(IncomingShareSessionTest, AcceptTransferSuccess) {
ConnectionResponseFrame::ACCEPT);
}
TEST_F(IncomingShareSessionTest, ProcessKeyVerificationResultSuccess) {
session_.OnConnected(&connection_);
session_.SetTokenForTests("1234");
bool introduction_received = false;
EXPECT_THAT(
session_.ProcessKeyVerificationResult(
PairedKeyVerificationRunner::PairedKeyVerificationResult::kSuccess,
OSType::WINDOWS,
[&introduction_received](std::optional<IntroductionFrame>) {
introduction_received = true;
}),
IsTrue());
EXPECT_THAT(session_.self_share(), IsFalse());
EXPECT_THAT(session_.token(), IsEmpty());
EXPECT_THAT(session_.os_type(), Eq(OSType::WINDOWS));
EXPECT_THAT(introduction_received, IsFalse());
// Send Introduction frame
nearby::sharing::service::proto::Frame frame =
nearby::sharing::service::proto::Frame();
frame.set_version(nearby::sharing::service::proto::Frame::V1);
V1Frame* v1frame = frame.mutable_v1();
v1frame->set_type(service::proto::V1Frame::INTRODUCTION);
v1frame->mutable_introduction();
std::vector<uint8_t> data;
data.resize(frame.ByteSizeLong());
EXPECT_THAT(frame.SerializeToArray(data.data(), data.size()), IsTrue());
connection_.WriteMessage(std::move(data));
EXPECT_THAT(introduction_received, IsTrue());
}
TEST_F(IncomingShareSessionTest, ProcessKeyVerificationResultFail) {
session_.OnConnected(&connection_);
session_.SetTokenForTests("1234");
bool introduction_received = false;
EXPECT_THAT(
session_.ProcessKeyVerificationResult(
PairedKeyVerificationRunner::PairedKeyVerificationResult::kFail,
OSType::WINDOWS,
[&introduction_received](std::optional<IntroductionFrame>) {
introduction_received = true;
}),
IsFalse());
EXPECT_THAT(session_.token(), Eq("1234"));
EXPECT_THAT(session_.os_type(), Eq(OSType::WINDOWS));
EXPECT_THAT(introduction_received, IsFalse());
// Send Introduction frame
nearby::sharing::service::proto::Frame frame =
nearby::sharing::service::proto::Frame();
frame.set_version(nearby::sharing::service::proto::Frame::V1);
V1Frame* v1frame = frame.mutable_v1();
v1frame->set_type(service::proto::V1Frame::INTRODUCTION);
v1frame->mutable_introduction();
std::vector<uint8_t> data;
data.resize(frame.ByteSizeLong());
EXPECT_THAT(frame.SerializeToArray(data.data(), data.size()), IsTrue());
connection_.WriteMessage(std::move(data));
EXPECT_THAT(introduction_received, IsFalse());
}
TEST_F(IncomingShareSessionTest, ProcessKeyVerificationResultUnable) {
session_.OnConnected(&connection_);
session_.SetTokenForTests("1234");
bool introduction_received = false;
EXPECT_THAT(
session_.ProcessKeyVerificationResult(
PairedKeyVerificationRunner::PairedKeyVerificationResult::kUnable,
OSType::WINDOWS,
[&introduction_received](std::optional<IntroductionFrame>) {
introduction_received = true;
}),
IsTrue());
EXPECT_THAT(session_.token(), Eq("1234"));
EXPECT_THAT(session_.os_type(), Eq(OSType::WINDOWS));
EXPECT_THAT(introduction_received, IsFalse());
// Send Introduction frame
nearby::sharing::service::proto::Frame frame =
nearby::sharing::service::proto::Frame();
frame.set_version(nearby::sharing::service::proto::Frame::V1);
V1Frame* v1frame = frame.mutable_v1();
v1frame->set_type(service::proto::V1Frame::INTRODUCTION);
v1frame->mutable_introduction();
std::vector<uint8_t> data;
data.resize(frame.ByteSizeLong());
EXPECT_THAT(frame.SerializeToArray(data.data(), data.size()), IsTrue());
connection_.WriteMessage(std::move(data));
EXPECT_THAT(introduction_received, IsTrue());
}
TEST_F(IncomingShareSessionTest, ProcessKeyVerificationResultUnknown) {
session_.OnConnected(&connection_);
session_.SetTokenForTests("1234");
bool introduction_received = false;
EXPECT_THAT(
session_.ProcessKeyVerificationResult(
PairedKeyVerificationRunner::PairedKeyVerificationResult::kUnknown,
OSType::WINDOWS,
[&introduction_received](std::optional<IntroductionFrame>) {
introduction_received = true;
}),
IsFalse());
EXPECT_THAT(session_.token(), Eq("1234"));
EXPECT_THAT(session_.os_type(), Eq(OSType::WINDOWS));
EXPECT_THAT(introduction_received, IsFalse());
// Send Introduction frame
nearby::sharing::service::proto::Frame frame =
nearby::sharing::service::proto::Frame();
frame.set_version(nearby::sharing::service::proto::Frame::V1);
V1Frame* v1frame = frame.mutable_v1();
v1frame->set_type(service::proto::V1Frame::INTRODUCTION);
v1frame->mutable_introduction();
std::vector<uint8_t> data;
data.resize(frame.ByteSizeLong());
EXPECT_THAT(frame.SerializeToArray(data.data(), data.size()), IsTrue());
connection_.WriteMessage(std::move(data));
EXPECT_THAT(introduction_received, IsFalse());
}
TEST_F(IncomingShareSessionTest, TryUpgradeBandwidthNotNeeded) {
session_.OnConnected(&connection_);
+82 -53
View File
@@ -2428,6 +2428,57 @@ void NearbySharingServiceImpl::OnIncomingDecryptedCertificate(
this, share_target_id));
}
void NearbySharingServiceImpl::OnIncomingSessionFrameRead(
int64_t share_target_id,
bool is_timeout,
std::optional<nearby::sharing::service::proto::V1Frame> frame) {
IncomingShareSession* session = GetIncomingShareSession(share_target_id);
if (session == nullptr || !session->IsConnected()) {
LOG(WARNING) << __func__
<< ": Session not connected, stop reading frames from target: "
<< share_target_id;
return;
}
if (is_timeout) {
LOG(WARNING) << __func__ << ": Timed out reading frame from target: "
<< share_target_id;
session->Abort(TransferMetadata::Status::kFailed);
return;
}
if (!frame.has_value()) {
// This is the case when the connection has been closed since we wait
// indefinitely for incoming frames.
return;
}
VLOG(1) << "Received incoming frame type: "
<< static_cast<int>(frame->type()) << " from " << share_target_id;
switch (frame->type()) {
case service::proto::V1Frame::CANCEL:
RunOnNearbySharingServiceThread("cancel_transfer", [this,
share_target_id]() {
LOG(INFO) << __func__ << ": Read the cancel frame, closing connection";
DoCancel(
share_target_id, [](StatusCodes status_codes) {},
/*is_initiator_of_cancellation=*/false);
});
break;
case service::proto::V1Frame::INTRODUCTION:
OnReceivedIntroduction(*session, frame->introduction());
// OnReceivedIntroduction will schedule the next ReadFrame.
return;
default:
LOG(ERROR) << __func__ << ": Discarding unknown frame of type: "
<< static_cast<int>(frame->type());
break;
}
session->frames_reader()->ReadFrame(
absl::bind_front(&NearbySharingServiceImpl::OnIncomingSessionFrameRead,
this, share_target_id),
absl::ZeroDuration());
}
void NearbySharingServiceImpl::OnIncomingConnectionKeyVerificationDone(
int64_t share_target_id,
PairedKeyVerificationRunner::PairedKeyVerificationResult result,
@@ -2438,11 +2489,15 @@ void NearbySharingServiceImpl::OnIncomingConnectionKeyVerificationDone(
return;
}
if (!session->ProcessKeyVerificationResult(
result, share_target_os_type,
absl::bind_front(&NearbySharingServiceImpl::OnReceivedIntroduction,
this, share_target_id))) {
result, share_target_os_type)) {
session->Abort(TransferMetadata::Status::kDeviceAuthenticationFailed);
return;
}
LOG(INFO) << "Waiting for introduction from " << share_target_id;
session->frames_reader()->ReadFrame(
absl::bind_front(&NearbySharingServiceImpl::OnIncomingSessionFrameRead,
this, share_target_id),
kReadFramesTimeout);
}
void NearbySharingServiceImpl::OnOutgoingConnectionKeyVerificationDone(
@@ -2497,51 +2552,37 @@ void NearbySharingServiceImpl::OnOutgoingConnectionKeyVerificationDone(
}
void NearbySharingServiceImpl::OnReceivedIntroduction(
int64_t share_target_id, std::optional<IntroductionFrame> frame) {
IncomingShareSession* session = GetIncomingShareSession(share_target_id);
if (!session || !session->IsConnected()) {
LOG(WARNING)
<< __func__
<< ": Ignore received introduction, due to no connection established.";
return;
}
if (!frame.has_value()) {
session->Abort(TransferMetadata::Status::kFailed);
LOG(WARNING) << __func__ << ": Invalid introduction frame";
return;
}
IncomingShareSession& session, const IntroductionFrame& frame) {
LOG(INFO) << __func__ << ": Successfully read the introduction frame.";
std::optional<TransferMetadata::Status> status =
session->ProcessIntroduction(*frame);
session.ProcessIntroduction(frame);
if (status.has_value()) {
Fail(*session, *status);
Fail(session, *status);
return;
}
FilePath save_path{settings_->GetCustomSavePath()};
// Override save path for this connection.
// This must be called before the transfer is accepted and payloads are being
// received.
nearby_connections_manager_->OverrideSavePath(session->endpoint_id(),
nearby_connections_manager_->OverrideSavePath(session.endpoint_id(),
save_path);
// Log analytics event of receiving introduction.
analytics_recorder_.NewReceiveIntroduction(
session->session_id(), session->share_target(),
/*referrer_package=*/std::nullopt, session->os_type());
session.session_id(), session.share_target(),
/*referrer_package=*/std::nullopt, session.os_type());
if (IsOutOfStorage(device_info_, save_path,
session->attachment_container().GetStorageSize())) {
Fail(*session, TransferMetadata::Status::kNotEnoughSpace);
session.attachment_container().GetStorageSize())) {
Fail(session, TransferMetadata::Status::kNotEnoughSpace);
LOG(WARNING) << __func__
<< ": Not enough space on the receiver. We have informed "
<< share_target_id;
<< session.share_target().id;
return;
}
OnStorageCheckCompleted(*session);
OnStorageCheckCompleted(session);
}
void NearbySharingServiceImpl::OnReceiveConnectionResponse(
@@ -2562,11 +2603,8 @@ void NearbySharingServiceImpl::OnReceiveConnectionResponse(
return;
}
session->SendPayloads(
[this, share_target_id](
bool is_timeout,
std::optional<nearby::sharing::service::proto::V1Frame> frame) {
OnFrameRead(share_target_id, is_timeout, std::move(frame));
},
absl::bind_front(&NearbySharingServiceImpl::OnOutgoingSessionFrameRead,
this, share_target_id),
absl::bind_front(
&NearbySharingServiceImpl::OnOutgoingPayloadTransferUpdates, this,
share_target_id));
@@ -2585,8 +2623,9 @@ void NearbySharingServiceImpl::OnStorageCheckCompleted(
Fail(*session, TransferMetadata::Status::kTimedOut);
}
},
absl::bind_front(&NearbySharingServiceImpl::OnFrameRead, this,
session.share_target().id))) {
absl::bind_front(
&NearbySharingServiceImpl::OnIncomingSessionFrameRead, this,
session.share_target().id))) {
return;
}
// Don't need to wait for user to accept for Self share.
@@ -2597,7 +2636,7 @@ void NearbySharingServiceImpl::OnStorageCheckCompleted(
OnTransferStarted(/*is_incoming=*/true);
}
void NearbySharingServiceImpl::OnFrameRead(
void NearbySharingServiceImpl::OnOutgoingSessionFrameRead(
int64_t share_target_id, bool is_timeout,
std::optional<nearby::sharing::service::proto::V1Frame> frame) {
if (!frame.has_value()) {
@@ -2616,35 +2655,25 @@ void NearbySharingServiceImpl::OnFrameRead(
/*is_initiator_of_cancellation=*/false);
});
break;
case nearby::sharing::service::proto::V1Frame::CERTIFICATE_INFO:
// No-op, no longer used.
break;
case nearby::sharing::service::proto::V1Frame::PROGRESS_UPDATE:
// No-op, no longer used.
break;
default:
LOG(ERROR) << __func__ << ": Discarding unknown frame of type: "
<< static_cast<int>(frame->type());
break;
}
ShareSession* session = GetShareSession(share_target_id);
if (!session || !session->frames_reader()) {
OutgoingShareSession* session =
outgoing_targets_manager_.GetOutgoingShareSession(share_target_id);
if (!session || !session->IsConnected()) {
LOG(WARNING) << __func__
<< ": Stopped reading further frames, due to no connection "
"established.";
<< ": Session not connected, stop reading frames from target: "
<< share_target_id;
return;
}
session->frames_reader()->ReadFrame(
[this, share_target_id](
bool is_timeout,
std::optional<nearby::sharing::service::proto::V1Frame> frame) {
OnFrameRead(share_target_id, is_timeout, std::move(frame));
}, absl::ZeroDuration());
absl::bind_front(&NearbySharingServiceImpl::OnOutgoingSessionFrameRead,
this, share_target_id),
absl::ZeroDuration());
}
void NearbySharingServiceImpl::OnConnectionDisconnected(
+7 -3
View File
@@ -311,15 +311,19 @@ class NearbySharingServiceImpl
int64_t share_target_id,
PairedKeyVerificationRunner::PairedKeyVerificationResult result,
::location::nearby::proto::sharing::OSType share_target_os_type);
void OnReceivedIntroduction(
void OnIncomingSessionFrameRead(
int64_t share_target_id,
std::optional<nearby::sharing::service::proto::IntroductionFrame> frame);
bool is_timeout,
std::optional<nearby::sharing::service::proto::V1Frame> frame);
void OnReceivedIntroduction(
IncomingShareSession& session,
const nearby::sharing::service::proto::IntroductionFrame& frame);
void OnReceiveConnectionResponse(
int64_t share_target_id,
std::optional<nearby::sharing::service::proto::ConnectionResponseFrame>
frame);
void OnStorageCheckCompleted(IncomingShareSession& session);
void OnFrameRead(
void OnOutgoingSessionFrameRead(
int64_t share_target_id, bool is_timeout,
std::optional<nearby::sharing::service::proto::V1Frame> frame);
-6
View File
@@ -188,12 +188,6 @@ bool OutgoingShareSession::InitiateSendAttachments(
return success;
}
bool OutgoingShareSession::ProcessKeyVerificationResult(
PairedKeyVerificationRunner::PairedKeyVerificationResult result,
location::nearby::proto::sharing::OSType share_target_os_type) {
return HandleKeyVerificationResult(result, share_target_os_type);
}
void OutgoingShareSession::OnConnectionDisconnected() {
disconnection_timeout_ = nullptr;
if (pending_complete_metadata_.has_value()) {
-4
View File
@@ -72,10 +72,6 @@ class OutgoingShareSession : public ShareSession {
bool InitiateSendAttachments(
std::unique_ptr<AttachmentContainer> attachment_container);
bool ProcessKeyVerificationResult(
PairedKeyVerificationRunner::PairedKeyVerificationResult result,
location::nearby::proto::sharing::OSType share_target_os_type);
// Returns true if the introduction frame is written successfully.
// `timeout_callback` is called if accept is not received from both sender and
// receiver within the timeout.
-32
View File
@@ -784,38 +784,6 @@ TEST_F(OutgoingShareSessionTest, SendNextPayload) {
session_.SendNextPayload();
}
TEST_F(OutgoingShareSessionTest, ProcessKeyVerificationResultFail) {
NearbyConnectionImpl connection(device_info_);
session_.set_session_id(1234);
ConnectionSuccess(&connection);
session_.SetTokenForTests("1234");
EXPECT_THAT(
session_.ProcessKeyVerificationResult(
PairedKeyVerificationRunner::PairedKeyVerificationResult::kFail,
OSType::WINDOWS),
IsFalse());
EXPECT_THAT(session_.token(), Eq("1234"));
EXPECT_THAT(session_.os_type(), Eq(OSType::WINDOWS));
}
TEST_F(OutgoingShareSessionTest, ProcessKeyVerificationResultSuccess) {
NearbyConnectionImpl connection(device_info_);
session_.set_session_id(1234);
ConnectionSuccess(&connection);
session_.SetTokenForTests("1234");
EXPECT_THAT(
session_.ProcessKeyVerificationResult(
PairedKeyVerificationRunner::PairedKeyVerificationResult::kSuccess,
OSType::WINDOWS),
IsTrue());
EXPECT_THAT(session_.token(), IsEmpty());
EXPECT_THAT(session_.os_type(), Eq(OSType::WINDOWS));
}
TEST_F(OutgoingShareSessionTest, DelayCompleteReceiverDisconnect) {
NearbyConnectionImpl connection(device_info_);
session_.set_session_id(1234);
+39 -39
View File
@@ -203,6 +203,45 @@ void ShareSession::RunPairedKeyVerification(
key_verification_runner_->Run(std::move(callback));
}
bool ShareSession::ProcessKeyVerificationResult(
PairedKeyVerificationRunner::PairedKeyVerificationResult result,
OSType share_target_os_type) {
os_type_ = share_target_os_type;
switch (result) {
case PairedKeyVerificationRunner::PairedKeyVerificationResult::kFail:
LOG(WARNING) << __func__ << ": Paired key handshake failed for target "
<< share_target().id << ". Disconnecting.";
return false;
case PairedKeyVerificationRunner::PairedKeyVerificationResult::kSuccess:
VLOG(1) << __func__ << ": Paired key handshake succeeded for target - "
<< share_target().id;
// If verification succeeds, this either means that the target is a
// self-share or a mutual contact. In either case, we should clear the
// token.
token_.resize(0);
break;
case PairedKeyVerificationRunner::PairedKeyVerificationResult::kUnable:
VLOG(1) << __func__
<< ": Unable to verify paired key encryption when "
"receiving connection from target - "
<< share_target().id;
// If we are unable to verify the paired key, we should clear the self
// share flag.
self_share_ = false;
break;
case PairedKeyVerificationRunner::PairedKeyVerificationResult::kUnknown:
LOG(WARNING) << __func__
<< ": Unknown PairedKeyVerificationResult for target "
<< share_target().id << ". Disconnecting.";
return false;
}
return true;
}
void ShareSession::OnDisconnect() {
OnConnectionDisconnected();
if (disconnect_status_ != TransferMetadata::Status::kUnknown) {
@@ -267,45 +306,6 @@ void ShareSession::WriteCancelFrame() {
WriteFrame(frame);
}
bool ShareSession::HandleKeyVerificationResult(
PairedKeyVerificationRunner::PairedKeyVerificationResult result,
location::nearby::proto::sharing::OSType share_target_os_type) {
os_type_ = share_target_os_type;
switch (result) {
case PairedKeyVerificationRunner::PairedKeyVerificationResult::kFail:
LOG(WARNING) << __func__ << ": Paired key handshake failed for target "
<< share_target().id << ". Disconnecting.";
return false;
case PairedKeyVerificationRunner::PairedKeyVerificationResult::kSuccess:
VLOG(1) << __func__ << ": Paired key handshake succeeded for target - "
<< share_target().id;
// If verification succeeds, this either means that the target is a
// self-share or a mutual contact. In either case, we should clear the
// token.
token_.resize(0);
break;
case PairedKeyVerificationRunner::PairedKeyVerificationResult::kUnable:
VLOG(1) << __func__
<< ": Unable to verify paired key encryption when "
"receiving connection from target - "
<< share_target().id;
// If we are unable to verify the paired key, we should clear the self
// share flag.
self_share_ = false;
break;
case PairedKeyVerificationRunner::PairedKeyVerificationResult::kUnknown:
LOG(WARNING) << __func__
<< ": Unknown PairedKeyVerificationResult for target "
<< share_target().id << ". Disconnecting.";
return false;
}
return true;
}
void ShareSession::InitializePayloadTracker(
absl::AnyInvocable<void()> payload_transfer_updates_callback) {
auto payload_updates_queue =
+9 -5
View File
@@ -23,6 +23,7 @@
#include <utility>
#include "absl/container/flat_hash_map.h"
#include "absl/functional/any_invocable.h"
#include "absl/strings/string_view.h"
#include "internal/platform/clock.h"
#include "internal/platform/task_runner.h"
@@ -71,6 +72,9 @@ class ShareSession {
void clear_certificate() { certificate_ = std::nullopt; }
NearbyConnection* connection() const { return connection_; }
// Returns true if the session has a valid connection.
// When `IsConnected()` is true, `connection()` is non-null, as is
// `frames_reader()`.
bool IsConnected() const { return connection_ != nullptr; }
void UpdateTransferMetadata(const TransferMetadata& transfer_metadata);
@@ -113,6 +117,11 @@ class ShareSession {
void(PairedKeyVerificationRunner::PairedKeyVerificationResult,
location::nearby::proto::sharing::OSType)>
callback);
// Processes the PairedKeyVerificationResult.
// Returns true if verification was successful.
bool ProcessKeyVerificationResult(
PairedKeyVerificationRunner::PairedKeyVerificationResult result,
location::nearby::proto::sharing::OSType share_target_os_type);
void OnDisconnect();
const AttachmentContainer& attachment_container() const {
@@ -165,11 +174,6 @@ class ShareSession {
return attachment_container_;
}
void WriteFrame(const nearby::sharing::service::proto::Frame& frame);
// Processes the PairedKeyVerificationResult.
// Returns true if verification was successful.
bool HandleKeyVerificationResult(
PairedKeyVerificationRunner::PairedKeyVerificationResult result,
location::nearby::proto::sharing::OSType share_target_os_type);
NearbyConnectionsManager& connections_manager() {
return connections_manager_;
+12 -19
View File
@@ -69,13 +69,6 @@ class TestShareSession : public ShareSession {
ShareSession::SetAttachmentPayloadId(attachment_id, payload_id);
}
bool HandleKeyVerificationResult(
PairedKeyVerificationRunner::PairedKeyVerificationResult result,
OSType share_target_os_type) {
return ShareSession::HandleKeyVerificationResult(result,
share_target_os_type);
}
FakeNearbyConnectionsManager& connections_manager() {
return connections_manager_;
}
@@ -319,21 +312,21 @@ TEST(ShareSessionTest, WriteCancelFrame) {
EXPECT_EQ(frame.v1().type(), V1Frame::CANCEL);
}
TEST(ShareSessionTest, HandleKeyVerificationResultFail) {
TEST(ShareSessionTest, ProcessKeyVerificationResultFail) {
ShareTarget share_target;
TestShareSession session(std::string(kEndpointId), share_target);
NearbyConnectionImpl connection(session.device_info());
session.SetNearbyConnection(&connection);
session.SetTokenForTests("9876");
EXPECT_FALSE(session.HandleKeyVerificationResult(
EXPECT_FALSE(session.ProcessKeyVerificationResult(
PairedKeyVerificationRunner::PairedKeyVerificationResult::kFail,
OSType::WINDOWS));
EXPECT_EQ(session.os_type(), OSType::WINDOWS);
EXPECT_FALSE(session.token().empty());
}
TEST(ShareSessionTest, HandleKeyVerificationResultSelfShareSuccess) {
TEST(ShareSessionTest, ProcessKeyVerificationResultSelfShareSuccess) {
ShareTarget share_target;
share_target.for_self_share = true;
TestShareSession session(std::string(kEndpointId), share_target);
@@ -341,7 +334,7 @@ TEST(ShareSessionTest, HandleKeyVerificationResultSelfShareSuccess) {
session.SetNearbyConnection(&connection);
session.SetTokenForTests("9876");
EXPECT_TRUE(session.HandleKeyVerificationResult(
EXPECT_TRUE(session.ProcessKeyVerificationResult(
PairedKeyVerificationRunner::PairedKeyVerificationResult::kSuccess,
OSType::WINDOWS));
EXPECT_EQ(session.os_type(), OSType::WINDOWS);
@@ -349,14 +342,14 @@ TEST(ShareSessionTest, HandleKeyVerificationResultSelfShareSuccess) {
EXPECT_TRUE(session.token().empty());
}
TEST(ShareSessionTest, HandleKeyVerificationResultNotSelfShareSuccess) {
TEST(ShareSessionTest, ProcessKeyVerificationResultNotSelfShareSuccess) {
ShareTarget share_target;
TestShareSession session(std::string(kEndpointId), share_target);
NearbyConnectionImpl connection(session.device_info());
session.SetNearbyConnection(&connection);
session.SetTokenForTests("9876");
EXPECT_TRUE(session.HandleKeyVerificationResult(
EXPECT_TRUE(session.ProcessKeyVerificationResult(
PairedKeyVerificationRunner::PairedKeyVerificationResult::kSuccess,
OSType::WINDOWS));
EXPECT_EQ(session.os_type(), OSType::WINDOWS);
@@ -365,7 +358,7 @@ TEST(ShareSessionTest, HandleKeyVerificationResultNotSelfShareSuccess) {
EXPECT_TRUE(session.token().empty());
}
TEST(ShareSessionTest, HandleKeyVerificationResultSelfShareUnable) {
TEST(ShareSessionTest, ProcessKeyVerificationResultSelfShareUnable) {
ShareTarget share_target;
share_target.for_self_share = true;
TestShareSession session(std::string(kEndpointId), share_target);
@@ -373,7 +366,7 @@ TEST(ShareSessionTest, HandleKeyVerificationResultSelfShareUnable) {
session.SetNearbyConnection(&connection);
session.SetTokenForTests("9876");
EXPECT_TRUE(session.HandleKeyVerificationResult(
EXPECT_TRUE(session.ProcessKeyVerificationResult(
PairedKeyVerificationRunner::PairedKeyVerificationResult::kUnable,
OSType::WINDOWS));
EXPECT_EQ(session.os_type(), OSType::WINDOWS);
@@ -381,14 +374,14 @@ TEST(ShareSessionTest, HandleKeyVerificationResultSelfShareUnable) {
EXPECT_FALSE(session.token().empty());
}
TEST(ShareSessionTest, HandleKeyVerificationResultNotSelfShareUnable) {
TEST(ShareSessionTest, ProcessKeyVerificationResultNotSelfShareUnable) {
ShareTarget share_target;
TestShareSession session(std::string(kEndpointId), share_target);
NearbyConnectionImpl connection(session.device_info());
session.SetNearbyConnection(&connection);
session.SetTokenForTests("9876");
EXPECT_TRUE(session.HandleKeyVerificationResult(
EXPECT_TRUE(session.ProcessKeyVerificationResult(
PairedKeyVerificationRunner::PairedKeyVerificationResult::kUnable,
OSType::WINDOWS));
EXPECT_EQ(session.os_type(), OSType::WINDOWS);
@@ -396,14 +389,14 @@ TEST(ShareSessionTest, HandleKeyVerificationResultNotSelfShareUnable) {
EXPECT_FALSE(session.token().empty());
}
TEST(ShareSessionTest, HandleKeyVerificationResultUnknown) {
TEST(ShareSessionTest, ProcessKeyVerificationResultUnknown) {
ShareTarget share_target;
TestShareSession session(std::string(kEndpointId), share_target);
NearbyConnectionImpl connection(session.device_info());
session.SetNearbyConnection(&connection);
session.SetTokenForTests("9876");
EXPECT_FALSE(session.HandleKeyVerificationResult(
EXPECT_FALSE(session.ProcessKeyVerificationResult(
PairedKeyVerificationRunner::PairedKeyVerificationResult::kUnknown,
OSType::WINDOWS));
EXPECT_EQ(session.os_type(), OSType::WINDOWS);