Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / base / metrics / histogram_delta_serialization_unittest.cc
blobb53520c5098787539d7d14691597cf125fde7be3
1 // Copyright 2013 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.
5 #include "base/metrics/histogram_delta_serialization.h"
7 #include <vector>
9 #include "base/metrics/histogram.h"
10 #include "base/metrics/histogram_base.h"
11 #include "base/metrics/statistics_recorder.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace base {
16 TEST(HistogramDeltaSerializationTest, DeserializeHistogramAndAddSamples) {
17 StatisticsRecorder statistic_recorder;
18 HistogramDeltaSerialization serializer("HistogramDeltaSerializationTest");
19 std::vector<std::string> deltas;
20 // Nothing was changed yet.
21 serializer.PrepareAndSerializeDeltas(&deltas);
22 EXPECT_TRUE(deltas.empty());
24 HistogramBase* histogram = Histogram::FactoryGet(
25 "TestHistogram", 1, 1000, 10, HistogramBase::kIPCSerializationSourceFlag);
26 histogram->Add(1);
27 histogram->Add(10);
28 histogram->Add(100);
29 histogram->Add(1000);
31 serializer.PrepareAndSerializeDeltas(&deltas);
32 EXPECT_FALSE(deltas.empty());
34 HistogramDeltaSerialization::DeserializeAndAddSamples(deltas);
36 // The histogram has kIPCSerializationSourceFlag. So samples will be ignored.
37 scoped_ptr<HistogramSamples> snapshot(histogram->SnapshotSamples());
38 EXPECT_EQ(1, snapshot->GetCount(1));
39 EXPECT_EQ(1, snapshot->GetCount(10));
40 EXPECT_EQ(1, snapshot->GetCount(100));
41 EXPECT_EQ(1, snapshot->GetCount(1000));
43 // Clear kIPCSerializationSourceFlag to emulate multi-process usage.
44 histogram->ClearFlags(HistogramBase::kIPCSerializationSourceFlag);
45 HistogramDeltaSerialization::DeserializeAndAddSamples(deltas);
47 scoped_ptr<HistogramSamples> snapshot2(histogram->SnapshotSamples());
48 EXPECT_EQ(2, snapshot2->GetCount(1));
49 EXPECT_EQ(2, snapshot2->GetCount(10));
50 EXPECT_EQ(2, snapshot2->GetCount(100));
51 EXPECT_EQ(2, snapshot2->GetCount(1000));
54 } // namespace base