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

Unified Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats_unittest.cc

Issue 1286643002: Fix UMA to track video data usage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Init prefs in compression stats map Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats_unittest.cc
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats_unittest.cc
index f69a5fc44704d459d03f727759a03749beb101db..42f93fb5c84f0bc9b405bdd219d52446c9d457c5 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats_unittest.cc
@@ -11,6 +11,7 @@
#include "base/prefs/pref_service.h"
#include "base/prefs/testing_pref_service.h"
#include "base/strings/string_number_conversions.h"
+#include "base/test/histogram_tester.h"
#include "base/test/test_simple_task_runner.h"
#include "base/time/time.h"
#include "base/values.h"
@@ -168,16 +169,20 @@ class DataReductionProxyCompressionStatsTest : public testing::Test {
ASSERT_EQ(kNumDaysInHistory, update->GetSize()) << "Pref: " << pref;
for (size_t i = 0; i < count; ++i) {
- EXPECT_EQ(
- values[i],
- GetListPrefInt64Value(*update, kNumDaysInHistory - count + i))
- << "index=" << (kNumDaysInHistory - count + i);
+ EXPECT_EQ(values[i],
+ GetListPrefInt64Value(*update, kNumDaysInHistory - count + i))
+ << pref << "; index=" << (kNumDaysInHistory - count + i);
}
for (size_t i = 0; i < kNumDaysInHistory - count; ++i) {
EXPECT_EQ(0, GetListPrefInt64Value(*update, i)) << "index=" << i;
}
}
+ // Verify that the pref value is equal to given value.
+ void VerifyPrefInt64(const char* pref, const int64 value) {
+ EXPECT_EQ(value, compression_stats_->GetInt64(pref));
+ }
+
// Verify all daily data saving pref list values.
void VerifyDailyDataSavingContentLengthPrefLists(
const int64* original_values, size_t original_count,
@@ -214,6 +219,42 @@ class DataReductionProxyCompressionStatsTest : public testing::Test {
kDailyContentLengthViaDataReductionProxy,
received_via_data_reduction_proxy_values,
received_via_data_reduction_proxy_count);
+
+ VerifyPrefInt64(
+ data_reduction_proxy::prefs::kDailyHttpOriginalContentLengthApplication,
+ original_values ? original_values[original_count - 1] : 0);
+ VerifyPrefInt64(
+ data_reduction_proxy::prefs::kDailyHttpReceivedContentLengthApplication,
+ received_values ? received_values[received_count - 1] : 0);
+
+ VerifyPrefInt64(
+ data_reduction_proxy::prefs::
+ kDailyOriginalContentLengthWithDataReductionProxyEnabledApplication,
+ original_with_data_reduction_proxy_enabled_values
+ ? original_with_data_reduction_proxy_enabled_values
+ [original_with_data_reduction_proxy_enabled_count - 1]
+ : 0);
+ VerifyPrefInt64(
+ data_reduction_proxy::prefs::
+ kDailyContentLengthWithDataReductionProxyEnabledApplication,
+ received_with_data_reduction_proxy_enabled_values
+ ? received_with_data_reduction_proxy_enabled_values
+ [received_with_data_reduction_proxy_count - 1]
+ : 0);
+
+ VerifyPrefInt64(
+ data_reduction_proxy::prefs::
+ kDailyOriginalContentLengthViaDataReductionProxyApplication,
+ original_via_data_reduction_proxy_values
+ ? original_via_data_reduction_proxy_values
+ [original_via_data_reduction_proxy_count - 1]
+ : 0);
+ VerifyPrefInt64(data_reduction_proxy::prefs::
+ kDailyContentLengthViaDataReductionProxyApplication,
+ received_via_data_reduction_proxy_values
+ ? received_via_data_reduction_proxy_values
+ [received_via_data_reduction_proxy_count - 1]
+ : 0);
}
// Verify daily data saving pref for request types.
@@ -284,10 +325,21 @@ class DataReductionProxyCompressionStatsTest : public testing::Test {
int64 original_content_length,
bool with_data_reduction_proxy_enabled,
DataReductionProxyRequestType request_type,
+ const std::string& mime_type,
base::Time now) {
compression_stats_->RecordRequestSizePrefs(
received_content_length, original_content_length,
- with_data_reduction_proxy_enabled, request_type, std::string(), now);
+ with_data_reduction_proxy_enabled, request_type, mime_type, now);
+ }
+
+ void RecordContentLengthPrefs(int64 received_content_length,
+ int64 original_content_length,
+ bool with_data_reduction_proxy_enabled,
+ DataReductionProxyRequestType request_type,
+ base::Time now) {
+ RecordContentLengthPrefs(received_content_length, original_content_length,
+ with_data_reduction_proxy_enabled, request_type,
+ "application/octet-stream", now);
}
DataReductionProxyCompressionStats* compression_stats() {
@@ -471,6 +523,7 @@ TEST_F(DataReductionProxyCompressionStatsTest, OneResponse) {
RecordContentLengthPrefs(
kReceivedLength, kOriginalLength, true, VIA_DATA_REDUCTION_PROXY,
FakeNow());
+
VerifyDailyDataSavingContentLengthPrefLists(
original, 1, received, 1,
original, 1, received, 1,
@@ -859,4 +912,61 @@ TEST_F(DataReductionProxyCompressionStatsTest, NormalizeHostname) {
EXPECT_EQ("http.www.co.in", NormalizeHostname("http://http.www.co.in"));
}
+TEST_F(DataReductionProxyCompressionStatsTest, RecordUma) {
+ const int64 kOriginalLength = 15000;
+ const int64 kReceivedLength = 10000;
+ base::HistogramTester tester;
+
+ RecordContentLengthPrefs(kReceivedLength, kOriginalLength, true,
+ VIA_DATA_REDUCTION_PROXY, FakeNow());
+
+ // Forward one day.
+ SetFakeTimeDeltaInHours(24);
+
+ // Proxy not enabled. Not via proxy.
+ RecordContentLengthPrefs(kReceivedLength, kOriginalLength, false,
+ UNKNOWN_TYPE, FakeNow());
+
+ // 15000 falls into the 12 KB bucket
+ tester.ExpectUniqueSample("Net.DailyOriginalContentLength", 12, 1);
+ tester.ExpectUniqueSample("Net.DailyOriginalContentLength_Application", 12,
+ 1);
+ tester.ExpectUniqueSample(
+ "Net.DailyOriginalContentLength_DataReductionProxyEnabled", 12, 1);
+ tester.ExpectUniqueSample(
+ "Net.DailyOriginalContentLength_DataReductionProxyEnabled_Application",
+ 12, 1);
+ tester.ExpectUniqueSample(
+ "Net.DailyOriginalContentLength_ViaDataReductionProxy", 12, 1);
+ tester.ExpectUniqueSample(
+ "Net.DailyOriginalContentLength_ViaDataReductionProxy_Application", 12,
+ 1);
+
+ // 10000 falls into the 9 KB bucket
+ tester.ExpectUniqueSample("Net.DailyContentLength", 9, 1);
+ tester.ExpectUniqueSample("Net.DailyReceivedContentLength_Application", 9, 1);
+ tester.ExpectUniqueSample("Net.DailyContentLength_DataReductionProxyEnabled",
+ 9, 1);
+ tester.ExpectUniqueSample(
+ "Net.DailyContentLength_DataReductionProxyEnabled_Application", 9, 1);
+ tester.ExpectUniqueSample("Net.DailyContentLength_ViaDataReductionProxy", 9,
+ 1);
+ tester.ExpectUniqueSample(
+ "Net.DailyContentLength_ViaDataReductionProxy_Application", 9, 1);
+
+ // floor((15000 - 10000) * 100) = 33.
+ tester.ExpectUniqueSample("Net.DailyContentSavingPercent", 33, 1);
+ tester.ExpectUniqueSample(
+ "Net.DailyContentSavingPercent_DataReductionProxyEnabled", 33, 1);
+ tester.ExpectUniqueSample(
+ "Net.DailyContentSavingPercent_ViaDataReductionProxy", 33, 1);
+
+ tester.ExpectUniqueSample("Net.DailyContentPercent_DataReductionProxyEnabled",
+ 100, 1);
+ tester.ExpectUniqueSample("Net.DailyContentPercent_ViaDataReductionProxy",
+ 100, 1);
+ tester.ExpectUniqueSample(
+ "Net.DailyContentPercent_DataReductionProxyEnabled_Unknown", 0, 1);
+}
+
} // namespace data_reduction_proxy

Powered by Google App Engine
This is Rietveld 408576698