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

Unified Diff: chrome/browser/extensions/api/bluetooth/bluetooth_event_router_unittest.cc

Issue 180163009: chrome.bluetooth API improvements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address code review feedback. Created 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/bluetooth/bluetooth_event_router_unittest.cc
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_event_router_unittest.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router_unittest.cc
index 7842636d7db9b8c0eec57a047fca3969409b08d4..335b8fd87ba412c252a3963c7c5c46ab4e51521f 100644
--- a/chrome/browser/extensions/api/bluetooth/bluetooth_event_router_unittest.cc
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router_unittest.cc
@@ -17,6 +17,7 @@
#include "chrome/test/base/testing_profile.h"
#include "content/public/browser/notification_service.h"
#include "content/public/test/test_browser_thread.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "device/bluetooth/test/mock_bluetooth_adapter.h"
#include "device/bluetooth/test/mock_bluetooth_device.h"
#include "device/bluetooth/test/mock_bluetooth_profile.h"
@@ -88,10 +89,10 @@ namespace bluetooth = api::bluetooth;
class ExtensionBluetoothEventRouterTest : public testing::Test {
public:
ExtensionBluetoothEventRouterTest()
- : mock_adapter_(new testing::StrictMock<device::MockBluetoothAdapter>()),
+ : ui_thread_(content::BrowserThread::UI, &message_loop_),
+ mock_adapter_(new testing::StrictMock<device::MockBluetoothAdapter>()),
test_profile_(new TestingProfile()),
- router_(test_profile_.get()),
- ui_thread_(content::BrowserThread::UI, &message_loop_) {
+ router_(test_profile_.get()) {
router_.SetAdapterForTest(mock_adapter_);
}
@@ -105,13 +106,14 @@ class ExtensionBluetoothEventRouterTest : public testing::Test {
}
protected:
+ base::MessageLoopForUI message_loop_;
+ // Note: |ui_thread_| must be declared before |router_|.
+ content::TestBrowserThread ui_thread_;
testing::StrictMock<device::MockBluetoothAdapter>* mock_adapter_;
testing::NiceMock<device::MockBluetoothProfile> mock_audio_profile_;
testing::NiceMock<device::MockBluetoothProfile> mock_health_profile_;
scoped_ptr<TestingProfile> test_profile_;
ExtensionBluetoothEventRouter router_;
- base::MessageLoopForUI message_loop_;
- content::TestBrowserThread ui_thread_;
};
TEST_F(ExtensionBluetoothEventRouterTest, BluetoothEventListener) {
@@ -185,69 +187,4 @@ TEST_F(ExtensionBluetoothEventRouterTest, UnloadExtension) {
EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1);
}
-TEST_F(ExtensionBluetoothEventRouterTest, DispatchConnectionEvent) {
- router_.AddProfile(
- kAudioProfileUuid, kTestExtensionId, &mock_audio_profile_);
-
- FakeExtensionSystem* fake_extension_system =
- static_cast<FakeExtensionSystem*>(ExtensionSystemFactory::GetInstance()->
- SetTestingFactoryAndUse(test_profile_.get(),
- &BuildFakeExtensionSystem));
-
- testing::NiceMock<device::MockBluetoothDevice> mock_device(
- mock_adapter_, 0, "device name", "device address", true, false);
- scoped_refptr<testing::NiceMock<device::MockBluetoothSocket> > mock_socket(
- new testing::NiceMock<device::MockBluetoothSocket>());
-
- router_.DispatchConnectionEvent(kTestExtensionId,
- kAudioProfileUuid,
- &mock_device,
- mock_socket);
-
- FakeEventRouter* fake_event_router =
- static_cast<FakeEventRouter*>(fake_extension_system->event_router());
-
- EXPECT_STREQ(kTestExtensionId, fake_event_router->extension_id().c_str());
- EXPECT_STREQ(bluetooth::OnConnection::kEventName,
- fake_event_router->event()->event_name.c_str());
-
- base::ListValue* event_args = fake_event_router->event()->event_args.get();
- base::DictionaryValue* socket_value = NULL;
- ASSERT_TRUE(event_args->GetDictionary(0, &socket_value));
- int socket_id;
- ASSERT_TRUE(socket_value->GetInteger("id", &socket_id));
- EXPECT_EQ(mock_socket.get(), router_.GetSocket(socket_id).get());
-
- base::DictionaryValue* profile_value = NULL;
- ASSERT_TRUE(socket_value->GetDictionary("profile", &profile_value));
- std::string profile_uuid;
- ASSERT_TRUE(profile_value->GetString("uuid", &profile_uuid));
- EXPECT_STREQ(kAudioProfileUuid, profile_uuid.c_str());
-
- EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1);
- router_.ReleaseSocket(socket_id);
-}
-
-TEST_F(ExtensionBluetoothEventRouterTest, DoNotDispatchConnectionEvent) {
- FakeExtensionSystem* fake_extension_system =
- static_cast<FakeExtensionSystem*>(ExtensionSystemFactory::GetInstance()->
- SetTestingFactoryAndUse(test_profile_.get(),
- &BuildFakeExtensionSystem));
- testing::NiceMock<device::MockBluetoothDevice> mock_device(
- mock_adapter_, 0, "device name", "device address", true, false);
- scoped_refptr<testing::NiceMock<device::MockBluetoothSocket> > mock_socket(
- new testing::NiceMock<device::MockBluetoothSocket>());
-
- // Connection event won't be dispatched for non-registered profiles.
- router_.DispatchConnectionEvent("test extension id",
- kAudioProfileUuid,
- &mock_device,
- mock_socket);
- FakeEventRouter* fake_event_router =
- static_cast<FakeEventRouter*>(fake_extension_system->event_router());
- EXPECT_TRUE(fake_event_router->event() == NULL);
-
- EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1);
-}
-
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698