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

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

Issue 10899037: Refactoring bluetooth API code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated the interfaces with class-level comments. Created 8 years, 3 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_interface.h"
8 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h" 8 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter_dbus.h"
9 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_device.h" 9 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_device_dbus.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 "chromeos/dbus/bluetooth_out_of_band_pairing_data.h"
18 #include "chrome/test/base/ui_test_utils.h" 19 #include "chrome/test/base/ui_test_utils.h"
19 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
20 21
22 using chromeos::BluetoothAdapterDBus;
21 using extensions::Extension; 23 using extensions::Extension;
22 24
23 namespace utils = extension_function_test_utils; 25 namespace utils = extension_function_test_utils;
24 namespace api = extensions::api; 26 namespace api = extensions::api;
25 27
26 namespace { 28 namespace {
27 29
28 static const char* kAdapterAddress = "A1:A2:A3:A4:A5:A6"; 30 static const char* kAdapterAddress = "A1:A2:A3:A4:A5:A6";
29 static const char* kName = "whatsinaname"; 31 static const char* kName = "whatsinaname";
30 32
31 class BluetoothApiTest : public PlatformAppApiTest { 33 class BluetoothApiTest : public PlatformAppApiTest {
32 public: 34 public:
33 BluetoothApiTest() : empty_extension_(utils::CreateEmptyExtension()) {} 35 BluetoothApiTest() : empty_extension_(utils::CreateEmptyExtension()) {}
34 36
35 virtual void SetUpOnMainThread() OVERRIDE { 37 virtual void SetUpOnMainThread() OVERRIDE {
36 // The browser will clean this up when it is torn down 38 // The browser will clean this up when it is torn down
37 mock_adapter_ = new testing::StrictMock<chromeos::MockBluetoothAdapter>( 39 mock_adapter_ =
38 kAdapterAddress, kName); 40 new testing::StrictMock<chromeos::MockBluetoothAdapterDBus>(
41 kAdapterAddress, kName);
39 event_router()->SetAdapterForTest(mock_adapter_); 42 event_router()->SetAdapterForTest(mock_adapter_);
40 43
41 device1_.reset(new testing::NiceMock<chromeos::MockBluetoothDevice>( 44 device1_.reset(new testing::NiceMock<chromeos::MockBluetoothDeviceDBus>(
42 mock_adapter_, "d1", "11:12:13:14:15:16", 45 mock_adapter_, "d1", "11:12:13:14:15:16",
43 true /* paired */, false /* bonded */, true /* connected */)); 46 true /* paired */, false /* bonded */, true /* connected */));
44 device2_.reset(new testing::NiceMock<chromeos::MockBluetoothDevice>( 47 device2_.reset(new testing::NiceMock<chromeos::MockBluetoothDeviceDBus>(
45 mock_adapter_, "d2", "21:22:23:24:25:26", 48 mock_adapter_, "d2", "21:22:23:24:25:26",
46 false /* paired */, true /* bonded */, false /* connected */)); 49 false /* paired */, true /* bonded */, false /* connected */));
47 } 50 }
48 51
49 void expectBooleanResult(bool expected, 52 void expectBooleanResult(bool expected,
50 UIThreadExtensionFunction* function) { 53 UIThreadExtensionFunction* function) {
51 scoped_ptr<base::Value> result( 54 scoped_ptr<base::Value> result(
52 utils::RunFunctionAndReturnSingleResult(function, "[]", browser())); 55 utils::RunFunctionAndReturnSingleResult(function, "[]", browser()));
53 ASSERT_TRUE(result.get() != NULL); 56 ASSERT_TRUE(result.get() != NULL);
54 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType()); 57 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType());
(...skipping 14 matching lines...) Expand all
69 } 72 }
70 73
71 template <class T> 74 template <class T>
72 T* setupFunction(T* function) { 75 T* setupFunction(T* function) {
73 function->set_extension(empty_extension_.get()); 76 function->set_extension(empty_extension_.get());
74 function->set_has_callback(true); 77 function->set_has_callback(true);
75 return function; 78 return function;
76 } 79 }
77 80
78 protected: 81 protected:
79 testing::StrictMock<chromeos::MockBluetoothAdapter>* mock_adapter_; 82 testing::StrictMock<chromeos::MockBluetoothAdapterDBus>* mock_adapter_;
80 scoped_ptr<testing::NiceMock<chromeos::MockBluetoothDevice> > device1_; 83 scoped_ptr<testing::NiceMock<chromeos::MockBluetoothDeviceDBus> > device1_;
81 scoped_ptr<testing::NiceMock<chromeos::MockBluetoothDevice> > device2_; 84 scoped_ptr<testing::NiceMock<chromeos::MockBluetoothDeviceDBus> > device2_;
82 85
83 chromeos::ExtensionBluetoothEventRouter* event_router() { 86 chromeos::ExtensionBluetoothEventRouter* event_router() {
84 return browser()->profile()->GetExtensionService()-> 87 return browser()->profile()->GetExtensionService()->
85 bluetooth_event_router(); 88 bluetooth_event_router();
86 } 89 }
87 90
88 private: 91 private:
89 scoped_refptr<Extension> empty_extension_; 92 scoped_refptr<Extension> empty_extension_;
90 }; 93 };
91 94
(...skipping 10 matching lines...) Expand all
102 chromeos::kBluetoothOutOfBandPairingDataSize); 105 chromeos::kBluetoothOutOfBandPairingDataSize);
103 return data; 106 return data;
104 } 107 }
105 108
106 static bool CallClosure(const base::Closure& callback) { 109 static bool CallClosure(const base::Closure& callback) {
107 callback.Run(); 110 callback.Run();
108 return true; 111 return true;
109 } 112 }
110 113
111 static bool CallOutOfBandPairingDataCallback( 114 static bool CallOutOfBandPairingDataCallback(
112 const chromeos::BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& 115 const BluetoothAdapterDBus::BluetoothOutOfBandPairingDataCallback&
113 callback) { 116 callback) {
114 callback.Run(GetOutOfBandPairingData()); 117 callback.Run(GetOutOfBandPairingData());
115 return true; 118 return true;
116 } 119 }
117 120
118 } // namespace 121 } // namespace
119 122
120 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, IsAvailable) { 123 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, IsAvailable) {
121 EXPECT_CALL(*mock_adapter_, IsPresent()) 124 EXPECT_CALL(*mock_adapter_, IsPresent())
122 .WillOnce(testing::Return(false)); 125 .WillOnce(testing::Return(false));
123 126
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 expectStringResult(kAdapterAddress, get_address); 160 expectStringResult(kAdapterAddress, get_address);
158 } 161 }
159 162
160 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetName) { 163 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetName) {
161 scoped_refptr<api::BluetoothGetNameFunction> get_name; 164 scoped_refptr<api::BluetoothGetNameFunction> get_name;
162 get_name = setupFunction(new api::BluetoothGetNameFunction); 165 get_name = setupFunction(new api::BluetoothGetNameFunction);
163 expectStringResult(kName, get_name); 166 expectStringResult(kName, get_name);
164 } 167 }
165 168
166 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevices) { 169 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevices) {
167 chromeos::BluetoothAdapter::ConstDeviceList devices; 170 chromeos::BluetoothAdapterDBus::ConstDeviceList devices;
168 devices.push_back(device1_.get()); 171 devices.push_back(device1_.get());
169 devices.push_back(device2_.get()); 172 devices.push_back(device2_.get());
170 173
171 EXPECT_CALL(*device1_, ProvidesServiceWithUUID(kCanonicalUuid)) 174 EXPECT_CALL(*device1_, ProvidesServiceWithUUID(kCanonicalUuid))
172 .WillOnce(testing::Return(false)); 175 .WillOnce(testing::Return(false));
173 EXPECT_CALL(*device2_, ProvidesServiceWithUUID(kCanonicalUuid)) 176 EXPECT_CALL(*device2_, ProvidesServiceWithUUID(kCanonicalUuid))
174 .WillOnce(testing::Return(true)); 177 .WillOnce(testing::Return(true));
175 178
176 EXPECT_CALL(*mock_adapter_, GetDevices()) 179 EXPECT_CALL(*mock_adapter_, GetDevices())
177 .WillOnce(testing::Return(devices)); 180 .WillOnce(testing::Return(devices));
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 event_router()->AdapterPoweredChanged(mock_adapter_, false); 439 event_router()->AdapterPoweredChanged(mock_adapter_, false);
437 event_router()->AdapterPresentChanged(mock_adapter_, true); 440 event_router()->AdapterPresentChanged(mock_adapter_, true);
438 event_router()->AdapterPresentChanged(mock_adapter_, false); 441 event_router()->AdapterPresentChanged(mock_adapter_, false);
439 event_router()->AdapterDiscoveringChanged(mock_adapter_, true); 442 event_router()->AdapterDiscoveringChanged(mock_adapter_, true);
440 event_router()->AdapterDiscoveringChanged(mock_adapter_, false); 443 event_router()->AdapterDiscoveringChanged(mock_adapter_, false);
441 444
442 listener.Reply("go"); 445 listener.Reply("go");
443 446
444 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 447 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
445 } 448 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698