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

Unified Diff: device/bluetooth/bluetooth_adapter_win_unittest.cc

Issue 11411130: Implemented BluetoothTaskManagerWin class. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed some style issues. Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/bluetooth_adapter_win_unittest.cc
diff --git a/device/bluetooth/bluetooth_adapter_win_unittest.cc b/device/bluetooth/bluetooth_adapter_win_unittest.cc
index e8fcb6fcac13194e734d711228d2d01729354bc6..68e705467f9637bc3356d4e85c3e56e42161dd20 100644
--- a/device/bluetooth/bluetooth_adapter_win_unittest.cc
+++ b/device/bluetooth/bluetooth_adapter_win_unittest.cc
@@ -5,108 +5,85 @@
#include <string>
#include "base/memory/ref_counted.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
#include "base/run_loop.h"
-#include "base/stringprintf.h"
-#include "base/time.h"
#include "content/public/test/test_browser_thread.h"
+#include "device/bluetooth/bluetooth_adapter.h"
+#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/bluetooth/bluetooth_adapter_win.h"
-#include "device/bluetooth/test/mock_bluetooth_adapter.h"
+#include "device/bluetooth/bluetooth_task_manager_win.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
-const char* kAdapterAddress = "bluetooth adapter address";
+const char* kAdapterAddress = "Bluetooth Adapter Address";
+const char* kAdapterName = "Bluetooth Adapter Name";
} // namespace
namespace device {
-class FakeBluetoothAdapterWin : public BluetoothAdapterWin {
- public:
- FakeBluetoothAdapterWin() : BluetoothAdapterWin() {}
-
- virtual void UpdateAdapterState() {
- address_ = adapter_address_;
- }
-
- void SetAdapterAddressForTest(const std::string& adapter_address) {
- adapter_address_ = adapter_address;
- }
-
- private:
- virtual ~FakeBluetoothAdapterWin() {}
- std::string adapter_address_;
- DISALLOW_COPY_AND_ASSIGN(FakeBluetoothAdapterWin);
-};
-
class BluetoothAdapterWinTest : public testing::Test {
public:
BluetoothAdapterWinTest()
- : ui_thread_(content::BrowserThread::UI, &loop_),
- ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
+ : ui_thread_(content::BrowserThread::UI, &ui_loop_),
+ adapter_(NULL),
+ adapter_win_(NULL) {
}
virtual void SetUp() {
- adapter_ = new FakeBluetoothAdapterWin();
- adapter_->TrackDefaultAdapter();
+ adapter_ = BluetoothAdapterFactory::DefaultAdapter();
+ adapter_win_ = static_cast<BluetoothAdapterWin*>(adapter_.get());
}
- void SetAdapterAddressForTest() {
- adapter_->SetAdapterAddressForTest(kAdapterAddress);
+ virtual void TearDown() {
+ ReleaseAdapter();
}
- int GetPollIntervalMs() const {
- return BluetoothAdapterWin::kPollIntervalMs;
+ void ReleaseAdapter() {
+ adapter_ = NULL;
+ adapter_win_ = NULL;
}
protected:
- scoped_refptr<FakeBluetoothAdapterWin> adapter_;
-
- // Main message loop for the test.
- MessageLoopForUI loop_;
-
- // Main thread for the test.
+ MessageLoopForUI ui_loop_;
content::TestBrowserThread ui_thread_;
-
- // NOTE: This should remain the last member so it'll be destroyed and
- // invalidate its weak pointers before any other members are destroyed.
- base::WeakPtrFactory<BluetoothAdapterWinTest> weak_ptr_factory_;
+ scoped_refptr<BluetoothAdapter> adapter_;
+ BluetoothAdapterWin* adapter_win_;
};
-TEST_F(BluetoothAdapterWinTest, Polling) {
+TEST_F(BluetoothAdapterWinTest, AdapterNotPresent) {
+ BluetoothTaskManagerWin::AdapterState state;
+ adapter_win_->AdapterStateChanged(state);
+ EXPECT_FALSE(adapter_win_->IsPresent());
+}
+
+TEST_F(BluetoothAdapterWinTest, AdapterPresent) {
+ BluetoothTaskManagerWin::AdapterState state;
+ state.address = kAdapterAddress;
+ state.name = kAdapterName;
+ adapter_win_->AdapterStateChanged(state);
+ EXPECT_TRUE(adapter_win_->IsPresent());
+}
+
+TEST_F(BluetoothAdapterWinTest, AdapterDestroyed) {
+ base::RunLoop run_loop;
MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(
- &BluetoothAdapterWinTest::SetAdapterAddressForTest,
- weak_ptr_factory_.GetWeakPtr()),
- base::TimeDelta::FromMilliseconds(GetPollIntervalMs() - 1));
- EXPECT_STRNE(kAdapterAddress, adapter_->address().c_str());
- base::RunLoop run_loop;
-
+ &BluetoothAdapterWinTest::ReleaseAdapter,
+ base::Unretained(this)),
+ base::TimeDelta::FromMilliseconds(1));
MessageLoop::current()->PostDelayedTask(
FROM_HERE,
run_loop.QuitClosure(),
- base::TimeDelta::FromMilliseconds(GetPollIntervalMs() + 1));
+ base::TimeDelta::FromMilliseconds(2));
run_loop.Run();
- EXPECT_STREQ(kAdapterAddress, adapter_->address().c_str());
+ // Adapter has been destroyed gracefully.
+ SUCCEED();
}
-TEST_F(BluetoothAdapterWinTest, IsPresent) {
- EXPECT_FALSE(adapter_->IsPresent());
- SetAdapterAddressForTest();
- base::RunLoop run_loop;
- MessageLoop::current()->PostDelayedTask(
- FROM_HERE,
- run_loop.QuitClosure(),
- base::TimeDelta::FromMilliseconds(GetPollIntervalMs()));
- run_loop.Run();
-
- EXPECT_TRUE(adapter_->IsPresent());
-}
} // namespace device

Powered by Google App Engine
This is Rietveld 408576698