OLD | NEW |
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 <stddef.h> |
| 6 #include <stdint.h> |
| 7 |
5 #include <string> | 8 #include <string> |
6 | 9 |
7 #include "base/command_line.h" | 10 #include "base/command_line.h" |
8 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
10 #include "base/prefs/pref_registry_simple.h" | 13 #include "base/prefs/pref_registry_simple.h" |
11 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
12 #include "base/prefs/testing_pref_service.h" | 15 #include "base/prefs/testing_pref_service.h" |
13 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
14 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
15 #include "base/test/histogram_tester.h" | 18 #include "base/test/histogram_tester.h" |
16 #include "base/time/time.h" | 19 #include "base/time/time.h" |
17 #include "base/values.h" | 20 #include "base/values.h" |
18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_comp
ression_stats.h" | 21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_comp
ression_stats.h" |
19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_pref
s.h" | 22 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_pref
s.h" |
20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test
_utils.h" | 23 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test
_utils.h" |
21 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_
names.h" | 24 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_
names.h" |
22 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc
hes.h" | 25 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc
hes.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
24 | 27 |
25 namespace { | 28 namespace { |
26 | 29 |
27 const int kWriteDelayMinutes = 60; | 30 const int kWriteDelayMinutes = 60; |
28 | 31 |
29 // Each bucket holds data usage for a 15 minute interval. History is maintained | 32 // Each bucket holds data usage for a 15 minute interval. History is maintained |
30 // for 60 days. | 33 // for 60 days. |
31 const int kNumExpectedBuckets = 60 * 24 * 60 / 15; | 34 const int kNumExpectedBuckets = 60 * 24 * 60 / 15; |
32 | 35 |
33 int64 GetListPrefInt64Value( | 36 int64_t GetListPrefInt64Value(const base::ListValue& list_update, |
34 const base::ListValue& list_update, size_t index) { | 37 size_t index) { |
35 std::string string_value; | 38 std::string string_value; |
36 EXPECT_TRUE(list_update.GetString(index, &string_value)); | 39 EXPECT_TRUE(list_update.GetString(index, &string_value)); |
37 | 40 |
38 int64 value = 0; | 41 int64_t value = 0; |
39 EXPECT_TRUE(base::StringToInt64(string_value, &value)); | 42 EXPECT_TRUE(base::StringToInt64(string_value, &value)); |
40 return value; | 43 return value; |
41 } | 44 } |
42 | 45 |
43 class DataUsageLoadVerifier { | 46 class DataUsageLoadVerifier { |
44 public: | 47 public: |
45 DataUsageLoadVerifier( | 48 DataUsageLoadVerifier( |
46 scoped_ptr<std::vector<data_reduction_proxy::DataUsageBucket>> expected) { | 49 scoped_ptr<std::vector<data_reduction_proxy::DataUsageBucket>> expected) { |
47 expected_ = expected.Pass(); | 50 expected_ = expected.Pass(); |
48 } | 51 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 136 } |
134 | 137 |
135 DataReductionProxyCompressionStats::SiteUsageMap* DataUsageMap() { | 138 DataReductionProxyCompressionStats::SiteUsageMap* DataUsageMap() { |
136 return &compression_stats_->data_usage_map_; | 139 return &compression_stats_->data_usage_map_; |
137 } | 140 } |
138 | 141 |
139 void SetUpPrefs() { | 142 void SetUpPrefs() { |
140 CreatePrefList(prefs::kDailyHttpOriginalContentLength); | 143 CreatePrefList(prefs::kDailyHttpOriginalContentLength); |
141 CreatePrefList(prefs::kDailyHttpReceivedContentLength); | 144 CreatePrefList(prefs::kDailyHttpReceivedContentLength); |
142 | 145 |
143 const int64 kOriginalLength = 150; | 146 const int64_t kOriginalLength = 150; |
144 const int64 kReceivedLength = 100; | 147 const int64_t kReceivedLength = 100; |
145 | 148 |
146 compression_stats_->SetInt64( | 149 compression_stats_->SetInt64( |
147 prefs::kHttpOriginalContentLength, kOriginalLength); | 150 prefs::kHttpOriginalContentLength, kOriginalLength); |
148 compression_stats_->SetInt64( | 151 compression_stats_->SetInt64( |
149 prefs::kHttpReceivedContentLength, kReceivedLength); | 152 prefs::kHttpReceivedContentLength, kReceivedLength); |
150 | 153 |
151 base::ListValue* original_daily_content_length_list = | 154 base::ListValue* original_daily_content_length_list = |
152 compression_stats_->GetList(prefs::kDailyHttpOriginalContentLength); | 155 compression_stats_->GetList(prefs::kDailyHttpOriginalContentLength); |
153 base::ListValue* received_daily_content_length_list = | 156 base::ListValue* received_daily_content_length_list = |
154 compression_stats_->GetList(prefs::kDailyHttpReceivedContentLength); | 157 compression_stats_->GetList(prefs::kDailyHttpReceivedContentLength); |
(...skipping 29 matching lines...) Expand all Loading... |
184 | 187 |
185 for (size_t i = 0; i < count; ++i) { | 188 for (size_t i = 0; i < count; ++i) { |
186 EXPECT_EQ(GetListPrefInt64Value(*delayed_list, i), | 189 EXPECT_EQ(GetListPrefInt64Value(*delayed_list, i), |
187 GetListPrefInt64Value(*written_list, i)); | 190 GetListPrefInt64Value(*written_list, i)); |
188 } | 191 } |
189 } | 192 } |
190 | 193 |
191 // Verify the pref value in |pref_service_| are equal to that in | 194 // Verify the pref value in |pref_service_| are equal to that in |
192 // |simple_pref_service|. | 195 // |simple_pref_service|. |
193 void VerifyPrefWasWritten(const char* pref) { | 196 void VerifyPrefWasWritten(const char* pref) { |
194 int64 delayed_pref = compression_stats_->GetInt64(pref); | 197 int64_t delayed_pref = compression_stats_->GetInt64(pref); |
195 int64 written_pref = pref_service()->GetInt64(pref); | 198 int64_t written_pref = pref_service()->GetInt64(pref); |
196 EXPECT_EQ(delayed_pref, written_pref); | 199 EXPECT_EQ(delayed_pref, written_pref); |
197 } | 200 } |
198 | 201 |
199 // Verify the pref values in |dict| are equal to that in |compression_stats_|. | 202 // Verify the pref values in |dict| are equal to that in |compression_stats_|. |
200 void VerifyPrefs(base::DictionaryValue* dict) { | 203 void VerifyPrefs(base::DictionaryValue* dict) { |
201 base::string16 dict_pref_string; | 204 base::string16 dict_pref_string; |
202 int64 dict_pref; | 205 int64_t dict_pref; |
203 int64 service_pref; | 206 int64_t service_pref; |
204 | 207 |
205 dict->GetString("historic_original_content_length", &dict_pref_string); | 208 dict->GetString("historic_original_content_length", &dict_pref_string); |
206 base::StringToInt64(dict_pref_string, &dict_pref); | 209 base::StringToInt64(dict_pref_string, &dict_pref); |
207 service_pref = | 210 service_pref = |
208 compression_stats_->GetInt64(prefs::kHttpOriginalContentLength); | 211 compression_stats_->GetInt64(prefs::kHttpOriginalContentLength); |
209 EXPECT_EQ(service_pref, dict_pref); | 212 EXPECT_EQ(service_pref, dict_pref); |
210 | 213 |
211 dict->GetString("historic_received_content_length", &dict_pref_string); | 214 dict->GetString("historic_received_content_length", &dict_pref_string); |
212 base::StringToInt64(dict_pref_string, &dict_pref); | 215 base::StringToInt64(dict_pref_string, &dict_pref); |
213 service_pref = | 216 service_pref = |
214 compression_stats_->GetInt64(prefs::kHttpReceivedContentLength); | 217 compression_stats_->GetInt64(prefs::kHttpReceivedContentLength); |
215 EXPECT_EQ(service_pref, dict_pref); | 218 EXPECT_EQ(service_pref, dict_pref); |
216 } | 219 } |
217 | 220 |
218 // Verify the pref list values are equal to the given values. | 221 // Verify the pref list values are equal to the given values. |
219 // If the count of values is less than kNumDaysInHistory, zeros are assumed | 222 // If the count of values is less than kNumDaysInHistory, zeros are assumed |
220 // at the beginning. | 223 // at the beginning. |
221 void VerifyPrefList(const char* pref, const int64* values, size_t count) { | 224 void VerifyPrefList(const char* pref, const int64_t* values, size_t count) { |
222 ASSERT_GE(kNumDaysInHistory, count); | 225 ASSERT_GE(kNumDaysInHistory, count); |
223 base::ListValue* update = compression_stats_->GetList(pref); | 226 base::ListValue* update = compression_stats_->GetList(pref); |
224 ASSERT_EQ(kNumDaysInHistory, update->GetSize()) << "Pref: " << pref; | 227 ASSERT_EQ(kNumDaysInHistory, update->GetSize()) << "Pref: " << pref; |
225 | 228 |
226 for (size_t i = 0; i < count; ++i) { | 229 for (size_t i = 0; i < count; ++i) { |
227 EXPECT_EQ(values[i], | 230 EXPECT_EQ(values[i], |
228 GetListPrefInt64Value(*update, kNumDaysInHistory - count + i)) | 231 GetListPrefInt64Value(*update, kNumDaysInHistory - count + i)) |
229 << pref << "; index=" << (kNumDaysInHistory - count + i); | 232 << pref << "; index=" << (kNumDaysInHistory - count + i); |
230 } | 233 } |
231 for (size_t i = 0; i < kNumDaysInHistory - count; ++i) { | 234 for (size_t i = 0; i < kNumDaysInHistory - count; ++i) { |
232 EXPECT_EQ(0, GetListPrefInt64Value(*update, i)) << "index=" << i; | 235 EXPECT_EQ(0, GetListPrefInt64Value(*update, i)) << "index=" << i; |
233 } | 236 } |
234 } | 237 } |
235 | 238 |
236 // Verify that the pref value is equal to given value. | 239 // Verify that the pref value is equal to given value. |
237 void VerifyPrefInt64(const char* pref, const int64 value) { | 240 void VerifyPrefInt64(const char* pref, const int64_t value) { |
238 EXPECT_EQ(value, compression_stats_->GetInt64(pref)); | 241 EXPECT_EQ(value, compression_stats_->GetInt64(pref)); |
239 } | 242 } |
240 | 243 |
241 // Verify all daily data saving pref list values. | 244 // Verify all daily data saving pref list values. |
242 void VerifyDailyDataSavingContentLengthPrefLists( | 245 void VerifyDailyDataSavingContentLengthPrefLists( |
243 const int64* original_values, size_t original_count, | 246 const int64_t* original_values, |
244 const int64* received_values, size_t received_count, | 247 size_t original_count, |
245 const int64* original_with_data_reduction_proxy_enabled_values, | 248 const int64_t* received_values, |
| 249 size_t received_count, |
| 250 const int64_t* original_with_data_reduction_proxy_enabled_values, |
246 size_t original_with_data_reduction_proxy_enabled_count, | 251 size_t original_with_data_reduction_proxy_enabled_count, |
247 const int64* received_with_data_reduction_proxy_enabled_values, | 252 const int64_t* received_with_data_reduction_proxy_enabled_values, |
248 size_t received_with_data_reduction_proxy_count, | 253 size_t received_with_data_reduction_proxy_count, |
249 const int64* original_via_data_reduction_proxy_values, | 254 const int64_t* original_via_data_reduction_proxy_values, |
250 size_t original_via_data_reduction_proxy_count, | 255 size_t original_via_data_reduction_proxy_count, |
251 const int64* received_via_data_reduction_proxy_values, | 256 const int64_t* received_via_data_reduction_proxy_values, |
252 size_t received_via_data_reduction_proxy_count) { | 257 size_t received_via_data_reduction_proxy_count) { |
253 VerifyPrefList(data_reduction_proxy::prefs::kDailyHttpOriginalContentLength, | 258 VerifyPrefList(data_reduction_proxy::prefs::kDailyHttpOriginalContentLength, |
254 original_values, original_count); | 259 original_values, original_count); |
255 VerifyPrefList(data_reduction_proxy::prefs::kDailyHttpReceivedContentLength, | 260 VerifyPrefList(data_reduction_proxy::prefs::kDailyHttpReceivedContentLength, |
256 received_values, received_count); | 261 received_values, received_count); |
257 VerifyPrefList( | 262 VerifyPrefList( |
258 data_reduction_proxy::prefs:: | 263 data_reduction_proxy::prefs:: |
259 kDailyOriginalContentLengthWithDataReductionProxyEnabled, | 264 kDailyOriginalContentLengthWithDataReductionProxyEnabled, |
260 original_with_data_reduction_proxy_enabled_values, | 265 original_with_data_reduction_proxy_enabled_values, |
261 original_with_data_reduction_proxy_enabled_count); | 266 original_with_data_reduction_proxy_enabled_count); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 VerifyPrefInt64(data_reduction_proxy::prefs:: | 312 VerifyPrefInt64(data_reduction_proxy::prefs:: |
308 kDailyContentLengthViaDataReductionProxyApplication, | 313 kDailyContentLengthViaDataReductionProxyApplication, |
309 received_via_data_reduction_proxy_values | 314 received_via_data_reduction_proxy_values |
310 ? received_via_data_reduction_proxy_values | 315 ? received_via_data_reduction_proxy_values |
311 [received_via_data_reduction_proxy_count - 1] | 316 [received_via_data_reduction_proxy_count - 1] |
312 : 0); | 317 : 0); |
313 } | 318 } |
314 | 319 |
315 // Verify daily data saving pref for request types. | 320 // Verify daily data saving pref for request types. |
316 void VerifyDailyRequestTypeContentLengthPrefLists( | 321 void VerifyDailyRequestTypeContentLengthPrefLists( |
317 const int64* original_values, size_t original_count, | 322 const int64_t* original_values, |
318 const int64* received_values, size_t received_count, | 323 size_t original_count, |
319 const int64* original_with_data_reduction_proxy_enabled_values, | 324 const int64_t* received_values, |
| 325 size_t received_count, |
| 326 const int64_t* original_with_data_reduction_proxy_enabled_values, |
320 size_t original_with_data_reduction_proxy_enabled_count, | 327 size_t original_with_data_reduction_proxy_enabled_count, |
321 const int64* received_with_data_reduction_proxy_enabled_values, | 328 const int64_t* received_with_data_reduction_proxy_enabled_values, |
322 size_t received_with_data_reduction_proxy_count, | 329 size_t received_with_data_reduction_proxy_count, |
323 const int64* https_with_data_reduction_proxy_enabled_values, | 330 const int64_t* https_with_data_reduction_proxy_enabled_values, |
324 size_t https_with_data_reduction_proxy_enabled_count, | 331 size_t https_with_data_reduction_proxy_enabled_count, |
325 const int64* short_bypass_with_data_reduction_proxy_enabled_values, | 332 const int64_t* short_bypass_with_data_reduction_proxy_enabled_values, |
326 size_t short_bypass_with_data_reduction_proxy_enabled_count, | 333 size_t short_bypass_with_data_reduction_proxy_enabled_count, |
327 const int64* long_bypass_with_data_reduction_proxy_enabled_values, | 334 const int64_t* long_bypass_with_data_reduction_proxy_enabled_values, |
328 size_t long_bypass_with_data_reduction_proxy_enabled_count, | 335 size_t long_bypass_with_data_reduction_proxy_enabled_count, |
329 const int64* unknown_with_data_reduction_proxy_enabled_values, | 336 const int64_t* unknown_with_data_reduction_proxy_enabled_values, |
330 size_t unknown_with_data_reduction_proxy_enabled_count) { | 337 size_t unknown_with_data_reduction_proxy_enabled_count) { |
331 VerifyPrefList(data_reduction_proxy::prefs::kDailyHttpOriginalContentLength, | 338 VerifyPrefList(data_reduction_proxy::prefs::kDailyHttpOriginalContentLength, |
332 original_values, original_count); | 339 original_values, original_count); |
333 VerifyPrefList(data_reduction_proxy::prefs::kDailyHttpReceivedContentLength, | 340 VerifyPrefList(data_reduction_proxy::prefs::kDailyHttpReceivedContentLength, |
334 received_values, received_count); | 341 received_values, received_count); |
335 VerifyPrefList( | 342 VerifyPrefList( |
336 data_reduction_proxy::prefs:: | 343 data_reduction_proxy::prefs:: |
337 kDailyOriginalContentLengthWithDataReductionProxyEnabled, | 344 kDailyOriginalContentLengthWithDataReductionProxyEnabled, |
338 original_with_data_reduction_proxy_enabled_values, | 345 original_with_data_reduction_proxy_enabled_values, |
339 original_with_data_reduction_proxy_enabled_count); | 346 original_with_data_reduction_proxy_enabled_count); |
(...skipping 17 matching lines...) Expand all Loading... |
357 kDailyContentLengthLongBypassWithDataReductionProxyEnabled, | 364 kDailyContentLengthLongBypassWithDataReductionProxyEnabled, |
358 long_bypass_with_data_reduction_proxy_enabled_values, | 365 long_bypass_with_data_reduction_proxy_enabled_values, |
359 long_bypass_with_data_reduction_proxy_enabled_count); | 366 long_bypass_with_data_reduction_proxy_enabled_count); |
360 VerifyPrefList( | 367 VerifyPrefList( |
361 data_reduction_proxy::prefs:: | 368 data_reduction_proxy::prefs:: |
362 kDailyContentLengthUnknownWithDataReductionProxyEnabled, | 369 kDailyContentLengthUnknownWithDataReductionProxyEnabled, |
363 unknown_with_data_reduction_proxy_enabled_values, | 370 unknown_with_data_reduction_proxy_enabled_values, |
364 unknown_with_data_reduction_proxy_enabled_count); | 371 unknown_with_data_reduction_proxy_enabled_count); |
365 } | 372 } |
366 | 373 |
367 int64 GetInt64(const char* pref_path) { | 374 int64_t GetInt64(const char* pref_path) { |
368 return compression_stats_->GetInt64(pref_path); | 375 return compression_stats_->GetInt64(pref_path); |
369 } | 376 } |
370 | 377 |
371 void SetInt64(const char* pref_path, int64 pref_value) { | 378 void SetInt64(const char* pref_path, int64_t pref_value) { |
372 compression_stats_->SetInt64(pref_path, pref_value); | 379 compression_stats_->SetInt64(pref_path, pref_value); |
373 } | 380 } |
374 | 381 |
375 std::string NormalizeHostname(const std::string& hostname) { | 382 std::string NormalizeHostname(const std::string& hostname) { |
376 return DataReductionProxyCompressionStats::NormalizeHostname(hostname); | 383 return DataReductionProxyCompressionStats::NormalizeHostname(hostname); |
377 } | 384 } |
378 | 385 |
379 void RecordContentLengthPrefs(int64 received_content_length, | 386 void RecordContentLengthPrefs(int64_t received_content_length, |
380 int64 original_content_length, | 387 int64_t original_content_length, |
381 bool with_data_reduction_proxy_enabled, | 388 bool with_data_reduction_proxy_enabled, |
382 DataReductionProxyRequestType request_type, | 389 DataReductionProxyRequestType request_type, |
383 const std::string& mime_type, | 390 const std::string& mime_type, |
384 base::Time now) { | 391 base::Time now) { |
385 compression_stats_->RecordRequestSizePrefs( | 392 compression_stats_->RecordRequestSizePrefs( |
386 received_content_length, original_content_length, | 393 received_content_length, original_content_length, |
387 with_data_reduction_proxy_enabled, request_type, mime_type, now); | 394 with_data_reduction_proxy_enabled, request_type, mime_type, now); |
388 } | 395 } |
389 | 396 |
390 void RecordContentLengthPrefs(int64 received_content_length, | 397 void RecordContentLengthPrefs(int64_t received_content_length, |
391 int64 original_content_length, | 398 int64_t original_content_length, |
392 bool with_data_reduction_proxy_enabled, | 399 bool with_data_reduction_proxy_enabled, |
393 DataReductionProxyRequestType request_type, | 400 DataReductionProxyRequestType request_type, |
394 base::Time now) { | 401 base::Time now) { |
395 RecordContentLengthPrefs(received_content_length, original_content_length, | 402 RecordContentLengthPrefs(received_content_length, original_content_length, |
396 with_data_reduction_proxy_enabled, request_type, | 403 with_data_reduction_proxy_enabled, request_type, |
397 "application/octet-stream", now); | 404 "application/octet-stream", now); |
398 } | 405 } |
399 | 406 |
400 void RecordDataUsage(const std::string& data_usage_host, | 407 void RecordDataUsage(const std::string& data_usage_host, |
401 int64 data_used, | 408 int64_t data_used, |
402 int64 original_size, | 409 int64_t original_size, |
403 const base::Time& time) { | 410 const base::Time& time) { |
404 compression_stats_->RecordDataUsage(data_usage_host, data_used, | 411 compression_stats_->RecordDataUsage(data_usage_host, data_used, |
405 original_size, time); | 412 original_size, time); |
406 } | 413 } |
407 | 414 |
408 void GetHistoricalDataUsage( | 415 void GetHistoricalDataUsage( |
409 const HistoricalDataUsageCallback& onLoadDataUsage, | 416 const HistoricalDataUsageCallback& onLoadDataUsage, |
410 const base::Time& now) { | 417 const base::Time& now) { |
411 compression_stats_->GetHistoricalDataUsageImpl(onLoadDataUsage, now); | 418 compression_stats_->GetHistoricalDataUsageImpl(onLoadDataUsage, now); |
412 } | 419 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 prefs::kUpdateDailyReceivedContentLengths, true); | 506 prefs::kUpdateDailyReceivedContentLengths, true); |
500 | 507 |
501 VerifyPrefWasWritten(prefs::kHttpOriginalContentLength); | 508 VerifyPrefWasWritten(prefs::kHttpOriginalContentLength); |
502 VerifyPrefWasWritten(prefs::kHttpReceivedContentLength); | 509 VerifyPrefWasWritten(prefs::kHttpReceivedContentLength); |
503 VerifyPrefListWasWritten(prefs::kDailyHttpOriginalContentLength); | 510 VerifyPrefListWasWritten(prefs::kDailyHttpOriginalContentLength); |
504 VerifyPrefListWasWritten(prefs::kDailyHttpReceivedContentLength); | 511 VerifyPrefListWasWritten(prefs::kDailyHttpReceivedContentLength); |
505 } | 512 } |
506 | 513 |
507 TEST_F(DataReductionProxyCompressionStatsTest, | 514 TEST_F(DataReductionProxyCompressionStatsTest, |
508 HistoricNetworkStatsInfoToValue) { | 515 HistoricNetworkStatsInfoToValue) { |
509 const int64 kOriginalLength = 150; | 516 const int64_t kOriginalLength = 150; |
510 const int64 kReceivedLength = 100; | 517 const int64_t kReceivedLength = 100; |
511 ResetCompressionStatsWithDelay( | 518 ResetCompressionStatsWithDelay( |
512 base::TimeDelta::FromMinutes(kWriteDelayMinutes)); | 519 base::TimeDelta::FromMinutes(kWriteDelayMinutes)); |
513 | 520 |
514 base::DictionaryValue* dict = nullptr; | 521 base::DictionaryValue* dict = nullptr; |
515 scoped_ptr<base::Value> stats_value( | 522 scoped_ptr<base::Value> stats_value( |
516 compression_stats()->HistoricNetworkStatsInfoToValue()); | 523 compression_stats()->HistoricNetworkStatsInfoToValue()); |
517 EXPECT_TRUE(stats_value->GetAsDictionary(&dict)); | 524 EXPECT_TRUE(stats_value->GetAsDictionary(&dict)); |
518 VerifyPrefs(dict); | 525 VerifyPrefs(dict); |
519 | 526 |
520 SetInt64(prefs::kHttpOriginalContentLength, kOriginalLength); | 527 SetInt64(prefs::kHttpOriginalContentLength, kOriginalLength); |
521 SetInt64(prefs::kHttpReceivedContentLength, kReceivedLength); | 528 SetInt64(prefs::kHttpReceivedContentLength, kReceivedLength); |
522 | 529 |
523 stats_value.reset(compression_stats()->HistoricNetworkStatsInfoToValue()); | 530 stats_value.reset(compression_stats()->HistoricNetworkStatsInfoToValue()); |
524 EXPECT_TRUE(stats_value->GetAsDictionary(&dict)); | 531 EXPECT_TRUE(stats_value->GetAsDictionary(&dict)); |
525 VerifyPrefs(dict); | 532 VerifyPrefs(dict); |
526 } | 533 } |
527 | 534 |
528 TEST_F(DataReductionProxyCompressionStatsTest, | 535 TEST_F(DataReductionProxyCompressionStatsTest, |
529 HistoricNetworkStatsInfoToValueDirect) { | 536 HistoricNetworkStatsInfoToValueDirect) { |
530 const int64 kOriginalLength = 150; | 537 const int64_t kOriginalLength = 150; |
531 const int64 kReceivedLength = 100; | 538 const int64_t kReceivedLength = 100; |
532 | 539 |
533 base::DictionaryValue* dict = nullptr; | 540 base::DictionaryValue* dict = nullptr; |
534 scoped_ptr<base::Value> stats_value( | 541 scoped_ptr<base::Value> stats_value( |
535 compression_stats()->HistoricNetworkStatsInfoToValue()); | 542 compression_stats()->HistoricNetworkStatsInfoToValue()); |
536 EXPECT_TRUE(stats_value->GetAsDictionary(&dict)); | 543 EXPECT_TRUE(stats_value->GetAsDictionary(&dict)); |
537 VerifyPrefs(dict); | 544 VerifyPrefs(dict); |
538 | 545 |
539 SetInt64(prefs::kHttpOriginalContentLength, kOriginalLength); | 546 SetInt64(prefs::kHttpOriginalContentLength, kOriginalLength); |
540 SetInt64(prefs::kHttpReceivedContentLength, kReceivedLength); | 547 SetInt64(prefs::kHttpReceivedContentLength, kReceivedLength); |
541 | 548 |
(...skipping 30 matching lines...) Expand all Loading... |
572 base::TimeDelta::FromMinutes(kWriteDelayMinutes)); | 579 base::TimeDelta::FromMinutes(kWriteDelayMinutes)); |
573 | 580 |
574 const base::ListValue* value = pref_service()->GetList( | 581 const base::ListValue* value = pref_service()->GetList( |
575 prefs::kDailyHttpOriginalContentLength); | 582 prefs::kDailyHttpOriginalContentLength); |
576 std::string string_value; | 583 std::string string_value; |
577 value->GetString(0, &string_value); | 584 value->GetString(0, &string_value); |
578 EXPECT_EQ("1234", string_value); | 585 EXPECT_EQ("1234", string_value); |
579 } | 586 } |
580 | 587 |
581 TEST_F(DataReductionProxyCompressionStatsTest, TotalLengths) { | 588 TEST_F(DataReductionProxyCompressionStatsTest, TotalLengths) { |
582 const int64 kOriginalLength = 200; | 589 const int64_t kOriginalLength = 200; |
583 const int64 kReceivedLength = 100; | 590 const int64_t kReceivedLength = 100; |
584 | 591 |
585 compression_stats()->UpdateContentLengths( | 592 compression_stats()->UpdateContentLengths( |
586 kReceivedLength, kOriginalLength, IsDataReductionProxyEnabled(), | 593 kReceivedLength, kOriginalLength, IsDataReductionProxyEnabled(), |
587 UNKNOWN_TYPE, std::string(), std::string()); | 594 UNKNOWN_TYPE, std::string(), std::string()); |
588 | 595 |
589 EXPECT_EQ(kReceivedLength, | 596 EXPECT_EQ(kReceivedLength, |
590 GetInt64(data_reduction_proxy::prefs::kHttpReceivedContentLength)); | 597 GetInt64(data_reduction_proxy::prefs::kHttpReceivedContentLength)); |
591 EXPECT_FALSE(IsDataReductionProxyEnabled()); | 598 EXPECT_FALSE(IsDataReductionProxyEnabled()); |
592 EXPECT_EQ(kOriginalLength, | 599 EXPECT_EQ(kOriginalLength, |
593 GetInt64(data_reduction_proxy::prefs::kHttpOriginalContentLength)); | 600 GetInt64(data_reduction_proxy::prefs::kHttpOriginalContentLength)); |
594 | 601 |
595 // Record the same numbers again, and total lengths should be doubled. | 602 // Record the same numbers again, and total lengths should be doubled. |
596 compression_stats()->UpdateContentLengths( | 603 compression_stats()->UpdateContentLengths( |
597 kReceivedLength, kOriginalLength, IsDataReductionProxyEnabled(), | 604 kReceivedLength, kOriginalLength, IsDataReductionProxyEnabled(), |
598 UNKNOWN_TYPE, std::string(), std::string()); | 605 UNKNOWN_TYPE, std::string(), std::string()); |
599 | 606 |
600 EXPECT_EQ(kReceivedLength * 2, | 607 EXPECT_EQ(kReceivedLength * 2, |
601 GetInt64(data_reduction_proxy::prefs::kHttpReceivedContentLength)); | 608 GetInt64(data_reduction_proxy::prefs::kHttpReceivedContentLength)); |
602 EXPECT_FALSE(IsDataReductionProxyEnabled()); | 609 EXPECT_FALSE(IsDataReductionProxyEnabled()); |
603 EXPECT_EQ(kOriginalLength * 2, | 610 EXPECT_EQ(kOriginalLength * 2, |
604 GetInt64(data_reduction_proxy::prefs::kHttpOriginalContentLength)); | 611 GetInt64(data_reduction_proxy::prefs::kHttpOriginalContentLength)); |
605 } | 612 } |
606 | 613 |
607 TEST_F(DataReductionProxyCompressionStatsTest, OneResponse) { | 614 TEST_F(DataReductionProxyCompressionStatsTest, OneResponse) { |
608 const int64 kOriginalLength = 200; | 615 const int64_t kOriginalLength = 200; |
609 const int64 kReceivedLength = 100; | 616 const int64_t kReceivedLength = 100; |
610 int64 original[] = {kOriginalLength}; | 617 int64_t original[] = {kOriginalLength}; |
611 int64 received[] = {kReceivedLength}; | 618 int64_t received[] = {kReceivedLength}; |
612 | 619 |
613 RecordContentLengthPrefs( | 620 RecordContentLengthPrefs( |
614 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, | 621 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, |
615 FakeNow()); | 622 FakeNow()); |
616 | 623 |
617 VerifyDailyDataSavingContentLengthPrefLists( | 624 VerifyDailyDataSavingContentLengthPrefLists( |
618 original, 1, received, 1, | 625 original, 1, received, 1, |
619 original, 1, received, 1, | 626 original, 1, received, 1, |
620 original, 1, received, 1); | 627 original, 1, received, 1); |
621 } | 628 } |
622 | 629 |
623 TEST_F(DataReductionProxyCompressionStatsTest, MultipleResponses) { | 630 TEST_F(DataReductionProxyCompressionStatsTest, MultipleResponses) { |
624 const int64 kOriginalLength = 150; | 631 const int64_t kOriginalLength = 150; |
625 const int64 kReceivedLength = 100; | 632 const int64_t kReceivedLength = 100; |
626 int64 original[] = {kOriginalLength}; | 633 int64_t original[] = {kOriginalLength}; |
627 int64 received[] = {kReceivedLength}; | 634 int64_t received[] = {kReceivedLength}; |
628 RecordContentLengthPrefs( | 635 RecordContentLengthPrefs( |
629 kReceivedLength, kOriginalLength, false, UNKNOWN_TYPE, FakeNow()); | 636 kReceivedLength, kOriginalLength, false, UNKNOWN_TYPE, FakeNow()); |
630 VerifyDailyDataSavingContentLengthPrefLists( | 637 VerifyDailyDataSavingContentLengthPrefLists( |
631 original, 1, received, 1, | 638 original, 1, received, 1, |
632 NULL, 0, NULL, 0, NULL, 0, NULL, 0); | 639 NULL, 0, NULL, 0, NULL, 0, NULL, 0); |
633 | 640 |
634 RecordContentLengthPrefs( | 641 RecordContentLengthPrefs( |
635 kReceivedLength, kOriginalLength, true, UNKNOWN_TYPE, FakeNow()); | 642 kReceivedLength, kOriginalLength, true, UNKNOWN_TYPE, FakeNow()); |
636 original[0] += kOriginalLength; | 643 original[0] += kOriginalLength; |
637 received[0] += kReceivedLength; | 644 received[0] += kReceivedLength; |
638 int64 original_proxy_enabled[] = {kOriginalLength}; | 645 int64_t original_proxy_enabled[] = {kOriginalLength}; |
639 int64 received_proxy_enabled[] = {kReceivedLength}; | 646 int64_t received_proxy_enabled[] = {kReceivedLength}; |
640 VerifyDailyDataSavingContentLengthPrefLists( | 647 VerifyDailyDataSavingContentLengthPrefLists( |
641 original, 1, received, 1, | 648 original, 1, received, 1, |
642 original_proxy_enabled, 1, received_proxy_enabled, 1, | 649 original_proxy_enabled, 1, received_proxy_enabled, 1, |
643 NULL, 0, NULL, 0); | 650 NULL, 0, NULL, 0); |
644 | 651 |
645 RecordContentLengthPrefs( | 652 RecordContentLengthPrefs( |
646 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, | 653 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, |
647 FakeNow()); | 654 FakeNow()); |
648 original[0] += kOriginalLength; | 655 original[0] += kOriginalLength; |
649 received[0] += kReceivedLength; | 656 received[0] += kReceivedLength; |
650 original_proxy_enabled[0] += kOriginalLength; | 657 original_proxy_enabled[0] += kOriginalLength; |
651 received_proxy_enabled[0] += kReceivedLength; | 658 received_proxy_enabled[0] += kReceivedLength; |
652 int64 original_via_proxy[] = {kOriginalLength}; | 659 int64_t original_via_proxy[] = {kOriginalLength}; |
653 int64 received_via_proxy[] = {kReceivedLength}; | 660 int64_t received_via_proxy[] = {kReceivedLength}; |
654 VerifyDailyDataSavingContentLengthPrefLists( | 661 VerifyDailyDataSavingContentLengthPrefLists( |
655 original, 1, received, 1, | 662 original, 1, received, 1, |
656 original_proxy_enabled, 1, received_proxy_enabled, 1, | 663 original_proxy_enabled, 1, received_proxy_enabled, 1, |
657 original_via_proxy, 1, received_via_proxy, 1); | 664 original_via_proxy, 1, received_via_proxy, 1); |
658 | 665 |
659 RecordContentLengthPrefs( | 666 RecordContentLengthPrefs( |
660 kReceivedLength, kOriginalLength, true, UNKNOWN_TYPE, FakeNow()); | 667 kReceivedLength, kOriginalLength, true, UNKNOWN_TYPE, FakeNow()); |
661 original[0] += kOriginalLength; | 668 original[0] += kOriginalLength; |
662 received[0] += kReceivedLength; | 669 received[0] += kReceivedLength; |
663 original_proxy_enabled[0] += kOriginalLength; | 670 original_proxy_enabled[0] += kOriginalLength; |
664 received_proxy_enabled[0] += kReceivedLength; | 671 received_proxy_enabled[0] += kReceivedLength; |
665 VerifyDailyDataSavingContentLengthPrefLists( | 672 VerifyDailyDataSavingContentLengthPrefLists( |
666 original, 1, received, 1, | 673 original, 1, received, 1, |
667 original_proxy_enabled, 1, received_proxy_enabled, 1, | 674 original_proxy_enabled, 1, received_proxy_enabled, 1, |
668 original_via_proxy, 1, received_via_proxy, 1); | 675 original_via_proxy, 1, received_via_proxy, 1); |
669 | 676 |
670 RecordContentLengthPrefs( | 677 RecordContentLengthPrefs( |
671 kReceivedLength, kOriginalLength, false, UNKNOWN_TYPE, FakeNow()); | 678 kReceivedLength, kOriginalLength, false, UNKNOWN_TYPE, FakeNow()); |
672 original[0] += kOriginalLength; | 679 original[0] += kOriginalLength; |
673 received[0] += kReceivedLength; | 680 received[0] += kReceivedLength; |
674 VerifyDailyDataSavingContentLengthPrefLists( | 681 VerifyDailyDataSavingContentLengthPrefLists( |
675 original, 1, received, 1, | 682 original, 1, received, 1, |
676 original_proxy_enabled, 1, received_proxy_enabled, 1, | 683 original_proxy_enabled, 1, received_proxy_enabled, 1, |
677 original_via_proxy, 1, received_via_proxy, 1); | 684 original_via_proxy, 1, received_via_proxy, 1); |
678 } | 685 } |
679 | 686 |
680 TEST_F(DataReductionProxyCompressionStatsTest, RequestType) { | 687 TEST_F(DataReductionProxyCompressionStatsTest, RequestType) { |
681 const int64 kContentLength = 200; | 688 const int64_t kContentLength = 200; |
682 int64 received[] = {0}; | 689 int64_t received[] = {0}; |
683 int64 https_received[] = {0}; | 690 int64_t https_received[] = {0}; |
684 int64 total_received[] = {0}; | 691 int64_t total_received[] = {0}; |
685 int64 proxy_enabled_received[] = {0}; | 692 int64_t proxy_enabled_received[] = {0}; |
686 | 693 |
687 RecordContentLengthPrefs( | 694 RecordContentLengthPrefs( |
688 kContentLength, kContentLength, true, HTTPS, FakeNow()); | 695 kContentLength, kContentLength, true, HTTPS, FakeNow()); |
689 total_received[0] += kContentLength; | 696 total_received[0] += kContentLength; |
690 proxy_enabled_received[0] += kContentLength; | 697 proxy_enabled_received[0] += kContentLength; |
691 https_received[0] += kContentLength; | 698 https_received[0] += kContentLength; |
692 VerifyDailyRequestTypeContentLengthPrefLists( | 699 VerifyDailyRequestTypeContentLengthPrefLists( |
693 total_received, 1, total_received, 1, | 700 total_received, 1, total_received, 1, |
694 proxy_enabled_received, 1, proxy_enabled_received, 1, | 701 proxy_enabled_received, 1, proxy_enabled_received, 1, |
695 https_received, 1, | 702 https_received, 1, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 VerifyDailyRequestTypeContentLengthPrefLists( | 761 VerifyDailyRequestTypeContentLengthPrefLists( |
755 total_received, 1, total_received, 1, | 762 total_received, 1, total_received, 1, |
756 proxy_enabled_received, 1, proxy_enabled_received, 1, | 763 proxy_enabled_received, 1, proxy_enabled_received, 1, |
757 https_received, 1, | 764 https_received, 1, |
758 received, 1, // short bypass | 765 received, 1, // short bypass |
759 received, 1, // long bypass | 766 received, 1, // long bypass |
760 received, 1); // unknown | 767 received, 1); // unknown |
761 } | 768 } |
762 | 769 |
763 TEST_F(DataReductionProxyCompressionStatsTest, ForwardOneDay) { | 770 TEST_F(DataReductionProxyCompressionStatsTest, ForwardOneDay) { |
764 const int64 kOriginalLength = 200; | 771 const int64_t kOriginalLength = 200; |
765 const int64 kReceivedLength = 100; | 772 const int64_t kReceivedLength = 100; |
766 | 773 |
767 RecordContentLengthPrefs( | 774 RecordContentLengthPrefs( |
768 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, | 775 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, |
769 FakeNow()); | 776 FakeNow()); |
770 | 777 |
771 // Forward one day. | 778 // Forward one day. |
772 SetFakeTimeDeltaInHours(24); | 779 SetFakeTimeDeltaInHours(24); |
773 | 780 |
774 // Proxy not enabled. Not via proxy. | 781 // Proxy not enabled. Not via proxy. |
775 RecordContentLengthPrefs( | 782 RecordContentLengthPrefs( |
776 kReceivedLength, kOriginalLength, false, UNKNOWN_TYPE, FakeNow()); | 783 kReceivedLength, kOriginalLength, false, UNKNOWN_TYPE, FakeNow()); |
777 | 784 |
778 int64 original[] = {kOriginalLength, kOriginalLength}; | 785 int64_t original[] = {kOriginalLength, kOriginalLength}; |
779 int64 received[] = {kReceivedLength, kReceivedLength}; | 786 int64_t received[] = {kReceivedLength, kReceivedLength}; |
780 int64 original_with_data_reduction_proxy_enabled[] = {kOriginalLength, 0}; | 787 int64_t original_with_data_reduction_proxy_enabled[] = {kOriginalLength, 0}; |
781 int64 received_with_data_reduction_proxy_enabled[] = {kReceivedLength, 0}; | 788 int64_t received_with_data_reduction_proxy_enabled[] = {kReceivedLength, 0}; |
782 int64 original_via_data_reduction_proxy[] = {kOriginalLength, 0}; | 789 int64_t original_via_data_reduction_proxy[] = {kOriginalLength, 0}; |
783 int64 received_via_data_reduction_proxy[] = {kReceivedLength, 0}; | 790 int64_t received_via_data_reduction_proxy[] = {kReceivedLength, 0}; |
784 VerifyDailyDataSavingContentLengthPrefLists( | 791 VerifyDailyDataSavingContentLengthPrefLists( |
785 original, 2, | 792 original, 2, |
786 received, 2, | 793 received, 2, |
787 original_with_data_reduction_proxy_enabled, 2, | 794 original_with_data_reduction_proxy_enabled, 2, |
788 received_with_data_reduction_proxy_enabled, 2, | 795 received_with_data_reduction_proxy_enabled, 2, |
789 original_via_data_reduction_proxy, 2, | 796 original_via_data_reduction_proxy, 2, |
790 received_via_data_reduction_proxy, 2); | 797 received_via_data_reduction_proxy, 2); |
791 | 798 |
792 // Proxy enabled. Not via proxy. | 799 // Proxy enabled. Not via proxy. |
793 RecordContentLengthPrefs( | 800 RecordContentLengthPrefs( |
(...skipping 21 matching lines...) Expand all Loading... |
815 original_via_data_reduction_proxy[1] += kOriginalLength; | 822 original_via_data_reduction_proxy[1] += kOriginalLength; |
816 received_via_data_reduction_proxy[1] += kReceivedLength; | 823 received_via_data_reduction_proxy[1] += kReceivedLength; |
817 VerifyDailyDataSavingContentLengthPrefLists( | 824 VerifyDailyDataSavingContentLengthPrefLists( |
818 original, 2, | 825 original, 2, |
819 received, 2, | 826 received, 2, |
820 original_with_data_reduction_proxy_enabled, 2, | 827 original_with_data_reduction_proxy_enabled, 2, |
821 received_with_data_reduction_proxy_enabled, 2, | 828 received_with_data_reduction_proxy_enabled, 2, |
822 original_via_data_reduction_proxy, 2, | 829 original_via_data_reduction_proxy, 2, |
823 received_via_data_reduction_proxy, 2); | 830 received_via_data_reduction_proxy, 2); |
824 | 831 |
825 // Proxy enabled and via proxy, with content length greater than max int32. | 832 // Proxy enabled and via proxy, with content length greater than max int32_t. |
826 const int64 kBigOriginalLength = 0x300000000LL; // 12G. | 833 const int64_t kBigOriginalLength = 0x300000000LL; // 12G. |
827 const int64 kBigReceivedLength = 0x200000000LL; // 8G. | 834 const int64_t kBigReceivedLength = 0x200000000LL; // 8G. |
828 RecordContentLengthPrefs(kBigReceivedLength, kBigOriginalLength, true, | 835 RecordContentLengthPrefs(kBigReceivedLength, kBigOriginalLength, true, |
829 VIA_DATA_REDUCTION_PROXY, FakeNow()); | 836 VIA_DATA_REDUCTION_PROXY, FakeNow()); |
830 original[1] += kBigOriginalLength; | 837 original[1] += kBigOriginalLength; |
831 received[1] += kBigReceivedLength; | 838 received[1] += kBigReceivedLength; |
832 original_with_data_reduction_proxy_enabled[1] += kBigOriginalLength; | 839 original_with_data_reduction_proxy_enabled[1] += kBigOriginalLength; |
833 received_with_data_reduction_proxy_enabled[1] += kBigReceivedLength; | 840 received_with_data_reduction_proxy_enabled[1] += kBigReceivedLength; |
834 original_via_data_reduction_proxy[1] += kBigOriginalLength; | 841 original_via_data_reduction_proxy[1] += kBigOriginalLength; |
835 received_via_data_reduction_proxy[1] += kBigReceivedLength; | 842 received_via_data_reduction_proxy[1] += kBigReceivedLength; |
836 VerifyDailyDataSavingContentLengthPrefLists( | 843 VerifyDailyDataSavingContentLengthPrefLists( |
837 original, 2, received, 2, original_with_data_reduction_proxy_enabled, 2, | 844 original, 2, received, 2, original_with_data_reduction_proxy_enabled, 2, |
838 received_with_data_reduction_proxy_enabled, 2, | 845 received_with_data_reduction_proxy_enabled, 2, |
839 original_via_data_reduction_proxy, 2, received_via_data_reduction_proxy, | 846 original_via_data_reduction_proxy, 2, received_via_data_reduction_proxy, |
840 2); | 847 2); |
841 } | 848 } |
842 | 849 |
843 TEST_F(DataReductionProxyCompressionStatsTest, PartialDayTimeChange) { | 850 TEST_F(DataReductionProxyCompressionStatsTest, PartialDayTimeChange) { |
844 const int64 kOriginalLength = 200; | 851 const int64_t kOriginalLength = 200; |
845 const int64 kReceivedLength = 100; | 852 const int64_t kReceivedLength = 100; |
846 int64 original[] = {0, kOriginalLength}; | 853 int64_t original[] = {0, kOriginalLength}; |
847 int64 received[] = {0, kReceivedLength}; | 854 int64_t received[] = {0, kReceivedLength}; |
848 | 855 |
849 RecordContentLengthPrefs( | 856 RecordContentLengthPrefs( |
850 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, | 857 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, |
851 FakeNow()); | 858 FakeNow()); |
852 VerifyDailyDataSavingContentLengthPrefLists( | 859 VerifyDailyDataSavingContentLengthPrefLists( |
853 original, 2, received, 2, | 860 original, 2, received, 2, |
854 original, 2, received, 2, | 861 original, 2, received, 2, |
855 original, 2, received, 2); | 862 original, 2, received, 2); |
856 | 863 |
857 // Forward 10 hours, stay in the same day. | 864 // Forward 10 hours, stay in the same day. |
858 // See kLastUpdateTime: "Now" in test is 03:45am. | 865 // See kLastUpdateTime: "Now" in test is 03:45am. |
859 SetFakeTimeDeltaInHours(10); | 866 SetFakeTimeDeltaInHours(10); |
860 RecordContentLengthPrefs( | 867 RecordContentLengthPrefs( |
861 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, | 868 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, |
862 FakeNow()); | 869 FakeNow()); |
863 original[1] += kOriginalLength; | 870 original[1] += kOriginalLength; |
864 received[1] += kReceivedLength; | 871 received[1] += kReceivedLength; |
865 VerifyDailyDataSavingContentLengthPrefLists( | 872 VerifyDailyDataSavingContentLengthPrefLists( |
866 original, 2, received, 2, | 873 original, 2, received, 2, |
867 original, 2, received, 2, | 874 original, 2, received, 2, |
868 original, 2, received, 2); | 875 original, 2, received, 2); |
869 | 876 |
870 // Forward 11 more hours, comes to tomorrow. | 877 // Forward 11 more hours, comes to tomorrow. |
871 AddFakeTimeDeltaInHours(11); | 878 AddFakeTimeDeltaInHours(11); |
872 RecordContentLengthPrefs( | 879 RecordContentLengthPrefs( |
873 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, | 880 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, |
874 FakeNow()); | 881 FakeNow()); |
875 int64 original2[] = {kOriginalLength * 2, kOriginalLength}; | 882 int64_t original2[] = {kOriginalLength * 2, kOriginalLength}; |
876 int64 received2[] = {kReceivedLength * 2, kReceivedLength}; | 883 int64_t received2[] = {kReceivedLength * 2, kReceivedLength}; |
877 VerifyDailyDataSavingContentLengthPrefLists( | 884 VerifyDailyDataSavingContentLengthPrefLists( |
878 original2, 2, received2, 2, | 885 original2, 2, received2, 2, |
879 original2, 2, received2, 2, | 886 original2, 2, received2, 2, |
880 original2, 2, received2, 2); | 887 original2, 2, received2, 2); |
881 } | 888 } |
882 | 889 |
883 TEST_F(DataReductionProxyCompressionStatsTest, ForwardMultipleDays) { | 890 TEST_F(DataReductionProxyCompressionStatsTest, ForwardMultipleDays) { |
884 const int64 kOriginalLength = 200; | 891 const int64_t kOriginalLength = 200; |
885 const int64 kReceivedLength = 100; | 892 const int64_t kReceivedLength = 100; |
886 RecordContentLengthPrefs( | 893 RecordContentLengthPrefs( |
887 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, | 894 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, |
888 FakeNow()); | 895 FakeNow()); |
889 | 896 |
890 // Forward three days. | 897 // Forward three days. |
891 SetFakeTimeDeltaInHours(3 * 24); | 898 SetFakeTimeDeltaInHours(3 * 24); |
892 | 899 |
893 RecordContentLengthPrefs( | 900 RecordContentLengthPrefs( |
894 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, | 901 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, |
895 FakeNow()); | 902 FakeNow()); |
896 | 903 |
897 int64 original[] = {kOriginalLength, 0, 0, kOriginalLength}; | 904 int64_t original[] = {kOriginalLength, 0, 0, kOriginalLength}; |
898 int64 received[] = {kReceivedLength, 0, 0, kReceivedLength}; | 905 int64_t received[] = {kReceivedLength, 0, 0, kReceivedLength}; |
899 VerifyDailyDataSavingContentLengthPrefLists( | 906 VerifyDailyDataSavingContentLengthPrefLists( |
900 original, 4, received, 4, | 907 original, 4, received, 4, |
901 original, 4, received, 4, | 908 original, 4, received, 4, |
902 original, 4, received, 4); | 909 original, 4, received, 4); |
903 | 910 |
904 // Forward four more days. | 911 // Forward four more days. |
905 AddFakeTimeDeltaInHours(4 * 24); | 912 AddFakeTimeDeltaInHours(4 * 24); |
906 RecordContentLengthPrefs( | 913 RecordContentLengthPrefs( |
907 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, | 914 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, |
908 FakeNow()); | 915 FakeNow()); |
909 int64 original2[] = { | 916 int64_t original2[] = { |
910 kOriginalLength, 0, 0, kOriginalLength, 0, 0, 0, kOriginalLength, | 917 kOriginalLength, 0, 0, kOriginalLength, 0, 0, 0, kOriginalLength, |
911 }; | 918 }; |
912 int64 received2[] = { | 919 int64_t received2[] = { |
913 kReceivedLength, 0, 0, kReceivedLength, 0, 0, 0, kReceivedLength, | 920 kReceivedLength, 0, 0, kReceivedLength, 0, 0, 0, kReceivedLength, |
914 }; | 921 }; |
915 VerifyDailyDataSavingContentLengthPrefLists( | 922 VerifyDailyDataSavingContentLengthPrefLists( |
916 original2, 8, received2, 8, | 923 original2, 8, received2, 8, |
917 original2, 8, received2, 8, | 924 original2, 8, received2, 8, |
918 original2, 8, received2, 8); | 925 original2, 8, received2, 8); |
919 | 926 |
920 // Forward |kNumDaysInHistory| more days. | 927 // Forward |kNumDaysInHistory| more days. |
921 AddFakeTimeDeltaInHours(kNumDaysInHistory * 24); | 928 AddFakeTimeDeltaInHours(kNumDaysInHistory * 24); |
922 RecordContentLengthPrefs( | 929 RecordContentLengthPrefs( |
923 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, | 930 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, |
924 FakeNow()); | 931 FakeNow()); |
925 int64 original3[] = {kOriginalLength}; | 932 int64_t original3[] = {kOriginalLength}; |
926 int64 received3[] = {kReceivedLength}; | 933 int64_t received3[] = {kReceivedLength}; |
927 VerifyDailyDataSavingContentLengthPrefLists( | 934 VerifyDailyDataSavingContentLengthPrefLists( |
928 original3, 1, received3, 1, | 935 original3, 1, received3, 1, |
929 original3, 1, received3, 1, | 936 original3, 1, received3, 1, |
930 original3, 1, received3, 1); | 937 original3, 1, received3, 1); |
931 | 938 |
932 // Forward |kNumDaysInHistory| + 1 more days. | 939 // Forward |kNumDaysInHistory| + 1 more days. |
933 AddFakeTimeDeltaInHours((kNumDaysInHistory + 1)* 24); | 940 AddFakeTimeDeltaInHours((kNumDaysInHistory + 1)* 24); |
934 RecordContentLengthPrefs( | 941 RecordContentLengthPrefs( |
935 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, | 942 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, |
936 FakeNow()); | 943 FakeNow()); |
937 VerifyDailyDataSavingContentLengthPrefLists( | 944 VerifyDailyDataSavingContentLengthPrefLists( |
938 original3, 1, received3, 1, | 945 original3, 1, received3, 1, |
939 original3, 1, received3, 1, | 946 original3, 1, received3, 1, |
940 original3, 1, received3, 1); | 947 original3, 1, received3, 1); |
941 } | 948 } |
942 | 949 |
943 TEST_F(DataReductionProxyCompressionStatsTest, BackwardAndForwardOneDay) { | 950 TEST_F(DataReductionProxyCompressionStatsTest, BackwardAndForwardOneDay) { |
944 const int64 kOriginalLength = 200; | 951 const int64_t kOriginalLength = 200; |
945 const int64 kReceivedLength = 100; | 952 const int64_t kReceivedLength = 100; |
946 int64 original[] = {kOriginalLength}; | 953 int64_t original[] = {kOriginalLength}; |
947 int64 received[] = {kReceivedLength}; | 954 int64_t received[] = {kReceivedLength}; |
948 | 955 |
949 RecordContentLengthPrefs( | 956 RecordContentLengthPrefs( |
950 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, | 957 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, |
951 FakeNow()); | 958 FakeNow()); |
952 | 959 |
953 // Backward one day. | 960 // Backward one day. |
954 SetFakeTimeDeltaInHours(-24); | 961 SetFakeTimeDeltaInHours(-24); |
955 RecordContentLengthPrefs( | 962 RecordContentLengthPrefs( |
956 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, | 963 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, |
957 FakeNow()); | 964 FakeNow()); |
958 original[0] += kOriginalLength; | 965 original[0] += kOriginalLength; |
959 received[0] += kReceivedLength; | 966 received[0] += kReceivedLength; |
960 VerifyDailyDataSavingContentLengthPrefLists( | 967 VerifyDailyDataSavingContentLengthPrefLists( |
961 original, 1, received, 1, | 968 original, 1, received, 1, |
962 original, 1, received, 1, | 969 original, 1, received, 1, |
963 original, 1, received, 1); | 970 original, 1, received, 1); |
964 | 971 |
965 // Then, Forward one day | 972 // Then, Forward one day |
966 AddFakeTimeDeltaInHours(24); | 973 AddFakeTimeDeltaInHours(24); |
967 RecordContentLengthPrefs( | 974 RecordContentLengthPrefs( |
968 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, | 975 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, |
969 FakeNow()); | 976 FakeNow()); |
970 int64 original2[] = {kOriginalLength * 2, kOriginalLength}; | 977 int64_t original2[] = {kOriginalLength * 2, kOriginalLength}; |
971 int64 received2[] = {kReceivedLength * 2, kReceivedLength}; | 978 int64_t received2[] = {kReceivedLength * 2, kReceivedLength}; |
972 VerifyDailyDataSavingContentLengthPrefLists( | 979 VerifyDailyDataSavingContentLengthPrefLists( |
973 original2, 2, received2, 2, | 980 original2, 2, received2, 2, |
974 original2, 2, received2, 2, | 981 original2, 2, received2, 2, |
975 original2, 2, received2, 2); | 982 original2, 2, received2, 2); |
976 } | 983 } |
977 | 984 |
978 TEST_F(DataReductionProxyCompressionStatsTest, BackwardTwoDays) { | 985 TEST_F(DataReductionProxyCompressionStatsTest, BackwardTwoDays) { |
979 const int64 kOriginalLength = 200; | 986 const int64_t kOriginalLength = 200; |
980 const int64 kReceivedLength = 100; | 987 const int64_t kReceivedLength = 100; |
981 int64 original[] = {kOriginalLength}; | 988 int64_t original[] = {kOriginalLength}; |
982 int64 received[] = {kReceivedLength}; | 989 int64_t received[] = {kReceivedLength}; |
983 | 990 |
984 RecordContentLengthPrefs( | 991 RecordContentLengthPrefs( |
985 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, | 992 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, |
986 FakeNow()); | 993 FakeNow()); |
987 // Backward two days. | 994 // Backward two days. |
988 SetFakeTimeDeltaInHours(-2 * 24); | 995 SetFakeTimeDeltaInHours(-2 * 24); |
989 RecordContentLengthPrefs( | 996 RecordContentLengthPrefs( |
990 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, | 997 kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY, |
991 FakeNow()); | 998 FakeNow()); |
992 VerifyDailyDataSavingContentLengthPrefLists( | 999 VerifyDailyDataSavingContentLengthPrefLists( |
993 original, 1, received, 1, | 1000 original, 1, received, 1, |
994 original, 1, received, 1, | 1001 original, 1, received, 1, |
995 original, 1, received, 1); | 1002 original, 1, received, 1); |
996 } | 1003 } |
997 | 1004 |
998 TEST_F(DataReductionProxyCompressionStatsTest, NormalizeHostname) { | 1005 TEST_F(DataReductionProxyCompressionStatsTest, NormalizeHostname) { |
999 EXPECT_EQ("www.foo.com", NormalizeHostname("http://www.foo.com")); | 1006 EXPECT_EQ("www.foo.com", NormalizeHostname("http://www.foo.com")); |
1000 EXPECT_EQ("foo.com", NormalizeHostname("https://foo.com")); | 1007 EXPECT_EQ("foo.com", NormalizeHostname("https://foo.com")); |
1001 EXPECT_EQ("bar.co.uk", NormalizeHostname("http://bar.co.uk")); | 1008 EXPECT_EQ("bar.co.uk", NormalizeHostname("http://bar.co.uk")); |
1002 EXPECT_EQ("http.www.co.in", NormalizeHostname("http://http.www.co.in")); | 1009 EXPECT_EQ("http.www.co.in", NormalizeHostname("http://http.www.co.in")); |
1003 } | 1010 } |
1004 | 1011 |
1005 TEST_F(DataReductionProxyCompressionStatsTest, RecordUma) { | 1012 TEST_F(DataReductionProxyCompressionStatsTest, RecordUma) { |
1006 const int64 kOriginalLength = 15000; | 1013 const int64_t kOriginalLength = 15000; |
1007 const int64 kReceivedLength = 10000; | 1014 const int64_t kReceivedLength = 10000; |
1008 base::HistogramTester tester; | 1015 base::HistogramTester tester; |
1009 | 1016 |
1010 RecordContentLengthPrefs(kReceivedLength, kOriginalLength, true, | 1017 RecordContentLengthPrefs(kReceivedLength, kOriginalLength, true, |
1011 VIA_DATA_REDUCTION_PROXY, FakeNow()); | 1018 VIA_DATA_REDUCTION_PROXY, FakeNow()); |
1012 | 1019 |
1013 // Forward one day. | 1020 // Forward one day. |
1014 SetFakeTimeDeltaInHours(24); | 1021 SetFakeTimeDeltaInHours(24); |
1015 | 1022 |
1016 // Proxy not enabled. Not via proxy. | 1023 // Proxy not enabled. Not via proxy. |
1017 RecordContentLengthPrefs(kReceivedLength, kOriginalLength, false, | 1024 RecordContentLengthPrefs(kReceivedLength, kOriginalLength, false, |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1287 expected_data_usage = | 1294 expected_data_usage = |
1288 make_scoped_ptr(new std::vector<data_reduction_proxy::DataUsageBucket>( | 1295 make_scoped_ptr(new std::vector<data_reduction_proxy::DataUsageBucket>( |
1289 kNumExpectedBuckets)); | 1296 kNumExpectedBuckets)); |
1290 DataUsageLoadVerifier verifier2(expected_data_usage.Pass()); | 1297 DataUsageLoadVerifier verifier2(expected_data_usage.Pass()); |
1291 LoadHistoricalDataUsage(base::Bind(&DataUsageLoadVerifier::OnLoadDataUsage, | 1298 LoadHistoricalDataUsage(base::Bind(&DataUsageLoadVerifier::OnLoadDataUsage, |
1292 base::Unretained(&verifier2))); | 1299 base::Unretained(&verifier2))); |
1293 base::RunLoop().RunUntilIdle(); | 1300 base::RunLoop().RunUntilIdle(); |
1294 } | 1301 } |
1295 | 1302 |
1296 } // namespace data_reduction_proxy | 1303 } // namespace data_reduction_proxy |
OLD | NEW |