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

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

Issue 2753963002: Refactoring and rewriting the chromoting jni instance to be chromoting session. (Closed)
Patch Set: Updating based on feedback. 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
« no previous file with comments | « remoting/client/client_status_logger.cc ('k') | remoting/client/client_telemetry_logger.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "remoting/client/client_status_logger.h"
6
7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h"
9 #include "remoting/protocol/performance_tracker.h"
10 #include "remoting/signaling/mock_signal_strategy.h"
11 #include "remoting/signaling/server_log_entry_unittest.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/libjingle_xmpp/xmllite/xmlelement.h"
15
16 using buzz::XmlElement;
17 using buzz::QName;
18 using remoting::protocol::ConnectionToHost;
19 using testing::_;
20 using testing::DeleteArg;
21 using testing::InSequence;
22 using testing::Return;
23
24 namespace remoting {
25
26 namespace {
27
28 ACTION_P(QuitRunLoop, run_loop) {
29 run_loop->QuitWhenIdle();
30 }
31
32 const char kTestBotJid[] = "remotingunittest@bot.talk.google.com";
33 const char kClientJid[] = "host@domain.com/1234";
34
35 MATCHER_P2(IsStateChange, new_state, error, "") {
36 XmlElement* entry = GetSingleLogEntryFromStanza(arg);
37 if (!entry) {
38 return false;
39 }
40
41 bool is_state_change = (
42 entry->Attr(QName(std::string(), "event-name")) == "session-state" &&
43 entry->Attr(QName(std::string(), "session-state")) == new_state &&
44 entry->Attr(QName(std::string(), "role")) == "client" &&
45 entry->Attr(QName(std::string(), "mode")) == "me2me");
46 if (!std::string(error).empty()) {
47 is_state_change = is_state_change &&
48 entry->Attr(QName(std::string(), "connection-error")) == error;
49 }
50 return is_state_change;
51 }
52
53 MATCHER(IsStatisticsLog, "") {
54 XmlElement* entry = GetSingleLogEntryFromStanza(arg);
55 if (!entry) {
56 return false;
57 }
58
59 return entry->Attr(QName(std::string(), "event-name")) ==
60 "connection-statistics";
61 }
62
63 } // namespace
64
65 class ClientStatusLoggerTest : public testing::Test {
66 public:
67 ClientStatusLoggerTest() {}
68 void SetUp() override {
69 EXPECT_CALL(signal_strategy_, AddListener(_));
70 EXPECT_CALL(signal_strategy_, RemoveListener(_));
71 client_status_logger_.reset(
72 new ClientStatusLogger(ServerLogEntry::ME2ME,
73 &signal_strategy_,
74 kTestBotJid));
75 }
76
77 protected:
78 base::MessageLoop message_loop_;
79 MockSignalStrategy signal_strategy_;
80 std::unique_ptr<ClientStatusLogger> client_status_logger_;
81 };
82
83 TEST_F(ClientStatusLoggerTest, LogStateChange) {
84 base::RunLoop run_loop;
85 {
86 InSequence s;
87 EXPECT_CALL(signal_strategy_, GetLocalJid())
88 .WillRepeatedly(Return(kClientJid));
89 EXPECT_CALL(signal_strategy_, AddListener(_));
90 EXPECT_CALL(signal_strategy_, GetNextId());
91 EXPECT_CALL(signal_strategy_, SendStanzaPtr(
92 IsStateChange("connected", std::string())))
93 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
94 EXPECT_CALL(signal_strategy_, RemoveListener(_))
95 .WillOnce(QuitRunLoop(&run_loop))
96 .RetiresOnSaturation();
97 }
98 client_status_logger_->LogSessionStateChange(ConnectionToHost::CONNECTED,
99 protocol::OK);
100
101 // Setting the state to CONNECTED causes the log to be sent. Setting the
102 // state to DISCONNECTED causes |signal_strategy_| to be cleaned up,
103 // which removes the listener and terminates the test.
104 client_status_logger_->SetSignalingStateForTest(SignalStrategy::CONNECTED);
105 client_status_logger_->SetSignalingStateForTest(SignalStrategy::DISCONNECTED);
106 run_loop.Run();
107 }
108
109 TEST_F(ClientStatusLoggerTest, LogStateChangeError) {
110 base::RunLoop run_loop;
111 {
112 InSequence s;
113 EXPECT_CALL(signal_strategy_, GetLocalJid())
114 .WillRepeatedly(Return(kClientJid));
115 EXPECT_CALL(signal_strategy_, AddListener(_));
116 EXPECT_CALL(signal_strategy_, GetNextId());
117 EXPECT_CALL(signal_strategy_, SendStanzaPtr(
118 IsStateChange("connection-failed", "host-is-offline")))
119 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
120 EXPECT_CALL(signal_strategy_, RemoveListener(_))
121 .WillOnce(QuitRunLoop(&run_loop))
122 .RetiresOnSaturation();
123 }
124 client_status_logger_->LogSessionStateChange(ConnectionToHost::FAILED,
125 protocol::PEER_IS_OFFLINE);
126
127 client_status_logger_->SetSignalingStateForTest(SignalStrategy::CONNECTED);
128 client_status_logger_->SetSignalingStateForTest(SignalStrategy::DISCONNECTED);
129 run_loop.Run();
130 }
131
132 TEST_F(ClientStatusLoggerTest, LogStatistics) {
133 base::RunLoop run_loop;
134 {
135 InSequence s;
136 EXPECT_CALL(signal_strategy_, GetLocalJid())
137 .WillRepeatedly(Return(kClientJid));
138 EXPECT_CALL(signal_strategy_, AddListener(_));
139 EXPECT_CALL(signal_strategy_, GetNextId());
140 EXPECT_CALL(signal_strategy_, SendStanzaPtr(
141 IsStatisticsLog()))
142 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
143 EXPECT_CALL(signal_strategy_, RemoveListener(_))
144 .WillOnce(QuitRunLoop(&run_loop))
145 .RetiresOnSaturation();
146 }
147
148 protocol::PerformanceTracker perf_tracker;
149 client_status_logger_->LogStatistics(&perf_tracker);
150
151 client_status_logger_->SetSignalingStateForTest(SignalStrategy::CONNECTED);
152 client_status_logger_->SetSignalingStateForTest(SignalStrategy::DISCONNECTED);
153 run_loop.Run();
154 }
155
156 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/client_status_logger.cc ('k') | remoting/client/client_telemetry_logger.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698