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

Side by Side Diff: remoting/protocol/fake_authenticator.h

Issue 2808283002: Improve tests for Mixed-Case JIDs. (Closed)
Patch Set: . Created 3 years, 8 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
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 #ifndef REMOTING_PROTOCOL_FAKE_AUTHENTICATOR_H_ 5 #ifndef REMOTING_PROTOCOL_FAKE_AUTHENTICATOR_H_
6 #define REMOTING_PROTOCOL_FAKE_AUTHENTICATOR_H_ 6 #define REMOTING_PROTOCOL_FAKE_AUTHENTICATOR_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 HOST, 49 HOST,
50 CLIENT, 50 CLIENT,
51 }; 51 };
52 52
53 enum Action { 53 enum Action {
54 ACCEPT, 54 ACCEPT,
55 REJECT, 55 REJECT,
56 REJECT_CHANNEL 56 REJECT_CHANNEL
57 }; 57 };
58 58
59 FakeAuthenticator(Type type, int round_trips, Action action, bool async); 59 struct Config {
60 Config();
61 Config(Action action);
62 Config(int round_trips, Action action, bool async);
63
64 int round_trips = 1;
65 Action action = Action::ACCEPT;
66 bool async = false;
67 };
68
69 FakeAuthenticator(Type type,
70 Config config,
71 const std::string& local_id,
72 const std::string& remote_id);
73
74 // Special constructor for authenticators in ACCEPTED or REJECTED state that
75 // don't exchange any messages.
76 FakeAuthenticator(Action action);
60 77
61 ~FakeAuthenticator() override; 78 ~FakeAuthenticator() override;
62 79
63 // Set the number of messages that the authenticator needs to process before 80 // Set the number of messages that the authenticator needs to process before
64 // started() returns true. Default to 0. 81 // started() returns true. Default to 0.
65 void set_messages_till_started(int messages); 82 void set_messages_till_started(int messages);
66 83
67 // Sets auth key to be returned by GetAuthKey(). Must be called when 84 // Sets auth key to be returned by GetAuthKey(). Must be called when
68 // |round_trips| is set to 0. 85 // |round_trips| is set to 0.
69 void set_auth_key(const std::string& auth_key) { auth_key_ = auth_key; } 86 void set_auth_key(const std::string& auth_key) { auth_key_ = auth_key; }
(...skipping 12 matching lines...) Expand all
82 RejectionReason rejection_reason() const override; 99 RejectionReason rejection_reason() const override;
83 void ProcessMessage(const buzz::XmlElement* message, 100 void ProcessMessage(const buzz::XmlElement* message,
84 const base::Closure& resume_callback) override; 101 const base::Closure& resume_callback) override;
85 std::unique_ptr<buzz::XmlElement> GetNextMessage() override; 102 std::unique_ptr<buzz::XmlElement> GetNextMessage() override;
86 const std::string& GetAuthKey() const override; 103 const std::string& GetAuthKey() const override;
87 std::unique_ptr<ChannelAuthenticator> CreateChannelAuthenticator() 104 std::unique_ptr<ChannelAuthenticator> CreateChannelAuthenticator()
88 const override; 105 const override;
89 106
90 protected: 107 protected:
91 const Type type_; 108 const Type type_;
92 const int round_trips_; 109 const Config config_;
93 const Action action_; 110 const std::string local_id_;
94 const bool async_; 111 const std::string remote_id_;
95 112
96 // Total number of messages that have been processed. 113 // Total number of messages that have been processed.
97 int messages_ = 0; 114 int messages_ = 0;
98 // Number of messages that the authenticator needs to process before started() 115 // Number of messages that the authenticator needs to process before started()
99 // returns true. Default to 0. 116 // returns true. Default to 0.
100 int messages_till_started_ = 0; 117 int messages_till_started_ = 0;
101 118
102 int pause_message_index_ = -1; 119 int pause_message_index_ = -1;
103 base::Closure resume_closure_; 120 base::Closure resume_closure_;
104 121
105 std::string auth_key_; 122 std::string auth_key_;
106 123
107 DISALLOW_COPY_AND_ASSIGN(FakeAuthenticator); 124 DISALLOW_COPY_AND_ASSIGN(FakeAuthenticator);
108 }; 125 };
109 126
110 class FakeHostAuthenticatorFactory : public AuthenticatorFactory { 127 class FakeHostAuthenticatorFactory : public AuthenticatorFactory {
111 public: 128 public:
112 FakeHostAuthenticatorFactory( 129 FakeHostAuthenticatorFactory(int messages_till_start,
113 int round_trips, int messages_till_start, 130 FakeAuthenticator::Config config);
joedow 2017/04/11 16:20:34 nit: Config struct passed by const ref?
Sergey Ulanov 2017/04/11 21:14:20 That struct is only 12 bytes, not much bigger than
114 FakeAuthenticator::Action action, bool async);
115 ~FakeHostAuthenticatorFactory() override; 131 ~FakeHostAuthenticatorFactory() override;
116 132
117 // AuthenticatorFactory interface. 133 // AuthenticatorFactory interface.
118 std::unique_ptr<Authenticator> CreateAuthenticator( 134 std::unique_ptr<Authenticator> CreateAuthenticator(
119 const std::string& local_jid, 135 const std::string& local_jid,
120 const std::string& remote_jid) override; 136 const std::string& remote_jid) override;
121 137
122 private: 138 private:
123 const int round_trips_;
124 const int messages_till_started_; 139 const int messages_till_started_;
125 const FakeAuthenticator::Action action_; 140 const FakeAuthenticator::Config config_;
126 const bool async_;
127 141
128 DISALLOW_COPY_AND_ASSIGN(FakeHostAuthenticatorFactory); 142 DISALLOW_COPY_AND_ASSIGN(FakeHostAuthenticatorFactory);
129 }; 143 };
130 144
131 } // namespace protocol 145 } // namespace protocol
132 } // namespace remoting 146 } // namespace remoting
133 147
134 #endif // REMOTING_PROTOCOL_FAKE_AUTHENTICATOR_H_ 148 #endif // REMOTING_PROTOCOL_FAKE_AUTHENTICATOR_H_
OLDNEW
« no previous file with comments | « no previous file | remoting/protocol/fake_authenticator.cc » ('j') | remoting/protocol/jingle_session_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698