Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(345)

Unified Diff: remoting/host/heartbeat_sender_unittest.cc

Issue 719983002: Reporting of policy errors via host-offline-reason: part 3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hor-nohoststatussender
Patch Set: Removed ReportAckOrTimeout and ref-counting. Renamed MinimumHeartbeatSupporter to HostSignalingMan… Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/host/heartbeat_sender_unittest.cc
diff --git a/remoting/host/heartbeat_sender_unittest.cc b/remoting/host/heartbeat_sender_unittest.cc
index 4a6888c08c03745a147b4bc642cc146fa333db58..56351c9d94bdd67c1d2819672d3a67b53d7e91c0 100644
--- a/remoting/host/heartbeat_sender_unittest.cc
+++ b/remoting/host/heartbeat_sender_unittest.cc
@@ -14,7 +14,6 @@
#include "remoting/base/constants.h"
#include "remoting/base/rsa_key_pair.h"
#include "remoting/base/test_rsa_key_pair.h"
-#include "remoting/host/mock_callback.h"
#include "remoting/signaling/iq_sender.h"
#include "remoting/signaling/mock_signal_strategy.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -42,6 +41,7 @@ const char kHostId[] = "0";
const char kTestJid[] = "user@gmail.com/chromoting123";
const char kStanzaId[] = "123";
const int kTestInterval = 123;
+const base::TimeDelta kTestTimeout = base::TimeDelta::FromSeconds(123);
} // namespace
@@ -53,6 +53,16 @@ ACTION_P(RemoveListener, list) {
list->erase(arg0);
}
+class MockClosure {
+ public:
+ MOCK_CONST_METHOD0(Run, void());
+};
+
+class MockAckCallback {
+ public:
+ MOCK_CONST_METHOD1(Run, void(HeartbeatSender::AckOrTimeout));
+};
+
class HeartbeatSenderTest
: public testing::Test {
protected:
@@ -72,8 +82,10 @@ class HeartbeatSenderTest
.Times(0);
heartbeat_sender_.reset(new HeartbeatSender(
- mock_heartbeat_successful_callback_.GetCallback(),
- mock_unknown_host_id_error_callback_.GetCallback(),
+ base::Bind(&MockClosure::Run,
+ base::Unretained(&mock_heartbeat_successful_callback_)),
+ base::Bind(&MockClosure::Run,
+ base::Unretained(&mock_unknown_host_id_error_callback_)),
kHostId, &signal_strategy_, key_pair_, kTestBotJid));
}
@@ -246,6 +258,8 @@ TEST_F(HeartbeatSenderTest, ProcessResponseSetInterval) {
// Make sure SetHostOfflineReason sends a correct stanza.
TEST_F(HeartbeatSenderTest, DoSetHostOfflineReason) {
XmlElement* sent_iq = NULL;
+ MockAckCallback mock_ack_callback;
+
EXPECT_CALL(signal_strategy_, GetLocalJid())
.WillRepeatedly(Return(kTestJid));
EXPECT_CALL(signal_strategy_, GetNextId())
@@ -255,10 +269,11 @@ TEST_F(HeartbeatSenderTest, DoSetHostOfflineReason) {
EXPECT_CALL(signal_strategy_, GetState())
.WillOnce(Return(SignalStrategy::DISCONNECTED))
.WillRepeatedly(Return(SignalStrategy::CONNECTED));
+ EXPECT_CALL(mock_ack_callback, Run(_)).Times(0);
heartbeat_sender_->SetHostOfflineReason(
- "test_error",
- base::Bind(base::DoNothing));
+ "test_error", kTestTimeout,
+ base::Bind(&MockAckCallback::Run, base::Unretained(&mock_ack_callback)));
Wez 2014/12/18 00:46:20 How is this related to the purpose of this test?
heartbeat_sender_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED);
base::RunLoop().RunUntilIdle();
@@ -272,7 +287,7 @@ TEST_F(HeartbeatSenderTest, DoSetHostOfflineReason) {
// Make sure SetHostOfflineReason triggers a callback when bot responds.
TEST_F(HeartbeatSenderTest, ProcessHostOfflineResponses) {
- MockClosure mock_ack_callback;
+ MockAckCallback mock_ack_callback;
EXPECT_CALL(signal_strategy_, GetLocalJid())
.WillRepeatedly(Return(kTestJid));
@@ -287,11 +302,11 @@ TEST_F(HeartbeatSenderTest, ProcessHostOfflineResponses) {
.WillRepeatedly(Return());
// Callback should not run, until response to offline-reason.
- EXPECT_CALL(mock_ack_callback, Run()).Times(0);
+ EXPECT_CALL(mock_ack_callback, Run(_)).Times(0);
heartbeat_sender_->SetHostOfflineReason(
- "test_error",
- mock_ack_callback.GetCallback());
+ "test_error", kTestTimeout,
+ base::Bind(&MockAckCallback::Run, base::Unretained(&mock_ack_callback)));
heartbeat_sender_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED);
base::RunLoop().RunUntilIdle();
@@ -301,7 +316,8 @@ TEST_F(HeartbeatSenderTest, ProcessHostOfflineResponses) {
base::RunLoop().RunUntilIdle();
// Callback should run once, when we get response to offline-reason.
- EXPECT_CALL(mock_ack_callback, Run()).Times(1);
+ EXPECT_CALL(mock_ack_callback, Run(HeartbeatSender::AckOrTimeout::Ack))
+ .Times(1);
Wez 2014/12/18 00:46:20 Tests should not mix EXPECT_CALL() in with logic t
Łukasz Anforowicz 2014/12/18 19:02:33 According to GMock documentation the behavior is w
ProcessResponseWithInterval(
true, // <- This is a response to offline-reason.
kTestInterval);
@@ -309,7 +325,7 @@ TEST_F(HeartbeatSenderTest, ProcessHostOfflineResponses) {
// When subsequent responses to offline-reason come,
// the callback should not be called again.
- EXPECT_CALL(mock_ack_callback, Run()).Times(0);
+ EXPECT_CALL(mock_ack_callback, Run(_)).Times(0);
ProcessResponseWithInterval(true, kTestInterval);
base::RunLoop().RunUntilIdle();

Powered by Google App Engine
This is Rietveld 408576698