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" |
11 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" | 11 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" |
12 #include "chrome/browser/extensions/extension_apitest.h" | 12 #include "chrome/browser/extensions/extension_apitest.h" |
13 #include "chrome/browser/extensions/extension_function_test_utils.h" | 13 #include "chrome/browser/extensions/extension_function_test_utils.h" |
14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
15 #include "chrome/browser/extensions/extension_test_message_listener.h" | 15 #include "chrome/browser/extensions/extension_test_message_listener.h" |
16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
17 #include "chromeos/dbus/bluetooth_out_of_band_client.h" | 17 #include "chromeos/dbus/bluetooth_out_of_band_client.h" |
| 18 #include "chrome/test/base/ui_test_utils.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
19 | 20 |
20 using extensions::Extension; | 21 using extensions::Extension; |
21 | 22 |
22 namespace utils = extension_function_test_utils; | 23 namespace utils = extension_function_test_utils; |
23 namespace api = extensions::api; | 24 namespace api = extensions::api; |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 class BluetoothApiTest : public PlatformAppApiTest { | 28 class BluetoothApiTest : public PlatformAppApiTest { |
(...skipping 21 matching lines...) Expand all Loading... |
49 template <class T> | 50 template <class T> |
50 T* setupFunction(T* function) { | 51 T* setupFunction(T* function) { |
51 function->set_extension(empty_extension_.get()); | 52 function->set_extension(empty_extension_.get()); |
52 function->set_has_callback(true); | 53 function->set_has_callback(true); |
53 return function; | 54 return function; |
54 } | 55 } |
55 | 56 |
56 protected: | 57 protected: |
57 testing::StrictMock<chromeos::MockBluetoothAdapter>* mock_adapter_; | 58 testing::StrictMock<chromeos::MockBluetoothAdapter>* mock_adapter_; |
58 | 59 |
59 private: | |
60 chromeos::ExtensionBluetoothEventRouter* event_router() { | 60 chromeos::ExtensionBluetoothEventRouter* event_router() { |
61 return browser()->profile()->GetExtensionService()-> | 61 return browser()->profile()->GetExtensionService()-> |
62 bluetooth_event_router(); | 62 bluetooth_event_router(); |
63 } | 63 } |
64 | 64 |
| 65 private: |
65 scoped_refptr<Extension> empty_extension_; | 66 scoped_refptr<Extension> empty_extension_; |
66 }; | 67 }; |
67 | 68 |
68 static const char kOutOfBandPairingDataHash[] = "0123456789ABCDEh"; | 69 static const char kOutOfBandPairingDataHash[] = "0123456789ABCDEh"; |
69 static const char kOutOfBandPairingDataRandomizer[] = "0123456789ABCDEr"; | 70 static const char kOutOfBandPairingDataRandomizer[] = "0123456789ABCDEr"; |
70 | 71 |
71 static chromeos::BluetoothOutOfBandPairingData GetOutOfBandPairingData() { | 72 static chromeos::BluetoothOutOfBandPairingData GetOutOfBandPairingData() { |
72 chromeos::BluetoothOutOfBandPairingData data; | 73 chromeos::BluetoothOutOfBandPairingData data; |
73 memcpy(&(data.hash), kOutOfBandPairingDataHash, | 74 memcpy(&(data.hash), kOutOfBandPairingDataHash, |
74 chromeos::kBluetoothOutOfBandPairingDataSize); | 75 chromeos::kBluetoothOutOfBandPairingDataSize); |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 // Reset to try stopping with an error | 317 // Reset to try stopping with an error |
317 testing::Mock::VerifyAndClearExpectations(mock_adapter_); | 318 testing::Mock::VerifyAndClearExpectations(mock_adapter_); |
318 EXPECT_CALL(*mock_adapter_, | 319 EXPECT_CALL(*mock_adapter_, |
319 SetDiscovering(false, | 320 SetDiscovering(false, |
320 testing::_, | 321 testing::_, |
321 testing::Truly(CallClosure))); | 322 testing::Truly(CallClosure))); |
322 stop_function = setupFunction(new api::BluetoothStopDiscoveryFunction); | 323 stop_function = setupFunction(new api::BluetoothStopDiscoveryFunction); |
323 error = utils::RunFunctionAndReturnError(stop_function, "[]", browser()); | 324 error = utils::RunFunctionAndReturnError(stop_function, "[]", browser()); |
324 ASSERT_TRUE(!error.empty()); | 325 ASSERT_TRUE(!error.empty()); |
325 } | 326 } |
| 327 |
| 328 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Events) { |
| 329 ResultCatcher catcher; |
| 330 catcher.RestrictToProfile(browser()->profile()); |
| 331 |
| 332 // Load and wait for setup |
| 333 ExtensionTestMessageListener listener("ready", true); |
| 334 const extensions::Extension* extension = |
| 335 LoadExtension(test_data_dir_.AppendASCII("bluetooth")); |
| 336 GURL page_url = extension->GetResourceURL("test_events.html"); |
| 337 ui_test_utils::NavigateToURL(browser(), page_url); |
| 338 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 339 |
| 340 event_router()->AdapterPoweredChanged(mock_adapter_, true); |
| 341 event_router()->AdapterPoweredChanged(mock_adapter_, false); |
| 342 event_router()->AdapterPresentChanged(mock_adapter_, true); |
| 343 event_router()->AdapterPresentChanged(mock_adapter_, false); |
| 344 |
| 345 listener.Reply("go"); |
| 346 |
| 347 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 348 } |
OLD | NEW |