OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/wifi_sync/wifi_config_delegate_chromeos.h" | |
6 | |
7 #include "base/macros.h" | |
8 #include "base/values.h" | |
9 #include "chromeos/network/managed_network_configuration_handler.h" | |
10 #include "components/wifi_sync/wifi_credential.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 namespace wifi_sync { | |
14 | |
15 namespace { | |
16 const char kSsid[] = "fake-ssid"; | |
17 const char kSsidNonUtf8[] = "\xc0"; | |
18 const char kUserHash[] = "fake-user-hash"; | |
19 } | |
20 | |
21 class FakeManagedNetworkConfigurationHandler | |
mukesh agrawal
2015/01/15 03:01:48
Taking a cue from the advice on FakeWifiConfigDele
| |
22 : public chromeos::ManagedNetworkConfigurationHandler { | |
23 public: | |
24 FakeManagedNetworkConfigurationHandler() | |
25 : create_configuration_count_(0) { | |
26 } | |
27 | |
28 // ManagedNetworkConfigurationHandler implementation. | |
29 void AddObserver(chromeos::NetworkPolicyObserver* observer) override { | |
30 NOTIMPLEMENTED(); | |
31 } | |
32 void RemoveObserver(chromeos::NetworkPolicyObserver* observer) override { | |
33 NOTIMPLEMENTED(); | |
34 } | |
35 void GetProperties( | |
36 const std::string& service_path, | |
37 const chromeos::network_handler::DictionaryResultCallback& callback, | |
38 const chromeos::network_handler::ErrorCallback& error_callback) override { | |
39 NOTIMPLEMENTED(); | |
40 } | |
41 void GetManagedProperties( | |
42 const std::string& userhash, | |
43 const std::string& service_path, | |
44 const chromeos::network_handler::DictionaryResultCallback& callback, | |
45 const chromeos::network_handler::ErrorCallback& error_callback) override { | |
46 NOTIMPLEMENTED(); | |
47 } | |
48 void SetProperties( | |
49 const std::string& service_path, | |
50 const base::DictionaryValue& user_settings, | |
51 const base::Closure& callback, | |
52 const chromeos::network_handler::ErrorCallback& error_callback) const | |
53 override { | |
54 NOTIMPLEMENTED(); | |
55 } | |
56 void CreateConfiguration( | |
57 const std::string& userhash, | |
58 const base::DictionaryValue& properties, | |
59 const chromeos::network_handler::StringResultCallback& callback, | |
60 const chromeos::network_handler::ErrorCallback& error_callback) const | |
61 override { | |
62 ++create_configuration_count_; | |
erikwright (departed)
2015/01/15 15:12:51
You don't really need a call count, since your tes
mukesh agrawal
2015/01/15 19:05:55
Done.
Thanks for the detailed advice here. I've u
erikwright (departed)
2015/01/16 14:42:15
The fact that the success callback is null is not
| |
63 } | |
64 void RemoveConfiguration( | |
65 const std::string& service_path, | |
66 const base::Closure& callback, | |
67 const chromeos::network_handler::ErrorCallback& error_callback) const | |
68 override { | |
69 NOTIMPLEMENTED(); | |
70 } | |
71 void SetPolicy( | |
72 ::onc::ONCSource onc_source, | |
73 const std::string& userhash, | |
74 const base::ListValue& network_configs_onc, | |
75 const base::DictionaryValue& global_network_config) override { | |
76 NOTIMPLEMENTED(); | |
77 } | |
78 bool IsAnyPolicyApplicationRunning() const override { | |
79 NOTIMPLEMENTED(); | |
80 return false; | |
81 } | |
82 const base::DictionaryValue* FindPolicyByGUID( | |
83 const std::string userhash, | |
84 const std::string& guid, | |
85 ::onc::ONCSource* onc_source) const override { | |
86 NOTIMPLEMENTED(); | |
87 return nullptr; | |
88 } | |
89 const GuidToPolicyMap* GetNetworkConfigsFromPolicy( | |
90 const std::string& userhash) const override { | |
91 NOTIMPLEMENTED(); | |
92 return nullptr; | |
93 } | |
94 const base::DictionaryValue* GetGlobalConfigFromPolicy( | |
95 const std::string& userhash) const override { | |
96 NOTIMPLEMENTED(); | |
97 return nullptr; | |
98 } | |
99 const base::DictionaryValue* FindPolicyByGuidAndProfile( | |
100 const std::string& guid, | |
101 const std::string& profile_path) const override { | |
102 NOTIMPLEMENTED(); | |
103 return nullptr; | |
104 } | |
105 | |
106 // Returns the number of times CreateConfiguration has been called. | |
107 size_t GetCreateConfigurationCount() const { | |
erikwright (departed)
2015/01/15 15:12:51
nit: accessor style:
size_t create_configuration_
mukesh agrawal
2015/01/15 19:05:55
Done.
| |
108 return create_configuration_count_; | |
109 } | |
110 | |
111 private: | |
112 // The number of times CreateConfiguration has been called on this fake. | |
113 mutable size_t create_configuration_count_; | |
114 }; | |
115 | |
116 class WifiConfigDelegateChromeOsTest : public testing::Test { | |
117 protected: | |
118 WifiConfigDelegateChromeOsTest() | |
119 : fake_managed_network_configuration_handler_( | |
120 new FakeManagedNetworkConfigurationHandler()) { | |
121 config_delegate_.reset( | |
122 new WifiConfigDelegateChromeOs( | |
123 kUserHash, | |
124 fake_managed_network_configuration_handler_.get())); | |
125 } | |
126 | |
127 // Wrapper for WifiConfigDelegateChromeOs::AddToLocalNetworks. | |
128 void AddToLocalNetworks(const WifiCredential& network_credential) { | |
129 config_delegate_->AddToLocalNetworks(network_credential); | |
130 } | |
131 | |
132 // Returns a new WifiCredential constructed from the given parameters. | |
133 WifiCredential MakeCredential(const std::string& ssid, | |
134 WifiSecurityClass security_class, | |
135 const std::string& passphrase) { | |
136 scoped_ptr<WifiCredential> credential = | |
137 WifiCredential::Create( | |
138 WifiCredential::MakeSsidBytesForTest(ssid), | |
139 security_class, | |
140 passphrase); | |
141 CHECK(credential); | |
142 return *credential; | |
143 } | |
144 | |
145 // Returns the number of times CreateConfiguration has been called | |
146 // on |fake_managed_network_configuration_handler_|. | |
147 size_t GetCreateConfigurationCount() const { | |
erikwright (departed)
2015/01/15 15:12:50
nit: accessor style: create_configuration_call_cou
mukesh agrawal
2015/01/15 19:05:55
Done.
| |
148 return fake_managed_network_configuration_handler_ | |
149 ->GetCreateConfigurationCount(); | |
150 } | |
151 | |
152 private: | |
153 scoped_ptr<WifiConfigDelegateChromeOs> config_delegate_; | |
154 scoped_ptr<FakeManagedNetworkConfigurationHandler> | |
155 fake_managed_network_configuration_handler_; | |
156 | |
157 DISALLOW_COPY_AND_ASSIGN(WifiConfigDelegateChromeOsTest); | |
158 }; | |
159 | |
160 TEST_F(WifiConfigDelegateChromeOsTest, AddToLocalNetworksOpen) { | |
161 AddToLocalNetworks(MakeCredential(kSsid, SECURITY_CLASS_NONE, "")); | |
162 EXPECT_EQ(1U, GetCreateConfigurationCount()); | |
163 } | |
164 | |
165 TEST_F(WifiConfigDelegateChromeOsTest, AddToLocalNetworksWep) { | |
166 AddToLocalNetworks(MakeCredential(kSsid, SECURITY_CLASS_WEP, "abcde")); | |
167 EXPECT_EQ(1U, GetCreateConfigurationCount()); | |
168 } | |
169 | |
170 TEST_F(WifiConfigDelegateChromeOsTest, AddToLocalNetworksPsk) { | |
171 AddToLocalNetworks( | |
172 MakeCredential(kSsid, SECURITY_CLASS_PSK, "fake-psk-passphrase")); | |
173 EXPECT_EQ(1U, GetCreateConfigurationCount()); | |
174 } | |
175 | |
176 TEST_F(WifiConfigDelegateChromeOsTest, AddToLocalNetworksNonUtf8) { | |
177 AddToLocalNetworks(MakeCredential(kSsidNonUtf8, SECURITY_CLASS_PSK, "")); | |
178 // TODO(quiche): Change 0 to 1, once we support non-UTF-8 SSIDs. | |
179 EXPECT_EQ(0U, GetCreateConfigurationCount()); | |
180 } | |
181 | |
182 } // namespace wifi_sync | |
OLD | NEW |