OLD | NEW |
(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 RapporParameters& parameters, |
| 17 const std::string& sample) { |
| 18 RecordSampleInternal(parameters, sample); |
| 19 } |
| 20 void SetCohort(uint32_t cohort) { |
| 21 cohort_ = cohort; |
| 22 } |
| 23 }; |
| 24 |
| 25 TEST(RapporServiceTest, RapporMetrics) { |
| 26 const RapporParameters kTestRapporParameters = { |
| 27 "MyRappor", 16 /* Bloom filter size bytes */, |
| 28 4 /* Bloom filter hash count */, |
| 29 PROBABILITY_75 /* Fake data probability */, |
| 30 PROBABILITY_50 /* Fake one probability */, |
| 31 PROBABILITY_75 /* One coin probability */, |
| 32 PROBABILITY_50 /* Zero coin probability */ |
| 33 }; |
| 34 |
| 35 TestRapporService rappor_service; |
| 36 rappor_service.SetCohort(0); |
| 37 |
| 38 rappor_service.TestRecordSample(kTestRapporParameters, "foo"); |
| 39 rappor_service.TestRecordSample(kTestRapporParameters, "bar"); |
| 40 |
| 41 RapporReports reports; |
| 42 rappor_service.GetReports(&reports); |
| 43 EXPECT_EQ(1, reports.report_size()); |
| 44 |
| 45 const RapporReports::Report& report = reports.report(0); |
| 46 EXPECT_TRUE(report.name_hash()); |
| 47 EXPECT_EQ(16u, report.bits().size()); |
| 48 } |
| 49 |
| 50 } // namespace rappor |
OLD | NEW |