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

Unified Diff: remoting/client/client_status_logger_unittest.cc

Issue 320403002: Pull out common code from client and host versions of LogToServer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add unittests for LogToServer Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/client/client_status_logger.cc ('k') | remoting/client/jni/chromoting_jni_instance.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/client/client_status_logger_unittest.cc
diff --git a/remoting/client/client_status_logger_unittest.cc b/remoting/client/client_status_logger_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0bda85abd713e87143fc8a07869d63e6474dde91
--- /dev/null
+++ b/remoting/client/client_status_logger_unittest.cc
@@ -0,0 +1,155 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/client/client_status_logger.h"
+
+#include "base/message_loop/message_loop.h"
+#include "base/message_loop/message_loop_proxy.h"
+#include "remoting/client/chromoting_stats.h"
+#include "remoting/jingle_glue/mock_objects.h"
+#include "remoting/jingle_glue/server_log_entry_unittest.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
+
+using buzz::XmlElement;
+using buzz::QName;
+using remoting::protocol::ConnectionToHost;
+using testing::_;
+using testing::DeleteArg;
+using testing::InSequence;
+using testing::Return;
+
+namespace remoting {
+
+namespace {
+
+ACTION_P(QuitMainMessageLoop, message_loop) {
+ message_loop->PostTask(FROM_HERE, base::MessageLoop::QuitClosure());
+}
+
+const char kTestBotJid[] = "remotingunittest@bot.talk.google.com";
+const char kClientJid[] = "host@domain.com/1234";
+
+MATCHER_P2(IsStateChange, new_state, error, "") {
+ XmlElement* entry = GetSingleLogEntryFromStanza(arg);
+ if (!entry) {
+ return false;
+ }
+
+ bool is_state_change = (
+ entry->Attr(QName(std::string(), "event-name")) == "session-state" &&
+ entry->Attr(QName(std::string(), "session-state")) == new_state &&
+ entry->Attr(QName(std::string(), "role")) == "client" &&
+ entry->Attr(QName(std::string(), "mode")) == "me2me");
+ if (!std::string(error).empty()) {
+ is_state_change = is_state_change &&
+ entry->Attr(QName(std::string(), "connection-error")) == error;
+ }
+ return is_state_change;
+}
+
+MATCHER(IsStatisticsLog, "") {
+ XmlElement* entry = GetSingleLogEntryFromStanza(arg);
+ if (!entry) {
+ return false;
+ }
+
+ return entry->Attr(QName(std::string(), "event-name")) ==
+ "connection-statistics";
+}
+
+} // namespace
+
+class ClientStatusLoggerTest : public testing::Test {
+ public:
+ ClientStatusLoggerTest() {}
+ virtual void SetUp() OVERRIDE {
+ EXPECT_CALL(signal_strategy_, AddListener(_));
+ EXPECT_CALL(signal_strategy_, RemoveListener(_));
+ message_loop_proxy_ = base::MessageLoopProxy::current();
+ client_status_logger_.reset(
+ new ClientStatusLogger(ServerLogEntry::ME2ME,
+ &signal_strategy_,
+ kTestBotJid));
+ }
+
+ protected:
+ base::MessageLoop message_loop_;
+ scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
+ MockSignalStrategy signal_strategy_;
+ scoped_ptr<ClientStatusLogger> client_status_logger_;
+};
+
+TEST_F(ClientStatusLoggerTest, LogStateChange) {
+ {
+ InSequence s;
+ EXPECT_CALL(signal_strategy_, GetLocalJid())
+ .WillRepeatedly(Return(kClientJid));
+ EXPECT_CALL(signal_strategy_, AddListener(_));
+ EXPECT_CALL(signal_strategy_, GetNextId());
+ EXPECT_CALL(signal_strategy_, SendStanzaPtr(
+ IsStateChange("connected", std::string())))
+ .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
+ EXPECT_CALL(signal_strategy_, RemoveListener(_))
+ .WillOnce(QuitMainMessageLoop(&message_loop_))
+ .RetiresOnSaturation();
+ }
+ client_status_logger_->LogSessionStateChange(ConnectionToHost::CONNECTED,
+ protocol::OK);
+
+ // Setting the state to CONNECTED causes the log to be sent. Setting the
+ // state to DISCONNECTED causes |signal_strategy_| to be cleaned up,
+ // which removes the listener and terminates the test.
+ client_status_logger_->SetSignalingStateForTest(SignalStrategy::CONNECTED);
+ client_status_logger_->SetSignalingStateForTest(SignalStrategy::DISCONNECTED);
+ message_loop_.Run();
+}
+
+TEST_F(ClientStatusLoggerTest, LogStateChangeError) {
+ {
+ InSequence s;
+ EXPECT_CALL(signal_strategy_, GetLocalJid())
+ .WillRepeatedly(Return(kClientJid));
+ EXPECT_CALL(signal_strategy_, AddListener(_));
+ EXPECT_CALL(signal_strategy_, GetNextId());
+ EXPECT_CALL(signal_strategy_, SendStanzaPtr(
+ IsStateChange("connection-failed", "host-is-offline")))
+ .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
+ EXPECT_CALL(signal_strategy_, RemoveListener(_))
+ .WillOnce(QuitMainMessageLoop(&message_loop_))
+ .RetiresOnSaturation();
+ }
+ client_status_logger_->LogSessionStateChange(ConnectionToHost::FAILED,
+ protocol::PEER_IS_OFFLINE);
+
+ client_status_logger_->SetSignalingStateForTest(SignalStrategy::CONNECTED);
+ client_status_logger_->SetSignalingStateForTest(SignalStrategy::DISCONNECTED);
+ message_loop_.Run();
+}
+
+TEST_F(ClientStatusLoggerTest, LogStatistics) {
+ {
+ InSequence s;
+ EXPECT_CALL(signal_strategy_, GetLocalJid())
+ .WillRepeatedly(Return(kClientJid));
+ EXPECT_CALL(signal_strategy_, AddListener(_));
+ EXPECT_CALL(signal_strategy_, GetNextId());
+ EXPECT_CALL(signal_strategy_, SendStanzaPtr(
+ IsStatisticsLog()))
+ .WillOnce(DoAll(DeleteArg<0>(), Return(true)));
+ EXPECT_CALL(signal_strategy_, RemoveListener(_))
+ .WillOnce(QuitMainMessageLoop(&message_loop_))
+ .RetiresOnSaturation();
+ }
+
+ ChromotingStats stats;
+ client_status_logger_->LogStatistics(&stats);
+
+ client_status_logger_->SetSignalingStateForTest(SignalStrategy::CONNECTED);
+ client_status_logger_->SetSignalingStateForTest(SignalStrategy::DISCONNECTED);
+ message_loop_.Run();
+}
+
+} // namespace remoting
« no previous file with comments | « remoting/client/client_status_logger.cc ('k') | remoting/client/jni/chromoting_jni_instance.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698