| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/metrics/statistics_recorder.h" |
| 6 |
| 5 #include <stddef.h> | 7 #include <stddef.h> |
| 6 | 8 |
| 9 #include <memory> |
| 7 #include <vector> | 10 #include <vector> |
| 8 | 11 |
| 9 #include "base/bind.h" | 12 #include "base/bind.h" |
| 10 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/metrics/persistent_histogram_allocator.h" | 15 #include "base/metrics/persistent_histogram_allocator.h" |
| 14 #include "base/metrics/sparse_histogram.h" | 16 #include "base/metrics/sparse_histogram.h" |
| 15 #include "base/metrics/statistics_recorder.h" | |
| 16 #include "base/values.h" | 17 #include "base/values.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 namespace base { | 20 namespace base { |
| 20 | 21 |
| 21 class StatisticsRecorderTest : public testing::Test { | 22 class StatisticsRecorderTest : public testing::Test { |
| 22 protected: | 23 protected: |
| 23 void SetUp() override { | 24 void SetUp() override { |
| 24 // Get this first so it never gets created in persistent storage and will | 25 // Get this first so it never gets created in persistent storage and will |
| 25 // not appear in the StatisticsRecorder after it is re-initialized. | 26 // not appear in the StatisticsRecorder after it is re-initialized. |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 | 266 |
| 266 TEST_F(StatisticsRecorderTest, ToJSON) { | 267 TEST_F(StatisticsRecorderTest, ToJSON) { |
| 267 LOCAL_HISTOGRAM_COUNTS("TestHistogram1", 30); | 268 LOCAL_HISTOGRAM_COUNTS("TestHistogram1", 30); |
| 268 LOCAL_HISTOGRAM_COUNTS("TestHistogram1", 40); | 269 LOCAL_HISTOGRAM_COUNTS("TestHistogram1", 40); |
| 269 LOCAL_HISTOGRAM_COUNTS("TestHistogram2", 30); | 270 LOCAL_HISTOGRAM_COUNTS("TestHistogram2", 30); |
| 270 LOCAL_HISTOGRAM_COUNTS("TestHistogram2", 40); | 271 LOCAL_HISTOGRAM_COUNTS("TestHistogram2", 40); |
| 271 | 272 |
| 272 std::string json(StatisticsRecorder::ToJSON(std::string())); | 273 std::string json(StatisticsRecorder::ToJSON(std::string())); |
| 273 | 274 |
| 274 // Check for valid JSON. | 275 // Check for valid JSON. |
| 275 scoped_ptr<Value> root = JSONReader::Read(json); | 276 std::unique_ptr<Value> root = JSONReader::Read(json); |
| 276 ASSERT_TRUE(root.get()); | 277 ASSERT_TRUE(root.get()); |
| 277 | 278 |
| 278 DictionaryValue* root_dict = NULL; | 279 DictionaryValue* root_dict = NULL; |
| 279 ASSERT_TRUE(root->GetAsDictionary(&root_dict)); | 280 ASSERT_TRUE(root->GetAsDictionary(&root_dict)); |
| 280 | 281 |
| 281 // No query should be set. | 282 // No query should be set. |
| 282 ASSERT_FALSE(root_dict->HasKey("query")); | 283 ASSERT_FALSE(root_dict->HasKey("query")); |
| 283 | 284 |
| 284 ListValue* histogram_list = NULL; | 285 ListValue* histogram_list = NULL; |
| 285 ASSERT_TRUE(root_dict->GetList("histograms", &histogram_list)); | 286 ASSERT_TRUE(root_dict->GetList("histograms", &histogram_list)); |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 HistogramBase* histogram = Histogram::FactoryGet("TestHistogram", 1, 1000, 10, | 508 HistogramBase* histogram = Histogram::FactoryGet("TestHistogram", 1, 1000, 10, |
| 508 HistogramBase::kNoFlags); | 509 HistogramBase::kNoFlags); |
| 509 EXPECT_TRUE(histogram); | 510 EXPECT_TRUE(histogram); |
| 510 histogram->Add(1); | 511 histogram->Add(1); |
| 511 | 512 |
| 512 EXPECT_TRUE(callback_wrapper.called); | 513 EXPECT_TRUE(callback_wrapper.called); |
| 513 EXPECT_EQ(callback_wrapper.last_histogram_value, 1); | 514 EXPECT_EQ(callback_wrapper.last_histogram_value, 1); |
| 514 } | 515 } |
| 515 | 516 |
| 516 } // namespace base | 517 } // namespace base |
| OLD | NEW |