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

Side by Side Diff: components/rappor/rappor_service_unittest.cc

Issue 1058333002: Multi-dimension rappor metrics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup and add xml support Created 5 years, 8 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
« no previous file with comments | « components/rappor/rappor_service.cc ('k') | tools/metrics/common/models.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/rappor/rappor_service.h" 5 #include "components/rappor/rappor_service.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/prefs/testing_pref_service.h" 8 #include "base/prefs/testing_pref_service.h"
9 #include "components/rappor/byte_vector_utils.h" 9 #include "components/rappor/byte_vector_utils.h"
10 #include "components/rappor/proto/rappor_metric.pb.h" 10 #include "components/rappor/proto/rappor_metric.pb.h"
(...skipping 21 matching lines...) Expand all
32 rappor_service.Update(COARSE_LEVEL, true); 32 rappor_service.Update(COARSE_LEVEL, true);
33 EXPECT_LT(base::TimeDelta(), rappor_service.next_rotation()); 33 EXPECT_LT(base::TimeDelta(), rappor_service.next_rotation());
34 EXPECT_TRUE(rappor_service.test_uploader()->is_running()); 34 EXPECT_TRUE(rappor_service.test_uploader()->is_running());
35 } 35 }
36 36
37 // Check that samples can be recorded and exported. 37 // Check that samples can be recorded and exported.
38 TEST(RapporServiceTest, RecordAndExportMetrics) { 38 TEST(RapporServiceTest, RecordAndExportMetrics) {
39 TestRapporService rappor_service; 39 TestRapporService rappor_service;
40 40
41 // Multiple samples for the same metric should only generate one report. 41 // Multiple samples for the same metric should only generate one report.
42 rappor_service.RecordSample("MyMetric", ETLD_PLUS_ONE_RAPPOR_TYPE, "foo"); 42 rappor_service.RecordSample("MyMetric", UMA_STRING_RAPPOR_TYPE, "foo");
43 rappor_service.RecordSample("MyMetric", ETLD_PLUS_ONE_RAPPOR_TYPE, "bar"); 43 rappor_service.RecordSample("MyMetric", UMA_STRING_RAPPOR_TYPE, "bar");
44 44
45 RapporReports reports; 45 RapporReports reports;
46 rappor_service.GetReports(&reports); 46 rappor_service.GetReports(&reports);
47 EXPECT_EQ(1, reports.report_size()); 47 EXPECT_EQ(1, reports.report_size());
48 48
49 const RapporReports::Report& report = reports.report(0); 49 const RapporReports::Report& report = reports.report(0);
50 EXPECT_TRUE(report.name_hash()); 50 EXPECT_TRUE(report.name_hash());
51 // ETLD_PLUS_ONE_RAPPOR_TYPE has 128 bits 51 // UMA_STRING_RAPPOR_TYPE has 128 bits
52 EXPECT_EQ(16u, report.bits().size()); 52 EXPECT_EQ(16u, report.bits().size());
53 } 53 }
54 54
55 // Check that the reporting level is respected. 55 // Check that the reporting level is respected.
56 TEST(RapporServiceTest, RecordingLevel) { 56 TEST(RapporServiceTest, RecordingLevel) {
57 TestRapporService rappor_service; 57 TestRapporService rappor_service;
58 rappor_service.Update(COARSE_LEVEL, false); 58 rappor_service.Update(COARSE_LEVEL, false);
59 59
60 // ETLD_PLUS_ONE_RAPPOR_TYPE is a FINE_LEVEL metric 60 // UMA_STRING_RAPPOR_TYPE is a FINE_LEVEL metric
61 rappor_service.RecordSample("FineMetric", ETLD_PLUS_ONE_RAPPOR_TYPE, "foo"); 61 rappor_service.RecordSample("FineMetric", UMA_STRING_RAPPOR_TYPE, "foo");
62 62
63 RapporReports reports; 63 RapporReports reports;
64 rappor_service.GetReports(&reports); 64 rappor_service.GetReports(&reports);
65 EXPECT_EQ(0, reports.report_size()); 65 EXPECT_EQ(0, reports.report_size());
66 } 66 }
67 67
68 // Check that GetRecordedSampleForMetric works as expected. 68 // Check that GetRecordedSampleForMetric works as expected.
69 TEST(RapporServiceTest, GetRecordedSampleForMetric) { 69 TEST(RapporServiceTest, GetRecordedSampleForMetric) {
70 TestRapporService rappor_service; 70 TestRapporService rappor_service;
71 71
72 // Multiple samples for the same metric; only the latest is remembered. 72 // Multiple samples for the same metric; only the latest is remembered.
73 rappor_service.RecordSample("MyMetric", ETLD_PLUS_ONE_RAPPOR_TYPE, "foo"); 73 rappor_service.RecordSample("MyMetric", UMA_STRING_RAPPOR_TYPE, "foo");
74 rappor_service.RecordSample("MyMetric", ETLD_PLUS_ONE_RAPPOR_TYPE, "bar"); 74 rappor_service.RecordSample("MyMetric", UMA_STRING_RAPPOR_TYPE, "bar");
75 75
76 std::string sample; 76 std::string sample;
77 RapporType type; 77 RapporType type;
78 EXPECT_FALSE( 78 EXPECT_FALSE(
79 rappor_service.GetRecordedSampleForMetric("WrongMetric", &sample, &type)); 79 rappor_service.GetRecordedSampleForMetric("WrongMetric", &sample, &type));
80 EXPECT_TRUE( 80 EXPECT_TRUE(
81 rappor_service.GetRecordedSampleForMetric("MyMetric", &sample, &type)); 81 rappor_service.GetRecordedSampleForMetric("MyMetric", &sample, &type));
82 EXPECT_EQ("bar", sample); 82 EXPECT_EQ("bar", sample);
83 EXPECT_EQ(ETLD_PLUS_ONE_RAPPOR_TYPE, type); 83 EXPECT_EQ(UMA_STRING_RAPPOR_TYPE, type);
84 } 84 }
85 85
86 // Check that the incognito is respected. 86 // Check that the incognito is respected.
87 TEST(RapporServiceTest, Incognito) { 87 TEST(RapporServiceTest, Incognito) {
88 TestRapporService rappor_service; 88 TestRapporService rappor_service;
89 rappor_service.set_is_incognito(true); 89 rappor_service.set_is_incognito(true);
90 90
91 rappor_service.RecordSample("MyMetric", COARSE_RAPPOR_TYPE, "foo"); 91 rappor_service.RecordSample("MyMetric", COARSE_RAPPOR_TYPE, "foo");
92 92
93 RapporReports reports; 93 RapporReports reports;
94 rappor_service.GetReports(&reports); 94 rappor_service.GetReports(&reports);
95 EXPECT_EQ(0, reports.report_size()); 95 EXPECT_EQ(0, reports.report_size());
96 } 96 }
97 97
98 } // namespace rappor 98 } // namespace rappor
OLDNEW
« no previous file with comments | « components/rappor/rappor_service.cc ('k') | tools/metrics/common/models.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698