OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "google_apis/gcm/engine/connection_factory_impl.h" | 5 #include "google_apis/gcm/engine/connection_factory_impl.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 const int kNumAttempts = 50; | 595 const int kNumAttempts = 50; |
596 factory()->SetMultipleConnectResults(net::ERR_CONNECTION_FAILED, | 596 factory()->SetMultipleConnectResults(net::ERR_CONNECTION_FAILED, |
597 kNumAttempts); | 597 kNumAttempts); |
598 | 598 |
599 factory()->Connect(); | 599 factory()->Connect(); |
600 WaitForConnections(); | 600 WaitForConnections(); |
601 | 601 |
602 // There should be one failed client event for each failed connection, but | 602 // There should be one failed client event for each failed connection, but |
603 // there is a maximum cap of kMaxClientEvents, which is 30. There should also | 603 // there is a maximum cap of kMaxClientEvents, which is 30. There should also |
604 // be a single event which records the events which were discarded. | 604 // be a single event which records the events which were discarded. |
605 const auto client_events = GetClientEvents(); | 605 auto client_events = GetClientEvents(); |
606 ASSERT_EQ(31, client_events.size()); | 606 ASSERT_EQ(31, client_events.size()); |
607 | 607 |
608 bool found_discarded_events = false; | 608 bool found_discarded_events = false; |
609 for (const auto& client_event : client_events) { | 609 for (const auto& client_event : client_events) { |
610 if (client_event.type() == mcs_proto::ClientEvent::DISCARDED_EVENTS) { | 610 if (client_event.type() == mcs_proto::ClientEvent::DISCARDED_EVENTS) { |
611 // There should only be one event for discarded events. | 611 // There should only be one event for discarded events. |
612 EXPECT_FALSE(found_discarded_events); | 612 EXPECT_FALSE(found_discarded_events); |
613 found_discarded_events = true; | 613 found_discarded_events = true; |
614 // There should be 50-30=20 discarded events. | 614 // There should be 50-30=20 discarded events. |
615 EXPECT_EQ(20U, client_event.number_discarded_events()); | 615 EXPECT_EQ(20U, client_event.number_discarded_events()); |
616 } else { | 616 } else { |
617 EXPECT_EQ(mcs_proto::ClientEvent::FAILED_CONNECTION, client_event.type()); | 617 EXPECT_EQ(mcs_proto::ClientEvent::FAILED_CONNECTION, client_event.type()); |
618 EXPECT_EQ(net::ERR_CONNECTION_FAILED, client_event.error_code()); | 618 EXPECT_EQ(net::ERR_CONNECTION_FAILED, client_event.error_code()); |
619 } | 619 } |
620 } | 620 } |
621 EXPECT_TRUE(found_discarded_events); | 621 EXPECT_TRUE(found_discarded_events); |
622 | 622 |
623 factory()->SetConnectResult(net::OK); | 623 factory()->SetConnectResult(net::OK); |
624 WaitForConnections(); | 624 WaitForConnections(); |
625 EXPECT_TRUE(factory()->IsEndpointReachable()); | 625 EXPECT_TRUE(factory()->IsEndpointReachable()); |
626 EXPECT_TRUE(connected_server().is_valid()); | 626 EXPECT_TRUE(connected_server().is_valid()); |
627 | 627 |
628 // Old client events should have been reset after the successful connection. | 628 // Old client events should have been reset after the successful connection. |
629 const auto new_client_events = GetClientEvents(); | 629 client_events = GetClientEvents(); |
630 ASSERT_EQ(0, new_client_events.size()); | 630 ASSERT_EQ(0, client_events.size()); |
| 631 |
| 632 // Test that EndConnectionAttempt doesn't write empty events to the tracker. |
| 633 // There should be 2 events: 1) the successful connection which was previously |
| 634 // established. 2) the unsuccessful connection triggered as a result of the |
| 635 // SOCKET_FAILURE signal. The NETWORK_CHANGE signal should not cause an |
| 636 // additional event since there is no in progress event. |
| 637 factory()->SetConnectResult(net::ERR_CONNECTION_FAILED); |
| 638 factory()->SignalConnectionReset(ConnectionFactory::SOCKET_FAILURE); |
| 639 factory()->SignalConnectionReset(ConnectionFactory::NETWORK_CHANGE); |
| 640 WaitForConnections(); |
| 641 |
| 642 client_events = GetClientEvents(); |
| 643 ASSERT_EQ(2, client_events.size()); |
631 } | 644 } |
632 | 645 |
633 } // namespace gcm | 646 } // namespace gcm |
OLD | NEW |