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

Side by Side Diff: remoting/jingle_glue/iq_sender_unittest.cc

Issue 10161010: Handle IQ responses asynchronously. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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/jingle_glue/iq_sender.cc ('k') | remoting/jingle_glue/signal_strategy.h » ('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) 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/memory/ref_counted.h" 6 #include "base/memory/ref_counted.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "remoting/jingle_glue/iq_sender.h" 9 #include "remoting/jingle_glue/iq_sender.h"
10 #include "remoting/jingle_glue/mock_objects.h" 10 #include "remoting/jingle_glue/mock_objects.h"
(...skipping 21 matching lines...) Expand all
32 const char kNamespacePrefix[] = "tes"; 32 const char kNamespacePrefix[] = "tes";
33 const char kBodyTag[] = "test"; 33 const char kBodyTag[] = "test";
34 const char kType[] = "get"; 34 const char kType[] = "get";
35 const char kTo[] = "user@domain.com"; 35 const char kTo[] = "user@domain.com";
36 36
37 class MockCallback { 37 class MockCallback {
38 public: 38 public:
39 MOCK_METHOD2(OnReply, void(IqRequest* request, const XmlElement* reply)); 39 MOCK_METHOD2(OnReply, void(IqRequest* request, const XmlElement* reply));
40 }; 40 };
41 41
42 MATCHER_P(XmlEq, expected, "") {
43 return arg->Str() == expected->Str();
44 }
45
42 } // namespace 46 } // namespace
43 47
44 class IqSenderTest : public testing::Test { 48 class IqSenderTest : public testing::Test {
45 public: 49 public:
46 IqSenderTest() { 50 IqSenderTest() {
47 EXPECT_CALL(signal_strategy_, AddListener(NotNull())); 51 EXPECT_CALL(signal_strategy_, AddListener(NotNull()));
48 sender_.reset(new IqSender(&signal_strategy_)); 52 sender_.reset(new IqSender(&signal_strategy_));
49 EXPECT_CALL(signal_strategy_, RemoveListener( 53 EXPECT_CALL(signal_strategy_, RemoveListener(
50 static_cast<SignalStrategy::Listener*>(sender_.get()))); 54 static_cast<SignalStrategy::Listener*>(sender_.get())));
51 } 55 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 92
89 scoped_ptr<XmlElement> response(new XmlElement(buzz::QN_IQ)); 93 scoped_ptr<XmlElement> response(new XmlElement(buzz::QN_IQ));
90 response->AddAttr(QName("", "type"), "result"); 94 response->AddAttr(QName("", "type"), "result");
91 response->AddAttr(QName("", "id"), kStanzaId); 95 response->AddAttr(QName("", "id"), kStanzaId);
92 response->AddAttr(QName("", "from"), kTo); 96 response->AddAttr(QName("", "from"), kTo);
93 97
94 XmlElement* result = new XmlElement( 98 XmlElement* result = new XmlElement(
95 QName("test:namespace", "response-body")); 99 QName("test:namespace", "response-body"));
96 response->AddElement(result); 100 response->AddElement(result);
97 101
98 EXPECT_CALL(callback_, OnReply(request_.get(), response.get()));
99 EXPECT_TRUE(sender_->OnSignalStrategyIncomingStanza(response.get())); 102 EXPECT_TRUE(sender_->OnSignalStrategyIncomingStanza(response.get()));
103
104 EXPECT_CALL(callback_, OnReply(request_.get(), XmlEq(response.get())));
105 message_loop_.RunAllPending();
100 } 106 }
101 107
102 TEST_F(IqSenderTest, Timeout) { 108 TEST_F(IqSenderTest, Timeout) {
103 ASSERT_NO_FATAL_FAILURE({ 109 ASSERT_NO_FATAL_FAILURE({
104 SendTestMessage(); 110 SendTestMessage();
105 }); 111 });
106 112
107 request_->SetTimeout(base::TimeDelta::FromMilliseconds(2)); 113 request_->SetTimeout(base::TimeDelta::FromMilliseconds(2));
108 114
109 EXPECT_CALL(callback_, OnReply(request_.get(), NULL)) 115 EXPECT_CALL(callback_, OnReply(request_.get(), NULL))
110 .WillOnce(InvokeWithoutArgs(&message_loop_, &MessageLoop::Quit)); 116 .WillOnce(InvokeWithoutArgs(&message_loop_, &MessageLoop::Quit));
111 message_loop_.Run(); 117 message_loop_.Run();
112 } 118 }
113 119
114 TEST_F(IqSenderTest, InvalidFrom) { 120 TEST_F(IqSenderTest, InvalidFrom) {
115 ASSERT_NO_FATAL_FAILURE({ 121 ASSERT_NO_FATAL_FAILURE({
116 SendTestMessage(); 122 SendTestMessage();
117 }); 123 });
118 124
119 scoped_ptr<XmlElement> response(new XmlElement(buzz::QN_IQ)); 125 scoped_ptr<XmlElement> response(new XmlElement(buzz::QN_IQ));
120 response->AddAttr(QName("", "type"), "result"); 126 response->AddAttr(QName("", "type"), "result");
121 response->AddAttr(QName("", "id"), kStanzaId); 127 response->AddAttr(QName("", "id"), kStanzaId);
122 response->AddAttr(QName("", "from"), "different_user@domain.com"); 128 response->AddAttr(QName("", "from"), "different_user@domain.com");
123 129
124 XmlElement* result = new XmlElement( 130 XmlElement* result = new XmlElement(
125 QName("test:namespace", "response-body")); 131 QName("test:namespace", "response-body"));
126 response->AddElement(result); 132 response->AddElement(result);
127 133
128 EXPECT_CALL(callback_, OnReply(request_.get(), response.get())) 134 EXPECT_CALL(callback_, OnReply(_, _))
129 .Times(0); 135 .Times(0);
130 EXPECT_FALSE(sender_->OnSignalStrategyIncomingStanza(response.get())); 136 EXPECT_FALSE(sender_->OnSignalStrategyIncomingStanza(response.get()));
137 message_loop_.RunAllPending();
131 } 138 }
132 139
133 TEST_F(IqSenderTest, IdMatchingHack) { 140 TEST_F(IqSenderTest, IdMatchingHack) {
134 ASSERT_NO_FATAL_FAILURE({ 141 ASSERT_NO_FATAL_FAILURE({
135 SendTestMessage(); 142 SendTestMessage();
136 }); 143 });
137 144
138 scoped_ptr<XmlElement> response(new XmlElement(buzz::QN_IQ)); 145 scoped_ptr<XmlElement> response(new XmlElement(buzz::QN_IQ));
139 response->AddAttr(QName("", "type"), "result"); 146 response->AddAttr(QName("", "type"), "result");
140 response->AddAttr(QName("", "id"), "DIFFERENT_ID"); 147 response->AddAttr(QName("", "id"), "DIFFERENT_ID");
141 response->AddAttr(QName("", "from"), kTo); 148 response->AddAttr(QName("", "from"), kTo);
142 149
143 XmlElement* result = new XmlElement( 150 XmlElement* result = new XmlElement(
144 QName("test:namespace", "response-body")); 151 QName("test:namespace", "response-body"));
145 response->AddElement(result); 152 response->AddElement(result);
146 153
147 EXPECT_CALL(callback_, OnReply(request_.get(), response.get()));
148 EXPECT_TRUE(sender_->OnSignalStrategyIncomingStanza(response.get())); 154 EXPECT_TRUE(sender_->OnSignalStrategyIncomingStanza(response.get()));
155
156 EXPECT_CALL(callback_, OnReply(request_.get(), XmlEq(response.get())));
157 message_loop_.RunAllPending();
149 } 158 }
150 159
151 } // namespace remoting 160 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/jingle_glue/iq_sender.cc ('k') | remoting/jingle_glue/signal_strategy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698