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

Unified Diff: components/rappor/sampler_unittest.cc

Issue 1090683003: Alternative Multi-dimensional Rappor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use 64-bit shift 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/rappor/sampler.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/rappor/sampler_unittest.cc
diff --git a/components/rappor/sampler_unittest.cc b/components/rappor/sampler_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2790c6f4118d44d0682fed587a1aff6890f7b962
--- /dev/null
+++ b/components/rappor/sampler_unittest.cc
@@ -0,0 +1,60 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/rappor/sampler.h"
+
+#include "components/rappor/byte_vector_utils.h"
+#include "components/rappor/proto/rappor_metric.pb.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace rappor {
+
+const RapporParameters kTestRapporParameters = {
+ 1 /* Num cohorts */,
+ 1 /* Bloom filter size bytes */,
+ 4 /* Bloom filter hash count */,
+ PROBABILITY_75 /* Fake data probability */,
+ PROBABILITY_50 /* Fake one probability */,
+ PROBABILITY_75 /* One coin probability */,
+ PROBABILITY_50 /* Zero coin probability */,
+ FINE_LEVEL /* Reporting level (not used) */};
+
+class TestSamplerFactory {
+ public:
+ static scoped_ptr<Sample> CreateSample() {
+ return scoped_ptr<Sample>(new Sample(0, kTestRapporParameters));
+ }
+};
+
+namespace internal {
+
+// Test that exporting deletes samples.
+TEST(RapporSamplerTest, TestExport) {
+ Sampler sampler;
+
+ scoped_ptr<Sample> sample1 = TestSamplerFactory::CreateSample();
+ sample1->SetStringField("Foo", "Junk");
+ sampler.AddSample("Metric1", sample1.Pass());
+
+ scoped_ptr<Sample> sample2 = TestSamplerFactory::CreateSample();
+ sample2->SetStringField("Foo", "Junk2");
+ sampler.AddSample("Metric1", sample2.Pass());
+
+ // Since the two samples were for one metric, we should randomly get one
+ // of the two.
+ RapporReports reports;
+ std::string secret = HmacByteVectorGenerator::GenerateEntropyInput();
+ sampler.ExportMetrics(secret, &reports);
+ EXPECT_EQ(1, reports.report_size());
+ EXPECT_EQ(1u, reports.report(0).bits().size());
+
+ // First export should clear the metric.
+ RapporReports reports2;
+ sampler.ExportMetrics(secret, &reports2);
+ EXPECT_EQ(0, reports2.report_size());
+}
+
+} // namespace internal
+
+} // namespace rappor
« no previous file with comments | « components/rappor/sampler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698