OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/message_loop.h" | |
6 #include "base/message_loop_proxy.h" | |
7 #include "remoting/jingle_glue/mock_objects.h" | |
8 #include "remoting/host/log_to_server.h" | |
9 #include "testing/gmock_mutant.h" | |
10 #include "testing/gmock/include/gmock/gmock.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 using testing::_; | |
14 using testing::InSequence; | |
15 | |
16 namespace remoting { | |
17 | |
18 namespace { | |
19 | |
20 ACTION_P(QuitMainMessageLoop, message_loop) { | |
21 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | |
22 } | |
23 | |
24 } | |
Sergey Ulanov
2011/11/22 02:01:43
// namespace
simonmorris
2011/11/22 23:27:35
Done.
| |
25 | |
26 class LogToServerTest : public testing::Test { | |
27 public: | |
28 LogToServerTest() {} | |
29 virtual void SetUp() OVERRIDE { | |
30 message_loop_proxy_ = base::MessageLoopProxy::current(); | |
31 log_to_server_.reset(new LogToServer(message_loop_proxy_)); | |
32 } | |
33 | |
34 protected: | |
35 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | |
36 scoped_ptr<LogToServer> log_to_server_; | |
37 MessageLoop message_loop_; | |
38 MockSignalStrategy signal_strategy_; | |
39 }; | |
40 | |
41 TEST_F(LogToServerTest, SendNow) { | |
42 { | |
43 InSequence s; | |
44 EXPECT_CALL(signal_strategy_, AddListener(_)); | |
45 EXPECT_CALL(signal_strategy_, GetNextId()); | |
46 EXPECT_CALL(signal_strategy_, SendStanza(_)); | |
47 EXPECT_CALL(signal_strategy_, RemoveListener(_)) | |
48 .WillOnce(QuitMainMessageLoop(&message_loop_)) | |
49 .RetiresOnSaturation(); | |
50 } | |
51 log_to_server_->OnSignallingConnected(&signal_strategy_, | |
52 "host@domain.com/1234"); | |
53 log_to_server_->OnClientAuthenticated("client@domain.com/5678"); | |
54 log_to_server_->OnSignallingDisconnected(); | |
55 message_loop_.Run(); | |
56 } | |
57 | |
58 TEST_F(LogToServerTest, SendLater) { | |
59 { | |
60 InSequence s; | |
61 EXPECT_CALL(signal_strategy_, AddListener(_)); | |
62 EXPECT_CALL(signal_strategy_, GetNextId()); | |
63 EXPECT_CALL(signal_strategy_, SendStanza(_)); | |
64 EXPECT_CALL(signal_strategy_, RemoveListener(_)) | |
65 .WillOnce(QuitMainMessageLoop(&message_loop_)) | |
66 .RetiresOnSaturation(); | |
67 } | |
68 log_to_server_->OnClientAuthenticated("client@domain.com/5678"); | |
69 log_to_server_->OnSignallingConnected(&signal_strategy_, | |
70 "host@domain.com/1234"); | |
71 log_to_server_->OnSignallingDisconnected(); | |
72 message_loop_.Run(); | |
73 } | |
74 | |
75 TEST_F(LogToServerTest, SendTwoEntriesLater) { | |
76 { | |
77 InSequence s; | |
78 EXPECT_CALL(signal_strategy_, AddListener(_)); | |
79 EXPECT_CALL(signal_strategy_, GetNextId()); | |
80 EXPECT_CALL(signal_strategy_, SendStanza(_)); | |
81 EXPECT_CALL(signal_strategy_, RemoveListener(_)) | |
82 .WillOnce(QuitMainMessageLoop(&message_loop_)) | |
83 .RetiresOnSaturation(); | |
84 } | |
85 log_to_server_->OnClientAuthenticated("client@domain.com/5678"); | |
86 log_to_server_->OnClientAuthenticated("client2@domain.com/6789"); | |
87 log_to_server_->OnSignallingConnected(&signal_strategy_, | |
88 "host@domain.com/1234"); | |
89 log_to_server_->OnSignallingDisconnected(); | |
90 message_loop_.Run(); | |
91 } | |
92 | |
93 } // namespace remoting | |
OLD | NEW |