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

Side by Side Diff: chromeos/network/onc/onc_utils_unittest.cc

Issue 1228543002: Translate ONC ProxySettings <-> Shill ProxyConfig (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix assumptions in ShillToONC Created 5 years, 5 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/network/onc/onc_utils.h" 5 #include "chromeos/network/onc/onc_utils.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/json/json_file_value_serializer.h"
10 #include "base/logging.h"
11 #include "base/strings/string_number_conversions.h"
9 #include "base/values.h" 12 #include "base/values.h"
13 #include "chromeos/chromeos_test_utils.h"
14 #include "chromeos/network/network_ui_data.h"
10 #include "chromeos/network/onc/onc_signature.h" 15 #include "chromeos/network/onc/onc_signature.h"
11 #include "chromeos/network/onc/onc_test_utils.h" 16 #include "chromeos/network/onc/onc_test_utils.h"
12 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
13 18
14 namespace chromeos { 19 namespace chromeos {
20
21 namespace {
22
23 scoped_ptr<base::Value> ReadTestJson(const std::string& filename) {
pneubeck (no reviews) 2015/07/09 07:16:12 optional nit: this could eventually be put into a
stevenjb 2015/07/09 18:24:28 Eventually :) We should do that if/when we need it
24 base::Value* result = nullptr;
25 base::FilePath path;
26 if (!test_utils::GetTestDataPath("network", filename, &path)) {
27 NOTREACHED() << "Unable to get test file path for: " << filename;
28 return make_scoped_ptr(result);
29 }
30 JSONFileValueDeserializer deserializer(path);
31 deserializer.set_allow_trailing_comma(true);
32 std::string error_message;
33 result = deserializer.Deserialize(nullptr, &error_message);
34 CHECK(result != nullptr) << "Couldn't json-deserialize file: " << filename
35 << ": " << error_message;
36 return make_scoped_ptr(result);
37 }
38
39 } // namespace
40
15 namespace onc { 41 namespace onc {
16 42
17 TEST(ONCDecrypterTest, BrokenEncryptionIterations) { 43 TEST(ONCDecrypterTest, BrokenEncryptionIterations) {
18 scoped_ptr<base::DictionaryValue> encrypted_onc = 44 scoped_ptr<base::DictionaryValue> encrypted_onc =
19 test_utils::ReadTestDictionary("broken-encrypted-iterations.onc"); 45 test_utils::ReadTestDictionary("broken-encrypted-iterations.onc");
20 46
21 scoped_ptr<base::DictionaryValue> decrypted_onc = 47 scoped_ptr<base::DictionaryValue> decrypted_onc =
22 Decrypt("test0000", *encrypted_onc); 48 Decrypt("test0000", *encrypted_onc);
23 49
24 EXPECT_EQ(NULL, decrypted_onc.get()); 50 EXPECT_EQ(NULL, decrypted_onc.get());
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 networks_with_cert_refs->DeepCopy()); 155 networks_with_cert_refs->DeepCopy());
130 156
131 bool success = ResolveServerCertRefsInNetworks(certs, 157 bool success = ResolveServerCertRefsInNetworks(certs,
132 actual_resolved_onc.get()); 158 actual_resolved_onc.get());
133 EXPECT_EQ(expected_success, success); 159 EXPECT_EQ(expected_success, success);
134 EXPECT_TRUE(test_utils::Equals(expected_resolved_onc, 160 EXPECT_TRUE(test_utils::Equals(expected_resolved_onc,
135 actual_resolved_onc.get())); 161 actual_resolved_onc.get()));
136 } 162 }
137 } 163 }
138 164
165 TEST(ONCUtils, ProxySettingsToProxyConfig) {
166 scoped_ptr<base::Value> test_data(ReadTestJson("proxy_config.json"));
167
168 base::ListValue* list_of_tests;
169 test_data->GetAsList(&list_of_tests);
170 ASSERT_TRUE(list_of_tests);
171
172 int index = 0;
173 for (base::ListValue::iterator it = list_of_tests->begin();
174 it != list_of_tests->end(); ++it, ++index) {
175 SCOPED_TRACE("Test case #" + base::IntToString(index));
176
177 base::DictionaryValue* test_case;
178 (*it)->GetAsDictionary(&test_case);
179
180 base::DictionaryValue* onc_proxy_settings;
181 test_case->GetDictionary("ONC_ProxySettings", &onc_proxy_settings);
182
183 base::DictionaryValue* expected_proxy_config;
184 test_case->GetDictionary("ProxyConfig", &expected_proxy_config);
185
186 scoped_ptr<base::DictionaryValue> actual_proxy_config =
187 ConvertOncProxySettingsToProxyConfig(*onc_proxy_settings);
188 EXPECT_TRUE(
189 test_utils::Equals(expected_proxy_config, actual_proxy_config.get()));
190 }
191 }
192
193 TEST(ONCUtils, ProxyConfigToOncProxySettings) {
194 scoped_ptr<base::Value> test_data(ReadTestJson("proxy_config.json"));
195
196 base::ListValue* list_of_tests;
197 test_data->GetAsList(&list_of_tests);
198 ASSERT_TRUE(list_of_tests);
199
200 int index = 0;
201 for (base::ListValue::iterator it = list_of_tests->begin();
202 it != list_of_tests->end(); ++it, ++index) {
203 SCOPED_TRACE("Test case #" + base::IntToString(index));
204
205 base::DictionaryValue* test_case;
206 (*it)->GetAsDictionary(&test_case);
207
208 base::DictionaryValue* shill_proxy_config;
209 test_case->GetDictionary("ProxyConfig", &shill_proxy_config);
210
211 base::DictionaryValue* onc_proxy_settings;
212 test_case->GetDictionary("ONC_ProxySettings", &onc_proxy_settings);
213
214 scoped_ptr<base::DictionaryValue> actual_proxy_settings =
215 ConvertProxyConfigToOncProxySettings(*shill_proxy_config);
216 EXPECT_TRUE(
217 test_utils::Equals(onc_proxy_settings, actual_proxy_settings.get()));
218 }
219 }
220
139 } // namespace onc 221 } // namespace onc
140 } // namespace chromeos 222 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698