Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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) {} |
| 133 virtual ~TestPairingDelegate() {} | 134 virtual ~TestPairingDelegate() {} |
| 134 | 135 |
| 135 void RequestPinCode(BluetoothDevice* device) OVERRIDE { | 136 void RequestPinCode(BluetoothDevice* device) OVERRIDE { |
| 136 ++call_count_; | 137 ++call_count_; |
| 137 ++request_pincode_count_; | 138 ++request_pincode_count_; |
| 138 QuitMessageLoop(); | 139 QuitMessageLoop(); |
| 139 } | 140 } |
| 140 | 141 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 153 } | 154 } |
| 154 | 155 |
| 155 void DisplayPasskey(BluetoothDevice* device, | 156 void DisplayPasskey(BluetoothDevice* device, |
| 156 uint32 passkey) OVERRIDE { | 157 uint32 passkey) OVERRIDE { |
| 157 ++call_count_; | 158 ++call_count_; |
| 158 ++display_passkey_count_; | 159 ++display_passkey_count_; |
| 159 last_passkey_ = passkey; | 160 last_passkey_ = passkey; |
| 160 QuitMessageLoop(); | 161 QuitMessageLoop(); |
| 161 } | 162 } |
| 162 | 163 |
| 164 void KeysEntered(BluetoothDevice* device, | |
| 165 uint32 entered) OVERRIDE { | |
| 166 ++call_count_; | |
| 167 ++keys_entered_count_; | |
| 168 last_entered_ = entered; | |
| 169 QuitMessageLoop(); | |
| 170 } | |
| 171 | |
| 163 void ConfirmPasskey(BluetoothDevice* device, | 172 void ConfirmPasskey(BluetoothDevice* device, |
| 164 uint32 passkey) OVERRIDE { | 173 uint32 passkey) OVERRIDE { |
| 165 ++call_count_; | 174 ++call_count_; |
| 166 ++confirm_passkey_count_; | 175 ++confirm_passkey_count_; |
| 167 last_passkey_ = passkey; | 176 last_passkey_ = passkey; |
| 168 QuitMessageLoop(); | 177 QuitMessageLoop(); |
| 169 } | 178 } |
| 170 | 179 |
| 171 void DismissDisplayOrConfirm() OVERRIDE { | 180 void DismissDisplayOrConfirm() OVERRIDE { |
| 172 ++call_count_; | 181 ++call_count_; |
| 173 ++dismiss_count_; | 182 ++dismiss_count_; |
| 174 QuitMessageLoop(); | 183 QuitMessageLoop(); |
| 175 } | 184 } |
| 176 | 185 |
| 177 int call_count_; | 186 int call_count_; |
| 178 int request_pincode_count_; | 187 int request_pincode_count_; |
| 179 int request_passkey_count_; | 188 int request_passkey_count_; |
| 180 int display_pincode_count_; | 189 int display_pincode_count_; |
| 181 int display_passkey_count_; | 190 int display_passkey_count_; |
| 191 int keys_entered_count_; | |
| 182 int confirm_passkey_count_; | 192 int confirm_passkey_count_; |
| 183 int dismiss_count_; | 193 int dismiss_count_; |
| 184 uint32 last_passkey_; | 194 uint32 last_passkey_; |
| 195 uint32 last_entered_; | |
| 185 std::string last_pincode_; | 196 std::string last_pincode_; |
| 186 | 197 |
| 187 private: | 198 private: |
| 188 // Some tests use a message loop since background processing is simulated; | 199 // Some tests use a message loop since background processing is simulated; |
| 189 // break out of those loops. | 200 // break out of those loops. |
| 190 void QuitMessageLoop() { | 201 void QuitMessageLoop() { |
| 191 if (MessageLoop::current() && MessageLoop::current()->is_running()) | 202 if (MessageLoop::current() && MessageLoop::current()->is_running()) |
| 192 MessageLoop::current()->Quit(); | 203 MessageLoop::current()->Quit(); |
| 193 } | 204 } |
| 194 }; | 205 }; |
| (...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1211 adapter_->AddObserver(&observer); | 1222 adapter_->AddObserver(&observer); |
| 1212 | 1223 |
| 1213 TestPairingDelegate pairing_delegate; | 1224 TestPairingDelegate pairing_delegate; |
| 1214 device->Connect( | 1225 device->Connect( |
| 1215 &pairing_delegate, | 1226 &pairing_delegate, |
| 1216 base::Bind(&BluetoothExperimentalChromeOSTest::Callback, | 1227 base::Bind(&BluetoothExperimentalChromeOSTest::Callback, |
| 1217 base::Unretained(this)), | 1228 base::Unretained(this)), |
| 1218 base::Bind(&BluetoothExperimentalChromeOSTest::ConnectErrorCallback, | 1229 base::Bind(&BluetoothExperimentalChromeOSTest::ConnectErrorCallback, |
| 1219 base::Unretained(this))); | 1230 base::Unretained(this))); |
| 1220 | 1231 |
| 1221 EXPECT_EQ(1, pairing_delegate.call_count_); | 1232 // One call for DisplayPasskey() and one for KeysEntered(). |
| 1233 EXPECT_EQ(2, pairing_delegate.call_count_); | |
| 1222 EXPECT_EQ(1, pairing_delegate.display_passkey_count_); | 1234 EXPECT_EQ(1, pairing_delegate.display_passkey_count_); |
| 1223 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); | 1235 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); |
| 1224 EXPECT_TRUE(device->IsConnecting()); | 1236 EXPECT_TRUE(device->IsConnecting()); |
| 1225 | 1237 |
|
keybuk
2013/04/18 23:50:36
Doesn't check the KeysEntered call here.
Should v
deymo
2013/04/19 01:35:00
Done.
| |
| 1226 // TODO(keybuk): verify we get typing notifications | 1238 // One call to KeysEntered() for each key, including [enter]. |
| 1239 for(int i = 1; i <= 7; ++i) { | |
| 1240 message_loop.Run(); | |
| 1241 | |
| 1242 EXPECT_EQ(2 + i, pairing_delegate.call_count_); | |
| 1243 EXPECT_EQ(1 + i, pairing_delegate.keys_entered_count_); | |
| 1244 EXPECT_EQ((uint32_t)i, pairing_delegate.last_entered_); | |
|
keybuk
2013/04/18 23:50:36
style: use static_cast<>
http://google-styleguide.
deymo
2013/04/19 01:35:00
Done.
| |
| 1245 } | |
| 1227 | 1246 |
| 1228 message_loop.Run(); | 1247 message_loop.Run(); |
| 1229 | 1248 |
| 1249 // 8 KeysEntered notifications (0 to 7, inclusive). Two aditional calls for | |
| 1250 // DisplayPasskey() and DismissDisplayOrConfirm(). | |
| 1251 EXPECT_EQ(10, pairing_delegate.call_count_); | |
| 1252 EXPECT_EQ(8, pairing_delegate.keys_entered_count_); | |
| 1253 EXPECT_EQ(7U, pairing_delegate.last_entered_); | |
| 1254 | |
| 1230 EXPECT_EQ(1, callback_count_); | 1255 EXPECT_EQ(1, callback_count_); |
| 1231 EXPECT_EQ(0, error_callback_count_); | 1256 EXPECT_EQ(0, error_callback_count_); |
| 1232 | 1257 |
| 1233 // One change for connected, and one for paired. | 1258 // One change for connected, and one for paired. |
| 1234 EXPECT_EQ(2, observer.device_changed_count_); | 1259 EXPECT_EQ(2, observer.device_changed_count_); |
| 1235 EXPECT_EQ(device, observer.last_device_); | 1260 EXPECT_EQ(device, observer.last_device_); |
| 1236 | 1261 |
| 1237 EXPECT_TRUE(device->IsConnected()); | 1262 EXPECT_TRUE(device->IsConnected()); |
| 1238 EXPECT_FALSE(device->IsConnecting()); | 1263 EXPECT_FALSE(device->IsConnecting()); |
| 1239 | 1264 |
| 1240 EXPECT_TRUE(device->IsPaired()); | 1265 EXPECT_TRUE(device->IsPaired()); |
| 1241 | 1266 |
| 1242 // Pairing dialog should be dismissed | 1267 // Pairing dialog should be dismissed |
| 1243 EXPECT_EQ(2, pairing_delegate.call_count_); | |
| 1244 EXPECT_EQ(1, pairing_delegate.dismiss_count_); | 1268 EXPECT_EQ(1, pairing_delegate.dismiss_count_); |
| 1245 | 1269 |
| 1246 // Make sure the trusted property has been set to true. | 1270 // Make sure the trusted property has been set to true. |
| 1247 FakeBluetoothDeviceClient::Properties* properties = | 1271 FakeBluetoothDeviceClient::Properties* properties = |
| 1248 fake_bluetooth_device_client_->GetProperties( | 1272 fake_bluetooth_device_client_->GetProperties( |
| 1249 dbus::ObjectPath(FakeBluetoothDeviceClient::kMotorolaKeyboardPath)); | 1273 dbus::ObjectPath(FakeBluetoothDeviceClient::kMotorolaKeyboardPath)); |
| 1250 EXPECT_TRUE(properties->trusted.value()); | 1274 EXPECT_TRUE(properties->trusted.value()); |
| 1251 } | 1275 } |
| 1252 | 1276 |
| 1253 TEST_F(BluetoothExperimentalChromeOSTest, PairSonyHeadphones) { | 1277 TEST_F(BluetoothExperimentalChromeOSTest, PairSonyHeadphones) { |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1839 EXPECT_FALSE(device->IsConnected()); | 1863 EXPECT_FALSE(device->IsConnected()); |
| 1840 EXPECT_FALSE(device->IsConnecting()); | 1864 EXPECT_FALSE(device->IsConnecting()); |
| 1841 EXPECT_FALSE(device->IsPaired()); | 1865 EXPECT_FALSE(device->IsPaired()); |
| 1842 | 1866 |
| 1843 // Pairing dialog should be dismissed | 1867 // Pairing dialog should be dismissed |
| 1844 EXPECT_EQ(1, pairing_delegate.call_count_); | 1868 EXPECT_EQ(1, pairing_delegate.call_count_); |
| 1845 EXPECT_EQ(1, pairing_delegate.dismiss_count_); | 1869 EXPECT_EQ(1, pairing_delegate.dismiss_count_); |
| 1846 } | 1870 } |
| 1847 | 1871 |
| 1848 } // namespace chromeos | 1872 } // namespace chromeos |
| OLD | NEW |