Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "remoting/host/register_support_host_request.h" | 5 #include "remoting/host/register_support_host_request.h" |
| 6 | 6 |
| 7 #include <list> | |
| 8 | |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 9 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 10 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 11 #include "remoting/base/constants.h" | 13 #include "remoting/base/constants.h" |
| 12 #include "remoting/host/host_key_pair.h" | 14 #include "remoting/host/host_key_pair.h" |
| 13 #include "remoting/host/in_memory_host_config.h" | 15 #include "remoting/host/in_memory_host_config.h" |
| 14 #include "remoting/host/test_key_pair.h" | 16 #include "remoting/host/test_key_pair.h" |
| 15 #include "remoting/jingle_glue/iq_sender.h" | 17 #include "remoting/jingle_glue/iq_sender.h" |
| 16 #include "remoting/jingle_glue/mock_objects.h" | 18 #include "remoting/jingle_glue/mock_objects.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 config_ = new InMemoryHostConfig(); | 54 config_ = new InMemoryHostConfig(); |
| 53 config_->SetString(kPrivateKeyConfigPath, kTestHostKeyPair); | 55 config_->SetString(kPrivateKeyConfigPath, kTestHostKeyPair); |
| 54 } | 56 } |
| 55 | 57 |
| 56 MockSignalStrategy signal_strategy_; | 58 MockSignalStrategy signal_strategy_; |
| 57 MessageLoop message_loop_; | 59 MessageLoop message_loop_; |
| 58 scoped_refptr<InMemoryHostConfig> config_; | 60 scoped_refptr<InMemoryHostConfig> config_; |
| 59 MockCallback callback_; | 61 MockCallback callback_; |
| 60 }; | 62 }; |
| 61 | 63 |
| 64 ACTION_P(SaveListener, list) { | |
| 65 list->push_back(arg0); | |
| 66 } | |
| 67 | |
| 62 TEST_F(RegisterSupportHostRequestTest, Send) { | 68 TEST_F(RegisterSupportHostRequestTest, Send) { |
| 63 // |iq_request| is freed by RegisterSupportHostRequest. | 69 // |iq_request| is freed by RegisterSupportHostRequest. |
| 64 int64 start_time = static_cast<int64>(base::Time::Now().ToDoubleT()); | 70 int64 start_time = static_cast<int64>(base::Time::Now().ToDoubleT()); |
| 65 | 71 |
| 66 SignalStrategy::Listener* listener; | 72 std::list<SignalStrategy::Listener*> listeners; |
| 67 EXPECT_CALL(signal_strategy_, AddListener(NotNull())) | 73 EXPECT_CALL(signal_strategy_, AddListener(NotNull())) |
| 68 .WillOnce(SaveArg<0>(&listener)); | 74 .WillRepeatedly(SaveListener(&listeners)); |
| 69 | 75 |
| 70 scoped_ptr<RegisterSupportHostRequest> request( | 76 scoped_ptr<RegisterSupportHostRequest> request( |
| 71 new RegisterSupportHostRequest()); | 77 new RegisterSupportHostRequest()); |
| 72 ASSERT_TRUE(request->Init( | 78 ASSERT_TRUE(request->Init( |
| 73 config_, base::Bind(&MockCallback::OnResponse, | 79 &signal_strategy_, config_, base::Bind(&MockCallback::OnResponse, |
| 74 base::Unretained(&callback_)))); | 80 base::Unretained(&callback_)))); |
| 75 | 81 |
| 76 XmlElement* sent_iq = NULL; | 82 XmlElement* sent_iq = NULL; |
| 77 EXPECT_CALL(signal_strategy_, GetNextId()) | 83 EXPECT_CALL(signal_strategy_, GetNextId()) |
| 78 .WillOnce(Return(kStanzaId)); | 84 .WillOnce(Return(kStanzaId)); |
| 79 EXPECT_CALL(signal_strategy_, GetLocalJid()) | 85 EXPECT_CALL(signal_strategy_, GetLocalJid()) |
| 80 .WillRepeatedly(Return(kTestJid)); | 86 .WillRepeatedly(Return(kTestJid)); |
| 81 EXPECT_CALL(signal_strategy_, SendStanza(NotNull())) | 87 EXPECT_CALL(signal_strategy_, SendStanza(NotNull())) |
| 82 .WillOnce(DoAll(SaveArg<0>(&sent_iq), Return(true))); | 88 .WillOnce(DoAll(SaveArg<0>(&sent_iq), Return(true))); |
| 83 | 89 |
| 84 request->OnSignallingConnected(&signal_strategy_); | 90 request->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); |
| 85 message_loop_.RunAllPending(); | 91 message_loop_.RunAllPending(); |
| 86 | 92 |
| 87 // Verify format of the query. | 93 // Verify format of the query. |
| 88 scoped_ptr<XmlElement> stanza(sent_iq); | 94 scoped_ptr<XmlElement> stanza(sent_iq); |
| 89 ASSERT_TRUE(stanza != NULL); | 95 ASSERT_TRUE(stanza != NULL); |
| 90 | 96 |
| 91 EXPECT_EQ(stanza->Attr(buzz::QName("", "to")), | 97 EXPECT_EQ(stanza->Attr(buzz::QName("", "to")), |
| 92 std::string(kChromotingBotJid)); | 98 std::string(kChromotingBotJid)); |
| 93 EXPECT_EQ(stanza->Attr(buzz::QName("", "type")), "set"); | 99 EXPECT_EQ(stanza->Attr(buzz::QName("", "type")), "set"); |
| 94 | 100 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 XmlElement* support_id = new XmlElement( | 135 XmlElement* support_id = new XmlElement( |
| 130 QName(kChromotingXmlNamespace, "support-id")); | 136 QName(kChromotingXmlNamespace, "support-id")); |
| 131 support_id->AddText(kSupportId); | 137 support_id->AddText(kSupportId); |
| 132 result->AddElement(support_id); | 138 result->AddElement(support_id); |
| 133 | 139 |
| 134 XmlElement* support_id_lifetime = new XmlElement( | 140 XmlElement* support_id_lifetime = new XmlElement( |
| 135 QName(kChromotingXmlNamespace, "support-id-lifetime")); | 141 QName(kChromotingXmlNamespace, "support-id-lifetime")); |
| 136 support_id_lifetime->AddText(kSupportIdLifetime); | 142 support_id_lifetime->AddText(kSupportIdLifetime); |
| 137 result->AddElement(support_id_lifetime); | 143 result->AddElement(support_id_lifetime); |
| 138 | 144 |
| 139 EXPECT_TRUE(listener->OnSignalStrategyIncomingStanza(response.get())); | 145 std::list<SignalStrategy::Listener*>::iterator it; |
| 146 bool consumed = false; | |
| 147 for (it = listeners.begin(); it != listeners.end(); it++) { | |
| 148 consumed = consumed | (*it)->OnSignalStrategyIncomingStanza(response.get()); | |
| 149 } | |
| 150 EXPECT_TRUE(consumed); | |
| 140 message_loop_.RunAllPending(); | 151 message_loop_.RunAllPending(); |
| 141 | 152 |
| 142 EXPECT_CALL(signal_strategy_, RemoveListener(listener)); | 153 EXPECT_CALL(signal_strategy_, RemoveListener(_)) |
| 154 .Times(listeners.size()); | |
|
Wez
2012/01/03 16:25:04
Ick. Confusing; at what point is |listeners.size(
Sergey Ulanov
2012/01/03 21:51:02
Done.
| |
| 143 } | 155 } |
| 144 | 156 |
| 145 } // namespace remoting | 157 } // namespace remoting |
| OLD | NEW |