| OLD | NEW |
| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 MockCallback callback_; | 84 MockCallback callback_; |
| 85 scoped_ptr<IqRequest> request_; | 85 scoped_ptr<IqRequest> request_; |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 TEST_F(IqSenderTest, SendIq) { | 88 TEST_F(IqSenderTest, SendIq) { |
| 89 ASSERT_NO_FATAL_FAILURE({ | 89 ASSERT_NO_FATAL_FAILURE({ |
| 90 SendTestMessage(); | 90 SendTestMessage(); |
| 91 }); | 91 }); |
| 92 | 92 |
| 93 scoped_ptr<XmlElement> response(new XmlElement(buzz::QN_IQ)); | 93 scoped_ptr<XmlElement> response(new XmlElement(buzz::QN_IQ)); |
| 94 response->AddAttr(QName("", "type"), "result"); | 94 response->AddAttr(QName(std::string(), "type"), "result"); |
| 95 response->AddAttr(QName("", "id"), kStanzaId); | 95 response->AddAttr(QName(std::string(), "id"), kStanzaId); |
| 96 response->AddAttr(QName("", "from"), kTo); | 96 response->AddAttr(QName(std::string(), "from"), kTo); |
| 97 | 97 |
| 98 XmlElement* result = new XmlElement( | 98 XmlElement* result = new XmlElement( |
| 99 QName("test:namespace", "response-body")); | 99 QName("test:namespace", "response-body")); |
| 100 response->AddElement(result); | 100 response->AddElement(result); |
| 101 | 101 |
| 102 EXPECT_TRUE(sender_->OnSignalStrategyIncomingStanza(response.get())); | 102 EXPECT_TRUE(sender_->OnSignalStrategyIncomingStanza(response.get())); |
| 103 | 103 |
| 104 EXPECT_CALL(callback_, OnReply(request_.get(), XmlEq(response.get()))); | 104 EXPECT_CALL(callback_, OnReply(request_.get(), XmlEq(response.get()))); |
| 105 message_loop_.RunUntilIdle(); | 105 message_loop_.RunUntilIdle(); |
| 106 } | 106 } |
| 107 | 107 |
| 108 TEST_F(IqSenderTest, Timeout) { | 108 TEST_F(IqSenderTest, Timeout) { |
| 109 ASSERT_NO_FATAL_FAILURE({ | 109 ASSERT_NO_FATAL_FAILURE({ |
| 110 SendTestMessage(); | 110 SendTestMessage(); |
| 111 }); | 111 }); |
| 112 | 112 |
| 113 request_->SetTimeout(base::TimeDelta::FromMilliseconds(2)); | 113 request_->SetTimeout(base::TimeDelta::FromMilliseconds(2)); |
| 114 | 114 |
| 115 EXPECT_CALL(callback_, OnReply(request_.get(), NULL)) | 115 EXPECT_CALL(callback_, OnReply(request_.get(), NULL)) |
| 116 .WillOnce(InvokeWithoutArgs(&message_loop_, &MessageLoop::Quit)); | 116 .WillOnce(InvokeWithoutArgs(&message_loop_, &MessageLoop::Quit)); |
| 117 message_loop_.Run(); | 117 message_loop_.Run(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 TEST_F(IqSenderTest, InvalidFrom) { | 120 TEST_F(IqSenderTest, InvalidFrom) { |
| 121 ASSERT_NO_FATAL_FAILURE({ | 121 ASSERT_NO_FATAL_FAILURE({ |
| 122 SendTestMessage(); | 122 SendTestMessage(); |
| 123 }); | 123 }); |
| 124 | 124 |
| 125 scoped_ptr<XmlElement> response(new XmlElement(buzz::QN_IQ)); | 125 scoped_ptr<XmlElement> response(new XmlElement(buzz::QN_IQ)); |
| 126 response->AddAttr(QName("", "type"), "result"); | 126 response->AddAttr(QName(std::string(), "type"), "result"); |
| 127 response->AddAttr(QName("", "id"), kStanzaId); | 127 response->AddAttr(QName(std::string(), "id"), kStanzaId); |
| 128 response->AddAttr(QName("", "from"), "different_user@domain.com"); | 128 response->AddAttr(QName(std::string(), "from"), "different_user@domain.com"); |
| 129 | 129 |
| 130 XmlElement* result = new XmlElement( | 130 XmlElement* result = new XmlElement( |
| 131 QName("test:namespace", "response-body")); | 131 QName("test:namespace", "response-body")); |
| 132 response->AddElement(result); | 132 response->AddElement(result); |
| 133 | 133 |
| 134 EXPECT_CALL(callback_, OnReply(_, _)) | 134 EXPECT_CALL(callback_, OnReply(_, _)) |
| 135 .Times(0); | 135 .Times(0); |
| 136 EXPECT_FALSE(sender_->OnSignalStrategyIncomingStanza(response.get())); | 136 EXPECT_FALSE(sender_->OnSignalStrategyIncomingStanza(response.get())); |
| 137 message_loop_.RunUntilIdle(); | 137 message_loop_.RunUntilIdle(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 TEST_F(IqSenderTest, IdMatchingHack) { | 140 TEST_F(IqSenderTest, IdMatchingHack) { |
| 141 ASSERT_NO_FATAL_FAILURE({ | 141 ASSERT_NO_FATAL_FAILURE({ |
| 142 SendTestMessage(); | 142 SendTestMessage(); |
| 143 }); | 143 }); |
| 144 | 144 |
| 145 scoped_ptr<XmlElement> response(new XmlElement(buzz::QN_IQ)); | 145 scoped_ptr<XmlElement> response(new XmlElement(buzz::QN_IQ)); |
| 146 response->AddAttr(QName("", "type"), "result"); | 146 response->AddAttr(QName(std::string(), "type"), "result"); |
| 147 response->AddAttr(QName("", "id"), "DIFFERENT_ID"); | 147 response->AddAttr(QName(std::string(), "id"), "DIFFERENT_ID"); |
| 148 response->AddAttr(QName("", "from"), kTo); | 148 response->AddAttr(QName(std::string(), "from"), kTo); |
| 149 | 149 |
| 150 XmlElement* result = new XmlElement( | 150 XmlElement* result = new XmlElement( |
| 151 QName("test:namespace", "response-body")); | 151 QName("test:namespace", "response-body")); |
| 152 response->AddElement(result); | 152 response->AddElement(result); |
| 153 | 153 |
| 154 EXPECT_TRUE(sender_->OnSignalStrategyIncomingStanza(response.get())); | 154 EXPECT_TRUE(sender_->OnSignalStrategyIncomingStanza(response.get())); |
| 155 | 155 |
| 156 EXPECT_CALL(callback_, OnReply(request_.get(), XmlEq(response.get()))); | 156 EXPECT_CALL(callback_, OnReply(request_.get(), XmlEq(response.get()))); |
| 157 message_loop_.RunUntilIdle(); | 157 message_loop_.RunUntilIdle(); |
| 158 } | 158 } |
| 159 | 159 |
| 160 } // namespace remoting | 160 } // namespace remoting |
| OLD | NEW |