| 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 "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" | 8 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" |
| 9 #include "chrome/browser/extensions/bluetooth_event_router.h" | 9 #include "chrome/browser/extensions/bluetooth_event_router.h" |
| 10 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 device1_.reset(new testing::NiceMock<MockBluetoothDevice>( | 53 device1_.reset(new testing::NiceMock<MockBluetoothDevice>( |
| 54 mock_adapter_, "d1", "11:12:13:14:15:16", | 54 mock_adapter_, "d1", "11:12:13:14:15:16", |
| 55 true /* paired */, false /* bonded */, true /* connected */)); | 55 true /* paired */, false /* bonded */, true /* connected */)); |
| 56 device2_.reset(new testing::NiceMock<MockBluetoothDevice>( | 56 device2_.reset(new testing::NiceMock<MockBluetoothDevice>( |
| 57 mock_adapter_, "d2", "21:22:23:24:25:26", | 57 mock_adapter_, "d2", "21:22:23:24:25:26", |
| 58 false /* paired */, true /* bonded */, false /* connected */)); | 58 false /* paired */, true /* bonded */, false /* connected */)); |
| 59 } | 59 } |
| 60 | 60 |
| 61 virtual void CleanUpOnMainThread() OVERRIDE { | 61 virtual void CleanUpOnMainThread() OVERRIDE { |
| 62 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)); | 62 event_router()->SetAdapterForTest(NULL); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void expectBooleanResult(bool expected, | 65 void expectBooleanResult(bool expected, |
| 66 UIThreadExtensionFunction* function) { | 66 UIThreadExtensionFunction* function) { |
| 67 scoped_ptr<base::Value> result( | 67 scoped_ptr<base::Value> result( |
| 68 utils::RunFunctionAndReturnSingleResult(function, "[]", browser())); | 68 utils::RunFunctionAndReturnSingleResult(function, "[]", browser())); |
| 69 ASSERT_TRUE(result.get() != NULL); | 69 ASSERT_TRUE(result.get() != NULL); |
| 70 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType()); | 70 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType()); |
| 71 bool boolean_value; | 71 bool boolean_value; |
| 72 result->GetAsBoolean(&boolean_value); | 72 result->GetAsBoolean(&boolean_value); |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 372 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 373 | 373 |
| 374 event_router()->AdapterPoweredChanged(mock_adapter_, true); | 374 event_router()->AdapterPoweredChanged(mock_adapter_, true); |
| 375 event_router()->AdapterPoweredChanged(mock_adapter_, false); | 375 event_router()->AdapterPoweredChanged(mock_adapter_, false); |
| 376 event_router()->AdapterPresentChanged(mock_adapter_, true); | 376 event_router()->AdapterPresentChanged(mock_adapter_, true); |
| 377 event_router()->AdapterPresentChanged(mock_adapter_, false); | 377 event_router()->AdapterPresentChanged(mock_adapter_, false); |
| 378 event_router()->AdapterDiscoveringChanged(mock_adapter_, true); | 378 event_router()->AdapterDiscoveringChanged(mock_adapter_, true); |
| 379 event_router()->AdapterDiscoveringChanged(mock_adapter_, false); | 379 event_router()->AdapterDiscoveringChanged(mock_adapter_, false); |
| 380 | 380 |
| 381 listener.Reply("go"); | 381 listener.Reply("go"); |
| 382 EXPECT_CALL(*mock_adapter_, |
| 383 RemoveObserver(testing::_)).WillOnce(testing::Return()); |
| 382 | 384 |
| 383 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 385 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 384 } | 386 } |
| 385 | 387 |
| 386 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevices) { | 388 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevices) { |
| 387 ResultCatcher catcher; | 389 ResultCatcher catcher; |
| 388 catcher.RestrictToProfile(browser()->profile()); | 390 catcher.RestrictToProfile(browser()->profile()); |
| 389 | 391 |
| 390 BluetoothAdapter::ConstDeviceList devices; | 392 BluetoothAdapter::ConstDeviceList devices; |
| 391 devices.push_back(device1_.get()); | 393 devices.push_back(device1_.get()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 // Load and wait for setup | 453 // Load and wait for setup |
| 452 ExtensionTestMessageListener listener("ready", true); | 454 ExtensionTestMessageListener listener("ready", true); |
| 453 ASSERT_TRUE(LoadExtension( | 455 ASSERT_TRUE(LoadExtension( |
| 454 test_data_dir_.AppendASCII("bluetooth/get_devices_error"))); | 456 test_data_dir_.AppendASCII("bluetooth/get_devices_error"))); |
| 455 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 457 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 456 | 458 |
| 457 listener.Reply("go"); | 459 listener.Reply("go"); |
| 458 | 460 |
| 459 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 461 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 460 } | 462 } |
| OLD | NEW |