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" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" |
| 13 #include "base/single_thread_task_runner.h" |
12 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
13 #include "remoting/base/constants.h" | 15 #include "remoting/base/constants.h" |
14 #include "remoting/signaling/mock_signal_strategy.h" | 16 #include "remoting/signaling/mock_signal_strategy.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | 19 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" |
18 #include "third_party/webrtc/libjingle/xmpp/constants.h" | 20 #include "third_party/webrtc/libjingle/xmpp/constants.h" |
19 | 21 |
20 using buzz::QName; | 22 using buzz::QName; |
21 using buzz::XmlElement; | 23 using buzz::XmlElement; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 base::MessageLoop message_loop_; | 91 base::MessageLoop message_loop_; |
90 }; | 92 }; |
91 | 93 |
92 TEST_F(HostChangeNotificationListenerTest, ReceiveValidNotification) { | 94 TEST_F(HostChangeNotificationListenerTest, ReceiveValidNotification) { |
93 EXPECT_CALL(mock_listener_, OnHostDeleted()) | 95 EXPECT_CALL(mock_listener_, OnHostDeleted()) |
94 .WillOnce(Return()); | 96 .WillOnce(Return()); |
95 std::unique_ptr<XmlElement> stanza = | 97 std::unique_ptr<XmlElement> stanza = |
96 GetNotificationStanza("delete", kHostId, kTestBotJid); | 98 GetNotificationStanza("delete", kHostId, kTestBotJid); |
97 host_change_notification_listener_->OnSignalStrategyIncomingStanza( | 99 host_change_notification_listener_->OnSignalStrategyIncomingStanza( |
98 stanza.get()); | 100 stanza.get()); |
99 message_loop_.PostTask(FROM_HERE, | 101 message_loop_.task_runner()->PostTask( |
100 base::Bind(base::MessageLoop::QuitWhenIdleClosure())); | 102 FROM_HERE, base::Bind(base::MessageLoop::QuitWhenIdleClosure())); |
101 message_loop_.Run(); | 103 base::RunLoop().Run(); |
102 } | 104 } |
103 | 105 |
104 TEST_F(HostChangeNotificationListenerTest, ReceiveNotificationBeforeDelete) { | 106 TEST_F(HostChangeNotificationListenerTest, ReceiveNotificationBeforeDelete) { |
105 EXPECT_CALL(mock_listener_, OnHostDeleted()) | 107 EXPECT_CALL(mock_listener_, OnHostDeleted()) |
106 .Times(0); | 108 .Times(0); |
107 std::unique_ptr<XmlElement> stanza = | 109 std::unique_ptr<XmlElement> stanza = |
108 GetNotificationStanza("delete", kHostId, kTestBotJid); | 110 GetNotificationStanza("delete", kHostId, kTestBotJid); |
109 host_change_notification_listener_->OnSignalStrategyIncomingStanza( | 111 host_change_notification_listener_->OnSignalStrategyIncomingStanza( |
110 stanza.get()); | 112 stanza.get()); |
111 host_change_notification_listener_.reset(); | 113 host_change_notification_listener_.reset(); |
112 message_loop_.PostTask(FROM_HERE, | 114 message_loop_.task_runner()->PostTask( |
113 base::Bind(base::MessageLoop::QuitWhenIdleClosure())); | 115 FROM_HERE, base::Bind(base::MessageLoop::QuitWhenIdleClosure())); |
114 message_loop_.Run(); | 116 base::RunLoop().Run(); |
115 } | 117 } |
116 | 118 |
117 | 119 |
118 TEST_F(HostChangeNotificationListenerTest, ReceiveInvalidHostIdNotification) { | 120 TEST_F(HostChangeNotificationListenerTest, ReceiveInvalidHostIdNotification) { |
119 EXPECT_CALL(mock_listener_, OnHostDeleted()) | 121 EXPECT_CALL(mock_listener_, OnHostDeleted()) |
120 .Times(0); | 122 .Times(0); |
121 std::unique_ptr<XmlElement> stanza = | 123 std::unique_ptr<XmlElement> stanza = |
122 GetNotificationStanza("delete", "1", kTestBotJid); | 124 GetNotificationStanza("delete", "1", kTestBotJid); |
123 host_change_notification_listener_->OnSignalStrategyIncomingStanza( | 125 host_change_notification_listener_->OnSignalStrategyIncomingStanza( |
124 stanza.get()); | 126 stanza.get()); |
125 message_loop_.PostTask(FROM_HERE, | 127 message_loop_.task_runner()->PostTask( |
126 base::Bind(base::MessageLoop::QuitWhenIdleClosure())); | 128 FROM_HERE, base::Bind(base::MessageLoop::QuitWhenIdleClosure())); |
127 message_loop_.Run(); | 129 base::RunLoop().Run(); |
128 } | 130 } |
129 | 131 |
130 TEST_F(HostChangeNotificationListenerTest, ReceiveInvalidBotJidNotification) { | 132 TEST_F(HostChangeNotificationListenerTest, ReceiveInvalidBotJidNotification) { |
131 EXPECT_CALL(mock_listener_, OnHostDeleted()) | 133 EXPECT_CALL(mock_listener_, OnHostDeleted()) |
132 .Times(0); | 134 .Times(0); |
133 std::unique_ptr<XmlElement> stanza = GetNotificationStanza( | 135 std::unique_ptr<XmlElement> stanza = GetNotificationStanza( |
134 "delete", kHostId, "notremotingbot@bot.talk.google.com"); | 136 "delete", kHostId, "notremotingbot@bot.talk.google.com"); |
135 host_change_notification_listener_->OnSignalStrategyIncomingStanza( | 137 host_change_notification_listener_->OnSignalStrategyIncomingStanza( |
136 stanza.get()); | 138 stanza.get()); |
137 message_loop_.PostTask(FROM_HERE, | 139 message_loop_.task_runner()->PostTask( |
138 base::Bind(base::MessageLoop::QuitWhenIdleClosure())); | 140 FROM_HERE, base::Bind(base::MessageLoop::QuitWhenIdleClosure())); |
139 message_loop_.Run(); | 141 base::RunLoop().Run(); |
140 } | 142 } |
141 | 143 |
142 TEST_F(HostChangeNotificationListenerTest, ReceiveNonDeleteNotification) { | 144 TEST_F(HostChangeNotificationListenerTest, ReceiveNonDeleteNotification) { |
143 EXPECT_CALL(mock_listener_, OnHostDeleted()) | 145 EXPECT_CALL(mock_listener_, OnHostDeleted()) |
144 .Times(0); | 146 .Times(0); |
145 std::unique_ptr<XmlElement> stanza = | 147 std::unique_ptr<XmlElement> stanza = |
146 GetNotificationStanza("update", kHostId, kTestBotJid); | 148 GetNotificationStanza("update", kHostId, kTestBotJid); |
147 host_change_notification_listener_->OnSignalStrategyIncomingStanza( | 149 host_change_notification_listener_->OnSignalStrategyIncomingStanza( |
148 stanza.get()); | 150 stanza.get()); |
149 message_loop_.PostTask(FROM_HERE, | 151 message_loop_.task_runner()->PostTask( |
150 base::Bind(base::MessageLoop::QuitWhenIdleClosure())); | 152 FROM_HERE, base::Bind(base::MessageLoop::QuitWhenIdleClosure())); |
151 message_loop_.Run(); | 153 base::RunLoop().Run(); |
152 } | 154 } |
153 | 155 |
154 } // namespace remoting | 156 } // namespace remoting |
OLD | NEW |