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

Side by Side Diff: device/bluetooth/bluetooth_experimental_chromeos_unittest.cc

Issue 13870020: Bluetooth: Add support for pairing display notifications (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fixed wrong check made twice Created 7 years, 8 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
« no previous file with comments | « device/bluetooth/bluetooth_device_experimental_chromeos.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chromeos/chromeos_switches.h" 8 #include "chromeos/chromeos_switches.h"
9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" 9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h"
10 #include "chromeos/dbus/fake_bluetooth_device_client.h" 10 #include "chromeos/dbus/fake_bluetooth_device_client.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 }; 121 };
122 122
123 class TestPairingDelegate : public BluetoothDevice::PairingDelegate { 123 class TestPairingDelegate : public BluetoothDevice::PairingDelegate {
124 public: 124 public:
125 TestPairingDelegate() 125 TestPairingDelegate()
126 : call_count_(0), 126 : call_count_(0),
127 request_pincode_count_(0), 127 request_pincode_count_(0),
128 request_passkey_count_(0), 128 request_passkey_count_(0),
129 display_pincode_count_(0), 129 display_pincode_count_(0),
130 display_passkey_count_(0), 130 display_passkey_count_(0),
131 keys_entered_count_(0),
131 confirm_passkey_count_(0), 132 confirm_passkey_count_(0),
132 dismiss_count_(0) {} 133 dismiss_count_(0),
134 last_passkey_(9999999U),
135 last_entered_(999U) {}
133 virtual ~TestPairingDelegate() {} 136 virtual ~TestPairingDelegate() {}
134 137
135 void RequestPinCode(BluetoothDevice* device) OVERRIDE { 138 void RequestPinCode(BluetoothDevice* device) OVERRIDE {
136 ++call_count_; 139 ++call_count_;
137 ++request_pincode_count_; 140 ++request_pincode_count_;
138 QuitMessageLoop(); 141 QuitMessageLoop();
139 } 142 }
140 143
141 void RequestPasskey(BluetoothDevice* device) OVERRIDE { 144 void RequestPasskey(BluetoothDevice* device) OVERRIDE {
142 ++call_count_; 145 ++call_count_;
(...skipping 10 matching lines...) Expand all
153 } 156 }
154 157
155 void DisplayPasskey(BluetoothDevice* device, 158 void DisplayPasskey(BluetoothDevice* device,
156 uint32 passkey) OVERRIDE { 159 uint32 passkey) OVERRIDE {
157 ++call_count_; 160 ++call_count_;
158 ++display_passkey_count_; 161 ++display_passkey_count_;
159 last_passkey_ = passkey; 162 last_passkey_ = passkey;
160 QuitMessageLoop(); 163 QuitMessageLoop();
161 } 164 }
162 165
166 void KeysEntered(BluetoothDevice* device,
167 uint32 entered) OVERRIDE {
168 ++call_count_;
169 ++keys_entered_count_;
170 last_entered_ = entered;
171 QuitMessageLoop();
172 }
173
163 void ConfirmPasskey(BluetoothDevice* device, 174 void ConfirmPasskey(BluetoothDevice* device,
164 uint32 passkey) OVERRIDE { 175 uint32 passkey) OVERRIDE {
165 ++call_count_; 176 ++call_count_;
166 ++confirm_passkey_count_; 177 ++confirm_passkey_count_;
167 last_passkey_ = passkey; 178 last_passkey_ = passkey;
168 QuitMessageLoop(); 179 QuitMessageLoop();
169 } 180 }
170 181
171 void DismissDisplayOrConfirm() OVERRIDE { 182 void DismissDisplayOrConfirm() OVERRIDE {
172 ++call_count_; 183 ++call_count_;
173 ++dismiss_count_; 184 ++dismiss_count_;
174 QuitMessageLoop(); 185 QuitMessageLoop();
175 } 186 }
176 187
177 int call_count_; 188 int call_count_;
178 int request_pincode_count_; 189 int request_pincode_count_;
179 int request_passkey_count_; 190 int request_passkey_count_;
180 int display_pincode_count_; 191 int display_pincode_count_;
181 int display_passkey_count_; 192 int display_passkey_count_;
193 int keys_entered_count_;
182 int confirm_passkey_count_; 194 int confirm_passkey_count_;
183 int dismiss_count_; 195 int dismiss_count_;
184 uint32 last_passkey_; 196 uint32 last_passkey_;
197 uint32 last_entered_;
185 std::string last_pincode_; 198 std::string last_pincode_;
186 199
187 private: 200 private:
188 // Some tests use a message loop since background processing is simulated; 201 // Some tests use a message loop since background processing is simulated;
189 // break out of those loops. 202 // break out of those loops.
190 void QuitMessageLoop() { 203 void QuitMessageLoop() {
191 if (MessageLoop::current() && MessageLoop::current()->is_running()) 204 if (MessageLoop::current() && MessageLoop::current()->is_running())
192 MessageLoop::current()->Quit(); 205 MessageLoop::current()->Quit();
193 } 206 }
194 }; 207 };
(...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 // One change for connected, and one for paired. 1245 // One change for connected, and one for paired.
1233 EXPECT_EQ(2, observer.device_changed_count_); 1246 EXPECT_EQ(2, observer.device_changed_count_);
1234 EXPECT_EQ(device, observer.last_device_); 1247 EXPECT_EQ(device, observer.last_device_);
1235 1248
1236 EXPECT_TRUE(device->IsConnected()); 1249 EXPECT_TRUE(device->IsConnected());
1237 EXPECT_FALSE(device->IsConnecting()); 1250 EXPECT_FALSE(device->IsConnecting());
1238 1251
1239 EXPECT_TRUE(device->IsPaired()); 1252 EXPECT_TRUE(device->IsPaired());
1240 1253
1241 // Pairing dialog should be dismissed 1254 // Pairing dialog should be dismissed
1242 EXPECT_EQ(2, pairing_delegate.call_count_);
1243 EXPECT_EQ(1, pairing_delegate.dismiss_count_); 1255 EXPECT_EQ(1, pairing_delegate.dismiss_count_);
1244 1256
1245 // Make sure the trusted property has been set to true. 1257 // Make sure the trusted property has been set to true.
1246 FakeBluetoothDeviceClient::Properties* properties = 1258 FakeBluetoothDeviceClient::Properties* properties =
1247 fake_bluetooth_device_client_->GetProperties( 1259 fake_bluetooth_device_client_->GetProperties(
1248 dbus::ObjectPath(FakeBluetoothDeviceClient::kAppleKeyboardPath)); 1260 dbus::ObjectPath(FakeBluetoothDeviceClient::kAppleKeyboardPath));
1249 EXPECT_TRUE(properties->trusted.value()); 1261 EXPECT_TRUE(properties->trusted.value());
1250 } 1262 }
1251 1263
1252 TEST_F(BluetoothExperimentalChromeOSTest, PairMotorolaKeyboard) { 1264 TEST_F(BluetoothExperimentalChromeOSTest, PairMotorolaKeyboard) {
(...skipping 14 matching lines...) Expand all
1267 adapter_->AddObserver(&observer); 1279 adapter_->AddObserver(&observer);
1268 1280
1269 TestPairingDelegate pairing_delegate; 1281 TestPairingDelegate pairing_delegate;
1270 device->Connect( 1282 device->Connect(
1271 &pairing_delegate, 1283 &pairing_delegate,
1272 base::Bind(&BluetoothExperimentalChromeOSTest::Callback, 1284 base::Bind(&BluetoothExperimentalChromeOSTest::Callback,
1273 base::Unretained(this)), 1285 base::Unretained(this)),
1274 base::Bind(&BluetoothExperimentalChromeOSTest::ConnectErrorCallback, 1286 base::Bind(&BluetoothExperimentalChromeOSTest::ConnectErrorCallback,
1275 base::Unretained(this))); 1287 base::Unretained(this)));
1276 1288
1277 EXPECT_EQ(1, pairing_delegate.call_count_); 1289 // One call for DisplayPasskey() and one for KeysEntered().
1290 EXPECT_EQ(2, pairing_delegate.call_count_);
1278 EXPECT_EQ(1, pairing_delegate.display_passkey_count_); 1291 EXPECT_EQ(1, pairing_delegate.display_passkey_count_);
1279 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); 1292 EXPECT_EQ(123456U, pairing_delegate.last_passkey_);
1293 EXPECT_EQ(1, pairing_delegate.keys_entered_count_);
1294 EXPECT_EQ(0U, pairing_delegate.last_entered_);
1295
1280 EXPECT_TRUE(device->IsConnecting()); 1296 EXPECT_TRUE(device->IsConnecting());
1281 1297
1282 // TODO(keybuk): verify we get typing notifications 1298 // One call to KeysEntered() for each key, including [enter].
1299 for(int i = 1; i <= 7; ++i) {
1300 message_loop.Run();
1301
1302 EXPECT_EQ(2 + i, pairing_delegate.call_count_);
1303 EXPECT_EQ(1 + i, pairing_delegate.keys_entered_count_);
1304 EXPECT_EQ(static_cast<uint32_t>(i), pairing_delegate.last_entered_);
1305 }
1283 1306
1284 message_loop.Run(); 1307 message_loop.Run();
1285 1308
1309 // 8 KeysEntered notifications (0 to 7, inclusive). Two aditional calls for
1310 // DisplayPasskey() and DismissDisplayOrConfirm().
1311 EXPECT_EQ(10, pairing_delegate.call_count_);
1312 EXPECT_EQ(8, pairing_delegate.keys_entered_count_);
1313 EXPECT_EQ(7U, pairing_delegate.last_entered_);
1314
1286 EXPECT_EQ(1, callback_count_); 1315 EXPECT_EQ(1, callback_count_);
1287 EXPECT_EQ(0, error_callback_count_); 1316 EXPECT_EQ(0, error_callback_count_);
1288 1317
1289 // One change for connected, and one for paired. 1318 // One change for connected, and one for paired.
1290 EXPECT_EQ(2, observer.device_changed_count_); 1319 EXPECT_EQ(2, observer.device_changed_count_);
1291 EXPECT_EQ(device, observer.last_device_); 1320 EXPECT_EQ(device, observer.last_device_);
1292 1321
1293 EXPECT_TRUE(device->IsConnected()); 1322 EXPECT_TRUE(device->IsConnected());
1294 EXPECT_FALSE(device->IsConnecting()); 1323 EXPECT_FALSE(device->IsConnecting());
1295 1324
1296 EXPECT_TRUE(device->IsPaired()); 1325 EXPECT_TRUE(device->IsPaired());
1297 1326
1298 // Pairing dialog should be dismissed 1327 // Pairing dialog should be dismissed
1299 EXPECT_EQ(2, pairing_delegate.call_count_);
1300 EXPECT_EQ(1, pairing_delegate.dismiss_count_); 1328 EXPECT_EQ(1, pairing_delegate.dismiss_count_);
1301 1329
1302 // Make sure the trusted property has been set to true. 1330 // Make sure the trusted property has been set to true.
1303 FakeBluetoothDeviceClient::Properties* properties = 1331 FakeBluetoothDeviceClient::Properties* properties =
1304 fake_bluetooth_device_client_->GetProperties( 1332 fake_bluetooth_device_client_->GetProperties(
1305 dbus::ObjectPath(FakeBluetoothDeviceClient::kMotorolaKeyboardPath)); 1333 dbus::ObjectPath(FakeBluetoothDeviceClient::kMotorolaKeyboardPath));
1306 EXPECT_TRUE(properties->trusted.value()); 1334 EXPECT_TRUE(properties->trusted.value());
1307 } 1335 }
1308 1336
1309 TEST_F(BluetoothExperimentalChromeOSTest, PairSonyHeadphones) { 1337 TEST_F(BluetoothExperimentalChromeOSTest, PairSonyHeadphones) {
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
1895 EXPECT_FALSE(device->IsConnected()); 1923 EXPECT_FALSE(device->IsConnected());
1896 EXPECT_FALSE(device->IsConnecting()); 1924 EXPECT_FALSE(device->IsConnecting());
1897 EXPECT_FALSE(device->IsPaired()); 1925 EXPECT_FALSE(device->IsPaired());
1898 1926
1899 // Pairing dialog should be dismissed 1927 // Pairing dialog should be dismissed
1900 EXPECT_EQ(1, pairing_delegate.call_count_); 1928 EXPECT_EQ(1, pairing_delegate.call_count_);
1901 EXPECT_EQ(1, pairing_delegate.dismiss_count_); 1929 EXPECT_EQ(1, pairing_delegate.dismiss_count_);
1902 } 1930 }
1903 1931
1904 } // namespace chromeos 1932 } // namespace chromeos
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_device_experimental_chromeos.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698