| 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 "chromeos/components/tether/disconnect_tethering_operation.h" | 5 #include "chromeos/components/tether/disconnect_tethering_operation.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "chromeos/components/tether/fake_ble_connection_manager.h" | 10 #include "chromeos/components/tether/fake_ble_connection_manager.h" |
| 11 #include "chromeos/components/tether/message_wrapper.h" | 11 #include "chromeos/components/tether/message_wrapper.h" |
| 12 #include "chromeos/components/tether/proto/tether.pb.h" | 12 #include "chromeos/components/tether/proto/tether.pb.h" |
| 13 #include "components/cryptauth/remote_device_test_util.h" | 13 #include "components/cryptauth/remote_device_test_util.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace chromeos { | 16 namespace chromeos { |
| 17 | 17 |
| 18 namespace tether { | 18 namespace tether { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 class TestObserver : public DisconnectTetheringOperation::Observer { | 22 class TestObserver : public DisconnectTetheringOperation::Observer { |
| 23 public: | 23 public: |
| 24 TestObserver() : has_run_callback_(false), success_(false) {} | 24 TestObserver() : success_(false) {} |
| 25 | 25 |
| 26 virtual ~TestObserver() {} | 26 virtual ~TestObserver() {} |
| 27 | 27 |
| 28 std::string last_device_id() { return last_device_id_; } |
| 29 |
| 28 bool WasLastOperationSuccessful() { | 30 bool WasLastOperationSuccessful() { |
| 29 EXPECT_TRUE(has_run_callback_); | 31 EXPECT_TRUE(!last_device_id_.empty()); |
| 30 return success_; | 32 return success_; |
| 31 } | 33 } |
| 32 | 34 |
| 33 // DisconnectTetheringOperation::Observer: | 35 // DisconnectTetheringOperation::Observer: |
| 34 void OnOperationFinished(bool success) override { | 36 void OnOperationFinished(const std::string& device_id, |
| 35 has_run_callback_ = true; | 37 bool success) override { |
| 38 last_device_id_ = device_id; |
| 36 success_ = success; | 39 success_ = success; |
| 37 } | 40 } |
| 38 | 41 |
| 39 private: | 42 private: |
| 40 bool has_run_callback_; | 43 std::string last_device_id_; |
| 41 bool success_; | 44 bool success_; |
| 42 }; | 45 }; |
| 43 | 46 |
| 44 std::string CreateDisconnectTetheringString() { | 47 std::string CreateDisconnectTetheringString() { |
| 45 DisconnectTetheringRequest request; | 48 DisconnectTetheringRequest request; |
| 46 return MessageWrapper(request).ToRawMessage(); | 49 return MessageWrapper(request).ToRawMessage(); |
| 47 } | 50 } |
| 48 | 51 |
| 49 } // namespace | 52 } // namespace |
| 50 | 53 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 std::unique_ptr<TestObserver> test_observer_; | 91 std::unique_ptr<TestObserver> test_observer_; |
| 89 | 92 |
| 90 std::unique_ptr<DisconnectTetheringOperation> operation_; | 93 std::unique_ptr<DisconnectTetheringOperation> operation_; |
| 91 | 94 |
| 92 private: | 95 private: |
| 93 DISALLOW_COPY_AND_ASSIGN(DisconnectTetheringOperationTest); | 96 DISALLOW_COPY_AND_ASSIGN(DisconnectTetheringOperationTest); |
| 94 }; | 97 }; |
| 95 | 98 |
| 96 TEST_F(DisconnectTetheringOperationTest, TestSuccess) { | 99 TEST_F(DisconnectTetheringOperationTest, TestSuccess) { |
| 97 SimulateDeviceAuthenticationAndVerifyMessageSent(); | 100 SimulateDeviceAuthenticationAndVerifyMessageSent(); |
| 101 EXPECT_EQ(test_device_.GetDeviceId(), test_observer_->last_device_id()); |
| 98 EXPECT_TRUE(test_observer_->WasLastOperationSuccessful()); | 102 EXPECT_TRUE(test_observer_->WasLastOperationSuccessful()); |
| 99 } | 103 } |
| 100 | 104 |
| 101 TEST_F(DisconnectTetheringOperationTest, TestFailure) { | 105 TEST_F(DisconnectTetheringOperationTest, TestFailure) { |
| 102 SimulateConnectionTimeout(); | 106 SimulateConnectionTimeout(); |
| 107 EXPECT_EQ(test_device_.GetDeviceId(), test_observer_->last_device_id()); |
| 103 EXPECT_FALSE(test_observer_->WasLastOperationSuccessful()); | 108 EXPECT_FALSE(test_observer_->WasLastOperationSuccessful()); |
| 104 } | 109 } |
| 105 | 110 |
| 106 } // namespace tether | 111 } // namespace tether |
| 107 | 112 |
| 108 } // namespace cryptauth | 113 } // namespace cryptauth |
| OLD | NEW |