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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 host_change_notification_listener_.reset(new HostChangeNotificationListener( | 59 host_change_notification_listener_.reset(new HostChangeNotificationListener( |
60 &mock_listener_, kHostId, &signal_strategy_, kTestBotJid)); | 60 &mock_listener_, kHostId, &signal_strategy_, kTestBotJid)); |
61 } | 61 } |
62 | 62 |
63 void TearDown() override { | 63 void TearDown() override { |
64 host_change_notification_listener_.reset(); | 64 host_change_notification_listener_.reset(); |
65 EXPECT_TRUE(signal_strategy_listeners_.empty()); | 65 EXPECT_TRUE(signal_strategy_listeners_.empty()); |
66 } | 66 } |
67 | 67 |
68 scoped_ptr<XmlElement> GetNotificationStanza(std::string operation, | 68 std::unique_ptr<XmlElement> GetNotificationStanza(std::string operation, |
69 std::string hostId, | 69 std::string hostId, |
70 std::string botJid) { | 70 std::string botJid) { |
71 scoped_ptr<XmlElement> stanza(new XmlElement(buzz::QN_IQ)); | 71 std::unique_ptr<XmlElement> stanza(new XmlElement(buzz::QN_IQ)); |
72 stanza->AddAttr(QName(std::string(), "type"), "set"); | 72 stanza->AddAttr(QName(std::string(), "type"), "set"); |
73 XmlElement* host_changed = | 73 XmlElement* host_changed = |
74 new XmlElement(QName(kChromotingXmlNamespace, "host-changed")); | 74 new XmlElement(QName(kChromotingXmlNamespace, "host-changed")); |
75 host_changed->AddAttr(QName(kChromotingXmlNamespace, "operation"), | 75 host_changed->AddAttr(QName(kChromotingXmlNamespace, "operation"), |
76 operation); | 76 operation); |
77 host_changed->AddAttr(QName(kChromotingXmlNamespace, "hostid"), hostId); | 77 host_changed->AddAttr(QName(kChromotingXmlNamespace, "hostid"), hostId); |
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; | 81 return stanza; |
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 std::unique_ptr<HostChangeNotificationListener> |
| 88 host_change_notification_listener_; |
88 base::MessageLoop message_loop_; | 89 base::MessageLoop message_loop_; |
89 }; | 90 }; |
90 | 91 |
91 TEST_F(HostChangeNotificationListenerTest, ReceiveValidNotification) { | 92 TEST_F(HostChangeNotificationListenerTest, ReceiveValidNotification) { |
92 EXPECT_CALL(mock_listener_, OnHostDeleted()) | 93 EXPECT_CALL(mock_listener_, OnHostDeleted()) |
93 .WillOnce(Return()); | 94 .WillOnce(Return()); |
94 scoped_ptr<XmlElement> stanza = GetNotificationStanza( | 95 std::unique_ptr<XmlElement> stanza = |
95 "delete", kHostId, kTestBotJid); | 96 GetNotificationStanza("delete", kHostId, kTestBotJid); |
96 host_change_notification_listener_->OnSignalStrategyIncomingStanza( | 97 host_change_notification_listener_->OnSignalStrategyIncomingStanza( |
97 stanza.get()); | 98 stanza.get()); |
98 message_loop_.PostTask(FROM_HERE, | 99 message_loop_.PostTask(FROM_HERE, |
99 base::Bind(base::MessageLoop::QuitWhenIdleClosure())); | 100 base::Bind(base::MessageLoop::QuitWhenIdleClosure())); |
100 message_loop_.Run(); | 101 message_loop_.Run(); |
101 } | 102 } |
102 | 103 |
103 TEST_F(HostChangeNotificationListenerTest, ReceiveNotificationBeforeDelete) { | 104 TEST_F(HostChangeNotificationListenerTest, ReceiveNotificationBeforeDelete) { |
104 EXPECT_CALL(mock_listener_, OnHostDeleted()) | 105 EXPECT_CALL(mock_listener_, OnHostDeleted()) |
105 .Times(0); | 106 .Times(0); |
106 scoped_ptr<XmlElement> stanza = GetNotificationStanza( | 107 std::unique_ptr<XmlElement> stanza = |
107 "delete", kHostId, kTestBotJid); | 108 GetNotificationStanza("delete", kHostId, kTestBotJid); |
108 host_change_notification_listener_->OnSignalStrategyIncomingStanza( | 109 host_change_notification_listener_->OnSignalStrategyIncomingStanza( |
109 stanza.get()); | 110 stanza.get()); |
110 host_change_notification_listener_.reset(); | 111 host_change_notification_listener_.reset(); |
111 message_loop_.PostTask(FROM_HERE, | 112 message_loop_.PostTask(FROM_HERE, |
112 base::Bind(base::MessageLoop::QuitWhenIdleClosure())); | 113 base::Bind(base::MessageLoop::QuitWhenIdleClosure())); |
113 message_loop_.Run(); | 114 message_loop_.Run(); |
114 } | 115 } |
115 | 116 |
116 | 117 |
117 TEST_F(HostChangeNotificationListenerTest, ReceiveInvalidHostIdNotification) { | 118 TEST_F(HostChangeNotificationListenerTest, ReceiveInvalidHostIdNotification) { |
118 EXPECT_CALL(mock_listener_, OnHostDeleted()) | 119 EXPECT_CALL(mock_listener_, OnHostDeleted()) |
119 .Times(0); | 120 .Times(0); |
120 scoped_ptr<XmlElement> stanza = GetNotificationStanza( | 121 std::unique_ptr<XmlElement> stanza = |
121 "delete", "1", kTestBotJid); | 122 GetNotificationStanza("delete", "1", kTestBotJid); |
122 host_change_notification_listener_->OnSignalStrategyIncomingStanza( | 123 host_change_notification_listener_->OnSignalStrategyIncomingStanza( |
123 stanza.get()); | 124 stanza.get()); |
124 message_loop_.PostTask(FROM_HERE, | 125 message_loop_.PostTask(FROM_HERE, |
125 base::Bind(base::MessageLoop::QuitWhenIdleClosure())); | 126 base::Bind(base::MessageLoop::QuitWhenIdleClosure())); |
126 message_loop_.Run(); | 127 message_loop_.Run(); |
127 } | 128 } |
128 | 129 |
129 TEST_F(HostChangeNotificationListenerTest, ReceiveInvalidBotJidNotification) { | 130 TEST_F(HostChangeNotificationListenerTest, ReceiveInvalidBotJidNotification) { |
130 EXPECT_CALL(mock_listener_, OnHostDeleted()) | 131 EXPECT_CALL(mock_listener_, OnHostDeleted()) |
131 .Times(0); | 132 .Times(0); |
132 scoped_ptr<XmlElement> stanza = GetNotificationStanza( | 133 std::unique_ptr<XmlElement> stanza = GetNotificationStanza( |
133 "delete", kHostId, "notremotingbot@bot.talk.google.com"); | 134 "delete", kHostId, "notremotingbot@bot.talk.google.com"); |
134 host_change_notification_listener_->OnSignalStrategyIncomingStanza( | 135 host_change_notification_listener_->OnSignalStrategyIncomingStanza( |
135 stanza.get()); | 136 stanza.get()); |
136 message_loop_.PostTask(FROM_HERE, | 137 message_loop_.PostTask(FROM_HERE, |
137 base::Bind(base::MessageLoop::QuitWhenIdleClosure())); | 138 base::Bind(base::MessageLoop::QuitWhenIdleClosure())); |
138 message_loop_.Run(); | 139 message_loop_.Run(); |
139 } | 140 } |
140 | 141 |
141 TEST_F(HostChangeNotificationListenerTest, ReceiveNonDeleteNotification) { | 142 TEST_F(HostChangeNotificationListenerTest, ReceiveNonDeleteNotification) { |
142 EXPECT_CALL(mock_listener_, OnHostDeleted()) | 143 EXPECT_CALL(mock_listener_, OnHostDeleted()) |
143 .Times(0); | 144 .Times(0); |
144 scoped_ptr<XmlElement> stanza = GetNotificationStanza( | 145 std::unique_ptr<XmlElement> stanza = |
145 "update", kHostId, kTestBotJid); | 146 GetNotificationStanza("update", kHostId, kTestBotJid); |
146 host_change_notification_listener_->OnSignalStrategyIncomingStanza( | 147 host_change_notification_listener_->OnSignalStrategyIncomingStanza( |
147 stanza.get()); | 148 stanza.get()); |
148 message_loop_.PostTask(FROM_HERE, | 149 message_loop_.PostTask(FROM_HERE, |
149 base::Bind(base::MessageLoop::QuitWhenIdleClosure())); | 150 base::Bind(base::MessageLoop::QuitWhenIdleClosure())); |
150 message_loop_.Run(); | 151 message_loop_.Run(); |
151 } | 152 } |
152 | 153 |
153 } // namespace remoting | 154 } // namespace remoting |
OLD | NEW |