Remove unused did_first_* fields from InternalDocumentStateData.
[chromium-blink-merge.git] / remoting / client / client_status_logger_unittest.cc
blob5332a9c33a0d559173878a36638709124f9a8dda
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.
5 #include "remoting/client/client_status_logger.h"
7 #include "base/message_loop/message_loop.h"
8 #include "remoting/client/chromoting_stats.h"
9 #include "remoting/signaling/mock_signal_strategy.h"
10 #include "remoting/signaling/server_log_entry_unittest.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h"
15 using buzz::XmlElement;
16 using buzz::QName;
17 using remoting::protocol::ConnectionToHost;
18 using testing::_;
19 using testing::DeleteArg;
20 using testing::InSequence;
21 using testing::Return;
23 namespace remoting {
25 namespace {
27 ACTION_P(QuitMainMessageLoop, message_loop) {
28 message_loop->PostTask(FROM_HERE, base::MessageLoop::QuitClosure());
31 const char kTestBotJid[] = "remotingunittest@bot.talk.google.com";
32 const char kClientJid[] = "host@domain.com/1234";
34 MATCHER_P2(IsStateChange, new_state, error, "") {
35 XmlElement* entry = GetSingleLogEntryFromStanza(arg);
36 if (!entry) {
37 return false;
40 bool is_state_change = (
41 entry->Attr(QName(std::string(), "event-name")) == "session-state" &&
42 entry->Attr(QName(std::string(), "session-state")) == new_state &&
43 entry->Attr(QName(std::string(), "role")) == "client" &&
44 entry->Attr(QName(std::string(), "mode")) == "me2me");
45 if (!std::string(error).empty()) {
46 is_state_change = is_state_change &&
47 entry->Attr(QName(std::string(), "connection-error")) == error;
49 return is_state_change;
52 MATCHER(IsStatisticsLog, "") {
53 XmlElement* entry = GetSingleLogEntryFromStanza(arg);
54 if (!entry) {
55 return false;
58 return entry->Attr(QName(std::string(), "event-name")) ==
59 "connection-statistics";
62 } // namespace
64 class ClientStatusLoggerTest : public testing::Test {
65 public:
66 ClientStatusLoggerTest() {}
67 void SetUp() override {
68 EXPECT_CALL(signal_strategy_, AddListener(_));
69 EXPECT_CALL(signal_strategy_, RemoveListener(_));
70 client_status_logger_.reset(
71 new ClientStatusLogger(ServerLogEntry::ME2ME,
72 &signal_strategy_,
73 kTestBotJid));
76 protected:
77 base::MessageLoop message_loop_;
78 MockSignalStrategy signal_strategy_;
79 scoped_ptr<ClientStatusLogger> client_status_logger_;
82 TEST_F(ClientStatusLoggerTest, LogStateChange) {
84 InSequence s;
85 EXPECT_CALL(signal_strategy_, GetLocalJid())
86 .WillRepeatedly(Return(kClientJid));
87 EXPECT_CALL(signal_strategy_, AddListener(_));
88 EXPECT_CALL(signal_strategy_, GetNextId());
89 EXPECT_CALL(signal_strategy_, SendStanzaPtr(
90 IsStateChange("connected", std::string())))
91 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
92 EXPECT_CALL(signal_strategy_, RemoveListener(_))
93 .WillOnce(QuitMainMessageLoop(&message_loop_))
94 .RetiresOnSaturation();
96 client_status_logger_->LogSessionStateChange(ConnectionToHost::CONNECTED,
97 protocol::OK);
99 // Setting the state to CONNECTED causes the log to be sent. Setting the
100 // state to DISCONNECTED causes |signal_strategy_| to be cleaned up,
101 // which removes the listener and terminates the test.
102 client_status_logger_->SetSignalingStateForTest(SignalStrategy::CONNECTED);
103 client_status_logger_->SetSignalingStateForTest(SignalStrategy::DISCONNECTED);
104 message_loop_.Run();
107 TEST_F(ClientStatusLoggerTest, LogStateChangeError) {
109 InSequence s;
110 EXPECT_CALL(signal_strategy_, GetLocalJid())
111 .WillRepeatedly(Return(kClientJid));
112 EXPECT_CALL(signal_strategy_, AddListener(_));
113 EXPECT_CALL(signal_strategy_, GetNextId());
114 EXPECT_CALL(signal_strategy_, SendStanzaPtr(
115 IsStateChange("connection-failed", "host-is-offline")))
116 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
117 EXPECT_CALL(signal_strategy_, RemoveListener(_))
118 .WillOnce(QuitMainMessageLoop(&message_loop_))
119 .RetiresOnSaturation();
121 client_status_logger_->LogSessionStateChange(ConnectionToHost::FAILED,
122 protocol::PEER_IS_OFFLINE);
124 client_status_logger_->SetSignalingStateForTest(SignalStrategy::CONNECTED);
125 client_status_logger_->SetSignalingStateForTest(SignalStrategy::DISCONNECTED);
126 message_loop_.Run();
129 TEST_F(ClientStatusLoggerTest, LogStatistics) {
131 InSequence s;
132 EXPECT_CALL(signal_strategy_, GetLocalJid())
133 .WillRepeatedly(Return(kClientJid));
134 EXPECT_CALL(signal_strategy_, AddListener(_));
135 EXPECT_CALL(signal_strategy_, GetNextId());
136 EXPECT_CALL(signal_strategy_, SendStanzaPtr(
137 IsStatisticsLog()))
138 .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
139 EXPECT_CALL(signal_strategy_, RemoveListener(_))
140 .WillOnce(QuitMainMessageLoop(&message_loop_))
141 .RetiresOnSaturation();
144 ChromotingStats stats;
145 client_status_logger_->LogStatistics(&stats);
147 client_status_logger_->SetSignalingStateForTest(SignalStrategy::CONNECTED);
148 client_status_logger_->SetSignalingStateForTest(SignalStrategy::DISCONNECTED);
149 message_loop_.Run();
152 } // namespace remoting