Commit 002c4b58 authored by Naomi Musgrave's avatar Naomi Musgrave Committed by Commit Bot

[Nearby] Implement bandwidth upgrade NearbyConnection interface

chrome/services/sharing/*
- Introduced InitiateBandwidthUpgrade to request a higher-bandwidth
  connection for a particular endpoint

chrome/browser/nearby_sharing/nearby_connections_manager*
- Browser side usage of InitiateBandwidthUpgrade.
  NearbyConnectionsManager uses InitiateBandwidthUpgrade to request
  a higher connection data rate. This is triggered by the
  NearbySharingService receiving an incoming payload.

Bug: 1076008
Change-Id: Iea1d38c4298aade06556b23baa6761cf51bb1da9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2359140Reviewed-by: default avatarAlex Chau <alexchau@chromium.org>
Reviewed-by: default avatarAlex Gough <ajgo@chromium.org>
Commit-Queue: Naomi Musgrave <nmusgrave@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799241}
parent 2ef332d6
...@@ -82,6 +82,11 @@ class MockNearbyConnections : public NearbyConnectionsMojom { ...@@ -82,6 +82,11 @@ class MockNearbyConnections : public NearbyConnectionsMojom {
StopAllEndpoints, StopAllEndpoints,
(DisconnectFromEndpointCallback callback), (DisconnectFromEndpointCallback callback),
(override)); (override));
MOCK_METHOD(void,
InitiateBandwidthUpgrade,
(const std::string& endpoint_id,
InitiateBandwidthUpgradeCallback callback),
(override));
}; };
#endif // CHROME_BROWSER_NEARBY_SHARING_MOCK_NEARBY_CONNECTIONS_H_ #endif // CHROME_BROWSER_NEARBY_SHARING_MOCK_NEARBY_CONNECTIONS_H_
...@@ -286,7 +286,19 @@ NearbyConnectionsManagerImpl::GetRawAuthenticationToken( ...@@ -286,7 +286,19 @@ NearbyConnectionsManagerImpl::GetRawAuthenticationToken(
void NearbyConnectionsManagerImpl::UpgradeBandwidth( void NearbyConnectionsManagerImpl::UpgradeBandwidth(
const std::string& endpoint_id) { const std::string& endpoint_id) {
// TODO(crbug/1076008): Implement. if (!nearby_connections_)
return;
nearby_connections_->InitiateBandwidthUpgrade(
endpoint_id,
base::BindOnce(
[](const std::string& endpoint_id, ConnectionsStatus status) {
NS_LOG(VERBOSE)
<< __func__ << ": Bandwidth upgrade attempted to endpoint "
<< endpoint_id << "over Nearby Connections with result "
<< status;
},
endpoint_id));
} }
void NearbyConnectionsManagerImpl::OnNearbyProfileChanged(Profile* profile) { void NearbyConnectionsManagerImpl::OnNearbyProfileChanged(Profile* profile) {
......
...@@ -900,6 +900,7 @@ TEST_F(NearbyConnectionsManagerImplTest, ShutdownDiscoveryConnectionFails) { ...@@ -900,6 +900,7 @@ TEST_F(NearbyConnectionsManagerImplTest, ShutdownDiscoveryConnectionFails) {
nearby_connection = connection; nearby_connection = connection;
run_loop.Quit(); run_loop.Quit();
})); }));
run_loop.Run();
EXPECT_FALSE(nearby_connection); EXPECT_FALSE(nearby_connection);
} }
...@@ -909,3 +910,53 @@ TEST_F(NearbyConnectionsManagerImplTest, ...@@ -909,3 +910,53 @@ TEST_F(NearbyConnectionsManagerImplTest,
EXPECT_CALL(nearby_connections_, StopAllEndpoints).Times(0); EXPECT_CALL(nearby_connections_, StopAllEndpoints).Times(0);
nearby_connections_manager_.Shutdown(); nearby_connections_manager_.Shutdown();
} }
TEST_F(NearbyConnectionsManagerImplTest,
UpgradeBandwidthAfterAdvertisingSucceeds) {
mojo::Remote<ConnectionLifecycleListener> listener_remote;
testing::NiceMock<MockIncomingConnectionListener>
incoming_connection_listener;
StartAdvertising(listener_remote, incoming_connection_listener);
// Upgrading bandwidth will succeed.
EXPECT_CALL(nearby_connections_, InitiateBandwidthUpgrade)
.WillOnce([&](const std::string& endpoint_id,
NearbyConnectionsMojom::InitiateBandwidthUpgradeCallback
callback) {
EXPECT_EQ(kRemoteEndpointId, endpoint_id);
std::move(callback).Run(Status::kSuccess);
});
nearby_connections_manager_.UpgradeBandwidth(kRemoteEndpointId);
}
TEST_F(NearbyConnectionsManagerImplTest,
UpgradeBandwidthAfterDiscoverySucceeds) {
// StartDiscovery will succeed.
mojo::Remote<EndpointDiscoveryListener> discovery_listener_remote;
testing::NiceMock<MockDiscoveryListener> discovery_listener;
StartDiscovery(discovery_listener_remote, discovery_listener);
// RequestConnection will succeed.
mojo::Remote<ConnectionLifecycleListener> connection_listener_remote;
mojo::Remote<PayloadListener> payload_listener_remote;
NearbyConnection* nearby_connection =
Connect(connection_listener_remote, payload_listener_remote,
ConnectionResponse::kAccepted);
EXPECT_TRUE(nearby_connection);
// Upgrading bandwidth will succeed.
EXPECT_CALL(nearby_connections_, InitiateBandwidthUpgrade)
.WillOnce([&](const std::string& endpoint_id,
NearbyConnectionsMojom::InitiateBandwidthUpgradeCallback
callback) {
EXPECT_EQ(kRemoteEndpointId, endpoint_id);
std::move(callback).Run(Status::kSuccess);
});
nearby_connections_manager_.UpgradeBandwidth(kRemoteEndpointId);
}
TEST_F(NearbyConnectionsManagerImplTest,
UpgradeBandwidthBeforeStartDiscoveryOrAdvertising) {
EXPECT_CALL(nearby_connections_, InitiateBandwidthUpgrade).Times(0);
nearby_connections_manager_.UpgradeBandwidth(kRemoteEndpointId);
}
...@@ -341,6 +341,13 @@ void NearbyConnections::StopAllEndpoints(StopAllEndpointsCallback callback) { ...@@ -341,6 +341,13 @@ void NearbyConnections::StopAllEndpoints(StopAllEndpointsCallback callback) {
core_->StopAllEndpoints(ResultCallbackFromMojom(std::move(callback))); core_->StopAllEndpoints(ResultCallbackFromMojom(std::move(callback)));
} }
void NearbyConnections::InitiateBandwidthUpgrade(
const std::string& endpoint_id,
InitiateBandwidthUpgradeCallback callback) {
core_->InitiateBandwidthUpgrade(endpoint_id,
ResultCallbackFromMojom(std::move(callback)));
}
base::File NearbyConnections::ExtractFileForPayload(int64_t payload_id) { base::File NearbyConnections::ExtractFileForPayload(int64_t payload_id) {
auto file_it = outgoing_file_map_.find(payload_id); auto file_it = outgoing_file_map_.find(payload_id);
if (file_it == outgoing_file_map_.end()) if (file_it == outgoing_file_map_.end())
......
...@@ -94,6 +94,9 @@ class NearbyConnections : public mojom::NearbyConnections { ...@@ -94,6 +94,9 @@ class NearbyConnections : public mojom::NearbyConnections {
void CancelPayload(int64_t payload_id, void CancelPayload(int64_t payload_id,
CancelPayloadCallback callback) override; CancelPayloadCallback callback) override;
void StopAllEndpoints(StopAllEndpointsCallback callback) override; void StopAllEndpoints(StopAllEndpointsCallback callback) override;
void InitiateBandwidthUpgrade(
const std::string& endpoint_id,
InitiateBandwidthUpgradeCallback callback) override;
// Return the file associated with |payload_id|. // Return the file associated with |payload_id|.
base::File ExtractFileForPayload(int64_t payload_id); base::File ExtractFileForPayload(int64_t payload_id);
......
...@@ -200,6 +200,57 @@ class NearbyConnectionsTest : public testing::Test { ...@@ -200,6 +200,57 @@ class NearbyConnectionsTest : public testing::Test {
return client_proxy; return client_proxy;
} }
ClientProxy* StartAdvertising(
FakeConnectionLifecycleListener& fake_connection_life_cycle_listener,
const EndpointData& endpoint_data) {
ClientProxy* client_proxy;
EXPECT_CALL(*service_controller_ptr_, StartAdvertising)
.WillOnce([&](ClientProxy* client, const std::string& service_id,
const ConnectionOptions& options,
const ConnectionRequestInfo& info) {
client_proxy = client;
EXPECT_EQ(kServiceId, service_id);
EXPECT_EQ(Strategy::kP2pPointToPoint, options.strategy);
EXPECT_TRUE(options.allowed.bluetooth);
EXPECT_TRUE(options.allowed.web_rtc);
EXPECT_TRUE(options.allowed.wifi_lan);
EXPECT_TRUE(options.auto_upgrade_bandwidth);
EXPECT_TRUE(options.enforce_topology_constraints);
EXPECT_EQ(
std::string(std::begin(kEndpointInfo), std::end(kEndpointInfo)),
info.name);
client_proxy->StartedAdvertising(service_id, options.strategy,
info.listener,
/*mediums=*/{});
client_proxy->OnConnectionInitiated(
endpoint_data.remote_endpoint_id,
{.authentication_token = kAuthenticationToken,
.raw_authentication_token = ByteArray(
kRawAuthenticationToken, sizeof(kRawAuthenticationToken)),
.endpoint_info =
ByteArrayFromMojom(endpoint_data.remote_endpoint_info),
.is_incoming_connection = false},
info.listener);
return Status{Status::kSuccess};
});
base::RunLoop start_advertising_run_loop;
nearby_connections_->StartAdvertising(
std::vector<uint8_t>(std::begin(kEndpointInfo),
std::end(kEndpointInfo)),
kServiceId, CreateAdvertisingOptions(),
fake_connection_life_cycle_listener.receiver.BindNewPipeAndPassRemote(),
base::BindLambdaForTesting([&](mojom::Status status) {
EXPECT_EQ(mojom::Status::kSuccess, status);
start_advertising_run_loop.Quit();
}));
start_advertising_run_loop.Run();
return client_proxy;
}
ClientProxy* RequestConnection( ClientProxy* RequestConnection(
FakeConnectionLifecycleListener& fake_connection_life_cycle_listener, FakeConnectionLifecycleListener& fake_connection_life_cycle_listener,
const EndpointData& endpoint_data) { const EndpointData& endpoint_data) {
...@@ -457,17 +508,34 @@ TEST_F(NearbyConnectionsTest, RequestConnectionOnBandwidthUpgrade) { ...@@ -457,17 +508,34 @@ TEST_F(NearbyConnectionsTest, RequestConnectionOnBandwidthUpgrade) {
client_proxy = client_proxy =
AcceptConnection(fake_payload_listener, endpoint_data.remote_endpoint_id); AcceptConnection(fake_payload_listener, endpoint_data.remote_endpoint_id);
base::RunLoop bandwidth_changed_run_loop; // The life cycle listener should be triggered by a bandwidth upgrade.
base::RunLoop upgraded_run_loop;
fake_connection_life_cycle_listener.bandwidth_changed_cb = fake_connection_life_cycle_listener.bandwidth_changed_cb =
base::BindLambdaForTesting( base::BindLambdaForTesting(
[&](const std::string& endpoint_id, int32_t quality) { [&](const std::string& endpoint_id, int32_t quality) {
EXPECT_EQ(endpoint_data.remote_endpoint_id, endpoint_id); EXPECT_EQ(endpoint_data.remote_endpoint_id, endpoint_id);
EXPECT_EQ(kQuality, quality); EXPECT_EQ(kQuality, quality);
bandwidth_changed_run_loop.Quit(); upgraded_run_loop.Quit();
}); });
client_proxy->OnBandwidthChanged(endpoint_data.remote_endpoint_id, kQuality); // Requesting a bandwidth upgrade should succeed.
bandwidth_changed_run_loop.Run(); EXPECT_CALL(*service_controller_ptr_, InitiateBandwidthUpgrade)
.WillOnce([&](ClientProxy* client, const std::string& endpoint_id) {
client_proxy = client;
EXPECT_EQ(endpoint_data.remote_endpoint_id, endpoint_id);
client_proxy->OnBandwidthChanged(endpoint_id, kQuality);
return Status{Status::kSuccess};
});
base::RunLoop bandwidth_upgrade_run_loop;
nearby_connections_->InitiateBandwidthUpgrade(
endpoint_data.remote_endpoint_id,
base::BindLambdaForTesting([&](mojom::Status status) {
EXPECT_EQ(mojom::Status::kSuccess, status);
bandwidth_upgrade_run_loop.Quit();
}));
bandwidth_upgrade_run_loop.Run();
upgraded_run_loop.Run();
} }
TEST_F(NearbyConnectionsTest, RequestConnectionOnDisconnected) { TEST_F(NearbyConnectionsTest, RequestConnectionOnDisconnected) {
...@@ -667,118 +735,77 @@ TEST_F(NearbyConnectionsTest, DISABLED_SendFilePayload) { ...@@ -667,118 +735,77 @@ TEST_F(NearbyConnectionsTest, DISABLED_SendFilePayload) {
})); }));
send_payload_run_loop.Run(); send_payload_run_loop.Run();
} }
TEST_F(NearbyConnectionsTest, StartAdvertisingRejected) {
TEST_F(NearbyConnectionsTest, StartAdvertising) {
FakeConnectionLifecycleListener fake_connection_life_cycle_listener; FakeConnectionLifecycleListener fake_connection_life_cycle_listener;
ClientProxy* client_proxy; EndpointData endpoint_data = CreateEndpointData(1);
ConnectionListener connections_listener;
EXPECT_CALL(*service_controller_ptr_, StartAdvertising)
.WillOnce([&](ClientProxy* client, const std::string& service_id,
const ConnectionOptions& options,
const ConnectionRequestInfo& info) {
EXPECT_EQ(kServiceId, service_id);
EXPECT_EQ(Strategy::kP2pPointToPoint, options.strategy);
EXPECT_TRUE(options.allowed.bluetooth);
EXPECT_TRUE(options.allowed.web_rtc);
EXPECT_TRUE(options.allowed.wifi_lan);
EXPECT_TRUE(options.auto_upgrade_bandwidth);
EXPECT_TRUE(options.enforce_topology_constraints);
EXPECT_EQ(
std::string(std::begin(kEndpointInfo), std::end(kEndpointInfo)),
info.name);
client_proxy = client;
connections_listener = info.listener;
return Status{Status::kSuccess};
});
base::RunLoop start_advertising_run_loop;
nearby_connections_->StartAdvertising(
std::vector<uint8_t>(std::begin(kEndpointInfo), std::end(kEndpointInfo)),
kServiceId, CreateAdvertisingOptions(),
fake_connection_life_cycle_listener.receiver.BindNewPipeAndPassRemote(),
base::BindLambdaForTesting([&](mojom::Status status) {
EXPECT_EQ(mojom::Status::kSuccess, status);
start_advertising_run_loop.Quit();
}));
start_advertising_run_loop.Run();
base::RunLoop initiated_run_loop; base::RunLoop initiated_run_loop;
fake_connection_life_cycle_listener.initiated_cb = base::BindLambdaForTesting( fake_connection_life_cycle_listener.initiated_cb = base::BindLambdaForTesting(
[&](const std::string& endpoint_id, mojom::ConnectionInfoPtr info) { [&](const std::string& endpoint_id, mojom::ConnectionInfoPtr info) {
EXPECT_EQ(kRemoteEndpointId, endpoint_id); EXPECT_EQ(endpoint_data.remote_endpoint_id, endpoint_id);
EXPECT_EQ(kAuthenticationToken, info->authentication_token); EXPECT_EQ(kAuthenticationToken, info->authentication_token);
EXPECT_EQ(std::vector<uint8_t>(std::begin(kRawAuthenticationToken), EXPECT_EQ(std::vector<uint8_t>(std::begin(kRawAuthenticationToken),
std::end(kRawAuthenticationToken)), std::end(kRawAuthenticationToken)),
info->raw_authentication_token); info->raw_authentication_token);
EXPECT_EQ(std::vector<uint8_t>(std::begin(kRemoteEndpointInfo), EXPECT_EQ(endpoint_data.remote_endpoint_info, info->endpoint_info);
std::end(kRemoteEndpointInfo)),
info->endpoint_info);
EXPECT_FALSE(info->is_incoming_connection); EXPECT_FALSE(info->is_incoming_connection);
initiated_run_loop.Quit(); initiated_run_loop.Quit();
}); });
client_proxy->OnConnectionInitiated(
kRemoteEndpointId, ClientProxy* client_proxy =
{.authentication_token = kAuthenticationToken, StartAdvertising(fake_connection_life_cycle_listener, endpoint_data);
.raw_authentication_token =
ByteArray(kRawAuthenticationToken, sizeof(kRawAuthenticationToken)),
.endpoint_info =
ByteArray(kRemoteEndpointInfo, sizeof(kRemoteEndpointInfo)),
.is_incoming_connection = false},
connections_listener);
initiated_run_loop.Run(); initiated_run_loop.Run();
base::RunLoop rejected_run_loop; base::RunLoop rejected_run_loop;
fake_connection_life_cycle_listener.rejected_cb = base::BindLambdaForTesting( fake_connection_life_cycle_listener.rejected_cb = base::BindLambdaForTesting(
[&](const std::string& endpoint_id, mojom::Status status) { [&](const std::string& endpoint_id, mojom::Status status) {
EXPECT_EQ(kRemoteEndpointId, endpoint_id); EXPECT_EQ(endpoint_data.remote_endpoint_id, endpoint_id);
EXPECT_EQ(mojom::Status::kConnectionRejected, status); EXPECT_EQ(mojom::Status::kConnectionRejected, status);
rejected_run_loop.Quit(); rejected_run_loop.Quit();
}); });
client_proxy->OnConnectionRejected(kRemoteEndpointId, client_proxy->OnConnectionRejected(endpoint_data.remote_endpoint_id,
{Status::kConnectionRejected}); {Status::kConnectionRejected});
rejected_run_loop.Run(); rejected_run_loop.Run();
}
TEST_F(NearbyConnectionsTest, StartAdvertisingAccepted) {
FakeConnectionLifecycleListener fake_connection_life_cycle_listener;
EndpointData endpoint_data = CreateEndpointData(1);
// Initiate connection again to test accepted flow. base::RunLoop initiated_run_loop;
base::RunLoop initiated_run_loop_2;
fake_connection_life_cycle_listener.initiated_cb = base::BindLambdaForTesting( fake_connection_life_cycle_listener.initiated_cb = base::BindLambdaForTesting(
[&](const std::string& endpoint_id, mojom::ConnectionInfoPtr info) { [&](const std::string& endpoint_id, mojom::ConnectionInfoPtr info) {
EXPECT_EQ(kRemoteEndpointId, endpoint_id); EXPECT_EQ(endpoint_data.remote_endpoint_id, endpoint_id);
EXPECT_EQ(kAuthenticationToken, info->authentication_token);
EXPECT_EQ(std::vector<uint8_t>(std::begin(kRawAuthenticationToken),
std::end(kRawAuthenticationToken)),
info->raw_authentication_token);
EXPECT_EQ(endpoint_data.remote_endpoint_info, info->endpoint_info);
EXPECT_FALSE(info->is_incoming_connection); EXPECT_FALSE(info->is_incoming_connection);
initiated_run_loop_2.Quit(); initiated_run_loop.Quit();
});
ClientProxy* client_proxy =
StartAdvertising(fake_connection_life_cycle_listener, endpoint_data);
initiated_run_loop.Run();
base::RunLoop accepted_run_loop;
fake_connection_life_cycle_listener.accepted_cb =
base::BindLambdaForTesting([&](const std::string& endpoint_id) {
EXPECT_EQ(endpoint_data.remote_endpoint_id, endpoint_id);
accepted_run_loop.Quit();
}); });
client_proxy->OnConnectionInitiated(kRemoteEndpointId,
{.is_incoming_connection = false},
connections_listener);
initiated_run_loop_2.Run();
FakePayloadListener fake_payload_listener; FakePayloadListener fake_payload_listener;
AcceptConnection(fake_payload_listener, kRemoteEndpointId); client_proxy =
AcceptConnection(fake_payload_listener, endpoint_data.remote_endpoint_id);
accepted_run_loop.Run();
} }
TEST_F(NearbyConnectionsTest, StopAdvertising) { TEST_F(NearbyConnectionsTest, StopAdvertising) {
FakeConnectionLifecycleListener fake_connection_life_cycle_listener; FakeConnectionLifecycleListener fake_connection_life_cycle_listener;
EndpointData endpoint_data = CreateEndpointData(1);
EXPECT_CALL(*service_controller_ptr_, StartAdvertising) StartAdvertising(fake_connection_life_cycle_listener, endpoint_data);
.WillOnce([](ClientProxy* client, const std::string& service_id,
const ConnectionOptions& options,
const ConnectionRequestInfo& info) {
client->StartedAdvertising(service_id, options.strategy, info.listener,
/*mediums=*/{});
return Status{Status::kSuccess};
});
base::RunLoop start_advertising_run_loop;
nearby_connections_->StartAdvertising(
std::vector<uint8_t>(std::begin(kEndpointInfo), std::end(kEndpointInfo)),
kServiceId, CreateAdvertisingOptions(), mojo::NullRemote(),
base::BindLambdaForTesting([&](mojom::Status status) {
EXPECT_EQ(mojom::Status::kSuccess, status);
start_advertising_run_loop.Quit();
}));
start_advertising_run_loop.Run();
EXPECT_CALL(*service_controller_ptr_, StopAdvertising) EXPECT_CALL(*service_controller_ptr_, StopAdvertising)
.WillOnce([](ClientProxy* client) { client->StoppedAdvertising(); }); .WillOnce([](ClientProxy* client) { client->StoppedAdvertising(); });
...@@ -800,9 +827,7 @@ TEST_F(NearbyConnectionsTest, DisconnectAllEndpoints) { ...@@ -800,9 +827,7 @@ TEST_F(NearbyConnectionsTest, DisconnectAllEndpoints) {
EndpointData endpoint_data = CreateEndpointData(1); EndpointData endpoint_data = CreateEndpointData(1);
ClientProxy* client_proxy = StartDiscovery(fake_discovery_listener); ClientProxy* client_proxy = StartDiscovery(fake_discovery_listener);
client_proxy->OnEndpointFound( client_proxy->OnEndpointFound(
kServiceId, kServiceId, endpoint_data.remote_endpoint_id,
std::string(endpoint_data.remote_endpoint_id.begin(),
endpoint_data.remote_endpoint_id.end()),
std::string(endpoint_data.remote_endpoint_info.begin(), std::string(endpoint_data.remote_endpoint_info.begin(),
endpoint_data.remote_endpoint_info.end()), endpoint_data.remote_endpoint_info.end()),
/*mediums=*/{}); /*mediums=*/{});
...@@ -818,9 +843,7 @@ TEST_F(NearbyConnectionsTest, DisconnectAllEndpoints) { ...@@ -818,9 +843,7 @@ TEST_F(NearbyConnectionsTest, DisconnectAllEndpoints) {
// Set up a pending connection to a different endpoint. // Set up a pending connection to a different endpoint.
EndpointData endpoint_data2 = CreateEndpointData(2); EndpointData endpoint_data2 = CreateEndpointData(2);
client_proxy->OnEndpointFound( client_proxy->OnEndpointFound(
kServiceId, kServiceId, endpoint_data2.remote_endpoint_id,
std::string(endpoint_data2.remote_endpoint_id.begin(),
endpoint_data2.remote_endpoint_id.end()),
std::string(endpoint_data2.remote_endpoint_info.begin(), std::string(endpoint_data2.remote_endpoint_info.begin(),
endpoint_data2.remote_endpoint_info.end()), endpoint_data2.remote_endpoint_info.end()),
/*mediums=*/{}); /*mediums=*/{});
...@@ -853,6 +876,91 @@ TEST_F(NearbyConnectionsTest, DisconnectAllEndpoints) { ...@@ -853,6 +876,91 @@ TEST_F(NearbyConnectionsTest, DisconnectAllEndpoints) {
stop_endpoints_run_loop.Run(); stop_endpoints_run_loop.Run();
} }
TEST_F(NearbyConnectionsTest, InitiateBandwidthUpgrade) {
// TODO(nmusgrave) test upgrade
// upgrade should fail if not advertising or discovering
// upgrade should fail if not a connection in place
}
TEST_F(NearbyConnectionsTest, InitiateBandwidthUpgradeFails) {
EndpointData endpoint_data = CreateEndpointData(1);
base::RunLoop bandwidth_upgrade_run_loop;
nearby_connections_->InitiateBandwidthUpgrade(
endpoint_data.remote_endpoint_id,
base::BindLambdaForTesting([&](mojom::Status status) {
EXPECT_EQ(mojom::Status::kOutOfOrderApiCall, status);
bandwidth_upgrade_run_loop.Quit();
}));
bandwidth_upgrade_run_loop.Run();
}
TEST_F(NearbyConnectionsTest, InitiateBandwidthUpgradeAfterDiscoveringFails) {
FakeEndpointDiscoveryListener fake_discovery_listener;
EndpointData endpoint_data = CreateEndpointData(1);
ClientProxy* client_proxy = StartDiscovery(fake_discovery_listener);
client_proxy->OnEndpointFound(
kServiceId, endpoint_data.remote_endpoint_id,
std::string(endpoint_data.remote_endpoint_info.begin(),
endpoint_data.remote_endpoint_info.end()),
/*mediums=*/{});
// Requesting a bandwidth upgrade should fail.
base::RunLoop bandwidth_upgrade_run_loop;
nearby_connections_->InitiateBandwidthUpgrade(
endpoint_data.remote_endpoint_id,
base::BindLambdaForTesting([&](mojom::Status status) {
EXPECT_EQ(mojom::Status::kOutOfOrderApiCall, status);
bandwidth_upgrade_run_loop.Quit();
}));
bandwidth_upgrade_run_loop.Run();
}
TEST_F(NearbyConnectionsTest, InitiateBandwidthUpgradeAfterAdvertisingFails) {
FakeConnectionLifecycleListener fake_connection_life_cycle_listener;
EndpointData endpoint_data = CreateEndpointData(1);
StartAdvertising(fake_connection_life_cycle_listener, endpoint_data);
// Requesting a bandwidth upgrade should fail.
base::RunLoop bandwidth_upgrade_run_loop;
nearby_connections_->InitiateBandwidthUpgrade(
endpoint_data.remote_endpoint_id,
base::BindLambdaForTesting([&](mojom::Status status) {
EXPECT_EQ(mojom::Status::kOutOfOrderApiCall, status);
bandwidth_upgrade_run_loop.Quit();
}));
bandwidth_upgrade_run_loop.Run();
}
TEST_F(NearbyConnectionsTest, InitiateBandwidthUpgradeAfterConnectionSucceeds) {
// This endpoint starts discovery.
FakeConnectionLifecycleListener fake_connection_life_cycle_listener;
EndpointData endpoint_data = CreateEndpointData(1);
StartAdvertising(fake_connection_life_cycle_listener, endpoint_data);
// An incoming connection request is accepted at this endpoint.
base::RunLoop accepted_run_loop;
fake_connection_life_cycle_listener.accepted_cb =
base::BindLambdaForTesting([&](const std::string& endpoint_id) {
EXPECT_EQ(endpoint_data.remote_endpoint_id, endpoint_id);
accepted_run_loop.Quit();
});
FakePayloadListener fake_payload_listener;
AcceptConnection(fake_payload_listener, endpoint_data.remote_endpoint_id);
accepted_run_loop.Run();
// Requesting a bandwidth upgrade should succeed.
base::RunLoop bandwidth_upgrade_run_loop;
nearby_connections_->InitiateBandwidthUpgrade(
endpoint_data.remote_endpoint_id,
base::BindLambdaForTesting([&](mojom::Status status) {
EXPECT_EQ(mojom::Status::kSuccess, status);
bandwidth_upgrade_run_loop.Quit();
}));
bandwidth_upgrade_run_loop.Run();
}
} // namespace connections } // namespace connections
} // namespace nearby } // namespace nearby
} // namespace location } // namespace location
...@@ -268,6 +268,16 @@ interface NearbyConnections { ...@@ -268,6 +268,16 @@ interface NearbyConnections {
// Possible return values include: // Possible return values include:
// Status::kSuccess disconnected from all endpoints successfully. // Status::kSuccess disconnected from all endpoints successfully.
StopAllEndpoints() => (Status status); StopAllEndpoints() => (Status status);
// Sends a request to initiate connection bandwidth upgrade.
//
// endpoint_id - The identifier for the remote endpoint which will be
// switching to a higher connection data rate and possibly
// different wireless protocol. On success, calls
// ConnectionLifecycleListener::OnBandwidthChanged.
// Possible return values include:
// Status::kSuccess if upgraded successfully.
InitiateBandwidthUpgrade(string endpoint_id) => (Status status);
}; };
// Provide all the dependencies that NearbyConnections library requires. // Provide all the dependencies that NearbyConnections library requires.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment