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

Side by Side 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, 7 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
« no previous file with comments | « components/rappor/sampler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/rappor/sampler.h"
6
7 #include "components/rappor/byte_vector_utils.h"
8 #include "components/rappor/proto/rappor_metric.pb.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace rappor {
12
13 const RapporParameters kTestRapporParameters = {
14 1 /* Num cohorts */,
15 1 /* Bloom filter size bytes */,
16 4 /* Bloom filter hash count */,
17 PROBABILITY_75 /* Fake data probability */,
18 PROBABILITY_50 /* Fake one probability */,
19 PROBABILITY_75 /* One coin probability */,
20 PROBABILITY_50 /* Zero coin probability */,
21 FINE_LEVEL /* Reporting level (not used) */};
22
23 class TestSamplerFactory {
24 public:
25 static scoped_ptr<Sample> CreateSample() {
26 return scoped_ptr<Sample>(new Sample(0, kTestRapporParameters));
27 }
28 };
29
30 namespace internal {
31
32 // Test that exporting deletes samples.
33 TEST(RapporSamplerTest, TestExport) {
34 Sampler sampler;
35
36 scoped_ptr<Sample> sample1 = TestSamplerFactory::CreateSample();
37 sample1->SetStringField("Foo", "Junk");
38 sampler.AddSample("Metric1", sample1.Pass());
39
40 scoped_ptr<Sample> sample2 = TestSamplerFactory::CreateSample();
41 sample2->SetStringField("Foo", "Junk2");
42 sampler.AddSample("Metric1", sample2.Pass());
43
44 // Since the two samples were for one metric, we should randomly get one
45 // of the two.
46 RapporReports reports;
47 std::string secret = HmacByteVectorGenerator::GenerateEntropyInput();
48 sampler.ExportMetrics(secret, &reports);
49 EXPECT_EQ(1, reports.report_size());
50 EXPECT_EQ(1u, reports.report(0).bits().size());
51
52 // First export should clear the metric.
53 RapporReports reports2;
54 sampler.ExportMetrics(secret, &reports2);
55 EXPECT_EQ(0, reports2.report_size());
56 }
57
58 } // namespace internal
59
60 } // namespace rappor
OLDNEW
« 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