Skip to content

Commit

Permalink
Implemented chrome.bluetooth.getProfiles().
Browse files Browse the repository at this point in the history
BUG=229636

Review URL: https://chromiumcodereview.appspot.com/14472013

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@196756 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
youngki@chromium.org committed Apr 26, 2013
1 parent 47b5e68 commit 6d3882c
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 10 deletions.
28 changes: 27 additions & 1 deletion chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ namespace AddProfile = extensions::api::bluetooth::AddProfile;
namespace Connect = extensions::api::bluetooth::Connect;
namespace Disconnect = extensions::api::bluetooth::Disconnect;
namespace GetDevices = extensions::api::bluetooth::GetDevices;
namespace GetProfiles = extensions::api::bluetooth::GetProfiles;
namespace GetServices = extensions::api::bluetooth::GetServices;
namespace Read = extensions::api::bluetooth::Read;
namespace RemoveProfile = extensions::api::bluetooth::RemoveProfile;
Expand Down Expand Up @@ -118,7 +119,32 @@ bool BluetoothRemoveProfileFunction::RunImpl() {

bool BluetoothGetProfilesFunction::DoWork(
scoped_refptr<device::BluetoothAdapter> adapter) {
return false;
scoped_ptr<GetProfiles::Params> params(GetProfiles::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
const bluetooth::GetProfilesOptions& options = params->options;

BluetoothDevice* device = adapter->GetDevice(options.device.address);
if (!device) {
SetError(kInvalidDevice);
SendResponse(false);
return false;
}

BluetoothDevice::ServiceList service_list = device->GetServices();

ListValue* profiles = new ListValue;
for (BluetoothDevice::ServiceList::const_iterator iter = service_list.begin();
iter != service_list.end();
++iter) {
bluetooth::Profile api_profile;
api_profile.uuid = *iter;
profiles->Append(api_profile.ToValue().release());
}

SetResult(profiles);
SendResponse(true);

return true;
}

bool BluetoothGetAdapterStateFunction::DoWork(
Expand Down
29 changes: 25 additions & 4 deletions chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,6 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, RemoveProfile) {
// TODO(youngki): Implement it to test BluetoothRemoveProfileFunction.
}

IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetProfiles) {
// TODO(youngki): Implement it to test BluetoothGetProfilesFunction.
}

IN_PROC_BROWSER_TEST_F(BluetoothApiTest, OnAdapterStateChanged) {
EXPECT_CALL(*mock_adapter_, GetAddress())
.WillOnce(testing::Return(kAdapterAddress));
Expand Down Expand Up @@ -422,6 +418,31 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Events) {
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
}

IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetProfiles) {
ResultCatcher catcher;
catcher.RestrictToProfile(browser()->profile());

BluetoothDevice::ServiceList service_list;
service_list.push_back("1234");
service_list.push_back("5678");

EXPECT_CALL(*device1_, GetServices())
.WillOnce(testing::Return(service_list));

EXPECT_CALL(*mock_adapter_, GetDevice(device1_->GetAddress()))
.WillOnce(testing::Return(device1_.get()));

// Load and wait for setup
ExtensionTestMessageListener listener("ready", true);
ASSERT_TRUE(
LoadExtension(test_data_dir_.AppendASCII("bluetooth/get_profiles")));
EXPECT_TRUE(listener.WaitUntilSatisfied());

listener.Reply("go");

EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
}

IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevices) {
ResultCatcher catcher;
catcher.RestrictToProfile(browser()->profile());
Expand Down
11 changes: 6 additions & 5 deletions chrome/common/extensions/api/bluetooth.idl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ namespace bluetooth {
callback DevicesCallback = void (Device[] result);
callback NameCallback = void (DOMString result);
callback OutOfBandPairingDataCallback = void (OutOfBandPairingData data);
callback ProfilesCallback = void(Profile[] result);
callback ResultCallback = void ();
callback ServicesCallback = void(ServiceRecord[] result);
callback SizeCallback = void (long result);
Expand Down Expand Up @@ -197,11 +198,6 @@ namespace bluetooth {
// Profile; only the uuid field of the Profile object is used.
static void removeProfile(Profile profile, ResultCallback callback);

// Returns the set of exported profiles for the device specified in options.
// This function will not initiate a connection to the remote device.
static void getProfiles(GetProfilesOptions options,
ResultCallback callback);

// Get information about the Bluetooth adapter.
// |callback| : Called with an AdapterState object describing the adapter
// state.
Expand All @@ -217,6 +213,11 @@ namespace bluetooth {
static void getDevices(GetDevicesOptions options,
ResultCallback callback);

// Returns the set of exported profiles for the device specified in options.
// This function will not initiate a connection to the remote device.
static void getProfiles(GetProfilesOptions options,
ProfilesCallback callback);

// Get a list of services provided by a device.
static void getServices(GetServicesOptions options,
ServicesCallback callback);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"manifest_version": 2,
"name": "Test the Bluetooth getProfiles API",
"version": "1.0",
"app": {
"background": {
"scripts": ["runtest.js"]
}
},
"permissions": ["bluetooth"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

function testGetProfiles() {
chrome.test.assertEq(2, profiles.length);
chrome.test.assertEq('1234', profiles[0].uuid);
chrome.test.assertEq('5678', profiles[1].uuid);
chrome.test.succeed();
}

var profiles = [];

function failOnError() {
if (chrome.runtime.lastError) {
chrome.test.fail(chrome.runtime.lastError.message);
}
}

chrome.bluetooth.getProfiles(
{
device: {
name: 'device',
address: '11:12:13:14:15:16',
paired: false,
connected: false
}
},
function(results) {
failOnError();
profiles = results;
chrome.test.sendMessage('ready',
function(message) {
chrome.test.runTests([testGetProfiles]);
});
});
1 change: 1 addition & 0 deletions device/bluetooth/bluetooth_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class BluetoothDevice {
virtual bool IsConnecting() const = 0;

// Returns the services (as UUID strings) that this device provides.
// TODO(youngki): Rename this to GetProfiles().
typedef std::vector<std::string> ServiceList;
virtual ServiceList GetServices() const = 0;

Expand Down

0 comments on commit 6d3882c

Please sign in to comment.