OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_SIGNALING_FAKE_SIGNAL_STRATEGY_H_ | 5 #ifndef REMOTING_SIGNALING_FAKE_SIGNAL_STRATEGY_H_ |
6 #define REMOTING_SIGNALING_FAKE_SIGNAL_STRATEGY_H_ | 6 #define REMOTING_SIGNALING_FAKE_SIGNAL_STRATEGY_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <queue> | 9 #include <queue> |
10 #include <string> | 10 #include <string> |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 void set_send_delay(base::TimeDelta delay) { | 39 void set_send_delay(base::TimeDelta delay) { |
40 send_delay_ = delay; | 40 send_delay_ = delay; |
41 } | 41 } |
42 | 42 |
43 // Connects current FakeSignalStrategy to receive messages from |peer|. | 43 // Connects current FakeSignalStrategy to receive messages from |peer|. |
44 void ConnectTo(FakeSignalStrategy* peer); | 44 void ConnectTo(FakeSignalStrategy* peer); |
45 | 45 |
46 void SetLocalJid(const std::string& jid); | 46 void SetLocalJid(const std::string& jid); |
47 | 47 |
| 48 // Simulates packet reordering by reorering the last session-info message and |
| 49 // the first transport-info message in a multi-stepped auth. |
| 50 void SimulatePackgeReordering(); |
| 51 |
48 // SignalStrategy interface. | 52 // SignalStrategy interface. |
49 void Connect() override; | 53 void Connect() override; |
50 void Disconnect() override; | 54 void Disconnect() override; |
51 State GetState() const override; | 55 State GetState() const override; |
52 Error GetError() const override; | 56 Error GetError() const override; |
53 std::string GetLocalJid() const override; | 57 std::string GetLocalJid() const override; |
54 void AddListener(Listener* listener) override; | 58 void AddListener(Listener* listener) override; |
55 void RemoveListener(Listener* listener) override; | 59 void RemoveListener(Listener* listener) override; |
56 bool SendStanza(std::unique_ptr<buzz::XmlElement> stanza) override; | 60 bool SendStanza(std::unique_ptr<buzz::XmlElement> stanza) override; |
57 std::string GetNextId() override; | 61 std::string GetNextId() override; |
58 | 62 |
59 private: | 63 private: |
60 typedef base::Callback<void(std::unique_ptr<buzz::XmlElement> message)> | 64 typedef base::Callback<void(std::unique_ptr<buzz::XmlElement> message)> |
61 PeerCallback; | 65 PeerCallback; |
62 | 66 |
63 static void DeliverMessageOnThread( | 67 static void DeliverMessageOnThread( |
64 scoped_refptr<base::SingleThreadTaskRunner> thread, | 68 scoped_refptr<base::SingleThreadTaskRunner> thread, |
65 base::WeakPtr<FakeSignalStrategy> target, | 69 base::WeakPtr<FakeSignalStrategy> target, |
66 std::unique_ptr<buzz::XmlElement> stanza); | 70 std::unique_ptr<buzz::XmlElement> stanza); |
67 | 71 |
68 // Called by the |peer_|. Takes ownership of |stanza|. | 72 // Called by the |peer_|. Takes ownership of |stanza|. |
69 void OnIncomingMessage(std::unique_ptr<buzz::XmlElement> stanza); | 73 void OnIncomingMessage(std::unique_ptr<buzz::XmlElement> stanza); |
| 74 void NotifyListeners(std::unique_ptr<buzz::XmlElement> stanza); |
70 void SetPeerCallback(const PeerCallback& peer_callback); | 75 void SetPeerCallback(const PeerCallback& peer_callback); |
71 | 76 |
72 scoped_refptr<base::SingleThreadTaskRunner> main_thread_; | 77 scoped_refptr<base::SingleThreadTaskRunner> main_thread_; |
73 | 78 |
74 std::string jid_; | 79 std::string jid_; |
75 PeerCallback peer_callback_; | 80 PeerCallback peer_callback_; |
76 base::ObserverList<Listener, true> listeners_; | 81 base::ObserverList<Listener, true> listeners_; |
77 | 82 |
78 int last_id_; | 83 int last_id_; |
79 | 84 |
80 base::TimeDelta send_delay_; | 85 base::TimeDelta send_delay_; |
81 | 86 |
| 87 bool simulate_reorder_ = false; |
| 88 std::unique_ptr<buzz::XmlElement> pending_session_info_; |
| 89 int session_info_counts_ = 0; |
| 90 |
82 // All received messages, includes thouse still in |pending_messages_|. | 91 // All received messages, includes thouse still in |pending_messages_|. |
83 std::list<buzz::XmlElement*> received_messages_; | 92 std::list<buzz::XmlElement*> received_messages_; |
84 | 93 |
85 base::WeakPtrFactory<FakeSignalStrategy> weak_factory_; | 94 base::WeakPtrFactory<FakeSignalStrategy> weak_factory_; |
86 | 95 |
87 DISALLOW_COPY_AND_ASSIGN(FakeSignalStrategy); | 96 DISALLOW_COPY_AND_ASSIGN(FakeSignalStrategy); |
88 }; | 97 }; |
89 | 98 |
90 } // namespace remoting | 99 } // namespace remoting |
91 | 100 |
92 #endif // REMOTING_SIGNALING_FAKE_SIGNAL_STRATEGY_H_ | 101 #endif // REMOTING_SIGNALING_FAKE_SIGNAL_STRATEGY_H_ |
OLD | NEW |