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

Side by Side Diff: components/wifi_sync/wifi_config_delegate_chromeos_unittest.cc

Issue 1426393003: NOT FOR REVIEW Base URL: https://chromium.googlesource.com/chromium/src.git@submit-4.5-split-wcss
Patch Set: Created 5 years, 1 month 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
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 "base/logging.h" 7 #include "base/logging.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chromeos/network/managed_network_configuration_handler.h" 10 #include "chromeos/network/managed_network_configuration_handler.h"
11 #include "chromeos/network/network_handler_callbacks.h" 11 #include "chromeos/network/network_handler_callbacks.h"
12 #include "components/wifi_sync/wifi_credential.h" 12 #include "components/wifi_sync/wifi_credential.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace wifi_sync {
16
17 namespace {
18 const char kSsid[] = "fake-ssid";
19 const char kSsidNonUtf8[] = "\xc0";
20 const char kUserHash[] = "fake-user-hash";
21 }
22
23 using chromeos::network_handler::DictionaryResultCallback; 15 using chromeos::network_handler::DictionaryResultCallback;
24 using chromeos::network_handler::ErrorCallback; 16 using chromeos::network_handler::ErrorCallback;
25 using chromeos::network_handler::StringResultCallback; 17 using chromeos::network_handler::StringResultCallback;
26 18
19 namespace wifi_sync {
20
21 namespace {
22
23 const char kSsid[] = "fake-ssid";
24 const char kSsidNonUtf8[] = "\xc0";
25 const char kUserHash[] = "fake-user-hash";
26
27 class FakeManagedNetworkConfigurationHandler 27 class FakeManagedNetworkConfigurationHandler
28 : public chromeos::ManagedNetworkConfigurationHandler { 28 : public chromeos::ManagedNetworkConfigurationHandler {
29 public: 29 public:
30 FakeManagedNetworkConfigurationHandler() 30 FakeManagedNetworkConfigurationHandler()
31 : create_configuration_called_(false) { 31 : create_configuration_called_(false) {
32 } 32 }
33 33
34 // ManagedNetworkConfigurationHandler implementation. 34 // ManagedNetworkConfigurationHandler implementation.
35 void AddObserver(chromeos::NetworkPolicyObserver* observer) override { 35 void AddObserver(chromeos::NetworkPolicyObserver* observer) override {
36 NOTIMPLEMENTED(); 36 NOTIMPLEMENTED();
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 121
122 private: 122 private:
123 // Whether or not CreateConfiguration has been called on this fake. 123 // Whether or not CreateConfiguration has been called on this fake.
124 mutable bool create_configuration_called_; 124 mutable bool create_configuration_called_;
125 // The last |callback| passed to CreateConfiguration. 125 // The last |callback| passed to CreateConfiguration.
126 mutable StringResultCallback create_configuration_success_callback_; 126 mutable StringResultCallback create_configuration_success_callback_;
127 // The last |error_callback| passed to CreateConfiguration. 127 // The last |error_callback| passed to CreateConfiguration.
128 mutable ErrorCallback create_configuration_error_callback_; 128 mutable ErrorCallback create_configuration_error_callback_;
129 }; 129 };
130 130
131 } // namespace
132
131 class WifiConfigDelegateChromeOsTest : public testing::Test { 133 class WifiConfigDelegateChromeOsTest : public testing::Test {
132 protected: 134 protected:
133 WifiConfigDelegateChromeOsTest() 135 WifiConfigDelegateChromeOsTest() {
134 : fake_managed_network_configuration_handler_(
135 new FakeManagedNetworkConfigurationHandler()) {
136 config_delegate_.reset( 136 config_delegate_.reset(
137 new WifiConfigDelegateChromeOs( 137 new WifiConfigDelegateChromeOs(
138 kUserHash, 138 kUserHash,
139 fake_managed_network_configuration_handler_.get())); 139 &fake_managed_network_configuration_handler_));
140 } 140 }
141 141
142 // Wrapper for WifiConfigDelegateChromeOs::AddToLocalNetworks. 142 // Wrapper for WifiConfigDelegateChromeOs::AddToLocalNetworks.
143 void AddToLocalNetworks(const WifiCredential& network_credential) { 143 void AddToLocalNetworks(const WifiCredential& network_credential) {
144 config_delegate_->AddToLocalNetworks(network_credential); 144 config_delegate_->AddToLocalNetworks(network_credential);
145 } 145 }
146 146
147 // Returns a new WifiCredential constructed from the given parameters. 147 // Returns a new WifiCredential constructed from the given parameters.
148 WifiCredential MakeCredential(const std::string& ssid, 148 WifiCredential MakeCredential(const std::string& ssid,
149 WifiSecurityClass security_class, 149 WifiSecurityClass security_class,
150 const std::string& passphrase) { 150 const std::string& passphrase) {
151 scoped_ptr<WifiCredential> credential = 151 scoped_ptr<WifiCredential> credential =
152 WifiCredential::Create( 152 WifiCredential::Create(
153 WifiCredential::MakeSsidBytesForTest(ssid), 153 WifiCredential::MakeSsidBytesForTest(ssid),
154 security_class, 154 security_class,
155 passphrase); 155 passphrase);
156 CHECK(credential); 156 CHECK(credential);
157 return *credential; 157 return *credential;
158 } 158 }
159 159
160 // Runs the last |callback| passed to CreateConfiguration, unless 160 // Runs the last |callback| passed to CreateConfiguration, unless
161 // that |callback| is null. 161 // that |callback| is null.
162 void RunCreateConfigurationSuccessCallback() { 162 void RunCreateConfigurationSuccessCallback() {
163 const char new_service_path[] = "/service/0"; 163 const char new_service_path[] = "/service/0";
164 const StringResultCallback callback = 164 const StringResultCallback callback =
165 fake_managed_network_configuration_handler_ 165 fake_managed_network_configuration_handler_
166 ->create_configuration_success_callback(); 166 .create_configuration_success_callback();
167 if (!callback.is_null()) 167 if (!callback.is_null())
168 callback.Run(new_service_path); 168 callback.Run(new_service_path);
169 } 169 }
170 170
171 // Returns whether or not CreateConfiguration has been called 171 // Returns whether or not CreateConfiguration has been called
172 // on |fake_managed_network_configuration_handler_|. 172 // on |fake_managed_network_configuration_handler_|.
173 size_t create_configuration_called() const { 173 bool create_configuration_called() const {
174 return fake_managed_network_configuration_handler_ 174 return fake_managed_network_configuration_handler_
175 ->create_configuration_called(); 175 .create_configuration_called();
176 } 176 }
177 177
178 // Returns the last |error_callback| passed to the CreateConfiguration 178 // Returns the last |error_callback| passed to the CreateConfiguration
179 // method of |fake_managed_network_configuration_handler_|. 179 // method of |fake_managed_network_configuration_handler_|.
180 const ErrorCallback& create_configuration_error_callback() const { 180 const ErrorCallback& create_configuration_error_callback() const {
181 return fake_managed_network_configuration_handler_ 181 return fake_managed_network_configuration_handler_
182 ->create_configuration_error_callback(); 182 .create_configuration_error_callback();
183 } 183 }
184 184
185 private: 185 private:
186 FakeManagedNetworkConfigurationHandler
187 fake_managed_network_configuration_handler_;
186 scoped_ptr<WifiConfigDelegateChromeOs> config_delegate_; 188 scoped_ptr<WifiConfigDelegateChromeOs> config_delegate_;
187 scoped_ptr<FakeManagedNetworkConfigurationHandler>
188 fake_managed_network_configuration_handler_;
189 189
190 DISALLOW_COPY_AND_ASSIGN(WifiConfigDelegateChromeOsTest); 190 DISALLOW_COPY_AND_ASSIGN(WifiConfigDelegateChromeOsTest);
191 }; 191 };
192 192
193 TEST_F(WifiConfigDelegateChromeOsTest, AddToLocalNetworksOpen) { 193 TEST_F(WifiConfigDelegateChromeOsTest, AddToLocalNetworksOpen) {
194 AddToLocalNetworks(MakeCredential(kSsid, SECURITY_CLASS_NONE, "")); 194 AddToLocalNetworks(MakeCredential(kSsid, SECURITY_CLASS_NONE, ""));
195 ASSERT_TRUE(create_configuration_called()); 195 ASSERT_TRUE(create_configuration_called());
196 RunCreateConfigurationSuccessCallback(); 196 RunCreateConfigurationSuccessCallback();
197 } 197 }
198 198
(...skipping 21 matching lines...) Expand all
220 AddToLocalNetworks(MakeCredential(kSsid, SECURITY_CLASS_NONE, "")); 220 AddToLocalNetworks(MakeCredential(kSsid, SECURITY_CLASS_NONE, ""));
221 EXPECT_TRUE(create_configuration_called()); 221 EXPECT_TRUE(create_configuration_called());
222 if (!create_configuration_error_callback().is_null()) { 222 if (!create_configuration_error_callback().is_null()) {
223 create_configuration_error_callback().Run( 223 create_configuration_error_callback().Run(
224 "Config.CreateConfiguration Failed", 224 "Config.CreateConfiguration Failed",
225 make_scoped_ptr(new base::DictionaryValue())); 225 make_scoped_ptr(new base::DictionaryValue()));
226 } 226 }
227 } 227 }
228 228
229 } // namespace wifi_sync 229 } // namespace wifi_sync
OLDNEW
« no previous file with comments | « components/wifi_sync/wifi_config_delegate_chromeos.cc ('k') | components/wifi_sync/wifi_config_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698