summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authortwifkak <twifkak@chromium.org>2015-08-10 09:39:33 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-10 16:40:26 +0000
commit36a9d6f54d27a5a093b8520a4015e8ec1a7c06bd (patch)
treeda74e9a868d6a39885ce9151780209e5e75377c9 /base
parenta30c059080613e2e92d8e79ba3dabee5afe5d0c6 (diff)
downloadchromium_src-36a9d6f54d27a5a093b8520a4015e8ec1a7c06bd.zip
chromium_src-36a9d6f54d27a5a093b8520a4015e8ec1a7c06bd.tar.gz
chromium_src-36a9d6f54d27a5a093b8520a4015e8ec1a7c06bd.tar.bz2
Fix HistogramTester::GetAllSamples when empty.
Fix GetAllSamples to return an empty vector when the histogram has no samples, instead of crashing. BUG= Review URL: https://codereview.chromium.org/1265403003 Cr-Commit-Position: refs/heads/master@{#342634}
Diffstat (limited to 'base')
-rw-r--r--base/test/histogram_tester.cc12
-rw-r--r--base/test/histogram_tester_unittest.cc6
2 files changed, 13 insertions, 5 deletions
diff --git a/base/test/histogram_tester.cc b/base/test/histogram_tester.cc
index 051f599..09b4ef3 100644
--- a/base/test/histogram_tester.cc
+++ b/base/test/histogram_tester.cc
@@ -79,11 +79,13 @@ std::vector<Bucket> HistogramTester::GetAllSamples(
std::vector<Bucket> samples;
scoped_ptr<HistogramSamples> snapshot =
GetHistogramSamplesSinceCreation(name);
- for (auto it = snapshot->Iterator(); !it->Done(); it->Next()) {
- HistogramBase::Sample sample;
- HistogramBase::Count count;
- it->Get(&sample, nullptr, &count);
- samples.push_back(Bucket(sample, count));
+ if (snapshot) {
+ for (auto it = snapshot->Iterator(); !it->Done(); it->Next()) {
+ HistogramBase::Sample sample;
+ HistogramBase::Count count;
+ it->Get(&sample, nullptr, &count);
+ samples.push_back(Bucket(sample, count));
+ }
}
return samples;
}
diff --git a/base/test/histogram_tester_unittest.cc b/base/test/histogram_tester_unittest.cc
index d4812d7..21b8170 100644
--- a/base/test/histogram_tester_unittest.cc
+++ b/base/test/histogram_tester_unittest.cc
@@ -11,6 +11,7 @@
#include "testing/gtest/include/gtest/gtest.h"
using ::testing::ElementsAre;
+using ::testing::IsEmpty;
namespace {
@@ -110,4 +111,9 @@ TEST_F(HistogramTesterTest, TestGetAllSamples) {
ElementsAre(Bucket(2, 1), Bucket(3, 2), Bucket(5, 1)));
}
+TEST_F(HistogramTesterTest, TestGetAllSamples_NoSamples) {
+ HistogramTester tester;
+ EXPECT_THAT(tester.GetAllSamples(kHistogram5), IsEmpty());
+}
+
} // namespace base