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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 utils::RunFunctionAndReturnError(set_oob_function, params, browser())); | 284 utils::RunFunctionAndReturnError(set_oob_function, params, browser())); |
285 EXPECT_FALSE(error.empty()); | 285 EXPECT_FALSE(error.empty()); |
286 | 286 |
287 // TODO(bryeung): Also test setting the data when there is support for | 287 // TODO(bryeung): Also test setting the data when there is support for |
288 // ArrayBuffers in the arguments to the RunFunctionAnd* methods. | 288 // ArrayBuffers in the arguments to the RunFunctionAnd* methods. |
289 // crbug.com/132796 | 289 // crbug.com/132796 |
290 } | 290 } |
291 | 291 |
292 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Discovery) { | 292 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Discovery) { |
293 // Try with a failure to start | 293 // Try with a failure to start |
| 294 EXPECT_CALL(*mock_adapter_, IsDiscovering()).WillOnce(testing::Return(false)); |
294 EXPECT_CALL(*mock_adapter_, | 295 EXPECT_CALL(*mock_adapter_, |
295 SetDiscovering(true, | 296 SetDiscovering(true, |
296 testing::_, | 297 testing::_, |
297 testing::Truly(CallClosure))); | 298 testing::Truly(CallClosure))); |
298 scoped_refptr<api::BluetoothStartDiscoveryFunction> start_function; | 299 scoped_refptr<api::BluetoothStartDiscoveryFunction> start_function; |
299 start_function = setupFunction(new api::BluetoothStartDiscoveryFunction); | 300 start_function = setupFunction(new api::BluetoothStartDiscoveryFunction); |
300 std::string error( | 301 std::string error( |
301 utils::RunFunctionAndReturnError(start_function, "[]", browser())); | 302 utils::RunFunctionAndReturnError(start_function, "[]", browser())); |
302 ASSERT_TRUE(!error.empty()); | 303 ASSERT_TRUE(!error.empty()); |
303 | 304 |
304 // Reset for a successful start | 305 // Reset for a successful start |
305 testing::Mock::VerifyAndClearExpectations(mock_adapter_); | 306 testing::Mock::VerifyAndClearExpectations(mock_adapter_); |
| 307 EXPECT_CALL(*mock_adapter_, IsDiscovering()).WillOnce(testing::Return(false)); |
306 EXPECT_CALL(*mock_adapter_, | 308 EXPECT_CALL(*mock_adapter_, |
307 SetDiscovering(true, | 309 SetDiscovering(true, |
308 testing::Truly(CallClosure), | 310 testing::Truly(CallClosure), |
309 testing::_)); | 311 testing::_)); |
310 | 312 |
311 start_function = setupFunction(new api::BluetoothStartDiscoveryFunction); | 313 start_function = setupFunction(new api::BluetoothStartDiscoveryFunction); |
312 (void)utils::RunFunctionAndReturnError(start_function, "[]", browser()); | 314 (void)utils::RunFunctionAndReturnError(start_function, "[]", browser()); |
313 | 315 |
314 // Reset to try stopping | 316 // Reset to try stopping |
315 testing::Mock::VerifyAndClearExpectations(mock_adapter_); | 317 testing::Mock::VerifyAndClearExpectations(mock_adapter_); |
(...skipping 10 matching lines...) Expand all Loading... |
326 EXPECT_CALL(*mock_adapter_, | 328 EXPECT_CALL(*mock_adapter_, |
327 SetDiscovering(false, | 329 SetDiscovering(false, |
328 testing::_, | 330 testing::_, |
329 testing::Truly(CallClosure))); | 331 testing::Truly(CallClosure))); |
330 stop_function = setupFunction(new api::BluetoothStopDiscoveryFunction); | 332 stop_function = setupFunction(new api::BluetoothStopDiscoveryFunction); |
331 error = utils::RunFunctionAndReturnError(stop_function, "[]", browser()); | 333 error = utils::RunFunctionAndReturnError(stop_function, "[]", browser()); |
332 ASSERT_TRUE(!error.empty()); | 334 ASSERT_TRUE(!error.empty()); |
333 } | 335 } |
334 | 336 |
335 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, DiscoveryCallback) { | 337 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, DiscoveryCallback) { |
| 338 EXPECT_CALL(*mock_adapter_, IsDiscovering()).WillOnce(testing::Return(false)); |
336 EXPECT_CALL(*mock_adapter_, | 339 EXPECT_CALL(*mock_adapter_, |
337 SetDiscovering(true, testing::Truly(CallClosure), testing::_)); | 340 SetDiscovering(true, testing::Truly(CallClosure), testing::_)); |
338 EXPECT_CALL(*mock_adapter_, | 341 EXPECT_CALL(*mock_adapter_, |
339 SetDiscovering(false, testing::Truly(CallClosure), testing::_)); | 342 SetDiscovering(false, testing::Truly(CallClosure), testing::_)); |
340 | 343 |
341 ResultCatcher catcher; | 344 ResultCatcher catcher; |
342 catcher.RestrictToProfile(browser()->profile()); | 345 catcher.RestrictToProfile(browser()->profile()); |
343 | 346 |
344 ExtensionTestMessageListener discovery_started("ready", true); | 347 ExtensionTestMessageListener discovery_started("ready", true); |
345 const extensions::Extension* extension = | 348 const extensions::Extension* extension = |
346 LoadExtension(test_data_dir_.AppendASCII("bluetooth")); | 349 LoadExtension(test_data_dir_.AppendASCII("bluetooth")); |
347 GURL page_url = extension->GetResourceURL("test_discovery.html"); | 350 GURL page_url = extension->GetResourceURL("test_discovery.html"); |
348 ui_test_utils::NavigateToURL(browser(), page_url); | 351 ui_test_utils::NavigateToURL(browser(), page_url); |
349 EXPECT_TRUE(discovery_started.WaitUntilSatisfied()); | 352 EXPECT_TRUE(discovery_started.WaitUntilSatisfied()); |
350 | 353 |
351 event_router()->DeviceAdded(mock_adapter_, device1_.get()); | 354 event_router()->DeviceAdded(mock_adapter_, device1_.get()); |
352 | 355 |
353 discovery_started.Reply("go"); | 356 discovery_started.Reply("go"); |
354 ExtensionTestMessageListener discovery_stopped("ready", true); | 357 ExtensionTestMessageListener discovery_stopped("ready", true); |
355 EXPECT_TRUE(discovery_stopped.WaitUntilSatisfied()); | 358 EXPECT_TRUE(discovery_stopped.WaitUntilSatisfied()); |
356 | 359 |
357 event_router()->DeviceAdded(mock_adapter_, device2_.get()); | 360 event_router()->DeviceAdded(mock_adapter_, device2_.get()); |
358 discovery_stopped.Reply("go"); | 361 discovery_stopped.Reply("go"); |
359 | 362 |
360 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 363 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
361 } | 364 } |
362 | 365 |
| 366 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, DiscoveryInProgress) { |
| 367 // Fake that the adapter is discovering |
| 368 EXPECT_CALL(*mock_adapter_, IsDiscovering()).WillOnce(testing::Return(true)); |
| 369 event_router()->AdapterDiscoveringChanged(mock_adapter_, true); |
| 370 |
| 371 // Cache a device before the extension starts discovering |
| 372 event_router()->DeviceAdded(mock_adapter_, device1_.get()); |
| 373 |
| 374 ResultCatcher catcher; |
| 375 catcher.RestrictToProfile(browser()->profile()); |
| 376 |
| 377 ExtensionTestMessageListener discovery_started("ready", true); |
| 378 const extensions::Extension* extension = |
| 379 LoadExtension(test_data_dir_.AppendASCII("bluetooth")); |
| 380 GURL page_url = extension->GetResourceURL("test_discovery_in_progress.html"); |
| 381 ui_test_utils::NavigateToURL(browser(), page_url); |
| 382 EXPECT_TRUE(discovery_started.WaitUntilSatisfied()); |
| 383 |
| 384 // This should be received in addition to the cached device above. |
| 385 event_router()->DeviceAdded(mock_adapter_, device2_.get()); |
| 386 |
| 387 discovery_started.Reply("go"); |
| 388 ExtensionTestMessageListener discovery_stopped("ready", true); |
| 389 EXPECT_TRUE(discovery_stopped.WaitUntilSatisfied()); |
| 390 |
| 391 event_router()->DeviceAdded(mock_adapter_, device2_.get()); |
| 392 discovery_stopped.Reply("go"); |
| 393 |
| 394 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 395 } |
| 396 |
363 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Events) { | 397 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Events) { |
364 ResultCatcher catcher; | 398 ResultCatcher catcher; |
365 catcher.RestrictToProfile(browser()->profile()); | 399 catcher.RestrictToProfile(browser()->profile()); |
366 | 400 |
367 // Load and wait for setup | 401 // Load and wait for setup |
368 ExtensionTestMessageListener listener("ready", true); | 402 ExtensionTestMessageListener listener("ready", true); |
369 const extensions::Extension* extension = | 403 const extensions::Extension* extension = |
370 LoadExtension(test_data_dir_.AppendASCII("bluetooth")); | 404 LoadExtension(test_data_dir_.AppendASCII("bluetooth")); |
371 GURL page_url = extension->GetResourceURL("test_events.html"); | 405 GURL page_url = extension->GetResourceURL("test_events.html"); |
372 ui_test_utils::NavigateToURL(browser(), page_url); | 406 ui_test_utils::NavigateToURL(browser(), page_url); |
373 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 407 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
374 | 408 |
375 event_router()->AdapterPoweredChanged(mock_adapter_, true); | 409 event_router()->AdapterPoweredChanged(mock_adapter_, true); |
376 event_router()->AdapterPoweredChanged(mock_adapter_, false); | 410 event_router()->AdapterPoweredChanged(mock_adapter_, false); |
377 event_router()->AdapterPresentChanged(mock_adapter_, true); | 411 event_router()->AdapterPresentChanged(mock_adapter_, true); |
378 event_router()->AdapterPresentChanged(mock_adapter_, false); | 412 event_router()->AdapterPresentChanged(mock_adapter_, false); |
379 event_router()->AdapterDiscoveringChanged(mock_adapter_, true); | 413 event_router()->AdapterDiscoveringChanged(mock_adapter_, true); |
380 event_router()->AdapterDiscoveringChanged(mock_adapter_, false); | 414 event_router()->AdapterDiscoveringChanged(mock_adapter_, false); |
381 | 415 |
382 listener.Reply("go"); | 416 listener.Reply("go"); |
383 | 417 |
384 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 418 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
385 } | 419 } |
OLD | NEW |