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
3 // found in the LICENSE file.
5 #include "base/basictypes.h"
6 #include "base/compiler_specific.h"
7 #include "base/prefs/pref_registry_simple.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/prefs/scoped_user_pref_update.h"
10 #include "base/prefs/testing_pref_service.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "components/data_reduction_proxy/browser/data_reduction_proxy_metrics.h"
13 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names.h"
14 #include "testing/gtest/include/gtest/gtest.h"
18 const size_t kNumDaysInHistory
= 60;
20 int64
GetListPrefInt64Value(
21 const base::ListValue
& list_update
, size_t index
) {
22 std::string string_value
;
23 EXPECT_TRUE(list_update
.GetString(index
, &string_value
));
26 EXPECT_TRUE(base::StringToInt64(string_value
, &value
));
32 namespace data_reduction_proxy
{
34 // Test UpdateContentLengthPrefs.
35 class ChromeNetworkDataSavingMetricsTest
: public testing::Test
{
37 ChromeNetworkDataSavingMetricsTest() {}
39 virtual void SetUp() OVERRIDE
{
40 PrefRegistrySimple
* registry
= pref_service_
.registry();
41 registry
->RegisterInt64Pref(
42 data_reduction_proxy::prefs::kHttpReceivedContentLength
, 0);
43 registry
->RegisterInt64Pref(
44 data_reduction_proxy::prefs::kHttpOriginalContentLength
, 0);
46 registry
->RegisterListPref(data_reduction_proxy::prefs::
47 kDailyHttpOriginalContentLength
);
48 registry
->RegisterListPref(data_reduction_proxy::prefs::
49 kDailyHttpReceivedContentLength
);
50 registry
->RegisterListPref(
51 data_reduction_proxy::prefs::
52 kDailyOriginalContentLengthWithDataReductionProxyEnabled
);
53 registry
->RegisterListPref(
54 data_reduction_proxy::prefs::
55 kDailyContentLengthWithDataReductionProxyEnabled
);
56 registry
->RegisterListPref(
57 data_reduction_proxy::prefs::
58 kDailyContentLengthHttpsWithDataReductionProxyEnabled
);
59 registry
->RegisterListPref(
60 data_reduction_proxy::prefs::
61 kDailyContentLengthShortBypassWithDataReductionProxyEnabled
);
62 registry
->RegisterListPref(
63 data_reduction_proxy::prefs::
64 kDailyContentLengthLongBypassWithDataReductionProxyEnabled
);
65 registry
->RegisterListPref(
66 data_reduction_proxy::prefs::
67 kDailyContentLengthUnknownWithDataReductionProxyEnabled
);
68 registry
->RegisterListPref(
69 data_reduction_proxy::prefs::
70 kDailyOriginalContentLengthViaDataReductionProxy
);
71 registry
->RegisterListPref(
72 data_reduction_proxy::prefs::
73 kDailyContentLengthViaDataReductionProxy
);
74 registry
->RegisterInt64Pref(
75 data_reduction_proxy::prefs::
76 kDailyHttpContentLengthLastUpdateDate
, 0L);
79 TestingPrefServiceSimple pref_service_
;
82 TEST_F(ChromeNetworkDataSavingMetricsTest
, TotalLengths
) {
83 const int64 kOriginalLength
= 200;
84 const int64 kReceivedLength
= 100;
86 UpdateContentLengthPrefs(
87 kReceivedLength
, kOriginalLength
,
88 false, UNKNOWN_TYPE
, &pref_service_
);
89 EXPECT_EQ(kReceivedLength
,
90 pref_service_
.GetInt64(
91 data_reduction_proxy::prefs::kHttpReceivedContentLength
));
92 EXPECT_EQ(kOriginalLength
,
93 pref_service_
.GetInt64(
94 data_reduction_proxy::prefs::kHttpOriginalContentLength
));
96 // Record the same numbers again, and total lengths should be dobuled.
97 UpdateContentLengthPrefs(
98 kReceivedLength
, kOriginalLength
,
99 false, UNKNOWN_TYPE
, &pref_service_
);
100 EXPECT_EQ(kReceivedLength
* 2,
101 pref_service_
.GetInt64(
102 data_reduction_proxy::prefs::kHttpReceivedContentLength
));
103 EXPECT_EQ(kOriginalLength
* 2,
104 pref_service_
.GetInt64(
105 data_reduction_proxy::prefs::kHttpOriginalContentLength
));
108 // The initial last update time used in test. There is no leap second a few
109 // days around this time used in the test.
110 // Note: No time zone is specified. Local time will be assumed by
111 // base::Time::FromString below.
112 const char kLastUpdateTime
[] = "Wed, 18 Sep 2013 03:45:26";
114 class ChromeNetworkDailyDataSavingMetricsTest
115 : public ChromeNetworkDataSavingMetricsTest
{
117 ChromeNetworkDailyDataSavingMetricsTest() {
118 base::Time::FromString(kLastUpdateTime
, &now_
);
121 virtual void SetUp() OVERRIDE
{
122 ChromeNetworkDataSavingMetricsTest::SetUp();
124 // Only create two lists in Setup to test that adding new lists is fine.
126 data_reduction_proxy::prefs::kDailyHttpOriginalContentLength
);
128 data_reduction_proxy::prefs::kDailyHttpReceivedContentLength
);
131 base::Time
FakeNow() const {
132 return now_
+ now_delta_
;
135 void SetFakeTimeDeltaInHours(int hours
) {
136 now_delta_
= base::TimeDelta::FromHours(hours
);
139 void AddFakeTimeDeltaInHours(int hours
) {
140 now_delta_
+= base::TimeDelta::FromHours(hours
);
143 // Create daily pref list of |kNumDaysInHistory| zero values.
144 void CreatePrefList(const char* pref
) {
145 ListPrefUpdate
update(&pref_service_
, pref
);
147 for (size_t i
= 0; i
< kNumDaysInHistory
; ++i
) {
148 update
->Insert(0, new base::StringValue(base::Int64ToString(0)));
152 // Verify the pref list values are equal to the given values.
153 // If the count of values is less than kNumDaysInHistory, zeros are assumed
155 void VerifyPrefList(const char* pref
, const int64
* values
, size_t count
) {
156 ASSERT_GE(kNumDaysInHistory
, count
);
157 ListPrefUpdate
update(&pref_service_
, pref
);
158 ASSERT_EQ(kNumDaysInHistory
, update
->GetSize()) << "Pref: " << pref
;
160 for (size_t i
= 0; i
< count
; ++i
) {
163 GetListPrefInt64Value(*update
, kNumDaysInHistory
- count
+ i
))
164 << "index=" << (kNumDaysInHistory
- count
+ i
);
166 for (size_t i
= 0; i
< kNumDaysInHistory
- count
; ++i
) {
167 EXPECT_EQ(0, GetListPrefInt64Value(*update
, i
)) << "index=" << i
;
171 // Verify all daily data saving pref list values.
172 void VerifyDailyDataSavingContentLengthPrefLists(
173 const int64
* original_values
, size_t original_count
,
174 const int64
* received_values
, size_t received_count
,
175 const int64
* original_with_data_reduction_proxy_enabled_values
,
176 size_t original_with_data_reduction_proxy_enabled_count
,
177 const int64
* received_with_data_reduction_proxy_enabled_values
,
178 size_t received_with_data_reduction_proxy_count
,
179 const int64
* original_via_data_reduction_proxy_values
,
180 size_t original_via_data_reduction_proxy_count
,
181 const int64
* received_via_data_reduction_proxy_values
,
182 size_t received_via_data_reduction_proxy_count
) {
183 VerifyPrefList(data_reduction_proxy::prefs::kDailyHttpOriginalContentLength
,
184 original_values
, original_count
);
185 VerifyPrefList(data_reduction_proxy::prefs::kDailyHttpReceivedContentLength
,
186 received_values
, received_count
);
188 data_reduction_proxy::prefs::
189 kDailyOriginalContentLengthWithDataReductionProxyEnabled
,
190 original_with_data_reduction_proxy_enabled_values
,
191 original_with_data_reduction_proxy_enabled_count
);
193 data_reduction_proxy::prefs::
194 kDailyContentLengthWithDataReductionProxyEnabled
,
195 received_with_data_reduction_proxy_enabled_values
,
196 received_with_data_reduction_proxy_count
);
198 data_reduction_proxy::prefs::
199 kDailyOriginalContentLengthViaDataReductionProxy
,
200 original_via_data_reduction_proxy_values
,
201 original_via_data_reduction_proxy_count
);
203 data_reduction_proxy::prefs::
204 kDailyContentLengthViaDataReductionProxy
,
205 received_via_data_reduction_proxy_values
,
206 received_via_data_reduction_proxy_count
);
209 // Verify daily data saving pref for request types.
210 void VerifyDailyRequestTypeContentLengthPrefLists(
211 const int64
* original_values
, size_t original_count
,
212 const int64
* received_values
, size_t received_count
,
213 const int64
* original_with_data_reduction_proxy_enabled_values
,
214 size_t original_with_data_reduction_proxy_enabled_count
,
215 const int64
* received_with_data_reduction_proxy_enabled_values
,
216 size_t received_with_data_reduction_proxy_count
,
217 const int64
* https_with_data_reduction_proxy_enabled_values
,
218 size_t https_with_data_reduction_proxy_enabled_count
,
219 const int64
* short_bypass_with_data_reduction_proxy_enabled_values
,
220 size_t short_bypass_with_data_reduction_proxy_enabled_count
,
221 const int64
* long_bypass_with_data_reduction_proxy_enabled_values
,
222 size_t long_bypass_with_data_reduction_proxy_enabled_count
,
223 const int64
* unknown_with_data_reduction_proxy_enabled_values
,
224 size_t unknown_with_data_reduction_proxy_enabled_count
) {
225 VerifyPrefList(data_reduction_proxy::prefs::kDailyHttpOriginalContentLength
,
226 original_values
, original_count
);
227 VerifyPrefList(data_reduction_proxy::prefs::kDailyHttpReceivedContentLength
,
228 received_values
, received_count
);
230 data_reduction_proxy::prefs::
231 kDailyOriginalContentLengthWithDataReductionProxyEnabled
,
232 original_with_data_reduction_proxy_enabled_values
,
233 original_with_data_reduction_proxy_enabled_count
);
235 data_reduction_proxy::prefs::
236 kDailyContentLengthWithDataReductionProxyEnabled
,
237 received_with_data_reduction_proxy_enabled_values
,
238 received_with_data_reduction_proxy_count
);
240 data_reduction_proxy::prefs::
241 kDailyContentLengthHttpsWithDataReductionProxyEnabled
,
242 https_with_data_reduction_proxy_enabled_values
,
243 https_with_data_reduction_proxy_enabled_count
);
245 data_reduction_proxy::prefs::
246 kDailyContentLengthShortBypassWithDataReductionProxyEnabled
,
247 short_bypass_with_data_reduction_proxy_enabled_values
,
248 short_bypass_with_data_reduction_proxy_enabled_count
);
250 data_reduction_proxy::prefs::
251 kDailyContentLengthLongBypassWithDataReductionProxyEnabled
,
252 long_bypass_with_data_reduction_proxy_enabled_values
,
253 long_bypass_with_data_reduction_proxy_enabled_count
);
255 data_reduction_proxy::prefs::
256 kDailyContentLengthUnknownWithDataReductionProxyEnabled
,
257 unknown_with_data_reduction_proxy_enabled_values
,
258 unknown_with_data_reduction_proxy_enabled_count
);
263 base::TimeDelta now_delta_
;
266 TEST_F(ChromeNetworkDailyDataSavingMetricsTest
, OneResponse
) {
267 const int64 kOriginalLength
= 200;
268 const int64 kReceivedLength
= 100;
269 int64 original
[] = {kOriginalLength
};
270 int64 received
[] = {kReceivedLength
};
272 UpdateContentLengthPrefsForDataReductionProxy(
273 kReceivedLength
, kOriginalLength
,
274 true, VIA_DATA_REDUCTION_PROXY
,
275 FakeNow(), &pref_service_
);
276 VerifyDailyDataSavingContentLengthPrefLists(
277 original
, 1, received
, 1,
278 original
, 1, received
, 1,
279 original
, 1, received
, 1);
282 TEST_F(ChromeNetworkDailyDataSavingMetricsTest
, MultipleResponses
) {
283 const int64 kOriginalLength
= 150;
284 const int64 kReceivedLength
= 100;
285 int64 original
[] = {kOriginalLength
};
286 int64 received
[] = {kReceivedLength
};
287 UpdateContentLengthPrefsForDataReductionProxy(
288 kReceivedLength
, kOriginalLength
,
290 FakeNow(), &pref_service_
);
291 VerifyDailyDataSavingContentLengthPrefLists(
292 original
, 1, received
, 1,
293 NULL
, 0, NULL
, 0, NULL
, 0, NULL
, 0);
295 UpdateContentLengthPrefsForDataReductionProxy(
296 kReceivedLength
, kOriginalLength
,
298 FakeNow(), &pref_service_
);
299 original
[0] += kOriginalLength
;
300 received
[0] += kReceivedLength
;
301 int64 original_proxy_enabled
[] = {kOriginalLength
};
302 int64 received_proxy_enabled
[] = {kReceivedLength
};
303 VerifyDailyDataSavingContentLengthPrefLists(
304 original
, 1, received
, 1,
305 original_proxy_enabled
, 1, received_proxy_enabled
, 1,
308 UpdateContentLengthPrefsForDataReductionProxy(
309 kReceivedLength
, kOriginalLength
,
310 true, VIA_DATA_REDUCTION_PROXY
,
311 FakeNow(), &pref_service_
);
312 original
[0] += kOriginalLength
;
313 received
[0] += kReceivedLength
;
314 original_proxy_enabled
[0] += kOriginalLength
;
315 received_proxy_enabled
[0] += kReceivedLength
;
316 int64 original_via_proxy
[] = {kOriginalLength
};
317 int64 received_via_proxy
[] = {kReceivedLength
};
318 VerifyDailyDataSavingContentLengthPrefLists(
319 original
, 1, received
, 1,
320 original_proxy_enabled
, 1, received_proxy_enabled
, 1,
321 original_via_proxy
, 1, received_via_proxy
, 1);
323 UpdateContentLengthPrefsForDataReductionProxy(
324 kReceivedLength
, kOriginalLength
,
325 true, UNKNOWN_TYPE
, FakeNow(), &pref_service_
);
326 original
[0] += kOriginalLength
;
327 received
[0] += kReceivedLength
;
328 original_proxy_enabled
[0] += kOriginalLength
;
329 received_proxy_enabled
[0] += kReceivedLength
;
330 VerifyDailyDataSavingContentLengthPrefLists(
331 original
, 1, received
, 1,
332 original_proxy_enabled
, 1, received_proxy_enabled
, 1,
333 original_via_proxy
, 1, received_via_proxy
, 1);
335 UpdateContentLengthPrefsForDataReductionProxy(
336 kReceivedLength
, kOriginalLength
,
337 false, UNKNOWN_TYPE
, FakeNow(), &pref_service_
);
338 original
[0] += kOriginalLength
;
339 received
[0] += kReceivedLength
;
340 VerifyDailyDataSavingContentLengthPrefLists(
341 original
, 1, received
, 1,
342 original_proxy_enabled
, 1, received_proxy_enabled
, 1,
343 original_via_proxy
, 1, received_via_proxy
, 1);
346 TEST_F(ChromeNetworkDailyDataSavingMetricsTest
, RequestType
) {
347 const int64 kContentLength
= 200;
348 int64 received
[] = {0};
349 int64 https_received
[] = {0};
350 int64 total_received
[] = {0};
351 int64 proxy_enabled_received
[] = {0};
353 UpdateContentLengthPrefsForDataReductionProxy(
354 kContentLength
, kContentLength
,
356 FakeNow(), &pref_service_
);
357 total_received
[0] += kContentLength
;
358 proxy_enabled_received
[0] += kContentLength
;
359 https_received
[0] += kContentLength
;
360 VerifyDailyRequestTypeContentLengthPrefLists(
361 total_received
, 1, total_received
, 1,
362 proxy_enabled_received
, 1, proxy_enabled_received
, 1,
364 received
, 0, // short bypass
365 received
, 0, // long bypass
366 received
, 0); // unknown
368 // Data reduction proxy is not enabled.
369 UpdateContentLengthPrefsForDataReductionProxy(
370 kContentLength
, kContentLength
,
372 FakeNow(), &pref_service_
);
373 total_received
[0] += kContentLength
;
374 VerifyDailyRequestTypeContentLengthPrefLists(
375 total_received
, 1, total_received
, 1,
376 proxy_enabled_received
, 1, proxy_enabled_received
, 1,
378 received
, 0, // short bypass
379 received
, 0, // long bypass
380 received
, 0); // unknown
382 UpdateContentLengthPrefsForDataReductionProxy(
383 kContentLength
, kContentLength
,
385 FakeNow(), &pref_service_
);
386 total_received
[0] += kContentLength
;
387 proxy_enabled_received
[0] += kContentLength
;
388 https_received
[0] += kContentLength
;
389 VerifyDailyRequestTypeContentLengthPrefLists(
390 total_received
, 1, total_received
, 1,
391 proxy_enabled_received
, 1, proxy_enabled_received
, 1,
393 received
, 0, // short bypass
394 received
, 0, // long bypass
395 received
, 0); // unknown
397 UpdateContentLengthPrefsForDataReductionProxy(
398 kContentLength
, kContentLength
,
400 FakeNow(), &pref_service_
);
401 total_received
[0] += kContentLength
;
402 proxy_enabled_received
[0] += kContentLength
;
403 received
[0] += kContentLength
;
404 VerifyDailyRequestTypeContentLengthPrefLists(
405 total_received
, 1, total_received
, 1,
406 proxy_enabled_received
, 1, proxy_enabled_received
, 1,
408 received
, 1, // short bypass
409 received
, 0, // long bypass
410 received
, 0); // unknown
412 UpdateContentLengthPrefsForDataReductionProxy(
413 kContentLength
, kContentLength
,
415 FakeNow(), &pref_service_
);
416 total_received
[0] += kContentLength
;
417 proxy_enabled_received
[0] += kContentLength
;
418 VerifyDailyRequestTypeContentLengthPrefLists(
419 total_received
, 1, total_received
, 1, // total
420 proxy_enabled_received
, 1, proxy_enabled_received
, 1,
422 received
, 1, // short bypass
423 received
, 1, // long bypass
424 received
, 0); // unknown
426 UpdateContentLengthPrefsForDataReductionProxy(
427 kContentLength
, kContentLength
,
429 FakeNow(), &pref_service_
);
430 total_received
[0] += kContentLength
;
431 proxy_enabled_received
[0] += kContentLength
;
432 VerifyDailyRequestTypeContentLengthPrefLists(
433 total_received
, 1, total_received
, 1,
434 proxy_enabled_received
, 1, proxy_enabled_received
, 1,
436 received
, 1, // short bypass
437 received
, 1, // long bypass
438 received
, 1); // unknown
441 TEST_F(ChromeNetworkDailyDataSavingMetricsTest
, ForwardOneDay
) {
442 const int64 kOriginalLength
= 200;
443 const int64 kReceivedLength
= 100;
445 UpdateContentLengthPrefsForDataReductionProxy(
446 kReceivedLength
, kOriginalLength
,
447 true, VIA_DATA_REDUCTION_PROXY
,
448 FakeNow(), &pref_service_
);
451 SetFakeTimeDeltaInHours(24);
453 // Proxy not enabled. Not via proxy.
454 UpdateContentLengthPrefsForDataReductionProxy(
455 kReceivedLength
, kOriginalLength
,
456 false, UNKNOWN_TYPE
, FakeNow(), &pref_service_
);
458 int64 original
[] = {kOriginalLength
, kOriginalLength
};
459 int64 received
[] = {kReceivedLength
, kReceivedLength
};
460 int64 original_with_data_reduction_proxy_enabled
[] = {kOriginalLength
, 0};
461 int64 received_with_data_reduction_proxy_enabled
[] = {kReceivedLength
, 0};
462 int64 original_via_data_reduction_proxy
[] = {kOriginalLength
, 0};
463 int64 received_via_data_reduction_proxy
[] = {kReceivedLength
, 0};
464 VerifyDailyDataSavingContentLengthPrefLists(
467 original_with_data_reduction_proxy_enabled
, 2,
468 received_with_data_reduction_proxy_enabled
, 2,
469 original_via_data_reduction_proxy
, 2,
470 received_via_data_reduction_proxy
, 2);
472 // Proxy enabled. Not via proxy.
473 UpdateContentLengthPrefsForDataReductionProxy(
474 kReceivedLength
, kOriginalLength
,
475 true, UNKNOWN_TYPE
, FakeNow(), &pref_service_
);
476 original
[1] += kOriginalLength
;
477 received
[1] += kReceivedLength
;
478 original_with_data_reduction_proxy_enabled
[1] += kOriginalLength
;
479 received_with_data_reduction_proxy_enabled
[1] += kReceivedLength
;
480 VerifyDailyDataSavingContentLengthPrefLists(
483 original_with_data_reduction_proxy_enabled
, 2,
484 received_with_data_reduction_proxy_enabled
, 2,
485 original_via_data_reduction_proxy
, 2,
486 received_via_data_reduction_proxy
, 2);
488 // Proxy enabled and via proxy.
489 UpdateContentLengthPrefsForDataReductionProxy(
490 kReceivedLength
, kOriginalLength
,
491 true, VIA_DATA_REDUCTION_PROXY
,
492 FakeNow(), &pref_service_
);
493 original
[1] += kOriginalLength
;
494 received
[1] += kReceivedLength
;
495 original_with_data_reduction_proxy_enabled
[1] += kOriginalLength
;
496 received_with_data_reduction_proxy_enabled
[1] += kReceivedLength
;
497 original_via_data_reduction_proxy
[1] += kOriginalLength
;
498 received_via_data_reduction_proxy
[1] += kReceivedLength
;
499 VerifyDailyDataSavingContentLengthPrefLists(
502 original_with_data_reduction_proxy_enabled
, 2,
503 received_with_data_reduction_proxy_enabled
, 2,
504 original_via_data_reduction_proxy
, 2,
505 received_via_data_reduction_proxy
, 2);
508 TEST_F(ChromeNetworkDailyDataSavingMetricsTest
, PartialDayTimeChange
) {
509 const int64 kOriginalLength
= 200;
510 const int64 kReceivedLength
= 100;
511 int64 original
[] = {0, kOriginalLength
};
512 int64 received
[] = {0, kReceivedLength
};
514 UpdateContentLengthPrefsForDataReductionProxy(
515 kReceivedLength
, kOriginalLength
,
516 true, VIA_DATA_REDUCTION_PROXY
,
517 FakeNow(), &pref_service_
);
518 VerifyDailyDataSavingContentLengthPrefLists(
519 original
, 2, received
, 2,
520 original
, 2, received
, 2,
521 original
, 2, received
, 2);
523 // Forward 10 hours, stay in the same day.
524 // See kLastUpdateTime: "Now" in test is 03:45am.
525 SetFakeTimeDeltaInHours(10);
526 UpdateContentLengthPrefsForDataReductionProxy(
527 kReceivedLength
, kOriginalLength
,
528 true, VIA_DATA_REDUCTION_PROXY
,
529 FakeNow(), &pref_service_
);
530 original
[1] += kOriginalLength
;
531 received
[1] += kReceivedLength
;
532 VerifyDailyDataSavingContentLengthPrefLists(
533 original
, 2, received
, 2,
534 original
, 2, received
, 2,
535 original
, 2, received
, 2);
537 // Forward 11 more hours, comes to tomorrow.
538 AddFakeTimeDeltaInHours(11);
539 UpdateContentLengthPrefsForDataReductionProxy(
540 kReceivedLength
, kOriginalLength
,
541 true, VIA_DATA_REDUCTION_PROXY
,
542 FakeNow(), &pref_service_
);
543 int64 original2
[] = {kOriginalLength
* 2, kOriginalLength
};
544 int64 received2
[] = {kReceivedLength
* 2, kReceivedLength
};
545 VerifyDailyDataSavingContentLengthPrefLists(
546 original2
, 2, received2
, 2,
547 original2
, 2, received2
, 2,
548 original2
, 2, received2
, 2);
551 TEST_F(ChromeNetworkDailyDataSavingMetricsTest
, ForwardMultipleDays
) {
552 const int64 kOriginalLength
= 200;
553 const int64 kReceivedLength
= 100;
554 UpdateContentLengthPrefsForDataReductionProxy(
555 kReceivedLength
, kOriginalLength
,
556 true, VIA_DATA_REDUCTION_PROXY
,
557 FakeNow(), &pref_service_
);
559 // Forward three days.
560 SetFakeTimeDeltaInHours(3 * 24);
562 UpdateContentLengthPrefsForDataReductionProxy(
563 kReceivedLength
, kOriginalLength
,
564 true, VIA_DATA_REDUCTION_PROXY
,
565 FakeNow(), &pref_service_
);
567 int64 original
[] = {kOriginalLength
, 0, 0, kOriginalLength
};
568 int64 received
[] = {kReceivedLength
, 0, 0, kReceivedLength
};
569 VerifyDailyDataSavingContentLengthPrefLists(
570 original
, 4, received
, 4,
571 original
, 4, received
, 4,
572 original
, 4, received
, 4);
574 // Forward four more days.
575 AddFakeTimeDeltaInHours(4 * 24);
576 UpdateContentLengthPrefsForDataReductionProxy(
577 kReceivedLength
, kOriginalLength
,
578 true, VIA_DATA_REDUCTION_PROXY
,
579 FakeNow(), &pref_service_
);
580 int64 original2
[] = {
581 kOriginalLength
, 0, 0, kOriginalLength
, 0, 0, 0, kOriginalLength
,
583 int64 received2
[] = {
584 kReceivedLength
, 0, 0, kReceivedLength
, 0, 0, 0, kReceivedLength
,
586 VerifyDailyDataSavingContentLengthPrefLists(
587 original2
, 8, received2
, 8,
588 original2
, 8, received2
, 8,
589 original2
, 8, received2
, 8);
591 // Forward |kNumDaysInHistory| more days.
592 AddFakeTimeDeltaInHours(kNumDaysInHistory
* 24);
593 UpdateContentLengthPrefsForDataReductionProxy(
594 kReceivedLength
, kOriginalLength
,
595 true, VIA_DATA_REDUCTION_PROXY
,
596 FakeNow(), &pref_service_
);
597 int64 original3
[] = {kOriginalLength
};
598 int64 received3
[] = {kReceivedLength
};
599 VerifyDailyDataSavingContentLengthPrefLists(
600 original3
, 1, received3
, 1,
601 original3
, 1, received3
, 1,
602 original3
, 1, received3
, 1);
604 // Forward |kNumDaysInHistory| + 1 more days.
605 AddFakeTimeDeltaInHours((kNumDaysInHistory
+ 1)* 24);
606 UpdateContentLengthPrefsForDataReductionProxy(
607 kReceivedLength
, kOriginalLength
,
608 true, VIA_DATA_REDUCTION_PROXY
,
609 FakeNow(), &pref_service_
);
610 VerifyDailyDataSavingContentLengthPrefLists(
611 original3
, 1, received3
, 1,
612 original3
, 1, received3
, 1,
613 original3
, 1, received3
, 1);
616 TEST_F(ChromeNetworkDailyDataSavingMetricsTest
, BackwardAndForwardOneDay
) {
617 const int64 kOriginalLength
= 200;
618 const int64 kReceivedLength
= 100;
619 int64 original
[] = {kOriginalLength
};
620 int64 received
[] = {kReceivedLength
};
622 UpdateContentLengthPrefsForDataReductionProxy(
623 kReceivedLength
, kOriginalLength
,
624 true, VIA_DATA_REDUCTION_PROXY
,
625 FakeNow(), &pref_service_
);
628 SetFakeTimeDeltaInHours(-24);
629 UpdateContentLengthPrefsForDataReductionProxy(
630 kReceivedLength
, kOriginalLength
,
631 true, VIA_DATA_REDUCTION_PROXY
,
632 FakeNow(), &pref_service_
);
633 original
[0] += kOriginalLength
;
634 received
[0] += kReceivedLength
;
635 VerifyDailyDataSavingContentLengthPrefLists(
636 original
, 1, received
, 1,
637 original
, 1, received
, 1,
638 original
, 1, received
, 1);
640 // Then, Forward one day
641 AddFakeTimeDeltaInHours(24);
642 UpdateContentLengthPrefsForDataReductionProxy(
643 kReceivedLength
, kOriginalLength
,
644 true, VIA_DATA_REDUCTION_PROXY
,
645 FakeNow(), &pref_service_
);
646 int64 original2
[] = {kOriginalLength
* 2, kOriginalLength
};
647 int64 received2
[] = {kReceivedLength
* 2, kReceivedLength
};
648 VerifyDailyDataSavingContentLengthPrefLists(
649 original2
, 2, received2
, 2,
650 original2
, 2, received2
, 2,
651 original2
, 2, received2
, 2);
654 TEST_F(ChromeNetworkDailyDataSavingMetricsTest
, BackwardTwoDays
) {
655 const int64 kOriginalLength
= 200;
656 const int64 kReceivedLength
= 100;
657 int64 original
[] = {kOriginalLength
};
658 int64 received
[] = {kReceivedLength
};
660 UpdateContentLengthPrefsForDataReductionProxy(
661 kReceivedLength
, kOriginalLength
,
662 true, VIA_DATA_REDUCTION_PROXY
,
663 FakeNow(), &pref_service_
);
664 // Backward two days.
665 SetFakeTimeDeltaInHours(-2 * 24);
666 UpdateContentLengthPrefsForDataReductionProxy(
667 kReceivedLength
, kOriginalLength
,
668 true, VIA_DATA_REDUCTION_PROXY
,
669 FakeNow(), &pref_service_
);
670 VerifyDailyDataSavingContentLengthPrefLists(
671 original
, 1, received
, 1,
672 original
, 1, received
, 1,
673 original
, 1, received
, 1);
676 } // namespace data_reduction_proxy