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

Side by Side Diff: remoting/client/client_status_logger_unittest.cc

Issue 2798393007: Use SignalingAddress in SignalStrategy insterface. (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 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 #include "remoting/client/client_status_logger.h" 5 #include "remoting/client/client_status_logger.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "remoting/protocol/performance_tracker.h" 9 #include "remoting/protocol/performance_tracker.h"
10 #include "remoting/signaling/mock_signal_strategy.h" 10 #include "remoting/signaling/mock_signal_strategy.h"
11 #include "remoting/signaling/server_log_entry_unittest.h" 11 #include "remoting/signaling/server_log_entry_unittest.h"
12 #include "remoting/signaling/signaling_address.h"
12 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/libjingle_xmpp/xmllite/xmlelement.h" 15 #include "third_party/libjingle_xmpp/xmllite/xmlelement.h"
15 16
16 using buzz::XmlElement; 17 using buzz::XmlElement;
17 using buzz::QName; 18 using buzz::QName;
18 using remoting::protocol::ConnectionToHost; 19 using remoting::protocol::ConnectionToHost;
19 using testing::_; 20 using testing::_;
20 using testing::DeleteArg; 21 using testing::DeleteArg;
21 using testing::InSequence; 22 using testing::InSequence;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 } 58 }
58 59
59 return entry->Attr(QName(std::string(), "event-name")) == 60 return entry->Attr(QName(std::string(), "event-name")) ==
60 "connection-statistics"; 61 "connection-statistics";
61 } 62 }
62 63
63 } // namespace 64 } // namespace
64 65
65 class ClientStatusLoggerTest : public testing::Test { 66 class ClientStatusLoggerTest : public testing::Test {
66 public: 67 public:
67 ClientStatusLoggerTest() {} 68 ClientStatusLoggerTest() : signal_strategy_(SignalingAddress(kClientJid)) {}
68 void SetUp() override { 69 void SetUp() override {
69 EXPECT_CALL(signal_strategy_, AddListener(_)); 70 EXPECT_CALL(signal_strategy_, AddListener(_));
70 EXPECT_CALL(signal_strategy_, RemoveListener(_)); 71 EXPECT_CALL(signal_strategy_, RemoveListener(_));
71 client_status_logger_.reset( 72 client_status_logger_.reset(
72 new ClientStatusLogger(ServerLogEntry::ME2ME, 73 new ClientStatusLogger(ServerLogEntry::ME2ME,
73 &signal_strategy_, 74 &signal_strategy_,
74 kTestBotJid)); 75 kTestBotJid));
75 } 76 }
76 77
77 protected: 78 protected:
78 base::MessageLoop message_loop_; 79 base::MessageLoop message_loop_;
79 MockSignalStrategy signal_strategy_; 80 MockSignalStrategy signal_strategy_;
80 std::unique_ptr<ClientStatusLogger> client_status_logger_; 81 std::unique_ptr<ClientStatusLogger> client_status_logger_;
81 }; 82 };
82 83
83 TEST_F(ClientStatusLoggerTest, LogStateChange) { 84 TEST_F(ClientStatusLoggerTest, LogStateChange) {
84 base::RunLoop run_loop; 85 base::RunLoop run_loop;
85 { 86 {
86 InSequence s; 87 InSequence s;
87 EXPECT_CALL(signal_strategy_, GetLocalJid())
88 .WillRepeatedly(Return(kClientJid));
89 EXPECT_CALL(signal_strategy_, AddListener(_)); 88 EXPECT_CALL(signal_strategy_, AddListener(_));
90 EXPECT_CALL(signal_strategy_, GetNextId()); 89 EXPECT_CALL(signal_strategy_, GetNextId());
91 EXPECT_CALL(signal_strategy_, SendStanzaPtr( 90 EXPECT_CALL(signal_strategy_, SendStanzaPtr(
92 IsStateChange("connected", std::string()))) 91 IsStateChange("connected", std::string())))
93 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 92 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
94 EXPECT_CALL(signal_strategy_, RemoveListener(_)) 93 EXPECT_CALL(signal_strategy_, RemoveListener(_))
95 .WillOnce(QuitRunLoop(&run_loop)) 94 .WillOnce(QuitRunLoop(&run_loop))
96 .RetiresOnSaturation(); 95 .RetiresOnSaturation();
97 } 96 }
98 client_status_logger_->LogSessionStateChange(ConnectionToHost::CONNECTED, 97 client_status_logger_->LogSessionStateChange(ConnectionToHost::CONNECTED,
99 protocol::OK); 98 protocol::OK);
100 99
101 // Setting the state to CONNECTED causes the log to be sent. Setting the 100 // Setting the state to CONNECTED causes the log to be sent. Setting the
102 // state to DISCONNECTED causes |signal_strategy_| to be cleaned up, 101 // state to DISCONNECTED causes |signal_strategy_| to be cleaned up,
103 // which removes the listener and terminates the test. 102 // which removes the listener and terminates the test.
104 client_status_logger_->SetSignalingStateForTest(SignalStrategy::CONNECTED); 103 client_status_logger_->SetSignalingStateForTest(SignalStrategy::CONNECTED);
105 client_status_logger_->SetSignalingStateForTest(SignalStrategy::DISCONNECTED); 104 client_status_logger_->SetSignalingStateForTest(SignalStrategy::DISCONNECTED);
106 run_loop.Run(); 105 run_loop.Run();
107 } 106 }
108 107
109 TEST_F(ClientStatusLoggerTest, LogStateChangeError) { 108 TEST_F(ClientStatusLoggerTest, LogStateChangeError) {
110 base::RunLoop run_loop; 109 base::RunLoop run_loop;
111 { 110 {
112 InSequence s; 111 InSequence s;
113 EXPECT_CALL(signal_strategy_, GetLocalJid())
114 .WillRepeatedly(Return(kClientJid));
115 EXPECT_CALL(signal_strategy_, AddListener(_)); 112 EXPECT_CALL(signal_strategy_, AddListener(_));
116 EXPECT_CALL(signal_strategy_, GetNextId()); 113 EXPECT_CALL(signal_strategy_, GetNextId());
117 EXPECT_CALL(signal_strategy_, SendStanzaPtr( 114 EXPECT_CALL(signal_strategy_, SendStanzaPtr(
118 IsStateChange("connection-failed", "host-is-offline"))) 115 IsStateChange("connection-failed", "host-is-offline")))
119 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 116 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
120 EXPECT_CALL(signal_strategy_, RemoveListener(_)) 117 EXPECT_CALL(signal_strategy_, RemoveListener(_))
121 .WillOnce(QuitRunLoop(&run_loop)) 118 .WillOnce(QuitRunLoop(&run_loop))
122 .RetiresOnSaturation(); 119 .RetiresOnSaturation();
123 } 120 }
124 client_status_logger_->LogSessionStateChange(ConnectionToHost::FAILED, 121 client_status_logger_->LogSessionStateChange(ConnectionToHost::FAILED,
125 protocol::PEER_IS_OFFLINE); 122 protocol::PEER_IS_OFFLINE);
126 123
127 client_status_logger_->SetSignalingStateForTest(SignalStrategy::CONNECTED); 124 client_status_logger_->SetSignalingStateForTest(SignalStrategy::CONNECTED);
128 client_status_logger_->SetSignalingStateForTest(SignalStrategy::DISCONNECTED); 125 client_status_logger_->SetSignalingStateForTest(SignalStrategy::DISCONNECTED);
129 run_loop.Run(); 126 run_loop.Run();
130 } 127 }
131 128
132 TEST_F(ClientStatusLoggerTest, LogStatistics) { 129 TEST_F(ClientStatusLoggerTest, LogStatistics) {
133 base::RunLoop run_loop; 130 base::RunLoop run_loop;
134 { 131 {
135 InSequence s; 132 InSequence s;
136 EXPECT_CALL(signal_strategy_, GetLocalJid())
137 .WillRepeatedly(Return(kClientJid));
138 EXPECT_CALL(signal_strategy_, AddListener(_)); 133 EXPECT_CALL(signal_strategy_, AddListener(_));
139 EXPECT_CALL(signal_strategy_, GetNextId()); 134 EXPECT_CALL(signal_strategy_, GetNextId());
140 EXPECT_CALL(signal_strategy_, SendStanzaPtr( 135 EXPECT_CALL(signal_strategy_, SendStanzaPtr(
141 IsStatisticsLog())) 136 IsStatisticsLog()))
142 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); 137 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
143 EXPECT_CALL(signal_strategy_, RemoveListener(_)) 138 EXPECT_CALL(signal_strategy_, RemoveListener(_))
144 .WillOnce(QuitRunLoop(&run_loop)) 139 .WillOnce(QuitRunLoop(&run_loop))
145 .RetiresOnSaturation(); 140 .RetiresOnSaturation();
146 } 141 }
147 142
148 protocol::PerformanceTracker perf_tracker; 143 protocol::PerformanceTracker perf_tracker;
149 client_status_logger_->LogStatistics(&perf_tracker); 144 client_status_logger_->LogStatistics(&perf_tracker);
150 145
151 client_status_logger_->SetSignalingStateForTest(SignalStrategy::CONNECTED); 146 client_status_logger_->SetSignalingStateForTest(SignalStrategy::CONNECTED);
152 client_status_logger_->SetSignalingStateForTest(SignalStrategy::DISCONNECTED); 147 client_status_logger_->SetSignalingStateForTest(SignalStrategy::DISCONNECTED);
153 run_loop.Run(); 148 run_loop.Run();
154 } 149 }
155 150
156 } // namespace remoting 151 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698