OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "device/bluetooth/bluez/bluetooth_advertisement_bluez.h" | 5 #include "device/bluetooth/bluez/bluetooth_advertisement_bluez.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 base::MessageLoopForIO message_loop_; | 193 base::MessageLoopForIO message_loop_; |
194 | 194 |
195 std::unique_ptr<TestAdvertisementObserver> observer_; | 195 std::unique_ptr<TestAdvertisementObserver> observer_; |
196 scoped_refptr<BluetoothAdapter> adapter_; | 196 scoped_refptr<BluetoothAdapter> adapter_; |
197 scoped_refptr<BluetoothAdvertisement> advertisement_; | 197 scoped_refptr<BluetoothAdvertisement> advertisement_; |
198 }; | 198 }; |
199 | 199 |
200 TEST_F(BluetoothAdvertisementBlueZTest, RegisterSucceeded) { | 200 TEST_F(BluetoothAdvertisementBlueZTest, RegisterSucceeded) { |
201 scoped_refptr<BluetoothAdvertisement> advertisement = CreateAdvertisement(); | 201 scoped_refptr<BluetoothAdvertisement> advertisement = CreateAdvertisement(); |
202 ExpectSuccess(); | 202 ExpectSuccess(); |
203 EXPECT_NE(nullptr, advertisement); | 203 EXPECT_TRUE(advertisement); |
204 | 204 |
205 UnregisterAdvertisement(advertisement); | 205 UnregisterAdvertisement(advertisement); |
206 ExpectSuccess(); | 206 ExpectSuccess(); |
207 } | 207 } |
208 | 208 |
209 TEST_F(BluetoothAdvertisementBlueZTest, DoubleRegisterFailed) { | 209 TEST_F(BluetoothAdvertisementBlueZTest, DoubleRegisterFailed) { |
210 scoped_refptr<BluetoothAdvertisement> advertisement = CreateAdvertisement(); | 210 scoped_refptr<BluetoothAdvertisement> advertisement = CreateAdvertisement(); |
211 ExpectSuccess(); | 211 ExpectSuccess(); |
212 EXPECT_NE(nullptr, advertisement); | 212 EXPECT_TRUE(advertisement); |
213 | 213 |
214 // Creating a second advertisement should give us an error. | 214 // Creating a second advertisement should give us an error. |
215 scoped_refptr<BluetoothAdvertisement> advertisement2 = CreateAdvertisement(); | 215 scoped_refptr<BluetoothAdvertisement> advertisement2 = CreateAdvertisement(); |
216 ExpectError(BluetoothAdvertisement::ERROR_ADVERTISEMENT_ALREADY_EXISTS); | 216 ExpectError(BluetoothAdvertisement::ERROR_ADVERTISEMENT_ALREADY_EXISTS); |
217 EXPECT_EQ(nullptr, advertisement2); | 217 EXPECT_FALSE(advertisement2); |
218 } | 218 } |
219 | 219 |
220 TEST_F(BluetoothAdvertisementBlueZTest, DoubleUnregisterFailed) { | 220 TEST_F(BluetoothAdvertisementBlueZTest, DoubleUnregisterFailed) { |
221 scoped_refptr<BluetoothAdvertisement> advertisement = CreateAdvertisement(); | 221 scoped_refptr<BluetoothAdvertisement> advertisement = CreateAdvertisement(); |
222 ExpectSuccess(); | 222 ExpectSuccess(); |
223 EXPECT_NE(nullptr, advertisement); | 223 EXPECT_TRUE(advertisement); |
224 | 224 |
225 UnregisterAdvertisement(advertisement); | 225 UnregisterAdvertisement(advertisement); |
226 ExpectSuccess(); | 226 ExpectSuccess(); |
227 | 227 |
228 // Unregistering an already unregistered advertisement should give us an | 228 // Unregistering an already unregistered advertisement should give us an |
229 // error. | 229 // error. |
230 UnregisterAdvertisement(advertisement); | 230 UnregisterAdvertisement(advertisement); |
231 ExpectError(BluetoothAdvertisement::ERROR_ADVERTISEMENT_DOES_NOT_EXIST); | 231 ExpectError(BluetoothAdvertisement::ERROR_ADVERTISEMENT_DOES_NOT_EXIST); |
232 } | 232 } |
233 | 233 |
234 TEST_F(BluetoothAdvertisementBlueZTest, UnregisterAfterReleasedFailed) { | 234 TEST_F(BluetoothAdvertisementBlueZTest, UnregisterAfterReleasedFailed) { |
235 scoped_refptr<BluetoothAdvertisement> advertisement = CreateAdvertisement(); | 235 scoped_refptr<BluetoothAdvertisement> advertisement = CreateAdvertisement(); |
236 ExpectSuccess(); | 236 ExpectSuccess(); |
237 EXPECT_NE(nullptr, advertisement); | 237 EXPECT_TRUE(advertisement); |
238 | 238 |
239 observer_.reset(new TestAdvertisementObserver(advertisement)); | 239 observer_.reset(new TestAdvertisementObserver(advertisement)); |
240 TriggerReleased(advertisement); | 240 TriggerReleased(advertisement); |
241 EXPECT_TRUE(observer_->released()); | 241 EXPECT_TRUE(observer_->released()); |
242 | 242 |
243 // Unregistering an advertisement that has been released should give us an | 243 // Unregistering an advertisement that has been released should give us an |
244 // error. | 244 // error. |
245 UnregisterAdvertisement(advertisement); | 245 UnregisterAdvertisement(advertisement); |
246 ExpectError(BluetoothAdvertisement::ERROR_ADVERTISEMENT_DOES_NOT_EXIST); | 246 ExpectError(BluetoothAdvertisement::ERROR_ADVERTISEMENT_DOES_NOT_EXIST); |
247 } | 247 } |
248 | 248 |
249 } // namespace bluez | 249 } // namespace bluez |
OLD | NEW |