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

Side by Side Diff: components/data_reduction_proxy/browser/data_reduction_proxy_settings_unittest.cc

Issue 279633003: Use non-static set_key interface on DataReductionProxySettings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/data_reduction_proxy/browser/data_reduction_proxy_settings. h" 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings. h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/md5.h" 8 #include "base/md5.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 23 matching lines...) Expand all
34 34
35 class DataReductionProxySettingsTest 35 class DataReductionProxySettingsTest
36 : public ConcreteDataReductionProxySettingsTest< 36 : public ConcreteDataReductionProxySettingsTest<
37 DataReductionProxySettings> { 37 DataReductionProxySettings> {
38 }; 38 };
39 39
40 40
41 TEST_F(DataReductionProxySettingsTest, TestAuthenticationInit) { 41 TEST_F(DataReductionProxySettingsTest, TestAuthenticationInit) {
42 AddProxyToCommandLine(); 42 AddProxyToCommandLine();
43 net::HttpAuthCache cache; 43 net::HttpAuthCache cache;
44 DataReductionProxySettings::InitDataReductionAuthentication(&cache); 44 DataReductionProxySettings::InitDataReductionAuthentication(
45 &cache, kDataReductionProxyKey);
45 DataReductionProxySettings::DataReductionProxyList proxies = 46 DataReductionProxySettings::DataReductionProxyList proxies =
46 DataReductionProxySettings::GetDataReductionProxies(); 47 DataReductionProxySettings::GetDataReductionProxies();
47 for (DataReductionProxySettings::DataReductionProxyList::iterator it = 48 for (DataReductionProxySettings::DataReductionProxyList::iterator it =
48 proxies.begin(); it != proxies.end(); ++it) { 49 proxies.begin(); it != proxies.end(); ++it) {
49 net::HttpAuthCache::Entry* entry = cache.LookupByPath(*it, 50 net::HttpAuthCache::Entry* entry = cache.LookupByPath(*it,
50 std::string("/")); 51 std::string("/"));
51 EXPECT_TRUE(entry != NULL); 52 EXPECT_TRUE(entry != NULL);
52 EXPECT_EQ(net::HttpAuth::AUTH_SCHEME_SPDYPROXY, entry->scheme()); 53 EXPECT_EQ(net::HttpAuth::AUTH_SCHEME_SPDYPROXY, entry->scheme());
53 EXPECT_EQ("SpdyProxy", entry->auth_challenge().substr(0,9)); 54 EXPECT_EQ("SpdyProxy", entry->auth_challenge().substr(0,9));
54 } 55 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 EXPECT_EQ("bar.com", proxies[1].host()); 114 EXPECT_EQ("bar.com", proxies[1].host());
114 EXPECT_EQ(80, proxies[1].EffectiveIntPort()); 115 EXPECT_EQ(80, proxies[1].EffectiveIntPort());
115 } 116 }
116 117
117 TEST_F(DataReductionProxySettingsTest, TestAuthHashGeneration) { 118 TEST_F(DataReductionProxySettingsTest, TestAuthHashGeneration) {
118 AddProxyToCommandLine(); 119 AddProxyToCommandLine();
119 std::string salt = "8675309"; // Jenny's number to test the hash generator. 120 std::string salt = "8675309"; // Jenny's number to test the hash generator.
120 std::string salted_key = salt + kDataReductionProxyKey + salt; 121 std::string salted_key = salt + kDataReductionProxyKey + salt;
121 base::string16 expected_hash = base::UTF8ToUTF16(base::MD5String(salted_key)); 122 base::string16 expected_hash = base::UTF8ToUTF16(base::MD5String(salted_key));
122 EXPECT_EQ(expected_hash, 123 EXPECT_EQ(expected_hash,
123 DataReductionProxySettings::AuthHashForSalt(8675309)); 124 DataReductionProxySettings::AuthHashForSalt(
125 8675309, kDataReductionProxyKey));
124 } 126 }
125 127
126 // Test that the auth key set by preprocessor directive is not used 128 // Test that the auth key set by preprocessor directive is not used
127 // when an origin is set via a switch. This test only does anything useful in 129 // when an origin is set via a switch. This test only does anything useful in
128 // Chrome builds. 130 // Chrome builds.
129 TEST_F(DataReductionProxySettingsTest, 131 TEST_F(DataReductionProxySettingsTest,
130 TestAuthHashGenerationWithOriginSetViaSwitch) { 132 TestAuthHashGenerationWithOriginSetViaSwitch) {
131 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 133 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
132 switches::kDataReductionProxy, kDataReductionProxy); 134 switches::kDataReductionProxy, kDataReductionProxy);
133 EXPECT_EQ(base::string16(), 135 EXPECT_EQ(base::string16(),
134 DataReductionProxySettings::AuthHashForSalt(8675309)); 136 DataReductionProxySettings::AuthHashForSalt(
137 8675309, kDataReductionProxyKey));
135 } 138 }
136 139
137 TEST_F(DataReductionProxySettingsTest, TestIsProxyEnabledOrManaged) { 140 TEST_F(DataReductionProxySettingsTest, TestIsProxyEnabledOrManaged) {
138 AddProxyToCommandLine(); 141 AddProxyToCommandLine();
139 settings_->InitPrefMembers(); 142 settings_->InitPrefMembers();
140 base::MessageLoopForUI loop; 143 base::MessageLoopForUI loop;
141 // The proxy is disabled initially. 144 // The proxy is disabled initially.
142 settings_->enabled_by_user_ = false; 145 settings_->enabled_by_user_ = false;
143 settings_->SetProxyConfigs(false, false, false); 146 settings_->SetProxyConfigs(false, false, false);
144 147
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 {"spdyproxy", true}, // 2. no salt. 203 {"spdyproxy", true}, // 2. no salt.
201 {"SpdyProxyxxx", true}, // 3. Salt not an int. 204 {"SpdyProxyxxx", true}, // 3. Salt not an int.
202 {"SpdyProxy1234567", false}, // 4. OK 205 {"SpdyProxy1234567", false}, // 4. OK
203 }; 206 };
204 207
205 for (int i = 0; i <= 4; ++i) { 208 for (int i = 0; i <= 4; ++i) {
206 scoped_refptr<net::AuthChallengeInfo> auth_info(new net::AuthChallengeInfo); 209 scoped_refptr<net::AuthChallengeInfo> auth_info(new net::AuthChallengeInfo);
207 auth_info->challenger = 210 auth_info->challenger =
208 net::HostPortPair::FromString(kDataReductionProxy); 211 net::HostPortPair::FromString(kDataReductionProxy);
209 auth_info->realm = tests[i].realm; 212 auth_info->realm = tests[i].realm;
210 base::string16 token = 213 base::string16 token = settings_->GetTokenForAuthChallenge(auth_info.get());
211 DataReductionProxySettings::GetTokenForAuthChallenge(auth_info.get());
212 EXPECT_EQ(tests[i].expected_empty_token, token.empty()); 214 EXPECT_EQ(tests[i].expected_empty_token, token.empty());
213 } 215 }
214 } 216 }
215 217
216 TEST_F(DataReductionProxySettingsTest, TestResetDataReductionStatistics) { 218 TEST_F(DataReductionProxySettingsTest, TestResetDataReductionStatistics) {
217 int64 original_content_length; 219 int64 original_content_length;
218 int64 received_content_length; 220 int64 received_content_length;
219 int64 last_update_time; 221 int64 last_update_time;
220 settings_->ResetDataReductionStatistics(); 222 settings_->ResetDataReductionStatistics();
221 settings_->GetContentLengths(kNumDaysInHistory, 223 settings_->GetContentLengths(kNumDaysInHistory,
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 scoped_refptr<net::TestURLRequestContextGetter> request_context = 395 scoped_refptr<net::TestURLRequestContextGetter> request_context =
394 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); 396 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current());
395 settings_->InitDataReductionProxySettings(&pref_service_, 397 settings_->InitDataReductionProxySettings(&pref_service_,
396 &pref_service_, 398 &pref_service_,
397 request_context.get()); 399 request_context.get());
398 400
399 base::MessageLoop::current()->RunUntilIdle(); 401 base::MessageLoop::current()->RunUntilIdle();
400 } 402 }
401 403
402 } // namespace data_reduction_proxy 404 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698