| 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 #include "remoting/signaling/log_to_server.h" | 5 #include "remoting/signaling/log_to_server.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/signaling/mock_signal_strategy.h" | 9 #include "remoting/signaling/mock_signal_strategy.h" |
| 10 #include "remoting/signaling/server_log_entry_unittest.h" | 10 #include "remoting/signaling/server_log_entry_unittest.h" |
| 11 #include "remoting/signaling/signaling_address.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 using buzz::XmlElement; | 15 using buzz::XmlElement; |
| 15 using buzz::QName; | 16 using buzz::QName; |
| 16 using testing::_; | 17 using testing::_; |
| 17 using testing::DeleteArg; | 18 using testing::DeleteArg; |
| 18 using testing::InSequence; | 19 using testing::InSequence; |
| 19 using testing::Return; | 20 using testing::Return; |
| 20 | 21 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 31 return false; | 32 return false; |
| 32 } | 33 } |
| 33 | 34 |
| 34 return entry->Attr(QName(std::string(), key)) == value; | 35 return entry->Attr(QName(std::string(), key)) == value; |
| 35 } | 36 } |
| 36 | 37 |
| 37 } // namespace | 38 } // namespace |
| 38 | 39 |
| 39 class LogToServerTest : public testing::Test { | 40 class LogToServerTest : public testing::Test { |
| 40 public: | 41 public: |
| 41 LogToServerTest() {} | 42 LogToServerTest() : signal_strategy_(SignalingAddress(kClientJid)) {} |
| 42 void SetUp() override { | 43 void SetUp() override { |
| 43 EXPECT_CALL(signal_strategy_, AddListener(_)); | 44 EXPECT_CALL(signal_strategy_, AddListener(_)); |
| 44 EXPECT_CALL(signal_strategy_, RemoveListener(_)); | 45 EXPECT_CALL(signal_strategy_, RemoveListener(_)); |
| 45 log_to_server_.reset( | 46 log_to_server_.reset( |
| 46 new LogToServer(ServerLogEntry::ME2ME, &signal_strategy_, kTestBotJid)); | 47 new LogToServer(ServerLogEntry::ME2ME, &signal_strategy_, kTestBotJid)); |
| 47 } | 48 } |
| 48 | 49 |
| 49 protected: | 50 protected: |
| 50 base::MessageLoop message_loop_; | 51 base::MessageLoop message_loop_; |
| 51 base::RunLoop run_loop_; | 52 base::RunLoop run_loop_; |
| 52 MockSignalStrategy signal_strategy_; | 53 MockSignalStrategy signal_strategy_; |
| 53 std::unique_ptr<LogToServer> log_to_server_; | 54 std::unique_ptr<LogToServer> log_to_server_; |
| 54 }; | 55 }; |
| 55 | 56 |
| 56 TEST_F(LogToServerTest, LogWhenConnected) { | 57 TEST_F(LogToServerTest, LogWhenConnected) { |
| 57 { | 58 { |
| 58 InSequence s; | 59 InSequence s; |
| 59 EXPECT_CALL(signal_strategy_, GetLocalJid()) | |
| 60 .WillRepeatedly(Return(kClientJid)); | |
| 61 EXPECT_CALL(signal_strategy_, AddListener(_)); | 60 EXPECT_CALL(signal_strategy_, AddListener(_)); |
| 62 EXPECT_CALL(signal_strategy_, GetNextId()); | 61 EXPECT_CALL(signal_strategy_, GetNextId()); |
| 63 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsLogEntry("a", "1"))) | 62 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsLogEntry("a", "1"))) |
| 64 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); | 63 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); |
| 65 EXPECT_CALL(signal_strategy_, GetNextId()); | 64 EXPECT_CALL(signal_strategy_, GetNextId()); |
| 66 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsLogEntry("b", "2"))) | 65 EXPECT_CALL(signal_strategy_, SendStanzaPtr(IsLogEntry("b", "2"))) |
| 67 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); | 66 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); |
| 68 EXPECT_CALL(signal_strategy_, RemoveListener(_)) | 67 EXPECT_CALL(signal_strategy_, RemoveListener(_)) |
| 69 .RetiresOnSaturation(); | 68 .RetiresOnSaturation(); |
| 70 } | 69 } |
| 71 | 70 |
| 72 ServerLogEntry entry1; | 71 ServerLogEntry entry1; |
| 73 ServerLogEntry entry2; | 72 ServerLogEntry entry2; |
| 74 entry1.Set("a", "1"); | 73 entry1.Set("a", "1"); |
| 75 entry2.Set("b", "2"); | 74 entry2.Set("b", "2"); |
| 76 log_to_server_->Log(entry1); | 75 log_to_server_->Log(entry1); |
| 77 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); | 76 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); |
| 78 log_to_server_->Log(entry2); | 77 log_to_server_->Log(entry2); |
| 79 run_loop_.RunUntilIdle(); | 78 run_loop_.RunUntilIdle(); |
| 80 } | 79 } |
| 81 | 80 |
| 82 TEST_F(LogToServerTest, DontLogWhenDisconnected) { | 81 TEST_F(LogToServerTest, DontLogWhenDisconnected) { |
| 83 EXPECT_CALL(signal_strategy_, GetLocalJid()) | |
| 84 .WillRepeatedly(Return(kClientJid)); | |
| 85 EXPECT_CALL(signal_strategy_, SendStanzaPtr(_)).Times(0); | 82 EXPECT_CALL(signal_strategy_, SendStanzaPtr(_)).Times(0); |
| 86 | 83 |
| 87 ServerLogEntry entry; | 84 ServerLogEntry entry; |
| 88 entry.Set("foo", "bar"); | 85 entry.Set("foo", "bar"); |
| 89 log_to_server_->Log(entry); | 86 log_to_server_->Log(entry); |
| 90 run_loop_.RunUntilIdle(); | 87 run_loop_.RunUntilIdle(); |
| 91 } | 88 } |
| 92 | 89 |
| 93 } // namespace remoting | 90 } // namespace remoting |
| OLD | NEW |