OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/download/download_stats.h" |
| 6 |
| 7 #include "base/test/histogram_tester.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 namespace content { |
| 12 |
| 13 namespace { |
| 14 |
| 15 void VerfiyParallelizableAverageStats(int64_t bytes_downloaded, |
| 16 const base::TimeDelta& time_span, |
| 17 const std::string& expected_suffix) { |
| 18 base::HistogramTester histogram_tester; |
| 19 int64_t expected_bandwidth = bytes_downloaded / time_span.InSeconds(); |
| 20 |
| 21 RecordParallelizableDownloadAverageStats(bytes_downloaded, time_span); |
| 22 histogram_tester.ExpectBucketCount("Download.ParallelizableDownloadBandwidth", |
| 23 expected_bandwidth, 1); |
| 24 histogram_tester.ExpectBucketCount("Download.Parallelizable.DownloadTime", |
| 25 time_span.InMilliseconds(), 1); |
| 26 histogram_tester.ExpectBucketCount("Download.Parallelizable.FileSize", |
| 27 bytes_downloaded / 1024, 1); |
| 28 histogram_tester.ExpectBucketCount( |
| 29 "Download.ParallelizableDownloadBandwidth." + expected_suffix, |
| 30 expected_bandwidth, 1); |
| 31 histogram_tester.ExpectBucketCount( |
| 32 "Download.Parallelizable.DownloadTime." + expected_suffix, |
| 33 time_span.InMilliseconds(), 1); |
| 34 } |
| 35 |
| 36 } // namespace |
| 37 |
| 38 TEST(DownloadStatsTest, ParallelizableAverageStatsSmall) { |
| 39 // Lowest bucket of the file size suffix. |
| 40 VerfiyParallelizableAverageStats(1, base::TimeDelta::FromSeconds(1), "0.5MB"); |
| 41 VerfiyParallelizableAverageStats(1024 * 1024 * 20, |
| 42 base::TimeDelta::FromSeconds(10), "50MB"); |
| 43 // Overflow bucket of the file size suffix. |
| 44 VerfiyParallelizableAverageStats(1024 * 1024 * 1024, |
| 45 base::TimeDelta::FromSeconds(1), "GT50MB"); |
| 46 } |
| 47 |
| 48 } // namespace content |
OLD | NEW |