Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: device/bluetooth/bluetooth_socket_chromeos_unittest.cc

Issue 982593002: Fix BluetoothAdapterProfileChromeOS lifecycle management (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address nits, remove test debug logging Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/bluetooth/bluetooth_socket_chromeos.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/memory/ref_counted.h" 6 #include "base/memory/ref_counted.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "chromeos/dbus/dbus_thread_manager.h" 8 #include "chromeos/dbus/dbus_thread_manager.h"
9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" 9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h"
10 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" 10 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 100
101 void SuccessCallback() { 101 void SuccessCallback() {
102 ++success_callback_count_; 102 ++success_callback_count_;
103 message_loop_.Quit(); 103 message_loop_.Quit();
104 } 104 }
105 105
106 void ErrorCallback(const std::string& message) { 106 void ErrorCallback(const std::string& message) {
107 ++error_callback_count_; 107 ++error_callback_count_;
108 last_message_ = message; 108 last_message_ = message;
109 109
110 message_loop_.Quit(); 110 if (message_loop_.is_running())
111 message_loop_.Quit();
111 } 112 }
112 113
113 void ConnectToServiceSuccessCallback(scoped_refptr<BluetoothSocket> socket) { 114 void ConnectToServiceSuccessCallback(scoped_refptr<BluetoothSocket> socket) {
114 ++success_callback_count_; 115 ++success_callback_count_;
115 last_socket_ = socket; 116 last_socket_ = socket;
116 117
117 message_loop_.Quit(); 118 message_loop_.Quit();
118 } 119 }
119 120
120 void SendSuccessCallback(int bytes_sent) { 121 void SendSuccessCallback(int bytes_sent) {
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 base::Unretained(this)), 552 base::Unretained(this)),
552 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, 553 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback,
553 base::Unretained(this))); 554 base::Unretained(this)));
554 message_loop_.Run(); 555 message_loop_.Run();
555 556
556 EXPECT_EQ(0U, success_callback_count_); 557 EXPECT_EQ(0U, success_callback_count_);
557 EXPECT_EQ(2U, error_callback_count_); 558 EXPECT_EQ(2U, error_callback_count_);
558 EXPECT_TRUE(last_socket_.get() == NULL); 559 EXPECT_TRUE(last_socket_.get() == NULL);
559 } 560 }
560 561
562 TEST_F(BluetoothSocketChromeOSTest, SocketListenTwice) {
563 adapter_->CreateRfcommService(
564 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid),
565 BluetoothAdapter::ServiceOptions(),
566 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback,
567 base::Unretained(this)),
568 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback,
569 base::Unretained(this)));
570
571 message_loop_.Run();
572
573 EXPECT_EQ(1U, success_callback_count_);
574 EXPECT_EQ(0U, error_callback_count_);
575 EXPECT_TRUE(last_socket_.get() != NULL);
576
577 // Take control of this socket.
578 scoped_refptr<BluetoothSocket> server_socket;
579 server_socket.swap(last_socket_);
580
581 server_socket->Accept(
582 base::Bind(&BluetoothSocketChromeOSTest::AcceptSuccessCallback,
583 base::Unretained(this)),
584 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback,
585 base::Unretained(this)));
586
587 server_socket->Close();
588
589 server_socket = NULL;
590
591 message_loop_.RunUntilIdle();
592
593 EXPECT_EQ(1U, success_callback_count_);
594 EXPECT_EQ(1U, error_callback_count_);
595
596 adapter_->CreateRfcommService(
597 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid),
598 BluetoothAdapter::ServiceOptions(),
599 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback,
600 base::Unretained(this)),
601 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback,
602 base::Unretained(this)));
603
604 message_loop_.Run();
605
606 EXPECT_EQ(2U, success_callback_count_);
607 EXPECT_EQ(1U, error_callback_count_);
608 EXPECT_TRUE(last_socket_.get() != NULL);
609
610 // Take control of this socket.
611 server_socket.swap(last_socket_);
612
613 server_socket->Accept(
614 base::Bind(&BluetoothSocketChromeOSTest::AcceptSuccessCallback,
615 base::Unretained(this)),
616 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback,
617 base::Unretained(this)));
618
619 server_socket->Close();
620
621 server_socket = NULL;
622
623 message_loop_.RunUntilIdle();
624
625 EXPECT_EQ(2U, success_callback_count_);
626 EXPECT_EQ(2U, error_callback_count_);
627 }
628
561 } // namespace chromeos 629 } // namespace chromeos
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_socket_chromeos.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698