OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "base/message_loop_proxy.h" | 6 #include "base/message_loop_proxy.h" |
7 #include "remoting/jingle_glue/mock_objects.h" | 7 #include "remoting/jingle_glue/mock_objects.h" |
8 #include "remoting/host/log_to_server.h" | 8 #include "remoting/host/log_to_server.h" |
9 #include "testing/gmock_mutant.h" | 9 #include "testing/gmock_mutant.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 24 message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
25 } | 25 } |
26 | 26 |
27 } // namespace | 27 } // namespace |
28 | 28 |
29 class LogToServerTest : public testing::Test { | 29 class LogToServerTest : public testing::Test { |
30 public: | 30 public: |
31 LogToServerTest() {} | 31 LogToServerTest() {} |
32 virtual void SetUp() OVERRIDE { | 32 virtual void SetUp() OVERRIDE { |
33 message_loop_proxy_ = base::MessageLoopProxy::current(); | 33 message_loop_proxy_ = base::MessageLoopProxy::current(); |
34 log_to_server_.reset(new LogToServer(message_loop_proxy_)); | 34 EXPECT_CALL(signal_strategy_, AddListener(_)); |
| 35 log_to_server_.reset(new LogToServer(&signal_strategy_)); |
| 36 EXPECT_CALL(signal_strategy_, RemoveListener(_)); |
35 } | 37 } |
36 | 38 |
37 protected: | 39 protected: |
| 40 MessageLoop message_loop_; |
38 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 41 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
| 42 MockSignalStrategy signal_strategy_; |
39 scoped_ptr<LogToServer> log_to_server_; | 43 scoped_ptr<LogToServer> log_to_server_; |
40 MessageLoop message_loop_; | |
41 MockSignalStrategy signal_strategy_; | |
42 }; | 44 }; |
43 | 45 |
44 TEST_F(LogToServerTest, SendNow) { | 46 TEST_F(LogToServerTest, SendNow) { |
45 { | 47 { |
46 InSequence s; | 48 InSequence s; |
47 EXPECT_CALL(signal_strategy_, GetLocalJid()) | 49 EXPECT_CALL(signal_strategy_, GetLocalJid()) |
48 .WillRepeatedly(Return("host@domain.com/1234")); | 50 .WillRepeatedly(Return("host@domain.com/1234")); |
49 EXPECT_CALL(signal_strategy_, AddListener(_)); | 51 EXPECT_CALL(signal_strategy_, AddListener(_)); |
50 EXPECT_CALL(signal_strategy_, GetNextId()); | 52 EXPECT_CALL(signal_strategy_, GetNextId()); |
51 EXPECT_CALL(signal_strategy_, SendStanza(_)) | 53 EXPECT_CALL(signal_strategy_, SendStanza(_)) |
52 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); | 54 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); |
53 EXPECT_CALL(signal_strategy_, RemoveListener(_)) | 55 EXPECT_CALL(signal_strategy_, RemoveListener(_)) |
54 .WillOnce(QuitMainMessageLoop(&message_loop_)) | 56 .WillOnce(QuitMainMessageLoop(&message_loop_)) |
55 .RetiresOnSaturation(); | 57 .RetiresOnSaturation(); |
56 } | 58 } |
57 log_to_server_->OnSignallingConnected(&signal_strategy_); | 59 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); |
58 log_to_server_->OnClientAuthenticated("client@domain.com/5678"); | 60 log_to_server_->OnClientAuthenticated("client@domain.com/5678"); |
59 log_to_server_->OnSignallingDisconnected(); | 61 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED); |
60 message_loop_.Run(); | 62 message_loop_.Run(); |
61 } | 63 } |
62 | 64 |
63 TEST_F(LogToServerTest, SendLater) { | 65 TEST_F(LogToServerTest, SendLater) { |
| 66 log_to_server_->OnClientAuthenticated("client@domain.com/5678"); |
64 { | 67 { |
65 InSequence s; | 68 InSequence s; |
66 EXPECT_CALL(signal_strategy_, GetLocalJid()) | 69 EXPECT_CALL(signal_strategy_, GetLocalJid()) |
67 .WillRepeatedly(Return("host@domain.com/1234")); | 70 .WillRepeatedly(Return("host@domain.com/1234")); |
68 EXPECT_CALL(signal_strategy_, AddListener(_)); | 71 EXPECT_CALL(signal_strategy_, AddListener(_)); |
69 EXPECT_CALL(signal_strategy_, GetNextId()); | 72 EXPECT_CALL(signal_strategy_, GetNextId()); |
70 EXPECT_CALL(signal_strategy_, SendStanza(_)) | 73 EXPECT_CALL(signal_strategy_, SendStanza(_)) |
71 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); | 74 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); |
72 EXPECT_CALL(signal_strategy_, RemoveListener(_)) | 75 EXPECT_CALL(signal_strategy_, RemoveListener(_)) |
73 .WillOnce(QuitMainMessageLoop(&message_loop_)) | 76 .WillOnce(QuitMainMessageLoop(&message_loop_)) |
74 .RetiresOnSaturation(); | 77 .RetiresOnSaturation(); |
75 } | 78 } |
76 log_to_server_->OnClientAuthenticated("client@domain.com/5678"); | 79 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); |
77 log_to_server_->OnSignallingConnected(&signal_strategy_); | 80 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED); |
78 log_to_server_->OnSignallingDisconnected(); | |
79 message_loop_.Run(); | 81 message_loop_.Run(); |
80 } | 82 } |
81 | 83 |
82 TEST_F(LogToServerTest, SendTwoEntriesLater) { | 84 TEST_F(LogToServerTest, SendTwoEntriesLater) { |
| 85 log_to_server_->OnClientAuthenticated("client@domain.com/5678"); |
| 86 log_to_server_->OnClientAuthenticated("client2@domain.com/6789"); |
83 { | 87 { |
84 InSequence s; | 88 InSequence s; |
85 EXPECT_CALL(signal_strategy_, GetLocalJid()) | 89 EXPECT_CALL(signal_strategy_, GetLocalJid()) |
86 .WillRepeatedly(Return("host@domain.com/1234")); | 90 .WillRepeatedly(Return("host@domain.com/1234")); |
87 EXPECT_CALL(signal_strategy_, AddListener(_)); | 91 EXPECT_CALL(signal_strategy_, AddListener(_)); |
88 EXPECT_CALL(signal_strategy_, GetNextId()); | 92 EXPECT_CALL(signal_strategy_, GetNextId()); |
89 EXPECT_CALL(signal_strategy_, SendStanza(_)) | 93 EXPECT_CALL(signal_strategy_, SendStanza(_)) |
90 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); | 94 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); |
91 EXPECT_CALL(signal_strategy_, RemoveListener(_)) | 95 EXPECT_CALL(signal_strategy_, RemoveListener(_)) |
92 .WillOnce(QuitMainMessageLoop(&message_loop_)) | 96 .WillOnce(QuitMainMessageLoop(&message_loop_)) |
93 .RetiresOnSaturation(); | 97 .RetiresOnSaturation(); |
94 } | 98 } |
95 log_to_server_->OnClientAuthenticated("client@domain.com/5678"); | 99 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED); |
96 log_to_server_->OnClientAuthenticated("client2@domain.com/6789"); | 100 log_to_server_->OnSignalStrategyStateChange(SignalStrategy::DISCONNECTED); |
97 log_to_server_->OnSignallingConnected(&signal_strategy_); | |
98 log_to_server_->OnSignallingDisconnected(); | |
99 message_loop_.Run(); | 101 message_loop_.Run(); |
100 } | 102 } |
101 | 103 |
102 } // namespace remoting | 104 } // namespace remoting |
OLD | NEW |