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

Unified Diff: trunk/src/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc

Issue 188663003: Revert 255262 "Migrate chrome.bluetooth API backend to use devic..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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: trunk/src/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc
===================================================================
--- trunk/src/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc (revision 255369)
+++ trunk/src/chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc (working copy)
@@ -17,19 +17,16 @@
#include "device/bluetooth/bluetooth_out_of_band_pairing_data.h"
#include "device/bluetooth/test/mock_bluetooth_adapter.h"
#include "device/bluetooth/test/mock_bluetooth_device.h"
-#include "device/bluetooth/test/mock_bluetooth_discovery_session.h"
#include "device/bluetooth/test/mock_bluetooth_profile.h"
#include "device/bluetooth/test/mock_bluetooth_socket.h"
#include "testing/gmock/include/gmock/gmock.h"
using device::BluetoothAdapter;
using device::BluetoothDevice;
-using device::BluetoothDiscoverySession;
using device::BluetoothOutOfBandPairingData;
using device::BluetoothProfile;
using device::MockBluetoothAdapter;
using device::MockBluetoothDevice;
-using device::MockBluetoothDiscoverySession;
using device::MockBluetoothProfile;
using extensions::Extension;
@@ -68,17 +65,6 @@
false /* paired */, false /* connected */));
}
- void DiscoverySessionCallback(
- const BluetoothAdapter::DiscoverySessionCallback& callback,
- const BluetoothAdapter::ErrorCallback& error_callback) {
- if (mock_session_.get()) {
- callback.Run(
- scoped_ptr<BluetoothDiscoverySession>(mock_session_.release()));
- return;
- }
- error_callback.Run();
- }
-
template <class T>
T* setupFunction(T* function) {
function->set_extension(empty_extension_.get());
@@ -88,7 +74,6 @@
protected:
testing::StrictMock<MockBluetoothAdapter>* mock_adapter_;
- scoped_ptr<testing::NiceMock<MockBluetoothDiscoverySession> > mock_session_;
scoped_ptr<testing::NiceMock<MockBluetoothDevice> > device1_;
scoped_ptr<testing::NiceMock<MockBluetoothDevice> > device2_;
scoped_ptr<testing::NiceMock<MockBluetoothProfile> > profile1_;
@@ -144,11 +129,18 @@
return true;
}
-static void StopDiscoverySessionCallback(const base::Closure& callback,
- const base::Closure& error_callback) {
+static void CallDiscoveryCallback(
+ const base::Closure& callback,
+ const BluetoothAdapter::ErrorCallback& error_callback) {
callback.Run();
}
+static void CallDiscoveryErrorCallback(
+ const base::Closure& callback,
+ const BluetoothAdapter::ErrorCallback& error_callback) {
+ error_callback.Run();
+}
+
static void CallOutOfBandPairingDataCallback(
const BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& callback,
const BluetoothAdapter::ErrorCallback& error_callback) {
@@ -324,12 +316,9 @@
}
IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Discovery) {
- // Try with a failure to start. This will return an error as we haven't
- // initialied a session object.
- EXPECT_CALL(*mock_adapter_, StartDiscoverySession(testing::_, testing::_))
- .WillOnce(
- testing::Invoke(this, &BluetoothApiTest::DiscoverySessionCallback));
-
+ // Try with a failure to start
+ EXPECT_CALL(*mock_adapter_, StartDiscovering(testing::_, testing::_))
+ .WillOnce(testing::Invoke(CallDiscoveryErrorCallback));
// StartDiscovery failure will remove the adapter that is no longer used.
EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_));
scoped_refptr<api::BluetoothStartDiscoveryFunction> start_function;
@@ -338,28 +327,19 @@
utils::RunFunctionAndReturnError(start_function.get(), "[]", browser()));
ASSERT_FALSE(error.empty());
- // Reset the adapter and initiate a discovery session. The ownership of the
- // mock session will be passed to the event router.
- ASSERT_FALSE(mock_session_.get());
+ // Reset for a successful start
SetUpMockAdapter();
+ EXPECT_CALL(*mock_adapter_, StartDiscovering(testing::_, testing::_))
+ .WillOnce(testing::Invoke(CallDiscoveryCallback));
- // Create a mock session to be returned as a result. Get a handle to it as
- // its ownership will be passed and |mock_session_| will be reset.
- mock_session_.reset(new testing::NiceMock<MockBluetoothDiscoverySession>());
- MockBluetoothDiscoverySession* session = mock_session_.get();
- EXPECT_CALL(*mock_adapter_, StartDiscoverySession(testing::_, testing::_))
- .WillOnce(
- testing::Invoke(this, &BluetoothApiTest::DiscoverySessionCallback));
start_function = setupFunction(new api::BluetoothStartDiscoveryFunction);
(void)
utils::RunFunctionAndReturnError(start_function.get(), "[]", browser());
- // End the discovery session. The StopDiscovery function should succeed.
+ // Reset to try stopping
testing::Mock::VerifyAndClearExpectations(mock_adapter_);
- EXPECT_CALL(*session, IsActive()).WillOnce(testing::Return(true));
- EXPECT_CALL(*session, Stop(testing::_, testing::_))
- .WillOnce(testing::Invoke(StopDiscoverySessionCallback));
-
+ EXPECT_CALL(*mock_adapter_, StopDiscovering(testing::_, testing::_))
+ .WillOnce(testing::Invoke(CallDiscoveryCallback));
// StopDiscovery success will remove the adapter that is no longer used.
EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_));
scoped_refptr<api::BluetoothStopDiscoveryFunction> stop_function;
@@ -367,10 +347,10 @@
(void) utils::RunFunctionAndReturnSingleResult(
stop_function.get(), "[]", browser());
- // Reset the adapter. Simulate failure for stop discovery. The event router
- // still owns the session. Make it appear inactive.
+ // Reset to try stopping with an error
SetUpMockAdapter();
- EXPECT_CALL(*session, IsActive()).WillOnce(testing::Return(false));
+ EXPECT_CALL(*mock_adapter_, StopDiscovering(testing::_, testing::_))
+ .WillOnce(testing::Invoke(CallDiscoveryErrorCallback));
EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_));
stop_function = setupFunction(new api::BluetoothStopDiscoveryFunction);
error =
@@ -380,14 +360,10 @@
}
IN_PROC_BROWSER_TEST_F(BluetoothApiTest, DiscoveryCallback) {
- mock_session_.reset(new testing::NiceMock<MockBluetoothDiscoverySession>());
- MockBluetoothDiscoverySession* session = mock_session_.get();
- EXPECT_CALL(*mock_adapter_, StartDiscoverySession(testing::_, testing::_))
- .WillOnce(
- testing::Invoke(this, &BluetoothApiTest::DiscoverySessionCallback));
- EXPECT_CALL(*session, IsActive()).WillOnce(testing::Return(true));
- EXPECT_CALL(*session, Stop(testing::_, testing::_))
- .WillOnce(testing::Invoke(StopDiscoverySessionCallback));
+ EXPECT_CALL(*mock_adapter_, StartDiscovering(testing::_, testing::_))
+ .WillOnce(testing::Invoke(CallDiscoveryCallback));
+ EXPECT_CALL(*mock_adapter_, StopDiscovering(testing::_, testing::_))
+ .WillOnce(testing::Invoke(CallDiscoveryCallback));
ResultCatcher catcher;
catcher.RestrictToProfile(browser()->profile());
@@ -432,22 +408,17 @@
ResultCatcher catcher;
catcher.RestrictToProfile(browser()->profile());
- mock_session_.reset(new testing::NiceMock<MockBluetoothDiscoverySession>());
- MockBluetoothDiscoverySession* session = mock_session_.get();
- EXPECT_CALL(*mock_adapter_, StartDiscoverySession(testing::_, testing::_))
- .WillOnce(
- testing::Invoke(this, &BluetoothApiTest::DiscoverySessionCallback));
- EXPECT_CALL(*session, IsActive()).WillOnce(testing::Return(true));
- EXPECT_CALL(*session, Stop(testing::_, testing::_))
- .WillOnce(testing::Invoke(StopDiscoverySessionCallback));
+ EXPECT_CALL(*mock_adapter_, StartDiscovering(testing::_, testing::_))
+ .WillOnce(testing::Invoke(CallDiscoveryCallback));
+ EXPECT_CALL(*mock_adapter_, StopDiscovering(testing::_, testing::_))
+ .WillOnce(testing::Invoke(CallDiscoveryCallback));
ExtensionTestMessageListener discovery_started("ready", true);
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("bluetooth/discovery_in_progress")));
EXPECT_TRUE(discovery_started.WaitUntilSatisfied());
- // Only this should be received. No additional notification should be sent for
- // devices discovered before the discovery session started.
+ // This should be received in addition to the cached device above.
event_router()->DeviceAdded(mock_adapter_, device2_.get());
discovery_started.Reply("go");

Powered by Google App Engine
This is Rietveld 408576698