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

Side by Side Diff: components/rappor/rappor_service_unittest.cc

Issue 1090683003: Alternative Multi-dimensional Rappor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Exporting and Test 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/rappor_service.h" 5 #include "components/rappor/rappor_service.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/prefs/testing_pref_service.h" 8 #include "base/prefs/testing_pref_service.h"
9 #include "components/metrics/metrics_hashes.h"
9 #include "components/rappor/byte_vector_utils.h" 10 #include "components/rappor/byte_vector_utils.h"
10 #include "components/rappor/proto/rappor_metric.pb.h" 11 #include "components/rappor/proto/rappor_metric.pb.h"
11 #include "components/rappor/rappor_parameters.h" 12 #include "components/rappor/rappor_parameters.h"
12 #include "components/rappor/rappor_pref_names.h" 13 #include "components/rappor/rappor_pref_names.h"
13 #include "components/rappor/test_log_uploader.h" 14 #include "components/rappor/test_log_uploader.h"
14 #include "components/rappor/test_rappor_service.h" 15 #include "components/rappor/test_rappor_service.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 namespace rappor { 18 namespace rappor {
18 19
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 TestRapporService rappor_service; 89 TestRapporService rappor_service;
89 rappor_service.set_is_incognito(true); 90 rappor_service.set_is_incognito(true);
90 91
91 rappor_service.RecordSample("MyMetric", COARSE_RAPPOR_TYPE, "foo"); 92 rappor_service.RecordSample("MyMetric", COARSE_RAPPOR_TYPE, "foo");
92 93
93 RapporReports reports; 94 RapporReports reports;
94 rappor_service.GetReports(&reports); 95 rappor_service.GetReports(&reports);
95 EXPECT_EQ(0, reports.report_size()); 96 EXPECT_EQ(0, reports.report_size());
96 } 97 }
97 98
99 // Check that Sample objects record correctly.
100 TEST(RapporServiceTest, SampleObj) {
101 TestRapporService rappor_service;
102 scoped_ptr<Sample> sample = rappor_service.MakeSampleObj(
103 COARSE_RAPPOR_TYPE);
104 sample->SetStringField("Url", "example.com");
105 sample->SetFlagsField("Flags1", 0xbcd, 12);
106 rappor_service.RecordSampleObj("ObjMetric", sample.Pass());
107 uint64_t urlHash = metrics::HashMetricName("ObjMetric.Url");
Alexei Svitkine (slow) 2015/04/22 21:00:13 Nit: hacker_style
Steven Holte 2015/04/22 21:59:32 Done.
108 uint64_t flagsHash = metrics::HashMetricName("ObjMetric.Flags1");
109 RapporReports reports;
110 rappor_service.GetReports(&reports);
111 EXPECT_EQ(2, reports.report_size());
112 size_t urlIndex = reports.report(0).name_hash() == urlHash ? 0 : 1;
113 size_t flagsIndex = urlIndex == 0 ? 1 : 0;
114 EXPECT_EQ(urlHash, reports.report(urlIndex).name_hash());
115 EXPECT_EQ(1u, reports.report(urlIndex).bits().size());
116 EXPECT_EQ(flagsHash, reports.report(flagsIndex).name_hash());
117 EXPECT_EQ(2u, reports.report(flagsIndex).bits().size());
118 }
119
98 } // namespace rappor 120 } // namespace rappor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698