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

Side by Side Diff: chromeos/components/tether/network_connection_handler_tether_delegate_unittest.cc

Issue 2857853005: [CrOS Tether] Create TetherDisconnector, which disconnects from active tethering sessions. (Closed)
Patch Set: hansberry@ comments. 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chromeos/components/tether/network_connection_handler_tether_delegate. h"
6
7 #include <memory>
8
9 #include "chromeos/components/tether/tether_connector.h"
10 #include "chromeos/components/tether/tether_disconnector.h"
11 #include "chromeos/network/network_connection_handler.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 using testing::_;
16 using testing::NiceMock;
17
18 namespace chromeos {
19
20 namespace tether {
21
22 namespace {
23
24 class TestNetworkConnectionHandler : public NetworkConnectionHandler {
25 public:
26 TestNetworkConnectionHandler() : NetworkConnectionHandler() {}
27 ~TestNetworkConnectionHandler() override {}
28
29 void CallTetherConnect(const std::string& tether_network_guid,
30 const base::Closure& success_callback,
31 const network_handler::ErrorCallback& error_callback) {
32 InitiateTetherNetworkConnection(tether_network_guid, success_callback,
33 error_callback);
34 }
35
36 // NetworkConnectionHandler:
37 void ConnectToNetwork(const std::string& service_path,
38 const base::Closure& success_callback,
39 const network_handler::ErrorCallback& error_callback,
40 bool check_error_state) override {}
41
42 void DisconnectNetwork(
43 const std::string& service_path,
44 const base::Closure& success_callback,
45 const network_handler::ErrorCallback& error_callback) override {}
46
47 bool HasConnectingNetwork(const std::string& service_path) override {
48 return false;
49 }
50
51 bool HasPendingConnectRequest() override { return false; }
52
53 void Init(NetworkStateHandler* network_state_handler,
54 NetworkConfigurationHandler* network_configuration_handler,
55 ManagedNetworkConfigurationHandler*
56 managed_network_configuration_handler) override {}
57 };
58
59 class MockTetherConnector : public TetherConnector {
60 public:
61 MockTetherConnector()
62 : TetherConnector(nullptr /* network_state_handler */,
63 nullptr /* wifi_hotspot_connector */,
64 nullptr /* active_host */,
65 nullptr /* tether_host_fetcher */,
66 nullptr /* connection_manager */,
67 nullptr /* tether_host_response_recorder */,
68 nullptr /* device_id_tether_network_guid_map */) {}
69 ~MockTetherConnector() override {}
70
71 MOCK_METHOD3(
72 ConnectToNetwork,
73 void(const std::string& tether_network_guid,
74 const base::Closure& success_callback,
75 const network_handler::StringResultCallback& error_callback));
76 };
77
78 class MockTetherDisconnector : public TetherDisconnector {
79 public:
80 MockTetherDisconnector()
81 : TetherDisconnector(nullptr /* network_connection_handler */,
82 nullptr /* network_state_handler */,
83 nullptr /* active_host */,
84 nullptr /* ble_connection_manager */,
85 nullptr /* network_configuration_remover */,
86 nullptr /* tether_connector */,
87 nullptr /* device_id_tether_network_guid_map */,
88 nullptr /* tether_host_fetcher */) {}
89 ~MockTetherDisconnector() override {}
90
91 MOCK_METHOD3(
92 DisconnectFomNetwork,
93 void(const std::string& tether_network_guid,
94 const base::Closure& success_callback,
95 const network_handler::StringResultCallback& error_callback));
96 };
97
98 } // namespace
99
100 // TODO(khorimoto): Also write a test for disconnection. This is part of a
101 // follow-up CL.
102 class NetworkConnectionHandlerTetherDelegateTest : public testing::Test {
103 protected:
104 NetworkConnectionHandlerTetherDelegateTest() {}
105
106 void SetUp() override {
107 test_network_connection_handler_ =
108 base::WrapUnique(new TestNetworkConnectionHandler());
109 mock_tether_connector_ =
110 base::WrapUnique(new NiceMock<MockTetherConnector>());
111 mock_tether_disconnector_ =
112 base::WrapUnique(new NiceMock<MockTetherDisconnector>());
113
114 delegate_ = base::MakeUnique<NetworkConnectionHandlerTetherDelegate>(
115 test_network_connection_handler_.get(), mock_tether_connector_.get(),
116 mock_tether_disconnector_.get());
117 }
118
119 std::unique_ptr<TestNetworkConnectionHandler>
120 test_network_connection_handler_;
121 std::unique_ptr<NiceMock<MockTetherConnector>> mock_tether_connector_;
122 std::unique_ptr<NiceMock<MockTetherDisconnector>> mock_tether_disconnector_;
123
124 std::unique_ptr<NetworkConnectionHandlerTetherDelegate> delegate_;
125
126 private:
127 DISALLOW_COPY_AND_ASSIGN(NetworkConnectionHandlerTetherDelegateTest);
128 };
129
130 TEST_F(NetworkConnectionHandlerTetherDelegateTest, TestConnect) {
131 EXPECT_CALL(*mock_tether_connector_, ConnectToNetwork(_, _, _));
132
133 test_network_connection_handler_->CallTetherConnect(
134 "tetherNetworkGuid", base::Closure(), network_handler::ErrorCallback());
135 }
136
137 } // namespace tether
138
139 } // namespace cryptauth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698