Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_controller.h" | 10 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_controller.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 TEST_F(BluetoothChooserControllerTest, AddDevice) { | 81 TEST_F(BluetoothChooserControllerTest, AddDevice) { |
| 82 EXPECT_CALL(mock_bluetooth_chooser_view_, OnOptionAdded(0)).Times(1); | 82 EXPECT_CALL(mock_bluetooth_chooser_view_, OnOptionAdded(0)).Times(1); |
| 83 bluetooth_chooser_controller_.AddOrUpdateDevice( | 83 bluetooth_chooser_controller_.AddOrUpdateDevice( |
| 84 "id_a", false /* should_update_name */, base::ASCIIToUTF16("a"), | 84 "id_a", false /* should_update_name */, base::ASCIIToUTF16("a"), |
| 85 true /* is_gatt_connected */, true /* is_paired */, | 85 true /* is_gatt_connected */, true /* is_paired */, |
| 86 -1 /* signal_strength_level */); | 86 -1 /* signal_strength_level */); |
| 87 EXPECT_EQ(1u, bluetooth_chooser_controller_.NumOptions()); | 87 EXPECT_EQ(1u, bluetooth_chooser_controller_.NumOptions()); |
| 88 EXPECT_EQ(base::ASCIIToUTF16("a"), | 88 EXPECT_EQ(base::ASCIIToUTF16("a"), |
| 89 bluetooth_chooser_controller_.GetOption(0)); | 89 bluetooth_chooser_controller_.GetOption(0)); |
| 90 EXPECT_EQ(-1, bluetooth_chooser_controller_.GetSignalStrengthLevel(0)); | 90 EXPECT_EQ(-1, bluetooth_chooser_controller_.GetSignalStrengthLevel(0)); |
| 91 EXPECT_TRUE(bluetooth_chooser_controller_.IsConnected(0)); | |
| 92 EXPECT_TRUE(bluetooth_chooser_controller_.IsPaired(0)); | |
| 91 testing::Mock::VerifyAndClearExpectations(&mock_bluetooth_chooser_view_); | 93 testing::Mock::VerifyAndClearExpectations(&mock_bluetooth_chooser_view_); |
| 92 | 94 |
| 93 EXPECT_CALL(mock_bluetooth_chooser_view_, OnOptionAdded(1)).Times(1); | 95 EXPECT_CALL(mock_bluetooth_chooser_view_, OnOptionAdded(1)).Times(1); |
| 94 bluetooth_chooser_controller_.AddOrUpdateDevice( | 96 bluetooth_chooser_controller_.AddOrUpdateDevice( |
| 95 "id_b", false /* should_update_name */, base::ASCIIToUTF16("b"), | 97 "id_b", false /* should_update_name */, base::ASCIIToUTF16("b"), |
| 96 true /* is_gatt_connected */, true /* is_paired */, | 98 true /* is_gatt_connected */, true /* is_paired */, |
| 97 0 /* signal_strength_level */); | 99 0 /* signal_strength_level */); |
| 98 EXPECT_EQ(2u, bluetooth_chooser_controller_.NumOptions()); | 100 EXPECT_EQ(2u, bluetooth_chooser_controller_.NumOptions()); |
| 99 EXPECT_EQ(base::ASCIIToUTF16("b"), | 101 EXPECT_EQ(base::ASCIIToUTF16("b"), |
| 100 bluetooth_chooser_controller_.GetOption(1)); | 102 bluetooth_chooser_controller_.GetOption(1)); |
| 101 EXPECT_EQ(0, bluetooth_chooser_controller_.GetSignalStrengthLevel(1)); | 103 EXPECT_EQ(0, bluetooth_chooser_controller_.GetSignalStrengthLevel(1)); |
| 104 EXPECT_TRUE(bluetooth_chooser_controller_.IsConnected(1)); | |
|
Jeffrey Yasskin
2016/09/21 00:39:25
Only the first two EXPECT_TRUE(bluetooth_chooser_c
juncai
2016/09/21 17:43:15
Done.
| |
| 105 EXPECT_TRUE(bluetooth_chooser_controller_.IsPaired(1)); | |
| 102 testing::Mock::VerifyAndClearExpectations(&mock_bluetooth_chooser_view_); | 106 testing::Mock::VerifyAndClearExpectations(&mock_bluetooth_chooser_view_); |
| 103 | 107 |
| 104 EXPECT_CALL(mock_bluetooth_chooser_view_, OnOptionAdded(2)).Times(1); | 108 EXPECT_CALL(mock_bluetooth_chooser_view_, OnOptionAdded(2)).Times(1); |
| 105 bluetooth_chooser_controller_.AddOrUpdateDevice( | 109 bluetooth_chooser_controller_.AddOrUpdateDevice( |
| 106 "id_c", false /* should_update_name */, base::ASCIIToUTF16("c"), | 110 "id_c", false /* should_update_name */, base::ASCIIToUTF16("c"), |
| 107 true /* is_gatt_connected */, true /* is_paired */, | 111 true /* is_gatt_connected */, true /* is_paired */, |
| 108 1 /* signal_strength_level */); | 112 1 /* signal_strength_level */); |
| 109 EXPECT_EQ(3u, bluetooth_chooser_controller_.NumOptions()); | 113 EXPECT_EQ(3u, bluetooth_chooser_controller_.NumOptions()); |
| 110 EXPECT_EQ(base::ASCIIToUTF16("c"), | 114 EXPECT_EQ(base::ASCIIToUTF16("c"), |
| 111 bluetooth_chooser_controller_.GetOption(2)); | 115 bluetooth_chooser_controller_.GetOption(2)); |
| 112 EXPECT_EQ(1, bluetooth_chooser_controller_.GetSignalStrengthLevel(2)); | 116 EXPECT_EQ(1, bluetooth_chooser_controller_.GetSignalStrengthLevel(2)); |
| 117 EXPECT_TRUE(bluetooth_chooser_controller_.IsConnected(2)); | |
| 118 EXPECT_TRUE(bluetooth_chooser_controller_.IsPaired(2)); | |
| 113 } | 119 } |
| 114 | 120 |
| 115 TEST_F(BluetoothChooserControllerTest, RemoveDevice) { | 121 TEST_F(BluetoothChooserControllerTest, RemoveDevice) { |
| 116 bluetooth_chooser_controller_.AddOrUpdateDevice( | 122 bluetooth_chooser_controller_.AddOrUpdateDevice( |
| 117 "id_a", false /* should_update_name */, base::ASCIIToUTF16("a"), | 123 "id_a", false /* should_update_name */, base::ASCIIToUTF16("a"), |
| 118 true /* is_gatt_connected */, true /* is_paired */, | 124 true /* is_gatt_connected */, true /* is_paired */, |
| 119 -1 /* signal_strength_level */); | 125 -1 /* signal_strength_level */); |
| 120 bluetooth_chooser_controller_.AddOrUpdateDevice( | 126 bluetooth_chooser_controller_.AddOrUpdateDevice( |
| 121 "id_b", false /* should_update_name */, base::ASCIIToUTF16("b"), | 127 "id_b", false /* should_update_name */, base::ASCIIToUTF16("b"), |
| 122 true /* is_gatt_connected */, true /* is_paired */, | 128 true /* is_gatt_connected */, true /* is_paired */, |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 // strength level is -1, and in this case, should still use the previously | 242 // strength level is -1, and in this case, should still use the previously |
| 237 // stored signal strength level. So here the signal strength level is | 243 // stored signal strength level. So here the signal strength level is |
| 238 // still 1. | 244 // still 1. |
| 239 bluetooth_chooser_controller_.AddOrUpdateDevice( | 245 bluetooth_chooser_controller_.AddOrUpdateDevice( |
| 240 "id_a", false /* should_update_name */, base::ASCIIToUTF16("a"), | 246 "id_a", false /* should_update_name */, base::ASCIIToUTF16("a"), |
| 241 true /* is_gatt_connected */, true /* is_paired */, | 247 true /* is_gatt_connected */, true /* is_paired */, |
| 242 -1 /* signal_strength_level */); | 248 -1 /* signal_strength_level */); |
| 243 EXPECT_EQ(1, bluetooth_chooser_controller_.GetSignalStrengthLevel(0)); | 249 EXPECT_EQ(1, bluetooth_chooser_controller_.GetSignalStrengthLevel(0)); |
| 244 } | 250 } |
| 245 | 251 |
| 252 TEST_F(BluetoothChooserControllerTest, UpdateConnectedStatus) { | |
| 253 bluetooth_chooser_controller_.AddOrUpdateDevice( | |
| 254 "id_a", false /* should_update_name */, base::ASCIIToUTF16("a"), | |
| 255 false /* is_gatt_connected */, false /* is_paired */, | |
| 256 1 /* signal_strength_level */); | |
| 257 EXPECT_FALSE(bluetooth_chooser_controller_.IsConnected(0)); | |
| 258 | |
| 259 EXPECT_CALL(mock_bluetooth_chooser_view_, OnOptionUpdated(0)).Times(1); | |
| 260 bluetooth_chooser_controller_.AddOrUpdateDevice( | |
| 261 "id_a", false /* should_update_name */, base::ASCIIToUTF16("a"), | |
| 262 true /* is_gatt_connected */, false /* is_paired */, | |
| 263 -1 /* signal_strength_level */); | |
| 264 EXPECT_TRUE(bluetooth_chooser_controller_.IsConnected(0)); | |
| 265 } | |
| 266 | |
| 267 TEST_F(BluetoothChooserControllerTest, UpdatePairedStatus) { | |
| 268 bluetooth_chooser_controller_.AddOrUpdateDevice( | |
| 269 "id_a", false /* should_update_name */, base::ASCIIToUTF16("a"), | |
| 270 true /* is_gatt_connected */, false /* is_paired */, | |
| 271 -1 /* signal_strength_level */); | |
| 272 EXPECT_FALSE(bluetooth_chooser_controller_.IsPaired(0)); | |
| 273 | |
| 274 EXPECT_CALL(mock_bluetooth_chooser_view_, OnOptionUpdated(0)).Times(1); | |
| 275 bluetooth_chooser_controller_.AddOrUpdateDevice( | |
| 276 "id_a", false /* should_update_name */, base::ASCIIToUTF16("a"), | |
| 277 true /* is_gatt_connected */, true /* is_paired */, | |
| 278 -1 /* signal_strength_level */); | |
| 279 EXPECT_TRUE(bluetooth_chooser_controller_.IsPaired(0)); | |
| 280 } | |
| 281 | |
| 246 TEST_F(BluetoothChooserControllerWithDevicesAddedTest, | 282 TEST_F(BluetoothChooserControllerWithDevicesAddedTest, |
| 247 InitialNoOptionsTextAndStatusText) { | 283 InitialNoOptionsTextAndStatusText) { |
| 248 EXPECT_EQ(l10n_util::GetStringUTF16( | 284 EXPECT_EQ(l10n_util::GetStringUTF16( |
| 249 IDS_BLUETOOTH_DEVICE_CHOOSER_NO_DEVICES_FOUND_PROMPT), | 285 IDS_BLUETOOTH_DEVICE_CHOOSER_NO_DEVICES_FOUND_PROMPT), |
| 250 bluetooth_chooser_controller_.GetNoOptionsText()); | 286 bluetooth_chooser_controller_.GetNoOptionsText()); |
| 251 EXPECT_EQ(base::string16(), bluetooth_chooser_controller_.GetStatus()); | 287 EXPECT_EQ(base::string16(), bluetooth_chooser_controller_.GetStatus()); |
| 252 } | 288 } |
| 253 | 289 |
| 254 TEST_F(BluetoothChooserControllerWithDevicesAddedTest, | 290 TEST_F(BluetoothChooserControllerWithDevicesAddedTest, |
| 255 BluetoothAdapterTurnedOff) { | 291 BluetoothAdapterTurnedOff) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 EXPECT_EQ(content::BluetoothChooser::Event::CANCELLED, last_event_); | 368 EXPECT_EQ(content::BluetoothChooser::Event::CANCELLED, last_event_); |
| 333 EXPECT_EQ(std::string(), last_device_id_); | 369 EXPECT_EQ(std::string(), last_device_id_); |
| 334 } | 370 } |
| 335 | 371 |
| 336 TEST_F(BluetoothChooserControllerWithDevicesAddedTest, | 372 TEST_F(BluetoothChooserControllerWithDevicesAddedTest, |
| 337 CloseShouldCallEventHandler) { | 373 CloseShouldCallEventHandler) { |
| 338 bluetooth_chooser_controller_.Close(); | 374 bluetooth_chooser_controller_.Close(); |
| 339 EXPECT_EQ(content::BluetoothChooser::Event::CANCELLED, last_event_); | 375 EXPECT_EQ(content::BluetoothChooser::Event::CANCELLED, last_event_); |
| 340 EXPECT_EQ(std::string(), last_device_id_); | 376 EXPECT_EQ(std::string(), last_device_id_); |
| 341 } | 377 } |
| OLD | NEW |