Move InMemoryURLIndex into chrome/browser/autocomplete
[chromium-blink-merge.git] / device / bluetooth / bluetooth_adapter_win_unittest.cc
blob4a7abd7c8b2df49707f3f67bfdf625e7ddfe86bb
1 // Copyright (c) 2012 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.
5 #include <string>
7 #include "base/bind.h"
8 #include "base/memory/ref_counted.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "base/test/test_simple_task_runner.h"
11 #include "device/bluetooth/bluetooth_adapter.h"
12 #include "device/bluetooth/bluetooth_adapter_win.h"
13 #include "device/bluetooth/bluetooth_device.h"
14 #include "device/bluetooth/bluetooth_task_manager_win.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 namespace {
19 const char kAdapterAddress[] = "A1:B2:C3:D4:E5:F6";
20 const char kAdapterName[] = "Bluetooth Adapter Name";
22 const char kTestAudioSdpName[] = "Audio";
23 const char kTestAudioSdpName2[] = "Audio2";
24 const char kTestAudioSdpBytes[] =
25 "35510900000a00010001090001350319110a09000435103506190100090019350619001909"
26 "010209000535031910020900093508350619110d090102090100250c417564696f20536f75"
27 "726365090311090001";
28 const device::BluetoothUUID kTestAudioSdpUuid("110a");
30 void MakeDeviceState(const std::string& name,
31 const std::string& address,
32 device::BluetoothTaskManagerWin::DeviceState* state) {
33 state->name = name;
34 state->address = address;
35 state->bluetooth_class = 0;
36 state->authenticated = false;
37 state->connected = false;
40 class AdapterObserver : public device::BluetoothAdapter::Observer {
41 public:
42 AdapterObserver() { ResetCounters(); }
44 void ResetCounters() {
45 num_present_changed_ = 0;
46 num_powered_changed_ = 0;
47 num_discovering_changed_ = 0;
48 num_device_added_ = 0;
49 num_device_removed_ = 0;
50 num_device_changed_ = 0;
53 virtual void AdapterPresentChanged(
54 device::BluetoothAdapter* adapter, bool present) override {
55 num_present_changed_++;
58 virtual void AdapterPoweredChanged(
59 device::BluetoothAdapter* adapter, bool powered) override {
60 num_powered_changed_++;
63 virtual void AdapterDiscoveringChanged(
64 device::BluetoothAdapter* adapter, bool discovering) override {
65 num_discovering_changed_++;
68 virtual void DeviceAdded(
69 device::BluetoothAdapter* adapter,
70 device::BluetoothDevice* device) override {
71 num_device_added_++;
74 virtual void DeviceRemoved(device::BluetoothAdapter* adapter,
75 device::BluetoothDevice* device) override {
76 num_device_removed_++;
79 virtual void DeviceChanged(device::BluetoothAdapter* adapter,
80 device::BluetoothDevice* device) override {
81 num_device_changed_++;
84 int num_present_changed() const { return num_present_changed_; }
86 int num_powered_changed() const { return num_powered_changed_; }
88 int num_discovering_changed() const { return num_discovering_changed_; }
90 int num_device_added() const { return num_device_added_; }
92 int num_device_removed() const { return num_device_removed_; }
94 int num_device_changed() const { return num_device_changed_; }
96 private:
97 int num_present_changed_;
98 int num_powered_changed_;
99 int num_discovering_changed_;
100 int num_device_added_;
101 int num_device_removed_;
102 int num_device_changed_;
105 } // namespace
107 namespace device {
109 class BluetoothAdapterWinTest : public testing::Test {
110 public:
111 BluetoothAdapterWinTest()
112 : ui_task_runner_(new base::TestSimpleTaskRunner()),
113 bluetooth_task_runner_(new base::TestSimpleTaskRunner()),
114 adapter_(new BluetoothAdapterWin(
115 base::Bind(&BluetoothAdapterWinTest::RunInitCallback,
116 base::Unretained(this)))),
117 adapter_win_(static_cast<BluetoothAdapterWin*>(adapter_.get())),
118 init_callback_called_(false) {
119 adapter_win_->InitForTest(ui_task_runner_, bluetooth_task_runner_);
122 virtual void SetUp() override {
123 adapter_win_->AddObserver(&adapter_observer_);
124 num_start_discovery_callbacks_ = 0;
125 num_start_discovery_error_callbacks_ = 0;
126 num_stop_discovery_callbacks_ = 0;
127 num_stop_discovery_error_callbacks_ = 0;
130 virtual void TearDown() override {
131 adapter_win_->RemoveObserver(&adapter_observer_);
134 void RunInitCallback() {
135 init_callback_called_ = true;
138 void IncrementNumStartDiscoveryCallbacks() {
139 num_start_discovery_callbacks_++;
142 void IncrementNumStartDiscoveryErrorCallbacks() {
143 num_start_discovery_error_callbacks_++;
146 void IncrementNumStopDiscoveryCallbacks() {
147 num_stop_discovery_callbacks_++;
150 void IncrementNumStopDiscoveryErrorCallbacks() {
151 num_stop_discovery_error_callbacks_++;
154 void CallAddDiscoverySession(
155 const base::Closure& callback,
156 const BluetoothAdapter::ErrorCallback& error_callback) {
157 adapter_win_->AddDiscoverySession(callback, error_callback);
160 void CallRemoveDiscoverySession(
161 const base::Closure& callback,
162 const BluetoothAdapter::ErrorCallback& error_callback) {
163 adapter_win_->RemoveDiscoverySession(callback, error_callback);
166 protected:
167 scoped_refptr<base::TestSimpleTaskRunner> ui_task_runner_;
168 scoped_refptr<base::TestSimpleTaskRunner> bluetooth_task_runner_;
169 scoped_refptr<BluetoothAdapter> adapter_;
170 BluetoothAdapterWin* adapter_win_;
171 AdapterObserver adapter_observer_;
172 bool init_callback_called_;
173 int num_start_discovery_callbacks_;
174 int num_start_discovery_error_callbacks_;
175 int num_stop_discovery_callbacks_;
176 int num_stop_discovery_error_callbacks_;
179 TEST_F(BluetoothAdapterWinTest, AdapterNotPresent) {
180 BluetoothTaskManagerWin::AdapterState state;
181 adapter_win_->AdapterStateChanged(state);
182 EXPECT_FALSE(adapter_win_->IsPresent());
185 TEST_F(BluetoothAdapterWinTest, AdapterPresent) {
186 BluetoothTaskManagerWin::AdapterState state;
187 state.address = kAdapterAddress;
188 state.name = kAdapterName;
189 adapter_win_->AdapterStateChanged(state);
190 EXPECT_TRUE(adapter_win_->IsPresent());
193 TEST_F(BluetoothAdapterWinTest, AdapterPresentChanged) {
194 BluetoothTaskManagerWin::AdapterState state;
195 state.address = kAdapterAddress;
196 state.name = kAdapterName;
197 adapter_win_->AdapterStateChanged(state);
198 EXPECT_EQ(1, adapter_observer_.num_present_changed());
199 adapter_win_->AdapterStateChanged(state);
200 EXPECT_EQ(1, adapter_observer_.num_present_changed());
201 BluetoothTaskManagerWin::AdapterState empty_state;
202 adapter_win_->AdapterStateChanged(empty_state);
203 EXPECT_EQ(2, adapter_observer_.num_present_changed());
206 TEST_F(BluetoothAdapterWinTest, AdapterPoweredChanged) {
207 BluetoothTaskManagerWin::AdapterState state;
208 state.powered = true;
209 adapter_win_->AdapterStateChanged(state);
210 EXPECT_EQ(1, adapter_observer_.num_powered_changed());
211 adapter_win_->AdapterStateChanged(state);
212 EXPECT_EQ(1, adapter_observer_.num_powered_changed());
213 state.powered = false;
214 adapter_win_->AdapterStateChanged(state);
215 EXPECT_EQ(2, adapter_observer_.num_powered_changed());
218 TEST_F(BluetoothAdapterWinTest, AdapterInitialized) {
219 EXPECT_FALSE(adapter_win_->IsInitialized());
220 EXPECT_FALSE(init_callback_called_);
221 BluetoothTaskManagerWin::AdapterState state;
222 adapter_win_->AdapterStateChanged(state);
223 EXPECT_TRUE(adapter_win_->IsInitialized());
224 EXPECT_TRUE(init_callback_called_);
227 TEST_F(BluetoothAdapterWinTest, SingleStartDiscovery) {
228 bluetooth_task_runner_->ClearPendingTasks();
229 CallAddDiscoverySession(
230 base::Bind(&BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks,
231 base::Unretained(this)),
232 BluetoothAdapter::ErrorCallback());
233 EXPECT_TRUE(ui_task_runner_->GetPendingTasks().empty());
234 EXPECT_EQ(1, bluetooth_task_runner_->GetPendingTasks().size());
235 EXPECT_FALSE(adapter_->IsDiscovering());
236 EXPECT_EQ(0, num_start_discovery_callbacks_);
237 adapter_win_->DiscoveryStarted(true);
238 ui_task_runner_->RunPendingTasks();
239 EXPECT_TRUE(adapter_->IsDiscovering());
240 EXPECT_EQ(1, num_start_discovery_callbacks_);
241 EXPECT_EQ(1, adapter_observer_.num_discovering_changed());
244 TEST_F(BluetoothAdapterWinTest, SingleStartDiscoveryFailure) {
245 CallAddDiscoverySession(
246 base::Closure(),
247 base::Bind(
248 &BluetoothAdapterWinTest::IncrementNumStartDiscoveryErrorCallbacks,
249 base::Unretained(this)));
250 adapter_win_->DiscoveryStarted(false);
251 ui_task_runner_->RunPendingTasks();
252 EXPECT_FALSE(adapter_->IsDiscovering());
253 EXPECT_EQ(1, num_start_discovery_error_callbacks_);
254 EXPECT_EQ(0, adapter_observer_.num_discovering_changed());
257 TEST_F(BluetoothAdapterWinTest, MultipleStartDiscoveries) {
258 bluetooth_task_runner_->ClearPendingTasks();
259 int num_discoveries = 5;
260 for (int i = 0; i < num_discoveries; i++) {
261 CallAddDiscoverySession(
262 base::Bind(
263 &BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks,
264 base::Unretained(this)),
265 BluetoothAdapter::ErrorCallback());
266 EXPECT_EQ(1, bluetooth_task_runner_->GetPendingTasks().size());
268 EXPECT_TRUE(ui_task_runner_->GetPendingTasks().empty());
269 EXPECT_FALSE(adapter_->IsDiscovering());
270 EXPECT_EQ(0, num_start_discovery_callbacks_);
271 adapter_win_->DiscoveryStarted(true);
272 ui_task_runner_->RunPendingTasks();
273 EXPECT_TRUE(adapter_->IsDiscovering());
274 EXPECT_EQ(num_discoveries, num_start_discovery_callbacks_);
275 EXPECT_EQ(1, adapter_observer_.num_discovering_changed());
278 TEST_F(BluetoothAdapterWinTest, MultipleStartDiscoveriesFailure) {
279 int num_discoveries = 5;
280 for (int i = 0; i < num_discoveries; i++) {
281 CallAddDiscoverySession(
282 base::Closure(),
283 base::Bind(
284 &BluetoothAdapterWinTest::IncrementNumStartDiscoveryErrorCallbacks,
285 base::Unretained(this)));
287 adapter_win_->DiscoveryStarted(false);
288 ui_task_runner_->RunPendingTasks();
289 EXPECT_FALSE(adapter_->IsDiscovering());
290 EXPECT_EQ(num_discoveries, num_start_discovery_error_callbacks_);
291 EXPECT_EQ(0, adapter_observer_.num_discovering_changed());
294 TEST_F(BluetoothAdapterWinTest, MultipleStartDiscoveriesAfterDiscovering) {
295 CallAddDiscoverySession(
296 base::Bind(&BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks,
297 base::Unretained(this)),
298 BluetoothAdapter::ErrorCallback());
299 adapter_win_->DiscoveryStarted(true);
300 ui_task_runner_->RunPendingTasks();
301 EXPECT_TRUE(adapter_->IsDiscovering());
302 EXPECT_EQ(1, num_start_discovery_callbacks_);
304 bluetooth_task_runner_->ClearPendingTasks();
305 for (int i = 0; i < 5; i++) {
306 int num_start_discovery_callbacks = num_start_discovery_callbacks_;
307 CallAddDiscoverySession(
308 base::Bind(
309 &BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks,
310 base::Unretained(this)),
311 BluetoothAdapter::ErrorCallback());
312 EXPECT_TRUE(adapter_->IsDiscovering());
313 EXPECT_TRUE(bluetooth_task_runner_->GetPendingTasks().empty());
314 EXPECT_TRUE(ui_task_runner_->GetPendingTasks().empty());
315 EXPECT_EQ(num_start_discovery_callbacks + 1,
316 num_start_discovery_callbacks_);
318 EXPECT_EQ(1, adapter_observer_.num_discovering_changed());
321 TEST_F(BluetoothAdapterWinTest, StartDiscoveryAfterDiscoveringFailure) {
322 CallAddDiscoverySession(
323 base::Closure(),
324 base::Bind(
325 &BluetoothAdapterWinTest::IncrementNumStartDiscoveryErrorCallbacks,
326 base::Unretained(this)));
327 adapter_win_->DiscoveryStarted(false);
328 ui_task_runner_->RunPendingTasks();
329 EXPECT_FALSE(adapter_->IsDiscovering());
330 EXPECT_EQ(1, num_start_discovery_error_callbacks_);
332 CallAddDiscoverySession(
333 base::Bind(&BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks,
334 base::Unretained(this)),
335 BluetoothAdapter::ErrorCallback());
336 adapter_win_->DiscoveryStarted(true);
337 ui_task_runner_->RunPendingTasks();
338 EXPECT_TRUE(adapter_->IsDiscovering());
339 EXPECT_EQ(1, num_start_discovery_callbacks_);
342 TEST_F(BluetoothAdapterWinTest, SingleStopDiscovery) {
343 CallAddDiscoverySession(
344 base::Closure(), BluetoothAdapter::ErrorCallback());
345 adapter_win_->DiscoveryStarted(true);
346 ui_task_runner_->ClearPendingTasks();
347 CallRemoveDiscoverySession(
348 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks,
349 base::Unretained(this)),
350 BluetoothAdapter::ErrorCallback());
351 EXPECT_TRUE(adapter_->IsDiscovering());
352 EXPECT_EQ(0, num_stop_discovery_callbacks_);
353 bluetooth_task_runner_->ClearPendingTasks();
354 adapter_win_->DiscoveryStopped();
355 ui_task_runner_->RunPendingTasks();
356 EXPECT_FALSE(adapter_->IsDiscovering());
357 EXPECT_EQ(1, num_stop_discovery_callbacks_);
358 EXPECT_TRUE(bluetooth_task_runner_->GetPendingTasks().empty());
359 EXPECT_EQ(2, adapter_observer_.num_discovering_changed());
362 TEST_F(BluetoothAdapterWinTest, MultipleStopDiscoveries) {
363 int num_discoveries = 5;
364 for (int i = 0; i < num_discoveries; i++) {
365 CallAddDiscoverySession(
366 base::Closure(), BluetoothAdapter::ErrorCallback());
368 adapter_win_->DiscoveryStarted(true);
369 ui_task_runner_->ClearPendingTasks();
370 bluetooth_task_runner_->ClearPendingTasks();
371 for (int i = 0; i < num_discoveries - 1; i++) {
372 CallRemoveDiscoverySession(
373 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks,
374 base::Unretained(this)),
375 BluetoothAdapter::ErrorCallback());
376 EXPECT_TRUE(bluetooth_task_runner_->GetPendingTasks().empty());
377 ui_task_runner_->RunPendingTasks();
378 EXPECT_EQ(i + 1, num_stop_discovery_callbacks_);
380 CallRemoveDiscoverySession(
381 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks,
382 base::Unretained(this)),
383 BluetoothAdapter::ErrorCallback());
384 EXPECT_EQ(1, bluetooth_task_runner_->GetPendingTasks().size());
385 EXPECT_TRUE(adapter_->IsDiscovering());
386 adapter_win_->DiscoveryStopped();
387 ui_task_runner_->RunPendingTasks();
388 EXPECT_FALSE(adapter_->IsDiscovering());
389 EXPECT_EQ(num_discoveries, num_stop_discovery_callbacks_);
390 EXPECT_EQ(2, adapter_observer_.num_discovering_changed());
393 TEST_F(BluetoothAdapterWinTest,
394 StartDiscoveryAndStartDiscoveryAndStopDiscoveries) {
395 CallAddDiscoverySession(
396 base::Bind(&BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks,
397 base::Unretained(this)),
398 BluetoothAdapter::ErrorCallback());
399 adapter_win_->DiscoveryStarted(true);
400 CallAddDiscoverySession(
401 base::Bind(&BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks,
402 base::Unretained(this)),
403 BluetoothAdapter::ErrorCallback());
404 ui_task_runner_->ClearPendingTasks();
405 bluetooth_task_runner_->ClearPendingTasks();
406 CallRemoveDiscoverySession(
407 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks,
408 base::Unretained(this)),
409 BluetoothAdapter::ErrorCallback());
410 EXPECT_TRUE(bluetooth_task_runner_->GetPendingTasks().empty());
411 CallRemoveDiscoverySession(
412 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks,
413 base::Unretained(this)),
414 BluetoothAdapter::ErrorCallback());
415 EXPECT_EQ(1, bluetooth_task_runner_->GetPendingTasks().size());
418 TEST_F(BluetoothAdapterWinTest,
419 StartDiscoveryAndStopDiscoveryAndStartDiscovery) {
420 CallAddDiscoverySession(
421 base::Closure(), BluetoothAdapter::ErrorCallback());
422 adapter_win_->DiscoveryStarted(true);
423 EXPECT_TRUE(adapter_->IsDiscovering());
424 CallRemoveDiscoverySession(
425 base::Closure(), BluetoothAdapter::ErrorCallback());
426 adapter_win_->DiscoveryStopped();
427 EXPECT_FALSE(adapter_->IsDiscovering());
428 CallAddDiscoverySession(
429 base::Closure(), BluetoothAdapter::ErrorCallback());
430 adapter_win_->DiscoveryStarted(true);
431 EXPECT_TRUE(adapter_->IsDiscovering());
434 TEST_F(BluetoothAdapterWinTest, StartDiscoveryBeforeDiscoveryStopped) {
435 CallAddDiscoverySession(
436 base::Closure(), BluetoothAdapter::ErrorCallback());
437 adapter_win_->DiscoveryStarted(true);
438 CallRemoveDiscoverySession(
439 base::Closure(), BluetoothAdapter::ErrorCallback());
440 CallAddDiscoverySession(
441 base::Closure(), BluetoothAdapter::ErrorCallback());
442 bluetooth_task_runner_->ClearPendingTasks();
443 adapter_win_->DiscoveryStopped();
444 EXPECT_EQ(1, bluetooth_task_runner_->GetPendingTasks().size());
447 TEST_F(BluetoothAdapterWinTest, StopDiscoveryWithoutStartDiscovery) {
448 CallRemoveDiscoverySession(
449 base::Closure(),
450 base::Bind(
451 &BluetoothAdapterWinTest::IncrementNumStopDiscoveryErrorCallbacks,
452 base::Unretained(this)));
453 EXPECT_EQ(1, num_stop_discovery_error_callbacks_);
456 TEST_F(BluetoothAdapterWinTest, StopDiscoveryBeforeDiscoveryStarted) {
457 CallAddDiscoverySession(
458 base::Closure(), BluetoothAdapter::ErrorCallback());
459 CallRemoveDiscoverySession(
460 base::Closure(), BluetoothAdapter::ErrorCallback());
461 bluetooth_task_runner_->ClearPendingTasks();
462 adapter_win_->DiscoveryStarted(true);
463 EXPECT_EQ(1, bluetooth_task_runner_->GetPendingTasks().size());
466 TEST_F(BluetoothAdapterWinTest, StartAndStopBeforeDiscoveryStarted) {
467 int num_expected_start_discoveries = 3;
468 int num_expected_stop_discoveries = 2;
469 for (int i = 0; i < num_expected_start_discoveries; i++) {
470 CallAddDiscoverySession(
471 base::Bind(
472 &BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks,
473 base::Unretained(this)),
474 BluetoothAdapter::ErrorCallback());
476 for (int i = 0; i < num_expected_stop_discoveries; i++) {
477 CallRemoveDiscoverySession(
478 base::Bind(
479 &BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks,
480 base::Unretained(this)),
481 BluetoothAdapter::ErrorCallback());
483 bluetooth_task_runner_->ClearPendingTasks();
484 adapter_win_->DiscoveryStarted(true);
485 EXPECT_TRUE(bluetooth_task_runner_->GetPendingTasks().empty());
486 ui_task_runner_->RunPendingTasks();
487 EXPECT_EQ(num_expected_start_discoveries, num_start_discovery_callbacks_);
488 EXPECT_EQ(num_expected_stop_discoveries, num_stop_discovery_callbacks_);
491 TEST_F(BluetoothAdapterWinTest, StopDiscoveryBeforeDiscoveryStartedAndFailed) {
492 CallAddDiscoverySession(
493 base::Closure(),
494 base::Bind(
495 &BluetoothAdapterWinTest::IncrementNumStartDiscoveryErrorCallbacks,
496 base::Unretained(this)));
497 CallRemoveDiscoverySession(
498 base::Bind(
499 &BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks,
500 base::Unretained(this)),
501 BluetoothAdapter::ErrorCallback());
502 ui_task_runner_->ClearPendingTasks();
503 adapter_win_->DiscoveryStarted(false);
504 ui_task_runner_->RunPendingTasks();
505 EXPECT_EQ(1, num_start_discovery_error_callbacks_);
506 EXPECT_EQ(1, num_stop_discovery_callbacks_);
507 EXPECT_EQ(0, adapter_observer_.num_discovering_changed());
510 TEST_F(BluetoothAdapterWinTest, DevicesPolled) {
511 BluetoothTaskManagerWin::DeviceState* android_phone_state =
512 new BluetoothTaskManagerWin::DeviceState();
513 MakeDeviceState("phone", "A1:B2:C3:D4:E5:E0", android_phone_state);
514 BluetoothTaskManagerWin::DeviceState* laptop_state =
515 new BluetoothTaskManagerWin::DeviceState();
516 MakeDeviceState("laptop", "A1:B2:C3:D4:E5:E1", laptop_state);
517 BluetoothTaskManagerWin::DeviceState* iphone_state =
518 new BluetoothTaskManagerWin::DeviceState();
519 MakeDeviceState("phone", "A1:B2:C3:D4:E5:E2", iphone_state);
520 ScopedVector<BluetoothTaskManagerWin::DeviceState> devices;
521 devices.push_back(android_phone_state);
522 devices.push_back(laptop_state);
523 devices.push_back(iphone_state);
525 // Add 3 devices
526 adapter_observer_.ResetCounters();
527 adapter_win_->DevicesPolled(devices);
528 EXPECT_EQ(3, adapter_observer_.num_device_added());
529 EXPECT_EQ(0, adapter_observer_.num_device_removed());
530 EXPECT_EQ(0, adapter_observer_.num_device_changed());
532 // Change a device name
533 android_phone_state->name = "phone2";
534 adapter_observer_.ResetCounters();
535 adapter_win_->DevicesPolled(devices);
536 EXPECT_EQ(0, adapter_observer_.num_device_added());
537 EXPECT_EQ(0, adapter_observer_.num_device_removed());
538 EXPECT_EQ(1, adapter_observer_.num_device_changed());
540 // Change a device address
541 android_phone_state->address = "A1:B2:C3:D4:E5:E6";
542 adapter_observer_.ResetCounters();
543 adapter_win_->DevicesPolled(devices);
544 EXPECT_EQ(1, adapter_observer_.num_device_added());
545 EXPECT_EQ(1, adapter_observer_.num_device_removed());
546 EXPECT_EQ(0, adapter_observer_.num_device_changed());
548 // Remove a device
549 devices.erase(devices.begin());
550 adapter_observer_.ResetCounters();
551 adapter_win_->DevicesPolled(devices);
552 EXPECT_EQ(0, adapter_observer_.num_device_added());
553 EXPECT_EQ(1, adapter_observer_.num_device_removed());
554 EXPECT_EQ(0, adapter_observer_.num_device_changed());
556 // Add a service
557 BluetoothTaskManagerWin::ServiceRecordState* audio_state =
558 new BluetoothTaskManagerWin::ServiceRecordState();
559 audio_state->name = kTestAudioSdpName;
560 base::HexStringToBytes(kTestAudioSdpBytes, &audio_state->sdp_bytes);
561 laptop_state->service_record_states.push_back(audio_state);
562 adapter_observer_.ResetCounters();
563 adapter_win_->DevicesPolled(devices);
564 EXPECT_EQ(0, adapter_observer_.num_device_added());
565 EXPECT_EQ(0, adapter_observer_.num_device_removed());
566 EXPECT_EQ(1, adapter_observer_.num_device_changed());
568 // Change a service
569 audio_state->name = kTestAudioSdpName2;
570 adapter_observer_.ResetCounters();
571 adapter_win_->DevicesPolled(devices);
572 EXPECT_EQ(0, adapter_observer_.num_device_added());
573 EXPECT_EQ(0, adapter_observer_.num_device_removed());
574 EXPECT_EQ(1, adapter_observer_.num_device_changed());
576 // Remove a service
577 laptop_state->service_record_states.clear();
578 adapter_observer_.ResetCounters();
579 adapter_win_->DevicesPolled(devices);
580 EXPECT_EQ(0, adapter_observer_.num_device_added());
581 EXPECT_EQ(0, adapter_observer_.num_device_removed());
582 EXPECT_EQ(1, adapter_observer_.num_device_changed());
585 } // namespace device