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 <string> |
| 8 |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 namespace rappor { |
| 12 |
| 13 class TestRapporService : public RapporService { |
| 14 public: |
| 15 void GetReports(RapporReports* reports) { |
| 16 LogMetrics(reports); |
| 17 } |
| 18 void TestRecordSamples(const RapporParameters& parameters, |
| 19 const std::vector<std::string>& samples) { |
| 20 RecordSamplesInternal(parameters, samples); |
| 21 } |
| 22 void SetCohort(uint32_t cohort) { |
| 23 cohort_ = cohort; |
| 24 } |
| 25 }; |
| 26 |
| 27 TEST(RapporServiceTest, RapporMetrics) { |
| 28 const RapporParameters kTestRapporParameters = { |
| 29 "MyRappor", 16 /* Bloom filter size bytes */, |
| 30 4 /* Bloom filter hash count */, |
| 31 PROBABILITY_75 /* Fake data probability */, |
| 32 PROBABILITY_50 /* Fake one probability */, |
| 33 PROBABILITY_75 /* One coin probability */, |
| 34 PROBABILITY_50 /* Zero coin probability */ |
| 35 }; |
| 36 |
| 37 TestRapporService rappor_service; |
| 38 rappor_service.SetCohort(0); |
| 39 |
| 40 std::vector<std::string> samples; |
| 41 samples.push_back("foo"); |
| 42 rappor_service.TestRecordSamples(kTestRapporParameters, samples); |
| 43 std::vector<std::string> samples2; |
| 44 samples2.push_back("bar"); |
| 45 rappor_service.TestRecordSamples(kTestRapporParameters, samples2); |
| 46 |
| 47 RapporReports reports; |
| 48 rappor_service.GetReports(&reports); |
| 49 EXPECT_EQ(1, reports.report_size()); |
| 50 |
| 51 const RapporReports::Report& report = reports.report(0); |
| 52 EXPECT_TRUE(report.name_hash()); |
| 53 EXPECT_EQ(16u, report.bits().size()); |
| 54 } |
| 55 |
| 56 } // namespace rappor |
OLD | NEW |