Commit 910048ac authored by bryeung@chromium.org's avatar bryeung@chromium.org

Bluetooth API: add discovering changed events

TEST=updated api test
BUG=138725


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149250 0039d316-1c4b-4281-b951-d872f2087c98
parent 65c81144
...@@ -83,6 +83,14 @@ void ExtensionBluetoothEventRouter::AdapterPoweredChanged( ...@@ -83,6 +83,14 @@ void ExtensionBluetoothEventRouter::AdapterPoweredChanged(
has_power); has_power);
} }
void ExtensionBluetoothEventRouter::AdapterDiscoveringChanged(
chromeos::BluetoothAdapter* adapter, bool discovering) {
DCHECK(adapter == adapter_.get());
DispatchBooleanValueEvent(
extensions::event_names::kBluetoothOnDiscoveringChanged,
discovering);
}
void ExtensionBluetoothEventRouter::DeviceAdded( void ExtensionBluetoothEventRouter::DeviceAdded(
chromeos::BluetoothAdapter* adapter, chromeos::BluetoothDevice* device) { chromeos::BluetoothAdapter* adapter, chromeos::BluetoothDevice* device) {
if (!send_discovery_events_) if (!send_discovery_events_)
......
...@@ -43,6 +43,8 @@ class ExtensionBluetoothEventRouter ...@@ -43,6 +43,8 @@ class ExtensionBluetoothEventRouter
bool present) OVERRIDE; bool present) OVERRIDE;
virtual void AdapterPoweredChanged(chromeos::BluetoothAdapter* adapter, virtual void AdapterPoweredChanged(chromeos::BluetoothAdapter* adapter,
bool has_power) OVERRIDE; bool has_power) OVERRIDE;
virtual void AdapterDiscoveringChanged(chromeos::BluetoothAdapter* adapter,
bool discovering) OVERRIDE;
virtual void DeviceAdded(chromeos::BluetoothAdapter* adapter, virtual void DeviceAdded(chromeos::BluetoothAdapter* adapter,
chromeos::BluetoothDevice* device) OVERRIDE; chromeos::BluetoothDevice* device) OVERRIDE;
......
...@@ -364,6 +364,8 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Events) { ...@@ -364,6 +364,8 @@ IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Events) {
event_router()->AdapterPoweredChanged(mock_adapter_, false); event_router()->AdapterPoweredChanged(mock_adapter_, false);
event_router()->AdapterPresentChanged(mock_adapter_, true); event_router()->AdapterPresentChanged(mock_adapter_, true);
event_router()->AdapterPresentChanged(mock_adapter_, false); event_router()->AdapterPresentChanged(mock_adapter_, false);
event_router()->AdapterDiscoveringChanged(mock_adapter_, true);
event_router()->AdapterDiscoveringChanged(mock_adapter_, false);
listener.Reply("go"); listener.Reply("go");
......
...@@ -62,6 +62,8 @@ const char kBluetoothOnAvailabilityChanged[] = ...@@ -62,6 +62,8 @@ const char kBluetoothOnAvailabilityChanged[] =
"experimental.bluetooth.onAvailabilityChanged"; "experimental.bluetooth.onAvailabilityChanged";
const char kBluetoothOnDeviceDiscovered[] = const char kBluetoothOnDeviceDiscovered[] =
"experimental.bluetooth.onDeviceDiscovered"; "experimental.bluetooth.onDeviceDiscovered";
const char kBluetoothOnDiscoveringChanged[] =
"experimental.bluetooth.onDiscoveringChanged";
const char kBluetoothOnPowerChanged[] = const char kBluetoothOnPowerChanged[] =
"experimental.bluetooth.onPowerChanged"; "experimental.bluetooth.onPowerChanged";
#endif #endif
......
...@@ -69,6 +69,7 @@ extern const char kOnOffscreenTabUpdated[]; ...@@ -69,6 +69,7 @@ extern const char kOnOffscreenTabUpdated[];
// Bluetooth. // Bluetooth.
extern const char kBluetoothOnAvailabilityChanged[]; extern const char kBluetoothOnAvailabilityChanged[];
extern const char kBluetoothOnDeviceDiscovered[]; extern const char kBluetoothOnDeviceDiscovered[];
extern const char kBluetoothOnDiscoveringChanged[];
extern const char kBluetoothOnPowerChanged[]; extern const char kBluetoothOnPowerChanged[];
#endif #endif
......
...@@ -212,5 +212,10 @@ namespace experimental.bluetooth { ...@@ -212,5 +212,10 @@ namespace experimental.bluetooth {
// Fired when the power state of bluetooth on the system changes. // Fired when the power state of bluetooth on the system changes.
// |powered| : True if bluetooth is powered, false otherwise. // |powered| : True if bluetooth is powered, false otherwise.
static void onPowerChanged(boolean has_power); static void onPowerChanged(boolean has_power);
// Fired when the discovering state of the system changes.
// |discovering| : True if the system is currently in discovery mode, false
// otherwise.
static void onDiscoveringChanged(boolean discovering);
}; };
}; };
...@@ -203,6 +203,8 @@ ...@@ -203,6 +203,8 @@
<ol> <ol>
<li> <li>
<a href="#event-onAvailabilityChanged">onAvailabilityChanged</a> <a href="#event-onAvailabilityChanged">onAvailabilityChanged</a>
</li><li>
<a href="#event-onDiscoveringChanged">onDiscoveringChanged</a>
</li><li> </li><li>
<a href="#event-onPowerChanged">onPowerChanged</a> <a href="#event-onPowerChanged">onPowerChanged</a>
</li> </li>
...@@ -1427,6 +1429,51 @@ ...@@ -1427,6 +1429,51 @@
<!-- OBJECT METHODS --> <!-- OBJECT METHODS -->
<!-- OBJECT EVENT FIELDS --> <!-- OBJECT EVENT FIELDS -->
<!-- FUNCTION PARAMETERS --> <!-- FUNCTION PARAMETERS -->
</div>
</div>
</dl>
</div>
<!-- EXTRA PARAMETERS -->
<!-- LISTENER RETURN VALUE -->
<dl>
</dl>
</div> <!-- /description -->
<!-- /description -->
</div><div class="apiItem">
<a name="event-onDiscoveringChanged"></a>
<h4>onDiscoveringChanged</h4>
<div class="summary">
<!-- Note: intentionally longer 80 columns -->
<span class="subdued">chrome.experimental.bluetooth.</span><span>onDiscoveringChanged</span><span class="subdued">.addListener</span>(function(<span>boolean discovering</span>) <span class="subdued">{...}</span><span></span>);
</div>
<div class="description">
<p>Fired when the discovering state of the system changes.</p>
<!-- LISTENER PARAMETERS -->
<div>
<h4>Listener parameters</h4>
<dl>
<div>
<div>
<dt>
<var>discovering</var>
<em>
<!-- TYPE -->
<div style="display:inline">
(
<span id="typeTemplate">
<span>
<span>boolean</span>
</span>
</span>
)
</div>
</em>
</dt>
<dd>True if the system is currently in discovery mode, false otherwise.</dd>
<!-- OBJECT PROPERTIES -->
<!-- OBJECT METHODS -->
<!-- OBJECT EVENT FIELDS -->
<!-- FUNCTION PARAMETERS -->
</div> </div>
</div> </div>
</dl> </dl>
......
...@@ -232,6 +232,8 @@ ...@@ -232,6 +232,8 @@
<ol> <ol>
<li> <li>
<a href="#event-onAvailabilityChanged">onAvailabilityChanged</a> <a href="#event-onAvailabilityChanged">onAvailabilityChanged</a>
</li><li>
<a href="#event-onDiscoveringChanged">onDiscoveringChanged</a>
</li><li> </li><li>
<a href="#event-onPowerChanged">onPowerChanged</a> <a href="#event-onPowerChanged">onPowerChanged</a>
</li> </li>
...@@ -1871,6 +1873,51 @@ ...@@ -1871,6 +1873,51 @@
<!-- OBJECT METHODS --> <!-- OBJECT METHODS -->
<!-- OBJECT EVENT FIELDS --> <!-- OBJECT EVENT FIELDS -->
<!-- FUNCTION PARAMETERS --> <!-- FUNCTION PARAMETERS -->
</div>
</div>
</dl>
</div>
<!-- EXTRA PARAMETERS -->
<!-- LISTENER RETURN VALUE -->
<dl>
</dl>
</div> <!-- /description -->
<!-- /description -->
</div><div class="apiItem">
<a name="event-onDiscoveringChanged"></a>
<h4>onDiscoveringChanged</h4>
<div class="summary">
<!-- Note: intentionally longer 80 columns -->
<span class="subdued">chrome.experimental.bluetooth.</span><span>onDiscoveringChanged</span><span class="subdued">.addListener</span>(function(<span>boolean discovering</span>) <span class="subdued">{...}</span><span></span>);
</div>
<div class="description">
<p>Fired when the discovering state of the system changes.</p>
<!-- LISTENER PARAMETERS -->
<div>
<h4>Listener parameters</h4>
<dl>
<div>
<div>
<dt>
<var>discovering</var>
<em>
<!-- TYPE -->
<div style="display:inline">
(
<span id="typeTemplate">
<span>
<span>boolean</span>
</span>
</span>
)
</div>
</em>
</dt>
<dd>True if the system is currently in discovery mode, false otherwise.</dd>
<!-- OBJECT PROPERTIES -->
<!-- OBJECT METHODS -->
<!-- OBJECT EVENT FIELDS -->
<!-- FUNCTION PARAMETERS -->
</div> </div>
</div> </div>
</dl> </dl>
......
...@@ -130,6 +130,7 @@ ...@@ -130,6 +130,7 @@
"chrome.experimental.bluetooth.isAvailable": "experimental.bluetooth.html#method-isAvailable", "chrome.experimental.bluetooth.isAvailable": "experimental.bluetooth.html#method-isAvailable",
"chrome.experimental.bluetooth.isPowered": "experimental.bluetooth.html#method-isPowered", "chrome.experimental.bluetooth.isPowered": "experimental.bluetooth.html#method-isPowered",
"chrome.experimental.bluetooth.onAvailabilityChanged": "experimental.bluetooth.html#event-onAvailabilityChanged", "chrome.experimental.bluetooth.onAvailabilityChanged": "experimental.bluetooth.html#event-onAvailabilityChanged",
"chrome.experimental.bluetooth.onDiscoveringChanged": "experimental.bluetooth.html#event-onDiscoveringChanged",
"chrome.experimental.bluetooth.onPowerChanged": "experimental.bluetooth.html#event-onPowerChanged", "chrome.experimental.bluetooth.onPowerChanged": "experimental.bluetooth.html#event-onPowerChanged",
"chrome.experimental.bluetooth.read": "experimental.bluetooth.html#method-read", "chrome.experimental.bluetooth.read": "experimental.bluetooth.html#method-read",
"chrome.experimental.bluetooth.setOutOfBandPairingData": "experimental.bluetooth.html#method-setOutOfBandPairingData", "chrome.experimental.bluetooth.setOutOfBandPairingData": "experimental.bluetooth.html#method-setOutOfBandPairingData",
......
...@@ -2,14 +2,16 @@ ...@@ -2,14 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
function testPowerEvents() { function testEvents() {
chrome.test.assertEq(kExpectedValues.length, powerChangedValues.length); chrome.test.assertEq(kExpectedValues.length, powerChangedValues.length);
chrome.test.assertEq(kExpectedValues.length, chrome.test.assertEq(kExpectedValues.length,
availabilityChangedValues.length); availabilityChangedValues.length);
chrome.test.assertEq(kExpectedValues.length, discoveringChangedValues.length);
for (var i = 0; i < kExpectedValues.length; ++i) { for (var i = 0; i < kExpectedValues.length; ++i) {
chrome.test.assertEq(kExpectedValues[i], powerChangedValues[i]); chrome.test.assertEq(kExpectedValues[i], powerChangedValues[i]);
chrome.test.assertEq(kExpectedValues[i], availabilityChangedValues[i]); chrome.test.assertEq(kExpectedValues[i], availabilityChangedValues[i]);
chrome.test.assertEq(kExpectedValues[i], discoveringChangedValues[i]);
} }
chrome.test.succeed(); chrome.test.succeed();
...@@ -17,6 +19,7 @@ function testPowerEvents() { ...@@ -17,6 +19,7 @@ function testPowerEvents() {
var powerChangedValues = []; var powerChangedValues = [];
var availabilityChangedValues = []; var availabilityChangedValues = [];
var discoveringChangedValues = [];
var kExpectedValues = [true, false]; var kExpectedValues = [true, false];
chrome.experimental.bluetooth.onPowerChanged.addListener( chrome.experimental.bluetooth.onPowerChanged.addListener(
function(result) { function(result) {
...@@ -26,9 +29,13 @@ chrome.experimental.bluetooth.onAvailabilityChanged.addListener( ...@@ -26,9 +29,13 @@ chrome.experimental.bluetooth.onAvailabilityChanged.addListener(
function(result) { function(result) {
availabilityChangedValues.push(result); availabilityChangedValues.push(result);
}); });
chrome.experimental.bluetooth.onDiscoveringChanged.addListener(
function(result) {
discoveringChangedValues.push(result);
});
chrome.test.sendMessage('ready', chrome.test.sendMessage('ready',
function(message) { function(message) {
chrome.test.runTests([ chrome.test.runTests([
testPowerEvents testEvents
]); ]);
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment