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 "remoting/protocol/fake_authenticator.h" | 5 #include "remoting/protocol/fake_authenticator.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
10 #include "net/socket/stream_socket.h" | 10 #include "net/socket/stream_socket.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 : type_(type), | 79 : type_(type), |
80 round_trips_(round_trips), | 80 round_trips_(round_trips), |
81 action_(action), | 81 action_(action), |
82 async_(async), | 82 async_(async), |
83 messages_(0) { | 83 messages_(0) { |
84 } | 84 } |
85 | 85 |
86 FakeAuthenticator::~FakeAuthenticator() { | 86 FakeAuthenticator::~FakeAuthenticator() { |
87 } | 87 } |
88 | 88 |
89 Authenticator::State FakeAuthenticator::state() const{ | 89 Authenticator::State FakeAuthenticator::state() const { |
90 EXPECT_LE(messages_, round_trips_ * 2); | 90 EXPECT_LE(messages_, round_trips_ * 2); |
91 if (messages_ >= round_trips_ * 2) { | 91 if (messages_ >= round_trips_ * 2) { |
92 if (action_ == REJECT) { | 92 if (action_ == REJECT) { |
93 return REJECTED; | 93 return REJECTED; |
94 } else { | 94 } else { |
95 return ACCEPTED; | 95 return ACCEPTED; |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
99 // Don't send the last message if this is a host that wants to | 99 // Don't send the last message if this is a host that wants to |
(...skipping 10 matching lines...) Expand all Loading... |
110 } else { | 110 } else { |
111 return WAITING_MESSAGE; | 111 return WAITING_MESSAGE; |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
115 Authenticator::RejectionReason FakeAuthenticator::rejection_reason() const { | 115 Authenticator::RejectionReason FakeAuthenticator::rejection_reason() const { |
116 EXPECT_EQ(REJECTED, state()); | 116 EXPECT_EQ(REJECTED, state()); |
117 return INVALID_CREDENTIALS; | 117 return INVALID_CREDENTIALS; |
118 } | 118 } |
119 | 119 |
120 void FakeAuthenticator::ProcessMessage(const buzz::XmlElement* message) { | 120 void FakeAuthenticator::ProcessMessage(const buzz::XmlElement* message, |
| 121 const base::Closure& resume_callback) { |
121 EXPECT_EQ(WAITING_MESSAGE, state()); | 122 EXPECT_EQ(WAITING_MESSAGE, state()); |
122 std::string id = | 123 std::string id = |
123 message->TextNamed(buzz::QName(kChromotingXmlNamespace, "id")); | 124 message->TextNamed(buzz::QName(kChromotingXmlNamespace, "id")); |
124 EXPECT_EQ(id, base::IntToString(messages_)); | 125 EXPECT_EQ(id, base::IntToString(messages_)); |
125 ++messages_; | 126 ++messages_; |
| 127 resume_callback.Run(); |
126 } | 128 } |
127 | 129 |
128 scoped_ptr<buzz::XmlElement> FakeAuthenticator::GetNextMessage() { | 130 scoped_ptr<buzz::XmlElement> FakeAuthenticator::GetNextMessage() { |
129 EXPECT_EQ(MESSAGE_READY, state()); | 131 EXPECT_EQ(MESSAGE_READY, state()); |
130 | 132 |
131 scoped_ptr<buzz::XmlElement> result(new buzz::XmlElement( | 133 scoped_ptr<buzz::XmlElement> result(new buzz::XmlElement( |
132 buzz::QName(kChromotingXmlNamespace, "authentication"))); | 134 buzz::QName(kChromotingXmlNamespace, "authentication"))); |
133 buzz::XmlElement* id = new buzz::XmlElement( | 135 buzz::XmlElement* id = new buzz::XmlElement( |
134 buzz::QName(kChromotingXmlNamespace, "id")); | 136 buzz::QName(kChromotingXmlNamespace, "id")); |
135 id->AddText(base::IntToString(messages_)); | 137 id->AddText(base::IntToString(messages_)); |
(...skipping 22 matching lines...) Expand all Loading... |
158 scoped_ptr<Authenticator> FakeHostAuthenticatorFactory::CreateAuthenticator( | 160 scoped_ptr<Authenticator> FakeHostAuthenticatorFactory::CreateAuthenticator( |
159 const std::string& local_jid, | 161 const std::string& local_jid, |
160 const std::string& remote_jid, | 162 const std::string& remote_jid, |
161 const buzz::XmlElement* first_message) { | 163 const buzz::XmlElement* first_message) { |
162 return scoped_ptr<Authenticator>(new FakeAuthenticator( | 164 return scoped_ptr<Authenticator>(new FakeAuthenticator( |
163 FakeAuthenticator::HOST, round_trips_, action_, async_)); | 165 FakeAuthenticator::HOST, round_trips_, action_, async_)); |
164 } | 166 } |
165 | 167 |
166 } // namespace protocol | 168 } // namespace protocol |
167 } // namespace remoting | 169 } // namespace remoting |
OLD | NEW |