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

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

Issue 49753002: RAPPOR implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Split Name/Parameters Created 6 years, 10 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
OLDNEW
(Empty)
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.
4
5 #include "components/rappor/rappor_service.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace rappor {
10
11 class TestRapporService : public RapporService {
12 public:
13 void GetReports(RapporReports* reports) {
14 LogMetrics(reports);
15 }
16 void TestRecordSample(const std::string& metric_name,
17 const RapporParameters& parameters,
18 const std::string& sample) {
19 RecordSampleInternal(metric_name, parameters, sample);
20 }
21 void SetCohort(uint32_t cohort) {
Alexei Svitkine (slow) 2014/02/05 18:07:01 I'd just name this SetCohortForTesting() and put i
Steven Holte 2014/02/05 22:44:37 Done.
22 cohort_ = cohort;
23 }
24 };
25
26 TEST(RapporServiceTest, RapporMetrics) {
27 const RapporParameters kTestRapporParameters = {
28 16 /* Bloom filter size bytes */,
29 4 /* Bloom filter hash count */,
30 PROBABILITY_75 /* Fake data probability */,
31 PROBABILITY_50 /* Fake one probability */,
32 PROBABILITY_75 /* One coin probability */,
33 PROBABILITY_50 /* Zero coin probability */
34 };
35
36 TestRapporService rappor_service;
37 rappor_service.SetCohort(0);
38
39 rappor_service.TestRecordSample("MyRappor", kTestRapporParameters, "foo");
40 rappor_service.TestRecordSample("MyRappor", kTestRapporParameters, "bar");
41
42 RapporReports reports;
43 rappor_service.GetReports(&reports);
44 EXPECT_EQ(1, reports.report_size());
45
46 const RapporReports::Report& report = reports.report(0);
47 EXPECT_TRUE(report.name_hash());
48 EXPECT_EQ(16u, report.bits().size());
49 }
50
51 } // namespace rappor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698