OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/wifi_sync/wifi_config_delegate_chromeos.h" | 5 #include "components/wifi_sync/wifi_config_delegate_chromeos.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
| 9 #include <memory> |
| 10 |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
10 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" |
11 #include "base/values.h" | 14 #include "base/values.h" |
12 #include "chromeos/network/managed_network_configuration_handler.h" | 15 #include "chromeos/network/managed_network_configuration_handler.h" |
13 #include "chromeos/network/network_handler_callbacks.h" | 16 #include "chromeos/network/network_handler_callbacks.h" |
14 #include "components/wifi_sync/wifi_credential.h" | 17 #include "components/wifi_sync/wifi_credential.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
16 | 19 |
17 namespace wifi_sync { | 20 namespace wifi_sync { |
18 | 21 |
19 namespace { | 22 namespace { |
20 const char kSsid[] = "fake-ssid"; | 23 const char kSsid[] = "fake-ssid"; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 146 |
144 // Wrapper for WifiConfigDelegateChromeOs::AddToLocalNetworks. | 147 // Wrapper for WifiConfigDelegateChromeOs::AddToLocalNetworks. |
145 void AddToLocalNetworks(const WifiCredential& network_credential) { | 148 void AddToLocalNetworks(const WifiCredential& network_credential) { |
146 config_delegate_->AddToLocalNetworks(network_credential); | 149 config_delegate_->AddToLocalNetworks(network_credential); |
147 } | 150 } |
148 | 151 |
149 // Returns a new WifiCredential constructed from the given parameters. | 152 // Returns a new WifiCredential constructed from the given parameters. |
150 WifiCredential MakeCredential(const std::string& ssid, | 153 WifiCredential MakeCredential(const std::string& ssid, |
151 WifiSecurityClass security_class, | 154 WifiSecurityClass security_class, |
152 const std::string& passphrase) { | 155 const std::string& passphrase) { |
153 scoped_ptr<WifiCredential> credential = | 156 std::unique_ptr<WifiCredential> credential = WifiCredential::Create( |
154 WifiCredential::Create( | 157 WifiCredential::MakeSsidBytesForTest(ssid), security_class, passphrase); |
155 WifiCredential::MakeSsidBytesForTest(ssid), | |
156 security_class, | |
157 passphrase); | |
158 CHECK(credential); | 158 CHECK(credential); |
159 return *credential; | 159 return *credential; |
160 } | 160 } |
161 | 161 |
162 // Runs the last |callback| passed to CreateConfiguration, unless | 162 // Runs the last |callback| passed to CreateConfiguration, unless |
163 // that |callback| is null. | 163 // that |callback| is null. |
164 void RunCreateConfigurationSuccessCallback() { | 164 void RunCreateConfigurationSuccessCallback() { |
165 const char new_service_path[] = "/service/0"; | 165 const char new_service_path[] = "/service/0"; |
166 const ServiceResultCallback callback = | 166 const ServiceResultCallback callback = |
167 fake_managed_network_configuration_handler_ | 167 fake_managed_network_configuration_handler_ |
(...skipping 10 matching lines...) Expand all Loading... |
178 } | 178 } |
179 | 179 |
180 // Returns the last |error_callback| passed to the CreateConfiguration | 180 // Returns the last |error_callback| passed to the CreateConfiguration |
181 // method of |fake_managed_network_configuration_handler_|. | 181 // method of |fake_managed_network_configuration_handler_|. |
182 const ErrorCallback& create_configuration_error_callback() const { | 182 const ErrorCallback& create_configuration_error_callback() const { |
183 return fake_managed_network_configuration_handler_ | 183 return fake_managed_network_configuration_handler_ |
184 ->create_configuration_error_callback(); | 184 ->create_configuration_error_callback(); |
185 } | 185 } |
186 | 186 |
187 private: | 187 private: |
188 scoped_ptr<WifiConfigDelegateChromeOs> config_delegate_; | 188 std::unique_ptr<WifiConfigDelegateChromeOs> config_delegate_; |
189 scoped_ptr<FakeManagedNetworkConfigurationHandler> | 189 std::unique_ptr<FakeManagedNetworkConfigurationHandler> |
190 fake_managed_network_configuration_handler_; | 190 fake_managed_network_configuration_handler_; |
191 | 191 |
192 DISALLOW_COPY_AND_ASSIGN(WifiConfigDelegateChromeOsTest); | 192 DISALLOW_COPY_AND_ASSIGN(WifiConfigDelegateChromeOsTest); |
193 }; | 193 }; |
194 | 194 |
195 TEST_F(WifiConfigDelegateChromeOsTest, AddToLocalNetworksOpen) { | 195 TEST_F(WifiConfigDelegateChromeOsTest, AddToLocalNetworksOpen) { |
196 AddToLocalNetworks(MakeCredential(kSsid, SECURITY_CLASS_NONE, "")); | 196 AddToLocalNetworks(MakeCredential(kSsid, SECURITY_CLASS_NONE, "")); |
197 ASSERT_TRUE(create_configuration_called()); | 197 ASSERT_TRUE(create_configuration_called()); |
198 RunCreateConfigurationSuccessCallback(); | 198 RunCreateConfigurationSuccessCallback(); |
199 } | 199 } |
200 | 200 |
(...skipping 16 matching lines...) Expand all Loading... |
217 EXPECT_FALSE(create_configuration_called()); | 217 EXPECT_FALSE(create_configuration_called()); |
218 } | 218 } |
219 | 219 |
220 TEST_F(WifiConfigDelegateChromeOsTest, | 220 TEST_F(WifiConfigDelegateChromeOsTest, |
221 AddToLocalNetworksCreateConfigurationFailure) { | 221 AddToLocalNetworksCreateConfigurationFailure) { |
222 AddToLocalNetworks(MakeCredential(kSsid, SECURITY_CLASS_NONE, "")); | 222 AddToLocalNetworks(MakeCredential(kSsid, SECURITY_CLASS_NONE, "")); |
223 EXPECT_TRUE(create_configuration_called()); | 223 EXPECT_TRUE(create_configuration_called()); |
224 if (!create_configuration_error_callback().is_null()) { | 224 if (!create_configuration_error_callback().is_null()) { |
225 create_configuration_error_callback().Run( | 225 create_configuration_error_callback().Run( |
226 "Config.CreateConfiguration Failed", | 226 "Config.CreateConfiguration Failed", |
227 make_scoped_ptr(new base::DictionaryValue())); | 227 base::WrapUnique(new base::DictionaryValue())); |
228 } | 228 } |
229 } | 229 } |
230 | 230 |
231 } // namespace wifi_sync | 231 } // namespace wifi_sync |
OLD | NEW |