Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(433)

Side by Side Diff: chrome/browser/extensions/api/bluetooth/bluetooth_apitest_chromeos.cc

Issue 10536159: Bluetooth Extension API: Add a discovery API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reland Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
19 19
20 using extensions::Extension; 20 using extensions::Extension;
21 21
22 namespace utils = extension_function_test_utils; 22 namespace utils = extension_function_test_utils;
23 namespace api = extensions::api; 23 namespace api = extensions::api;
24 24
25 namespace chromeos {
26
27 class BluetoothAdapater;
28
29 } // namespace chromeos
30
31
32 namespace { 25 namespace {
33 26
34 class BluetoothApiTest : public PlatformAppApiTest { 27 class BluetoothApiTest : public PlatformAppApiTest {
35 public: 28 public:
36 BluetoothApiTest() : empty_extension_(utils::CreateEmptyExtension()) {} 29 BluetoothApiTest() : empty_extension_(utils::CreateEmptyExtension()) {}
37 30
38 virtual void SetUpOnMainThread() OVERRIDE { 31 virtual void SetUpOnMainThread() OVERRIDE {
39 // The browser will clean this up when it is torn down 32 // The browser will clean this up when it is torn down
40 mock_adapter_ = new testing::StrictMock<chromeos::MockBluetoothAdapter>; 33 mock_adapter_ = new testing::StrictMock<chromeos::MockBluetoothAdapter>;
41 event_router()->SetAdapterForTest(mock_adapter_); 34 event_router()->SetAdapterForTest(mock_adapter_);
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 set_oob_function = setupFunction( 268 set_oob_function = setupFunction(
276 new api::BluetoothSetOutOfBandPairingDataFunction); 269 new api::BluetoothSetOutOfBandPairingDataFunction);
277 std::string error( 270 std::string error(
278 utils::RunFunctionAndReturnError(set_oob_function, params, browser())); 271 utils::RunFunctionAndReturnError(set_oob_function, params, browser()));
279 EXPECT_FALSE(error.empty()); 272 EXPECT_FALSE(error.empty());
280 273
281 // TODO(bryeung): Also test setting the data when there is support for 274 // TODO(bryeung): Also test setting the data when there is support for
282 // ArrayBuffers in the arguments to the RunFunctionAnd* methods. 275 // ArrayBuffers in the arguments to the RunFunctionAnd* methods.
283 // crbug.com/132796 276 // crbug.com/132796
284 } 277 }
278
279 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Discovery) {
280 // TODO(bryeung): test that no events are sent now (crbug.com/132616)
281
282 // Try with a failure to start
283 EXPECT_CALL(*mock_adapter_,
284 SetDiscovering(true,
285 testing::_,
286 testing::Truly(CallClosure)));
287 scoped_refptr<api::BluetoothStartDiscoveryFunction> start_function;
288 start_function = setupFunction(new api::BluetoothStartDiscoveryFunction);
289 std::string error(
290 utils::RunFunctionAndReturnError(start_function, "[]", browser()));
291 ASSERT_TRUE(!error.empty());
292
293 // Reset for a successful start
294 testing::Mock::VerifyAndClearExpectations(mock_adapter_);
295 EXPECT_CALL(*mock_adapter_,
296 SetDiscovering(true,
297 testing::Truly(CallClosure),
298 testing::_));
299
300 start_function = setupFunction(new api::BluetoothStartDiscoveryFunction);
301 (void)utils::RunFunctionAndReturnError(start_function, "[]", browser());
302
303 // TODO(bryeung): test that events are sent now (crbug.com/132616)
304
305 // Reset to try stopping
306 testing::Mock::VerifyAndClearExpectations(mock_adapter_);
307 EXPECT_CALL(*mock_adapter_,
308 SetDiscovering(false,
309 testing::Truly(CallClosure),
310 testing::_));
311 scoped_refptr<api::BluetoothStopDiscoveryFunction> stop_function;
312 stop_function = setupFunction(new api::BluetoothStopDiscoveryFunction);
313 (void)utils::RunFunctionAndReturnResult(stop_function, "[]", browser());
314
315 // TODO(bryeung): test that no events are sent now (crbug.com/132616)
316
317 // Reset to try stopping with an error
318 testing::Mock::VerifyAndClearExpectations(mock_adapter_);
319 EXPECT_CALL(*mock_adapter_,
320 SetDiscovering(false,
321 testing::_,
322 testing::Truly(CallClosure)));
323 stop_function = setupFunction(new api::BluetoothStopDiscoveryFunction);
324 error = utils::RunFunctionAndReturnError(stop_function, "[]", browser());
325 ASSERT_TRUE(!error.empty());
326 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.cc ('k') | chrome/browser/extensions/extension_event_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698