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/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 72 |
73 void FakeChannelAuthenticator::OnAuthBytesRead(int result) { | 73 void FakeChannelAuthenticator::OnAuthBytesRead(int result) { |
74 EXPECT_EQ(1, result); | 74 EXPECT_EQ(1, result); |
75 EXPECT_FALSE(did_read_bytes_); | 75 EXPECT_FALSE(did_read_bytes_); |
76 did_read_bytes_ = true; | 76 did_read_bytes_ = true; |
77 if (did_write_bytes_) | 77 if (did_write_bytes_) |
78 done_callback_.Run(result_, socket_.Pass()); | 78 done_callback_.Run(result_, socket_.Pass()); |
79 } | 79 } |
80 | 80 |
81 FakeAuthenticator::FakeAuthenticator( | 81 FakeAuthenticator::FakeAuthenticator( |
| 82 Type type, int round_trips, int messages_till_started, |
| 83 Action action, bool async) |
| 84 : type_(type), |
| 85 round_trips_(round_trips), |
| 86 action_(action), |
| 87 async_(async), |
| 88 messages_(0), |
| 89 messages_till_started_(messages_till_started) { |
| 90 } |
| 91 |
| 92 FakeAuthenticator::FakeAuthenticator( |
82 Type type, int round_trips, Action action, bool async) | 93 Type type, int round_trips, Action action, bool async) |
83 : type_(type), | 94 : type_(type), |
84 round_trips_(round_trips), | 95 round_trips_(round_trips), |
85 action_(action), | 96 action_(action), |
86 async_(async), | 97 async_(async), |
87 messages_(0) { | 98 messages_(0), |
| 99 messages_till_started_(0) { |
88 } | 100 } |
89 | 101 |
90 FakeAuthenticator::~FakeAuthenticator() { | 102 FakeAuthenticator::~FakeAuthenticator() { |
91 } | 103 } |
92 | 104 |
93 Authenticator::State FakeAuthenticator::state() const { | 105 Authenticator::State FakeAuthenticator::state() const { |
94 EXPECT_LE(messages_, round_trips_ * 2); | 106 EXPECT_LE(messages_, round_trips_ * 2); |
95 if (messages_ >= round_trips_ * 2) { | 107 if (messages_ >= round_trips_ * 2) { |
96 if (action_ == REJECT) { | 108 if (action_ == REJECT) { |
97 return REJECTED; | 109 return REJECTED; |
(...skipping 11 matching lines...) Expand all Loading... |
109 | 121 |
110 // We are not done yet. process next message. | 122 // We are not done yet. process next message. |
111 if ((messages_ % 2 == 0 && type_ == CLIENT) || | 123 if ((messages_ % 2 == 0 && type_ == CLIENT) || |
112 (messages_ % 2 == 1 && type_ == HOST)) { | 124 (messages_ % 2 == 1 && type_ == HOST)) { |
113 return MESSAGE_READY; | 125 return MESSAGE_READY; |
114 } else { | 126 } else { |
115 return WAITING_MESSAGE; | 127 return WAITING_MESSAGE; |
116 } | 128 } |
117 } | 129 } |
118 | 130 |
| 131 bool FakeAuthenticator::started() const { |
| 132 return messages_ > messages_till_started_; |
| 133 } |
| 134 |
119 Authenticator::RejectionReason FakeAuthenticator::rejection_reason() const { | 135 Authenticator::RejectionReason FakeAuthenticator::rejection_reason() const { |
120 EXPECT_EQ(REJECTED, state()); | 136 EXPECT_EQ(REJECTED, state()); |
121 return INVALID_CREDENTIALS; | 137 return INVALID_CREDENTIALS; |
122 } | 138 } |
123 | 139 |
124 void FakeAuthenticator::ProcessMessage(const buzz::XmlElement* message, | 140 void FakeAuthenticator::ProcessMessage(const buzz::XmlElement* message, |
125 const base::Closure& resume_callback) { | 141 const base::Closure& resume_callback) { |
126 EXPECT_EQ(WAITING_MESSAGE, state()); | 142 EXPECT_EQ(WAITING_MESSAGE, state()); |
127 std::string id = | 143 std::string id = |
128 message->TextNamed(buzz::QName(kChromotingXmlNamespace, "id")); | 144 message->TextNamed(buzz::QName(kChromotingXmlNamespace, "id")); |
(...skipping 17 matching lines...) Expand all Loading... |
146 } | 162 } |
147 | 163 |
148 scoped_ptr<ChannelAuthenticator> | 164 scoped_ptr<ChannelAuthenticator> |
149 FakeAuthenticator::CreateChannelAuthenticator() const { | 165 FakeAuthenticator::CreateChannelAuthenticator() const { |
150 EXPECT_EQ(ACCEPTED, state()); | 166 EXPECT_EQ(ACCEPTED, state()); |
151 return scoped_ptr<ChannelAuthenticator>( | 167 return scoped_ptr<ChannelAuthenticator>( |
152 new FakeChannelAuthenticator(action_ != REJECT_CHANNEL, async_)); | 168 new FakeChannelAuthenticator(action_ != REJECT_CHANNEL, async_)); |
153 } | 169 } |
154 | 170 |
155 FakeHostAuthenticatorFactory::FakeHostAuthenticatorFactory( | 171 FakeHostAuthenticatorFactory::FakeHostAuthenticatorFactory( |
156 int round_trips, FakeAuthenticator::Action action, bool async) | 172 int round_trips, int messages_till_started, |
| 173 FakeAuthenticator::Action action, bool async) |
157 : round_trips_(round_trips), | 174 : round_trips_(round_trips), |
| 175 messages_till_started_(messages_till_started), |
158 action_(action), async_(async) { | 176 action_(action), async_(async) { |
159 } | 177 } |
160 | 178 |
161 FakeHostAuthenticatorFactory::~FakeHostAuthenticatorFactory() { | 179 FakeHostAuthenticatorFactory::~FakeHostAuthenticatorFactory() { |
162 } | 180 } |
163 | 181 |
164 scoped_ptr<Authenticator> FakeHostAuthenticatorFactory::CreateAuthenticator( | 182 scoped_ptr<Authenticator> FakeHostAuthenticatorFactory::CreateAuthenticator( |
165 const std::string& local_jid, | 183 const std::string& local_jid, |
166 const std::string& remote_jid, | 184 const std::string& remote_jid, |
167 const buzz::XmlElement* first_message) { | 185 const buzz::XmlElement* first_message) { |
168 return scoped_ptr<Authenticator>(new FakeAuthenticator( | 186 return scoped_ptr<Authenticator>(new FakeAuthenticator( |
169 FakeAuthenticator::HOST, round_trips_, action_, async_)); | 187 FakeAuthenticator::HOST, round_trips_, |
| 188 messages_till_started_, action_, async_)); |
170 } | 189 } |
171 | 190 |
172 } // namespace protocol | 191 } // namespace protocol |
173 } // namespace remoting | 192 } // namespace remoting |
OLD | NEW |