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

Unified Diff: chromeos/components/tether/keep_alive_operation_unittest.cc

Issue 2918863002: [CrOS Tether] Update the KeepAliveTickle code to receive DeviceStatus updates. (Closed)
Patch Set: Rebased. Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chromeos/components/tether/keep_alive_operation_unittest.cc
diff --git a/chromeos/components/tether/keep_alive_operation_unittest.cc b/chromeos/components/tether/keep_alive_operation_unittest.cc
index 57e6e467fe4b452e961367977765d7b2b238a3fa..dd8ee94e48e7fdb4f85a718562113aa281b71e02 100644
--- a/chromeos/components/tether/keep_alive_operation_unittest.cc
+++ b/chromeos/components/tether/keep_alive_operation_unittest.cc
@@ -27,10 +27,26 @@ class TestObserver : public KeepAliveOperation::Observer {
bool has_run_callback() { return has_run_callback_; }
- void OnOperationFinished() override { has_run_callback_ = true; }
+ cryptauth::RemoteDevice last_remote_device_received() {
+ return last_remote_device_received_;
+ }
+
+ DeviceStatus* last_device_status_received() {
+ return last_device_status_received_.get();
+ }
+
+ void OnOperationFinished(
+ const cryptauth::RemoteDevice& remote_device,
+ std::unique_ptr<DeviceStatus> device_status) override {
+ has_run_callback_ = true;
+ last_remote_device_received_ = remote_device;
+ last_device_status_received_ = std::move(device_status);
+ }
private:
bool has_run_callback_;
+ cryptauth::RemoteDevice last_remote_device_received_;
+ std::unique_ptr<DeviceStatus> last_device_status_received_;
};
std::string CreateKeepAliveTickleString() {
@@ -38,6 +54,26 @@ std::string CreateKeepAliveTickleString() {
return MessageWrapper(tickle).ToRawMessage();
}
+DeviceStatus CreateFakeDeviceStatus() {
Ryan Hansberry 2017/06/01 23:45:52 Has this been copied from somewhere? If so, can we
Kyle Horimoto 2017/06/06 18:30:33 Done.
+ WifiStatus wifi_status;
+ wifi_status.set_status_code(
+ WifiStatus_StatusCode::WifiStatus_StatusCode_NOT_CONNECTED);
+
+ DeviceStatus device_status;
+ device_status.set_battery_percentage(75);
+ device_status.set_cell_provider("Google Fi");
+ device_status.set_connection_strength(4);
+ device_status.mutable_wifi_status()->CopyFrom(wifi_status);
+
+ return device_status;
+}
+
+std::string CreateKeepAliveTickleResponseString() {
+ KeepAliveTickleResponse response;
+ response.mutable_device_status()->CopyFrom(CreateFakeDeviceStatus());
+ return MessageWrapper(response).ToRawMessage();
+}
+
} // namespace
class KeepAliveOperationTest : public testing::Test {
@@ -81,10 +117,40 @@ class KeepAliveOperationTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(KeepAliveOperationTest);
};
-TEST_F(KeepAliveOperationTest, TestSendsKeepAliveTickle) {
+TEST_F(KeepAliveOperationTest, TestSendsKeepAliveTickleAndReceivesResponse) {
EXPECT_FALSE(test_observer_->has_run_callback());
+
SimulateDeviceAuthenticationAndVerifyMessageSent();
+ EXPECT_FALSE(test_observer_->has_run_callback());
+
+ fake_ble_connection_manager_->ReceiveMessage(
+ test_device_, CreateKeepAliveTickleResponseString());
+ EXPECT_TRUE(test_observer_->has_run_callback());
+ EXPECT_EQ(test_device_, test_observer_->last_remote_device_received());
+ ASSERT_TRUE(test_observer_->last_device_status_received());
+ EXPECT_EQ(CreateFakeDeviceStatus().SerializeAsString(),
+ test_observer_->last_device_status_received()->SerializeAsString());
+}
+
+TEST_F(KeepAliveOperationTest, TestCannotConnect) {
+ // Simulate the device failing to connect.
+ fake_ble_connection_manager_->SetDeviceStatus(
+ test_device_, cryptauth::SecureChannel::Status::CONNECTING);
+ fake_ble_connection_manager_->SetDeviceStatus(
+ test_device_, cryptauth::SecureChannel::Status::DISCONNECTED);
+ fake_ble_connection_manager_->SetDeviceStatus(
+ test_device_, cryptauth::SecureChannel::Status::CONNECTING);
+ fake_ble_connection_manager_->SetDeviceStatus(
+ test_device_, cryptauth::SecureChannel::Status::DISCONNECTED);
+ fake_ble_connection_manager_->SetDeviceStatus(
+ test_device_, cryptauth::SecureChannel::Status::CONNECTING);
+ fake_ble_connection_manager_->SetDeviceStatus(
+ test_device_, cryptauth::SecureChannel::Status::DISCONNECTED);
+
+ // The maximum number of connection failures has occurred.
EXPECT_TRUE(test_observer_->has_run_callback());
+ EXPECT_EQ(test_device_, test_observer_->last_remote_device_received());
+ EXPECT_FALSE(test_observer_->last_device_status_received());
}
} // namespace tether

Powered by Google App Engine
This is Rietveld 408576698