OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/host/host_change_notification_listener.h" | 5 #include "remoting/host/host_change_notification_listener.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 stanza->AddElement(host_changed); | 78 stanza->AddElement(host_changed); |
79 stanza->AddAttr(buzz::QN_FROM, botJid); | 79 stanza->AddAttr(buzz::QN_FROM, botJid); |
80 stanza->AddAttr(buzz::QN_TO, kTestJid); | 80 stanza->AddAttr(buzz::QN_TO, kTestJid); |
81 return stanza.Pass(); | 81 return stanza.Pass(); |
82 } | 82 } |
83 | 83 |
84 MockListener mock_listener_; | 84 MockListener mock_listener_; |
85 MockSignalStrategy signal_strategy_; | 85 MockSignalStrategy signal_strategy_; |
86 std::set<SignalStrategy::Listener*> signal_strategy_listeners_; | 86 std::set<SignalStrategy::Listener*> signal_strategy_listeners_; |
87 scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_; | 87 scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_; |
88 MessageLoop message_loop_; | 88 base::MessageLoop message_loop_; |
89 }; | 89 }; |
90 | 90 |
91 TEST_F(HostChangeNotificationListenerTest, ReceiveValidNotification) { | 91 TEST_F(HostChangeNotificationListenerTest, ReceiveValidNotification) { |
92 EXPECT_CALL(mock_listener_, OnHostDeleted()) | 92 EXPECT_CALL(mock_listener_, OnHostDeleted()) |
93 .WillOnce(Return()); | 93 .WillOnce(Return()); |
94 scoped_ptr<XmlElement> stanza = GetNotificationStanza( | 94 scoped_ptr<XmlElement> stanza = GetNotificationStanza( |
95 "delete", kHostId, kTestBotJid); | 95 "delete", kHostId, kTestBotJid); |
96 host_change_notification_listener_->OnSignalStrategyIncomingStanza( | 96 host_change_notification_listener_->OnSignalStrategyIncomingStanza( |
97 stanza.get()); | 97 stanza.get()); |
98 message_loop_.PostTask(FROM_HERE, base::Bind(MessageLoop::QuitClosure())); | 98 message_loop_.PostTask(FROM_HERE, |
| 99 base::Bind(base::MessageLoop::QuitClosure())); |
99 message_loop_.Run(); | 100 message_loop_.Run(); |
100 } | 101 } |
101 | 102 |
102 TEST_F(HostChangeNotificationListenerTest, ReceiveNotificationBeforeDelete) { | 103 TEST_F(HostChangeNotificationListenerTest, ReceiveNotificationBeforeDelete) { |
103 EXPECT_CALL(mock_listener_, OnHostDeleted()) | 104 EXPECT_CALL(mock_listener_, OnHostDeleted()) |
104 .Times(0); | 105 .Times(0); |
105 scoped_ptr<XmlElement> stanza = GetNotificationStanza( | 106 scoped_ptr<XmlElement> stanza = GetNotificationStanza( |
106 "delete", kHostId, kTestBotJid); | 107 "delete", kHostId, kTestBotJid); |
107 host_change_notification_listener_->OnSignalStrategyIncomingStanza( | 108 host_change_notification_listener_->OnSignalStrategyIncomingStanza( |
108 stanza.get()); | 109 stanza.get()); |
109 host_change_notification_listener_.reset(); | 110 host_change_notification_listener_.reset(); |
110 message_loop_.PostTask(FROM_HERE, base::Bind(MessageLoop::QuitClosure())); | 111 message_loop_.PostTask(FROM_HERE, |
| 112 base::Bind(base::MessageLoop::QuitClosure())); |
111 message_loop_.Run(); | 113 message_loop_.Run(); |
112 } | 114 } |
113 | 115 |
114 | 116 |
115 TEST_F(HostChangeNotificationListenerTest, ReceiveInvalidHostIdNotification) { | 117 TEST_F(HostChangeNotificationListenerTest, ReceiveInvalidHostIdNotification) { |
116 EXPECT_CALL(mock_listener_, OnHostDeleted()) | 118 EXPECT_CALL(mock_listener_, OnHostDeleted()) |
117 .Times(0); | 119 .Times(0); |
118 scoped_ptr<XmlElement> stanza = GetNotificationStanza( | 120 scoped_ptr<XmlElement> stanza = GetNotificationStanza( |
119 "delete", "1", kTestBotJid); | 121 "delete", "1", kTestBotJid); |
120 host_change_notification_listener_->OnSignalStrategyIncomingStanza( | 122 host_change_notification_listener_->OnSignalStrategyIncomingStanza( |
121 stanza.get()); | 123 stanza.get()); |
122 message_loop_.PostTask(FROM_HERE, base::Bind(MessageLoop::QuitClosure())); | 124 message_loop_.PostTask(FROM_HERE, |
| 125 base::Bind(base::MessageLoop::QuitClosure())); |
123 message_loop_.Run(); | 126 message_loop_.Run(); |
124 } | 127 } |
125 | 128 |
126 TEST_F(HostChangeNotificationListenerTest, ReceiveInvalidBotJidNotification) { | 129 TEST_F(HostChangeNotificationListenerTest, ReceiveInvalidBotJidNotification) { |
127 EXPECT_CALL(mock_listener_, OnHostDeleted()) | 130 EXPECT_CALL(mock_listener_, OnHostDeleted()) |
128 .Times(0); | 131 .Times(0); |
129 scoped_ptr<XmlElement> stanza = GetNotificationStanza( | 132 scoped_ptr<XmlElement> stanza = GetNotificationStanza( |
130 "delete", kHostId, "notremotingbot@bot.talk.google.com"); | 133 "delete", kHostId, "notremotingbot@bot.talk.google.com"); |
131 host_change_notification_listener_->OnSignalStrategyIncomingStanza( | 134 host_change_notification_listener_->OnSignalStrategyIncomingStanza( |
132 stanza.get()); | 135 stanza.get()); |
133 message_loop_.PostTask(FROM_HERE, base::Bind(MessageLoop::QuitClosure())); | 136 message_loop_.PostTask(FROM_HERE, |
| 137 base::Bind(base::MessageLoop::QuitClosure())); |
134 message_loop_.Run(); | 138 message_loop_.Run(); |
135 } | 139 } |
136 | 140 |
137 TEST_F(HostChangeNotificationListenerTest, ReceiveNonDeleteNotification) { | 141 TEST_F(HostChangeNotificationListenerTest, ReceiveNonDeleteNotification) { |
138 EXPECT_CALL(mock_listener_, OnHostDeleted()) | 142 EXPECT_CALL(mock_listener_, OnHostDeleted()) |
139 .Times(0); | 143 .Times(0); |
140 scoped_ptr<XmlElement> stanza = GetNotificationStanza( | 144 scoped_ptr<XmlElement> stanza = GetNotificationStanza( |
141 "update", kHostId, kTestBotJid); | 145 "update", kHostId, kTestBotJid); |
142 host_change_notification_listener_->OnSignalStrategyIncomingStanza( | 146 host_change_notification_listener_->OnSignalStrategyIncomingStanza( |
143 stanza.get()); | 147 stanza.get()); |
144 message_loop_.PostTask(FROM_HERE, base::Bind(MessageLoop::QuitClosure())); | 148 message_loop_.PostTask(FROM_HERE, |
| 149 base::Bind(base::MessageLoop::QuitClosure())); |
145 message_loop_.Run(); | 150 message_loop_.Run(); |
146 } | 151 } |
147 | 152 |
148 } // namespace remoting | 153 } // namespace remoting |
OLD | NEW |