Chromium Code Reviews| 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 "jingle/notifier/communicator/single_login_attempt.h" | 5 #include "jingle/notifier/communicator/single_login_attempt.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 new net::TestURLRequestContextGetter( | 88 new net::TestURLRequestContextGetter( |
| 89 base::MessageLoopProxy::current(), | 89 base::MessageLoopProxy::current(), |
| 90 scoped_ptr<net::TestURLRequestContext>( | 90 scoped_ptr<net::TestURLRequestContext>( |
| 91 new MyTestURLRequestContext())), | 91 new MyTestURLRequestContext())), |
| 92 ServerList( | 92 ServerList( |
| 93 1, | 93 1, |
| 94 ServerInformation( | 94 ServerInformation( |
| 95 net::HostPortPair("example.com", 100), SUPPORTS_SSLTCP)), | 95 net::HostPortPair("example.com", 100), SUPPORTS_SSLTCP)), |
| 96 false /* try_ssltcp_first */, | 96 false /* try_ssltcp_first */, |
| 97 "auth_mechanism"), | 97 "auth_mechanism"), |
| 98 attempt_(login_settings_, &fake_delegate_) {} | 98 attempt_(new SingleLoginAttempt(login_settings_, &fake_delegate_)) {} |
| 99 | 99 |
| 100 virtual void TearDown() OVERRIDE { | 100 virtual void TearDown() OVERRIDE { |
| 101 message_loop_.RunUntilIdle(); | 101 message_loop_.RunUntilIdle(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void FireRedirect(buzz::XmlElement* redirect_error) { | 104 void FireRedirect(buzz::XmlElement* redirect_error) { |
| 105 attempt_.OnError(buzz::XmppEngine::ERROR_STREAM, 0, redirect_error); | 105 attempt_->OnError(buzz::XmppEngine::ERROR_STREAM, 0, redirect_error); |
| 106 } | |
| 107 | |
| 108 ~SingleLoginAttemptTest() { | |
| 109 attempt_.reset(NULL); | |
|
awong
2013/07/29 20:59:59
Don't need the explicit NULL.
| |
| 110 message_loop_.RunUntilIdle(); | |
| 106 } | 111 } |
| 107 | 112 |
| 108 private: | 113 private: |
| 109 base::MessageLoop message_loop_; | 114 base::MessageLoop message_loop_; |
| 110 const LoginSettings login_settings_; | 115 const LoginSettings login_settings_; |
| 111 | 116 |
| 112 protected: | 117 protected: |
| 113 SingleLoginAttempt attempt_; | 118 scoped_ptr<SingleLoginAttempt> attempt_; |
| 114 FakeDelegate fake_delegate_; | 119 FakeDelegate fake_delegate_; |
| 115 FakeBaseTask fake_base_task_; | 120 FakeBaseTask fake_base_task_; |
| 116 }; | 121 }; |
| 117 | 122 |
| 118 // Fire OnConnect and make sure the base task gets passed to the | 123 // Fire OnConnect and make sure the base task gets passed to the |
| 119 // delegate properly. | 124 // delegate properly. |
| 120 TEST_F(SingleLoginAttemptTest, Basic) { | 125 TEST_F(SingleLoginAttemptTest, Basic) { |
| 121 attempt_.OnConnect(fake_base_task_.AsWeakPtr()); | 126 attempt_->OnConnect(fake_base_task_.AsWeakPtr()); |
| 122 EXPECT_EQ(CONNECTED, fake_delegate_.state()); | 127 EXPECT_EQ(CONNECTED, fake_delegate_.state()); |
| 123 EXPECT_EQ(fake_base_task_.AsWeakPtr().get(), | 128 EXPECT_EQ(fake_base_task_.AsWeakPtr().get(), |
| 124 fake_delegate_.base_task().get()); | 129 fake_delegate_.base_task().get()); |
| 125 } | 130 } |
| 126 | 131 |
| 127 // Fire OnErrors and make sure the delegate gets the | 132 // Fire OnErrors and make sure the delegate gets the |
| 128 // OnSettingsExhausted() event. | 133 // OnSettingsExhausted() event. |
| 129 TEST_F(SingleLoginAttemptTest, Error) { | 134 TEST_F(SingleLoginAttemptTest, Error) { |
| 130 for (int i = 0; i < 2; ++i) { | 135 for (int i = 0; i < 2; ++i) { |
| 131 EXPECT_EQ(IDLE, fake_delegate_.state()); | 136 EXPECT_EQ(IDLE, fake_delegate_.state()); |
| 132 attempt_.OnError(buzz::XmppEngine::ERROR_NONE, 0, NULL); | 137 attempt_->OnError(buzz::XmppEngine::ERROR_NONE, 0, NULL); |
| 133 } | 138 } |
| 134 EXPECT_EQ(SETTINGS_EXHAUSTED, fake_delegate_.state()); | 139 EXPECT_EQ(SETTINGS_EXHAUSTED, fake_delegate_.state()); |
| 135 } | 140 } |
| 136 | 141 |
| 137 // Fire OnErrors but replace the last one with OnConnect, and make | 142 // Fire OnErrors but replace the last one with OnConnect, and make |
| 138 // sure the delegate still gets the OnConnect message. | 143 // sure the delegate still gets the OnConnect message. |
| 139 TEST_F(SingleLoginAttemptTest, ErrorThenSuccess) { | 144 TEST_F(SingleLoginAttemptTest, ErrorThenSuccess) { |
| 140 attempt_.OnError(buzz::XmppEngine::ERROR_NONE, 0, NULL); | 145 attempt_->OnError(buzz::XmppEngine::ERROR_NONE, 0, NULL); |
| 141 attempt_.OnConnect(fake_base_task_.AsWeakPtr()); | 146 attempt_->OnConnect(fake_base_task_.AsWeakPtr()); |
| 142 EXPECT_EQ(CONNECTED, fake_delegate_.state()); | 147 EXPECT_EQ(CONNECTED, fake_delegate_.state()); |
| 143 EXPECT_EQ(fake_base_task_.AsWeakPtr().get(), | 148 EXPECT_EQ(fake_base_task_.AsWeakPtr().get(), |
| 144 fake_delegate_.base_task().get()); | 149 fake_delegate_.base_task().get()); |
| 145 } | 150 } |
| 146 | 151 |
| 147 buzz::XmlElement* MakeRedirectError(const std::string& redirect_server) { | 152 buzz::XmlElement* MakeRedirectError(const std::string& redirect_server) { |
| 148 buzz::XmlElement* stream_error = | 153 buzz::XmlElement* stream_error = |
| 149 new buzz::XmlElement(buzz::QN_STREAM_ERROR, true); | 154 new buzz::XmlElement(buzz::QN_STREAM_ERROR, true); |
| 150 stream_error->AddElement( | 155 stream_error->AddElement( |
| 151 new buzz::XmlElement(buzz::QN_XSTREAM_SEE_OTHER_HOST, true)); | 156 new buzz::XmlElement(buzz::QN_XSTREAM_SEE_OTHER_HOST, true)); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 TEST_F(SingleLoginAttemptTest, RedirectMissingSeeOtherHost) { | 243 TEST_F(SingleLoginAttemptTest, RedirectMissingSeeOtherHost) { |
| 239 scoped_ptr<buzz::XmlElement> redirect_error(MakeRedirectError(std::string())); | 244 scoped_ptr<buzz::XmlElement> redirect_error(MakeRedirectError(std::string())); |
| 240 redirect_error->RemoveChildAfter(NULL); | 245 redirect_error->RemoveChildAfter(NULL); |
| 241 FireRedirect(redirect_error.get()); | 246 FireRedirect(redirect_error.get()); |
| 242 EXPECT_EQ(IDLE, fake_delegate_.state()); | 247 EXPECT_EQ(IDLE, fake_delegate_.state()); |
| 243 } | 248 } |
| 244 | 249 |
| 245 // Fire 'Unauthorized' errors and make sure the delegate gets the | 250 // Fire 'Unauthorized' errors and make sure the delegate gets the |
| 246 // OnCredentialsRejected() event. | 251 // OnCredentialsRejected() event. |
| 247 TEST_F(SingleLoginAttemptTest, CredentialsRejected) { | 252 TEST_F(SingleLoginAttemptTest, CredentialsRejected) { |
| 248 attempt_.OnError(buzz::XmppEngine::ERROR_UNAUTHORIZED, 0, NULL); | 253 attempt_->OnError(buzz::XmppEngine::ERROR_UNAUTHORIZED, 0, NULL); |
| 249 EXPECT_EQ(CREDENTIALS_REJECTED, fake_delegate_.state()); | 254 EXPECT_EQ(CREDENTIALS_REJECTED, fake_delegate_.state()); |
| 250 } | 255 } |
| 251 | 256 |
| 252 } // namespace | 257 } // namespace |
| 253 | 258 |
| 254 } // namespace notifier | 259 } // namespace notifier |
| OLD | NEW |