Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(467)

Side by Side Diff: jingle/notifier/communicator/single_login_attempt_unittest.cc

Issue 10545170: [Sync] Propagate XMPP auth errors to SyncNotifierObservers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile error Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "jingle/notifier/base/const_communicator.h" 12 #include "jingle/notifier/base/const_communicator.h"
13 #include "jingle/notifier/base/fake_base_task.h" 13 #include "jingle/notifier/base/fake_base_task.h"
14 #include "jingle/notifier/communicator/login_settings.h" 14 #include "jingle/notifier/communicator/login_settings.h"
15 #include "net/base/mock_host_resolver.h" 15 #include "net/base/mock_host_resolver.h"
16 #include "net/url_request/url_request_test_util.h" 16 #include "net/url_request/url_request_test_util.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "talk/xmllite/xmlelement.h" 18 #include "talk/xmllite/xmlelement.h"
19 #include "talk/xmpp/constants.h" 19 #include "talk/xmpp/constants.h"
20 #include "talk/xmpp/xmppengine.h" 20 #include "talk/xmpp/xmppengine.h"
21 21
22 namespace buzz { 22 namespace buzz {
23 class XmppTaskParentInterface; 23 class XmppTaskParentInterface;
24 } // namespace buzz 24 } // namespace buzz
25 25
26 namespace notifier { 26 namespace notifier {
27 27
28 namespace { 28 namespace {
29 29
30 enum DelegateState { IDLE, CONNECTED, NEED_RECONNECT, REDIRECTED }; 30 enum DelegateState {
31 IDLE, CONNECTED, NEED_RECONNECT, REDIRECTED, REJECTED_CREDENTIALS
32 };
31 33
32 class FakeDelegate : public SingleLoginAttempt::Delegate { 34 class FakeDelegate : public SingleLoginAttempt::Delegate {
33 public: 35 public:
34 FakeDelegate() : state_(IDLE) {} 36 FakeDelegate() : state_(IDLE) {}
35 37
36 void OnConnect(base::WeakPtr<buzz::XmppTaskParentInterface> base_task) { 38 void OnConnect(
39 base::WeakPtr<buzz::XmppTaskParentInterface> base_task) OVERRIDE {
37 state_ = CONNECTED; 40 state_ = CONNECTED;
38 base_task_ = base_task; 41 base_task_ = base_task;
39 } 42 }
40 43
41 virtual void OnNeedReconnect() { 44 virtual void OnNeedReconnect() OVERRIDE {
42 state_ = NEED_RECONNECT; 45 state_ = NEED_RECONNECT;
43 } 46 }
44 47
45 virtual void OnRedirect(const ServerInformation& redirect_server) OVERRIDE { 48 virtual void OnRedirect(const ServerInformation& redirect_server) OVERRIDE {
46 state_ = REDIRECTED; 49 state_ = REDIRECTED;
47 redirect_server_ = redirect_server; 50 redirect_server_ = redirect_server;
48 } 51 }
49 52
53 virtual void OnRejectedCredentials() OVERRIDE {
54 state_ = REJECTED_CREDENTIALS;
55 }
56
50 DelegateState state() const { return state_; } 57 DelegateState state() const { return state_; }
51 58
52 base::WeakPtr<buzz::XmppTaskParentInterface> base_task() const { 59 base::WeakPtr<buzz::XmppTaskParentInterface> base_task() const {
53 return base_task_; 60 return base_task_;
54 } 61 }
55 62
56 const ServerInformation& redirect_server() const { 63 const ServerInformation& redirect_server() const {
57 return redirect_server_; 64 return redirect_server_;
58 } 65 }
59 66
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 233
227 // Fire a redirect with a missing see-other-host element and make sure 234 // Fire a redirect with a missing see-other-host element and make sure
228 // the delegate does not get a redirect. 235 // the delegate does not get a redirect.
229 TEST_F(SingleLoginAttemptTest, RedirectMissingSeeOtherHost) { 236 TEST_F(SingleLoginAttemptTest, RedirectMissingSeeOtherHost) {
230 scoped_ptr<buzz::XmlElement> redirect_error(MakeRedirectError("")); 237 scoped_ptr<buzz::XmlElement> redirect_error(MakeRedirectError(""));
231 redirect_error->RemoveChildAfter(NULL); 238 redirect_error->RemoveChildAfter(NULL);
232 FireRedirect(redirect_error.get()); 239 FireRedirect(redirect_error.get());
233 EXPECT_EQ(IDLE, fake_delegate_.state()); 240 EXPECT_EQ(IDLE, fake_delegate_.state());
234 } 241 }
235 242
243 // Fire 'Unauthorized' errors and make sure the delegate gets the
244 // OnRejectedCredentials() event.
245 TEST_F(SingleLoginAttemptTest, RejectedCredentials) {
246 attempt_.OnError(buzz::XmppEngine::ERROR_UNAUTHORIZED, 0, NULL);
247 EXPECT_EQ(REJECTED_CREDENTIALS, fake_delegate_.state());
248 }
249
236 } // namespace 250 } // namespace
237 251
238 } // namespace notifier 252 } // namespace notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698