Merge branch 'google3' to roll forward up to cl/353292511.

This commit is contained in:
hai007
2021-01-22 12:15:03 -08:00
36 changed files with 592 additions and 155 deletions
+72 -4
View File
@@ -93,8 +93,7 @@ class ClientProxyTest : public testing::Test {
void OnDiscoveryEndpointFound(ClientProxy* client, const Endpoint& endpoint) {
EXPECT_CALL(mock_discovery_.endpoint_found_cb, Call).Times(1);
client->OnEndpointFound(service_id_, endpoint.id, endpoint.info,
medium_);
client->OnEndpointFound(service_id_, endpoint.id, endpoint.info, medium_);
}
void OnDiscoveryEndpointLost(ClientProxy* client, const Endpoint& endpoint) {
@@ -112,6 +111,8 @@ class ClientProxyTest : public testing::Test {
connection_options_,
discovery_connection_listener_);
EXPECT_TRUE(client->HasPendingConnectionToEndpoint(endpoint.id));
// Cancellation flag has been created and added into map.
EXPECT_FALSE(client->GetCancellationFlag(endpoint.id)->Cancelled());
}
void OnDiscoveryConnectionLocalAccepted(ClientProxy* client,
@@ -174,6 +175,8 @@ class ClientProxyTest : public testing::Test {
const Endpoint& endpoint) {
EXPECT_CALL(mock_discovery_connection_.disconnected_cb, Call).Times(1);
client->OnDisconnected(endpoint.id, true);
// The Cancelled is always true as the default flag being returned.
EXPECT_TRUE(client->GetCancellationFlag(endpoint.id)->Cancelled());
}
void OnPayload(ClientProxy* client, const Endpoint& endpoint) {
@@ -235,8 +238,7 @@ TEST_F(ClientProxyTest, ClientIdIsUnique) {
}
TEST_F(ClientProxyTest, GeneratedEndpointIdIsUnique) {
EXPECT_NE(client1_.GetLocalEndpointId(),
client2_.GetLocalEndpointId());
EXPECT_NE(client1_.GetLocalEndpointId(), client2_.GetLocalEndpointId());
}
TEST_F(ClientProxyTest, ResetClearsState) {
@@ -369,6 +371,72 @@ TEST_F(ClientProxyTest, OnPayloadProgressChangesState) {
OnPayloadProgress(&client2_, advertising_endpoint);
}
TEST_F(ClientProxyTest, CanCancelEndpoint) {
Endpoint advertising_endpoint =
StartAdvertising(&client1_, advertising_connection_listener_);
StartDiscovery(&client2_, discovery_listener_);
OnDiscoveryEndpointFound(&client2_, advertising_endpoint);
OnDiscoveryConnectionInitiated(&client2_, advertising_endpoint);
EXPECT_FALSE(
client2_.GetCancellationFlag(advertising_endpoint.id)->Cancelled());
client2_.CancelEndpoint(advertising_endpoint.id);
// The Cancelled is always true as the default flag being returned.
EXPECT_TRUE(
client2_.GetCancellationFlag(advertising_endpoint.id)->Cancelled());
}
TEST_F(ClientProxyTest, CanCancelAllEndpoints) {
Endpoint advertising_endpoint =
StartAdvertising(&client1_, advertising_connection_listener_);
StartDiscovery(&client2_, discovery_listener_);
OnDiscoveryEndpointFound(&client2_, advertising_endpoint);
OnDiscoveryConnectionInitiated(&client2_, advertising_endpoint);
EXPECT_FALSE(
client2_.GetCancellationFlag(advertising_endpoint.id)->Cancelled());
client2_.CancelAllEndpoints();
// The Cancelled is always true as the default flag being returned.
EXPECT_TRUE(
client2_.GetCancellationFlag(advertising_endpoint.id)->Cancelled());
}
TEST_F(ClientProxyTest, CanCancelAllEndpointsWithDifferentEndpoint) {
ConnectionListener advertising_connection_listener_2;
ConnectionListener advertising_connection_listener_3;
ClientProxy client3;
StartDiscovery(&client1_, discovery_listener_);
Endpoint advertising_endpoint_2 =
StartAdvertising(&client2_, advertising_connection_listener_2);
Endpoint advertising_endpoint_3 =
StartAdvertising(&client3, advertising_connection_listener_3);
OnDiscoveryEndpointFound(&client1_, advertising_endpoint_2);
OnDiscoveryConnectionInitiated(&client1_, advertising_endpoint_2);
OnDiscoveryEndpointFound(&client1_, advertising_endpoint_3);
OnDiscoveryConnectionInitiated(&client1_, advertising_endpoint_3);
// The CancellationFlag of endpoint_2 and endpoint_3 have been added. Default
// Cancelled is false.
EXPECT_FALSE(
client1_.GetCancellationFlag(advertising_endpoint_2.id)->Cancelled());
EXPECT_FALSE(
client1_.GetCancellationFlag(advertising_endpoint_3.id)->Cancelled());
client1_.CancelAllEndpoints();
// Expect the CancellationFlag of endpoint_2 and endpoint_3 has been removed.
// The Cancelled is always true as the default flag being returned.
EXPECT_TRUE(
client1_.GetCancellationFlag(advertising_endpoint_2.id)->Cancelled());
EXPECT_TRUE(
client1_.GetCancellationFlag(advertising_endpoint_3.id)->Cancelled());
}
} // namespace
} // namespace connections
} // namespace nearby