| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/sampler.h" | 5 #include "components/rappor/sampler.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "components/rappor/byte_vector_utils.h" | 9 #include "components/rappor/byte_vector_utils.h" |
| 8 #include "components/rappor/proto/rappor_metric.pb.h" | 10 #include "components/rappor/proto/rappor_metric.pb.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 12 |
| 11 namespace rappor { | 13 namespace rappor { |
| 12 | 14 |
| 13 const RapporParameters kTestRapporParameters = { | 15 const RapporParameters kTestRapporParameters = { |
| 14 1 /* Num cohorts */, | 16 1 /* Num cohorts */, |
| 15 1 /* Bloom filter size bytes */, | 17 1 /* Bloom filter size bytes */, |
| 16 4 /* Bloom filter hash count */, | 18 4 /* Bloom filter hash count */, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 28 }; | 30 }; |
| 29 | 31 |
| 30 namespace internal { | 32 namespace internal { |
| 31 | 33 |
| 32 // Test that exporting deletes samples. | 34 // Test that exporting deletes samples. |
| 33 TEST(RapporSamplerTest, TestExport) { | 35 TEST(RapporSamplerTest, TestExport) { |
| 34 Sampler sampler; | 36 Sampler sampler; |
| 35 | 37 |
| 36 scoped_ptr<Sample> sample1 = TestSamplerFactory::CreateSample(); | 38 scoped_ptr<Sample> sample1 = TestSamplerFactory::CreateSample(); |
| 37 sample1->SetStringField("Foo", "Junk"); | 39 sample1->SetStringField("Foo", "Junk"); |
| 38 sampler.AddSample("Metric1", sample1.Pass()); | 40 sampler.AddSample("Metric1", std::move(sample1)); |
| 39 | 41 |
| 40 scoped_ptr<Sample> sample2 = TestSamplerFactory::CreateSample(); | 42 scoped_ptr<Sample> sample2 = TestSamplerFactory::CreateSample(); |
| 41 sample2->SetStringField("Foo", "Junk2"); | 43 sample2->SetStringField("Foo", "Junk2"); |
| 42 sampler.AddSample("Metric1", sample2.Pass()); | 44 sampler.AddSample("Metric1", std::move(sample2)); |
| 43 | 45 |
| 44 // Since the two samples were for one metric, we should randomly get one | 46 // Since the two samples were for one metric, we should randomly get one |
| 45 // of the two. | 47 // of the two. |
| 46 RapporReports reports; | 48 RapporReports reports; |
| 47 std::string secret = HmacByteVectorGenerator::GenerateEntropyInput(); | 49 std::string secret = HmacByteVectorGenerator::GenerateEntropyInput(); |
| 48 sampler.ExportMetrics(secret, &reports); | 50 sampler.ExportMetrics(secret, &reports); |
| 49 EXPECT_EQ(1, reports.report_size()); | 51 EXPECT_EQ(1, reports.report_size()); |
| 50 EXPECT_EQ(1u, reports.report(0).bits().size()); | 52 EXPECT_EQ(1u, reports.report(0).bits().size()); |
| 51 | 53 |
| 52 // First export should clear the metric. | 54 // First export should clear the metric. |
| 53 RapporReports reports2; | 55 RapporReports reports2; |
| 54 sampler.ExportMetrics(secret, &reports2); | 56 sampler.ExportMetrics(secret, &reports2); |
| 55 EXPECT_EQ(0, reports2.report_size()); | 57 EXPECT_EQ(0, reports2.report_size()); |
| 56 } | 58 } |
| 57 | 59 |
| 58 } // namespace internal | 60 } // namespace internal |
| 59 | 61 |
| 60 } // namespace rappor | 62 } // namespace rappor |
| OLD | NEW |