OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string.h> | 5 #include <string.h> |
6 | 6 |
7 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" | 7 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" |
8 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h" | 8 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h" |
9 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_device.h" | 9 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_device.h" |
10 #include "chrome/browser/chromeos/extensions/bluetooth_event_router.h" | 10 #include "chrome/browser/chromeos/extensions/bluetooth_event_router.h" |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 utils::RunFunctionAndReturnError(set_oob_function, params, browser())); | 272 utils::RunFunctionAndReturnError(set_oob_function, params, browser())); |
273 EXPECT_FALSE(error.empty()); | 273 EXPECT_FALSE(error.empty()); |
274 | 274 |
275 // TODO(bryeung): Also test setting the data when there is support for | 275 // TODO(bryeung): Also test setting the data when there is support for |
276 // ArrayBuffers in the arguments to the RunFunctionAnd* methods. | 276 // ArrayBuffers in the arguments to the RunFunctionAnd* methods. |
277 // crbug.com/132796 | 277 // crbug.com/132796 |
278 } | 278 } |
279 | 279 |
280 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Discovery) { | 280 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Discovery) { |
281 // Try with a failure to start | 281 // Try with a failure to start |
| 282 EXPECT_CALL(*mock_adapter_, IsDiscovering()).WillOnce(testing::Return(false)); |
282 EXPECT_CALL(*mock_adapter_, | 283 EXPECT_CALL(*mock_adapter_, |
283 SetDiscovering(true, | 284 SetDiscovering(true, |
284 testing::_, | 285 testing::_, |
285 testing::Truly(CallClosure))); | 286 testing::Truly(CallClosure))); |
286 scoped_refptr<api::BluetoothStartDiscoveryFunction> start_function; | 287 scoped_refptr<api::BluetoothStartDiscoveryFunction> start_function; |
287 start_function = setupFunction(new api::BluetoothStartDiscoveryFunction); | 288 start_function = setupFunction(new api::BluetoothStartDiscoveryFunction); |
288 std::string error( | 289 std::string error( |
289 utils::RunFunctionAndReturnError(start_function, "[]", browser())); | 290 utils::RunFunctionAndReturnError(start_function, "[]", browser())); |
290 ASSERT_TRUE(!error.empty()); | 291 ASSERT_TRUE(!error.empty()); |
291 | 292 |
292 // Reset for a successful start | 293 // Reset for a successful start |
293 testing::Mock::VerifyAndClearExpectations(mock_adapter_); | 294 testing::Mock::VerifyAndClearExpectations(mock_adapter_); |
| 295 EXPECT_CALL(*mock_adapter_, IsDiscovering()).WillOnce(testing::Return(false)); |
294 EXPECT_CALL(*mock_adapter_, | 296 EXPECT_CALL(*mock_adapter_, |
295 SetDiscovering(true, | 297 SetDiscovering(true, |
296 testing::Truly(CallClosure), | 298 testing::Truly(CallClosure), |
297 testing::_)); | 299 testing::_)); |
298 | 300 |
299 start_function = setupFunction(new api::BluetoothStartDiscoveryFunction); | 301 start_function = setupFunction(new api::BluetoothStartDiscoveryFunction); |
300 (void)utils::RunFunctionAndReturnError(start_function, "[]", browser()); | 302 (void)utils::RunFunctionAndReturnError(start_function, "[]", browser()); |
301 | 303 |
302 // Reset to try stopping | 304 // Reset to try stopping |
303 testing::Mock::VerifyAndClearExpectations(mock_adapter_); | 305 testing::Mock::VerifyAndClearExpectations(mock_adapter_); |
(...skipping 10 matching lines...) Expand all Loading... |
314 EXPECT_CALL(*mock_adapter_, | 316 EXPECT_CALL(*mock_adapter_, |
315 SetDiscovering(false, | 317 SetDiscovering(false, |
316 testing::_, | 318 testing::_, |
317 testing::Truly(CallClosure))); | 319 testing::Truly(CallClosure))); |
318 stop_function = setupFunction(new api::BluetoothStopDiscoveryFunction); | 320 stop_function = setupFunction(new api::BluetoothStopDiscoveryFunction); |
319 error = utils::RunFunctionAndReturnError(stop_function, "[]", browser()); | 321 error = utils::RunFunctionAndReturnError(stop_function, "[]", browser()); |
320 ASSERT_TRUE(!error.empty()); | 322 ASSERT_TRUE(!error.empty()); |
321 } | 323 } |
322 | 324 |
323 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, DiscoveryCallback) { | 325 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, DiscoveryCallback) { |
| 326 EXPECT_CALL(*mock_adapter_, IsDiscovering()).WillOnce(testing::Return(false)); |
324 EXPECT_CALL(*mock_adapter_, | 327 EXPECT_CALL(*mock_adapter_, |
325 SetDiscovering(true, testing::Truly(CallClosure), testing::_)); | 328 SetDiscovering(true, testing::Truly(CallClosure), testing::_)); |
326 EXPECT_CALL(*mock_adapter_, | 329 EXPECT_CALL(*mock_adapter_, |
327 SetDiscovering(false, testing::Truly(CallClosure), testing::_)); | 330 SetDiscovering(false, testing::Truly(CallClosure), testing::_)); |
328 | 331 |
329 ResultCatcher catcher; | 332 ResultCatcher catcher; |
330 catcher.RestrictToProfile(browser()->profile()); | 333 catcher.RestrictToProfile(browser()->profile()); |
331 | 334 |
332 ExtensionTestMessageListener discovery_started("ready", true); | 335 ExtensionTestMessageListener discovery_started("ready", true); |
333 const extensions::Extension* extension = | 336 const extensions::Extension* extension = |
334 LoadExtension(test_data_dir_.AppendASCII("bluetooth")); | 337 LoadExtension(test_data_dir_.AppendASCII("bluetooth")); |
335 GURL page_url = extension->GetResourceURL("test_discovery.html"); | 338 GURL page_url = extension->GetResourceURL("test_discovery.html"); |
336 ui_test_utils::NavigateToURL(browser(), page_url); | 339 ui_test_utils::NavigateToURL(browser(), page_url); |
337 EXPECT_TRUE(discovery_started.WaitUntilSatisfied()); | 340 EXPECT_TRUE(discovery_started.WaitUntilSatisfied()); |
338 | 341 |
339 event_router()->DeviceAdded(mock_adapter_, device1_.get()); | 342 event_router()->DeviceAdded(mock_adapter_, device1_.get()); |
340 | 343 |
341 discovery_started.Reply("go"); | 344 discovery_started.Reply("go"); |
342 ExtensionTestMessageListener discovery_stopped("ready", true); | 345 ExtensionTestMessageListener discovery_stopped("ready", true); |
343 EXPECT_TRUE(discovery_stopped.WaitUntilSatisfied()); | 346 EXPECT_TRUE(discovery_stopped.WaitUntilSatisfied()); |
344 | 347 |
345 event_router()->DeviceAdded(mock_adapter_, device2_.get()); | 348 event_router()->DeviceAdded(mock_adapter_, device2_.get()); |
346 discovery_stopped.Reply("go"); | 349 discovery_stopped.Reply("go"); |
347 | 350 |
348 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 351 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
349 } | 352 } |
350 | 353 |
| 354 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, DiscoveryInProgress) { |
| 355 // Fake that the adapter is discovering |
| 356 EXPECT_CALL(*mock_adapter_, IsDiscovering()).WillOnce(testing::Return(true)); |
| 357 event_router()->AdapterDiscoveringChanged(mock_adapter_, true); |
| 358 |
| 359 // Cache a device before the extension starts discovering |
| 360 event_router()->DeviceAdded(mock_adapter_, device1_.get()); |
| 361 |
| 362 ResultCatcher catcher; |
| 363 catcher.RestrictToProfile(browser()->profile()); |
| 364 |
| 365 ExtensionTestMessageListener discovery_started("ready", true); |
| 366 const extensions::Extension* extension = |
| 367 LoadExtension(test_data_dir_.AppendASCII("bluetooth")); |
| 368 GURL page_url = extension->GetResourceURL("test_discovery_in_progress.html"); |
| 369 ui_test_utils::NavigateToURL(browser(), page_url); |
| 370 EXPECT_TRUE(discovery_started.WaitUntilSatisfied()); |
| 371 |
| 372 // This should be received in addition to the cached device above. |
| 373 event_router()->DeviceAdded(mock_adapter_, device2_.get()); |
| 374 |
| 375 discovery_started.Reply("go"); |
| 376 ExtensionTestMessageListener discovery_stopped("ready", true); |
| 377 EXPECT_TRUE(discovery_stopped.WaitUntilSatisfied()); |
| 378 |
| 379 event_router()->DeviceAdded(mock_adapter_, device2_.get()); |
| 380 discovery_stopped.Reply("go"); |
| 381 |
| 382 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 383 } |
| 384 |
351 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Events) { | 385 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Events) { |
352 ResultCatcher catcher; | 386 ResultCatcher catcher; |
353 catcher.RestrictToProfile(browser()->profile()); | 387 catcher.RestrictToProfile(browser()->profile()); |
354 | 388 |
355 // Load and wait for setup | 389 // Load and wait for setup |
356 ExtensionTestMessageListener listener("ready", true); | 390 ExtensionTestMessageListener listener("ready", true); |
357 const extensions::Extension* extension = | 391 const extensions::Extension* extension = |
358 LoadExtension(test_data_dir_.AppendASCII("bluetooth")); | 392 LoadExtension(test_data_dir_.AppendASCII("bluetooth")); |
359 GURL page_url = extension->GetResourceURL("test_events.html"); | 393 GURL page_url = extension->GetResourceURL("test_events.html"); |
360 ui_test_utils::NavigateToURL(browser(), page_url); | 394 ui_test_utils::NavigateToURL(browser(), page_url); |
361 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 395 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
362 | 396 |
363 event_router()->AdapterPoweredChanged(mock_adapter_, true); | 397 event_router()->AdapterPoweredChanged(mock_adapter_, true); |
364 event_router()->AdapterPoweredChanged(mock_adapter_, false); | 398 event_router()->AdapterPoweredChanged(mock_adapter_, false); |
365 event_router()->AdapterPresentChanged(mock_adapter_, true); | 399 event_router()->AdapterPresentChanged(mock_adapter_, true); |
366 event_router()->AdapterPresentChanged(mock_adapter_, false); | 400 event_router()->AdapterPresentChanged(mock_adapter_, false); |
367 event_router()->AdapterDiscoveringChanged(mock_adapter_, true); | 401 event_router()->AdapterDiscoveringChanged(mock_adapter_, true); |
368 event_router()->AdapterDiscoveringChanged(mock_adapter_, false); | 402 event_router()->AdapterDiscoveringChanged(mock_adapter_, false); |
369 | 403 |
370 listener.Reply("go"); | 404 listener.Reply("go"); |
371 | 405 |
372 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 406 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
373 } | 407 } |
OLD | NEW |