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

Side by Side 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: Trying to see how things look without mock_callback.h 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "remoting/host/heartbeat_sender.h" 5 #include "remoting/host/heartbeat_sender.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/message_loop/message_loop_proxy.h" 11 #include "base/message_loop/message_loop_proxy.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "remoting/base/constants.h" 14 #include "remoting/base/constants.h"
15 #include "remoting/base/rsa_key_pair.h" 15 #include "remoting/base/rsa_key_pair.h"
16 #include "remoting/base/test_rsa_key_pair.h" 16 #include "remoting/base/test_rsa_key_pair.h"
17 #include "remoting/host/mock_callback.h"
18 #include "remoting/signaling/iq_sender.h" 17 #include "remoting/signaling/iq_sender.h"
19 #include "remoting/signaling/mock_signal_strategy.h" 18 #include "remoting/signaling/mock_signal_strategy.h"
20 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
22 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" 21 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h"
23 #include "third_party/webrtc/libjingle/xmpp/constants.h" 22 #include "third_party/webrtc/libjingle/xmpp/constants.h"
24 23
25 using buzz::QName; 24 using buzz::QName;
26 using buzz::XmlElement; 25 using buzz::XmlElement;
27 26
(...skipping 18 matching lines...) Expand all
46 } // namespace 45 } // namespace
47 46
48 ACTION_P(AddListener, list) { 47 ACTION_P(AddListener, list) {
49 list->insert(arg0); 48 list->insert(arg0);
50 } 49 }
51 ACTION_P(RemoveListener, list) { 50 ACTION_P(RemoveListener, list) {
52 EXPECT_TRUE(list->find(arg0) != list->end()); 51 EXPECT_TRUE(list->find(arg0) != list->end());
53 list->erase(arg0); 52 list->erase(arg0);
54 } 53 }
55 54
55 class MockClosure {
56 public:
57 MOCK_CONST_METHOD0(Run, void());
58 };
59
56 class HeartbeatSenderTest 60 class HeartbeatSenderTest
57 : public testing::Test { 61 : public testing::Test {
58 protected: 62 protected:
59 void SetUp() override { 63 void SetUp() override {
60 key_pair_ = RsaKeyPair::FromString(kTestRsaKeyPair); 64 key_pair_ = RsaKeyPair::FromString(kTestRsaKeyPair);
61 ASSERT_TRUE(key_pair_.get()); 65 ASSERT_TRUE(key_pair_.get());
62 66
63 EXPECT_CALL(signal_strategy_, GetState()) 67 EXPECT_CALL(signal_strategy_, GetState())
64 .WillOnce(Return(SignalStrategy::DISCONNECTED)); 68 .WillOnce(Return(SignalStrategy::DISCONNECTED));
65 EXPECT_CALL(signal_strategy_, AddListener(NotNull())) 69 EXPECT_CALL(signal_strategy_, AddListener(NotNull()))
66 .WillRepeatedly(AddListener(&signal_strategy_listeners_)); 70 .WillRepeatedly(AddListener(&signal_strategy_listeners_));
67 EXPECT_CALL(signal_strategy_, RemoveListener(NotNull())) 71 EXPECT_CALL(signal_strategy_, RemoveListener(NotNull()))
68 .WillRepeatedly(RemoveListener(&signal_strategy_listeners_)); 72 .WillRepeatedly(RemoveListener(&signal_strategy_listeners_));
69 EXPECT_CALL(signal_strategy_, GetLocalJid()) 73 EXPECT_CALL(signal_strategy_, GetLocalJid())
70 .WillRepeatedly(Return(kTestJid)); 74 .WillRepeatedly(Return(kTestJid));
71 EXPECT_CALL(mock_unknown_host_id_error_callback_, Run()) 75 EXPECT_CALL(mock_unknown_host_id_error_callback_, Run())
72 .Times(0); 76 .Times(0);
73 77
74 heartbeat_sender_.reset(new HeartbeatSender( 78 heartbeat_sender_.reset(new HeartbeatSender(
75 mock_heartbeat_successful_callback_.GetCallback(), 79 base::Bind(&MockClosure::Run,
76 mock_unknown_host_id_error_callback_.GetCallback(), 80 base::Unretained(&mock_heartbeat_successful_callback_)),
81 base::Bind(&MockClosure::Run,
82 base::Unretained(&mock_unknown_host_id_error_callback_)),
77 kHostId, &signal_strategy_, key_pair_, kTestBotJid)); 83 kHostId, &signal_strategy_, key_pair_, kTestBotJid));
78 } 84 }
79 85
80 void TearDown() override { 86 void TearDown() override {
81 heartbeat_sender_.reset(); 87 heartbeat_sender_.reset();
82 EXPECT_TRUE(signal_strategy_listeners_.empty()); 88 EXPECT_TRUE(signal_strategy_listeners_.empty());
83 } 89 }
84 90
85 void ValidateHeartbeatStanza(XmlElement* stanza, 91 void ValidateHeartbeatStanza(XmlElement* stanza,
86 const char* expected_sequence_id, 92 const char* expected_sequence_id,
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 .WillOnce(Return(SignalStrategy::DISCONNECTED)) 290 .WillOnce(Return(SignalStrategy::DISCONNECTED))
285 .WillRepeatedly(Return(SignalStrategy::CONNECTED)); 291 .WillRepeatedly(Return(SignalStrategy::CONNECTED));
286 EXPECT_CALL(mock_heartbeat_successful_callback_, Run()) 292 EXPECT_CALL(mock_heartbeat_successful_callback_, Run())
287 .WillRepeatedly(Return()); 293 .WillRepeatedly(Return());
288 294
289 // Callback should not run, until response to offline-reason. 295 // Callback should not run, until response to offline-reason.
290 EXPECT_CALL(mock_ack_callback, Run()).Times(0); 296 EXPECT_CALL(mock_ack_callback, Run()).Times(0);
291 297
292 heartbeat_sender_->SetHostOfflineReason( 298 heartbeat_sender_->SetHostOfflineReason(
293 "test_error", 299 "test_error",
294 mock_ack_callback.GetCallback()); 300 base::Bind(&MockClosure::Run, base::Unretained(&mock_ack_callback)));
295 heartbeat_sender_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); 301 heartbeat_sender_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED);
296 base::RunLoop().RunUntilIdle(); 302 base::RunLoop().RunUntilIdle();
297 303
298 ProcessResponseWithInterval( 304 ProcessResponseWithInterval(
299 false, // <- This is not a response to offline-reason. 305 false, // <- This is not a response to offline-reason.
300 kTestInterval); 306 kTestInterval);
301 base::RunLoop().RunUntilIdle(); 307 base::RunLoop().RunUntilIdle();
302 308
303 // Callback should run once, when we get response to offline-reason. 309 // Callback should run once, when we get response to offline-reason.
304 EXPECT_CALL(mock_ack_callback, Run()).Times(1); 310 EXPECT_CALL(mock_ack_callback, Run()).Times(1);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 EXPECT_TRUE(heartbeat_stanza->NextNamed(signature_tag) == NULL); 352 EXPECT_TRUE(heartbeat_stanza->NextNamed(signature_tag) == NULL);
347 353
348 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::FromString(kTestRsaKeyPair); 354 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::FromString(kTestRsaKeyPair);
349 ASSERT_TRUE(key_pair.get()); 355 ASSERT_TRUE(key_pair.get());
350 std::string expected_signature = 356 std::string expected_signature =
351 key_pair->SignMessage(std::string(kTestJid) + ' ' + expected_sequence_id); 357 key_pair->SignMessage(std::string(kTestJid) + ' ' + expected_sequence_id);
352 EXPECT_EQ(expected_signature, signature->BodyText()); 358 EXPECT_EQ(expected_signature, signature->BodyText());
353 } 359 }
354 360
355 } // namespace remoting 361 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698