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

Side by Side Diff: remoting/host/heartbeat_sender_unittest.cc

Issue 7809003: Simplify IqRequest interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix windows Created 9 years, 3 months 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 | Annotate | Revision Log
« no previous file with comments | « remoting/host/heartbeat_sender.cc ('k') | remoting/host/register_support_host_request.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/memory/ref_counted.h" 5 #include "base/memory/ref_counted.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/message_loop_proxy.h" 7 #include "base/message_loop_proxy.h"
8 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "remoting/base/constants.h" 9 #include "remoting/base/constants.h"
10 #include "remoting/host/heartbeat_sender.h" 10 #include "remoting/host/heartbeat_sender.h"
11 #include "remoting/host/host_key_pair.h" 11 #include "remoting/host/host_key_pair.h"
12 #include "remoting/host/in_memory_host_config.h" 12 #include "remoting/host/in_memory_host_config.h"
13 #include "remoting/host/test_key_pair.h" 13 #include "remoting/host/test_key_pair.h"
14 #include "remoting/jingle_glue/iq_request.h" 14 #include "remoting/jingle_glue/iq_request.h"
15 #include "remoting/jingle_glue/mock_objects.h" 15 #include "remoting/jingle_glue/mock_objects.h"
16 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" 18 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
19 #include "third_party/libjingle/source/talk/xmpp/constants.h" 19 #include "third_party/libjingle/source/talk/xmpp/constants.h"
20 20
21 using buzz::QName; 21 using buzz::QName;
22 using buzz::XmlElement; 22 using buzz::XmlElement;
23 23
24 using testing::_; 24 using testing::_;
25 using testing::DeleteArg; 25 using testing::DeleteArg;
26 using testing::DoAll; 26 using testing::DoAll;
27 using testing::Invoke; 27 using testing::Invoke;
28 using testing::NotNull; 28 using testing::NotNull;
29 using testing::Return; 29 using testing::Return;
30 using testing::SaveArg;
30 31
31 namespace remoting { 32 namespace remoting {
32 33
33 namespace { 34 namespace {
34 const char kHostId[] = "0"; 35 const char kHostId[] = "0";
35 const char kTestJid[] = "user@gmail.com/chromoting123"; 36 const char kTestJid[] = "user@gmail.com/chromoting123";
36 const int64 kTestTime = 123123123; 37 const int64 kTestTime = 123123123;
37 } // namespace 38 } // namespace
38 39
39 class HeartbeatSenderTest : public testing::Test { 40 class HeartbeatSenderTest : public testing::Test {
40 protected: 41 protected:
41 virtual void SetUp() { 42 virtual void SetUp() {
42 config_ = new InMemoryHostConfig(); 43 config_ = new InMemoryHostConfig();
43 config_->SetString(kHostIdConfigPath, kHostId); 44 config_->SetString(kHostIdConfigPath, kHostId);
44 config_->SetString(kPrivateKeyConfigPath, kTestHostKeyPair); 45 config_->SetString(kPrivateKeyConfigPath, kTestHostKeyPair);
45 } 46 }
46 47
47 MockSignalStrategy signal_strategy_; 48 MockSignalStrategy signal_strategy_;
48 MessageLoop message_loop_; 49 MessageLoop message_loop_;
49 scoped_refptr<InMemoryHostConfig> config_; 50 scoped_refptr<InMemoryHostConfig> config_;
50 }; 51 };
51 52
52 // Call Start() followed by Stop(), and makes sure an Iq stanza is 53 // Call Start() followed by Stop(), and makes sure an Iq stanza is
53 // being send. 54 // being sent.
54 TEST_F(HeartbeatSenderTest, DoSendStanza) { 55 TEST_F(HeartbeatSenderTest, DoSendStanza) {
55 // |iq_request| is freed by HeartbeatSender. 56 // |iq_request| is freed by HeartbeatSender.
56 MockIqRequest* iq_request = new MockIqRequest(); 57 MockIqRequest* iq_request = new MockIqRequest();
57 iq_request->Init(); 58 iq_request->Init();
58 59
59 EXPECT_CALL(*iq_request, set_callback(_)).Times(1); 60 EXPECT_CALL(*iq_request, set_callback(_)).Times(1);
60 61
61 scoped_ptr<HeartbeatSender> heartbeat_sender( 62 scoped_ptr<HeartbeatSender> heartbeat_sender(
62 new HeartbeatSender(base::MessageLoopProxy::current(), 63 new HeartbeatSender(base::MessageLoopProxy::current(),
63 config_)); 64 config_));
64 ASSERT_TRUE(heartbeat_sender->Init()); 65 ASSERT_TRUE(heartbeat_sender->Init());
65 66
66 EXPECT_CALL(signal_strategy_, CreateIqRequest()) 67 EXPECT_CALL(signal_strategy_, CreateIqRequest())
67 .WillOnce(Return(iq_request)); 68 .WillOnce(Return(iq_request));
68 69
69 EXPECT_CALL(*iq_request, SendIq(buzz::STR_SET, kChromotingBotJid, NotNull())) 70 XmlElement* sent_iq = NULL;
70 .WillOnce(DoAll(DeleteArg<2>(), Return())); 71 EXPECT_CALL(*iq_request, SendIq(NotNull()))
72 .WillOnce(SaveArg<0>(&sent_iq));
71 73
72 heartbeat_sender->OnSignallingConnected(&signal_strategy_, kTestJid); 74 heartbeat_sender->OnSignallingConnected(&signal_strategy_, kTestJid);
73 message_loop_.RunAllPending(); 75 message_loop_.RunAllPending();
74 76
77 scoped_ptr<XmlElement> stanza(sent_iq);
78 ASSERT_TRUE(stanza != NULL);
79
80 EXPECT_EQ(stanza->Attr(buzz::QName("", "to")),
81 std::string(kChromotingBotJid));
82 EXPECT_EQ(stanza->Attr(buzz::QName("", "type")), "set");
83
75 heartbeat_sender->OnSignallingDisconnected(); 84 heartbeat_sender->OnSignallingDisconnected();
76 message_loop_.RunAllPending(); 85 message_loop_.RunAllPending();
77 } 86 }
78 87
79 // Validate format of the heartbeat stanza. 88 // Validate format of the heartbeat stanza.
80 TEST_F(HeartbeatSenderTest, CreateHeartbeatMessage) { 89 TEST_F(HeartbeatSenderTest, CreateHeartbeatMessage) {
81 scoped_ptr<HeartbeatSender> heartbeat_sender( 90 scoped_ptr<HeartbeatSender> heartbeat_sender(
82 new HeartbeatSender(base::MessageLoopProxy::current(), 91 new HeartbeatSender(base::MessageLoopProxy::current(),
83 config_)); 92 config_));
84 ASSERT_TRUE(heartbeat_sender->Init()); 93 ASSERT_TRUE(heartbeat_sender->Init());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 141
133 scoped_ptr<HeartbeatSender> heartbeat_sender( 142 scoped_ptr<HeartbeatSender> heartbeat_sender(
134 new HeartbeatSender(base::MessageLoopProxy::current(), 143 new HeartbeatSender(base::MessageLoopProxy::current(),
135 config_)); 144 config_));
136 heartbeat_sender->ProcessResponse(response.get()); 145 heartbeat_sender->ProcessResponse(response.get());
137 146
138 EXPECT_EQ(kTestInterval * 1000, heartbeat_sender->interval_ms_); 147 EXPECT_EQ(kTestInterval * 1000, heartbeat_sender->interval_ms_);
139 } 148 }
140 149
141 } // namespace remoting 150 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/heartbeat_sender.cc ('k') | remoting/host/register_support_host_request.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698