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

Side by Side Diff: components/translate/core/common/translate_metrics_unittest.cc

Issue 2853853002: Fix overflow when logging MaxInt32 to a sparse histogram. (Closed)
Patch Set: Address comments. Created 3 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/tracing/child/child_trace_message_filter.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
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/translate/core/common/translate_metrics.h" 5 #include "components/translate/core/common/translate_metrics.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 Snapshot(); 102 Snapshot();
103 EXPECT_EQ(count, GetTotalCount()); 103 EXPECT_EQ(count, GetTotalCount());
104 } 104 }
105 105
106 void CheckValueInLogs(double value) { 106 void CheckValueInLogs(double value) {
107 Snapshot(); 107 Snapshot();
108 ASSERT_TRUE(samples_.get()); 108 ASSERT_TRUE(samples_.get());
109 for (std::unique_ptr<SampleCountIterator> i = samples_->Iterator(); 109 for (std::unique_ptr<SampleCountIterator> i = samples_->Iterator();
110 !i->Done(); i->Next()) { 110 !i->Done(); i->Next()) {
111 HistogramBase::Sample min; 111 HistogramBase::Sample min;
112 HistogramBase::Sample max; 112 int64_t max;
113 HistogramBase::Count count; 113 HistogramBase::Count count;
114 i->Get(&min, &max, &count); 114 i->Get(&min, &max, &count);
115 if (min <= value && value <= max && count >= 1) 115 if (min <= value && value <= max && count >= 1)
116 return; 116 return;
117 } 117 }
118 EXPECT_FALSE(true); 118 EXPECT_FALSE(true);
119 } 119 }
120 120
121 HistogramBase::Count GetCount(HistogramBase::Sample value) { 121 HistogramBase::Count GetCount(HistogramBase::Sample value) {
122 Snapshot(); 122 Snapshot();
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 EXPECT_EQ(recorder.GetCount(base::HashMetricName("en-AU,ru-Latn")), 1); 310 EXPECT_EQ(recorder.GetCount(base::HashMetricName("en-AU,ru-Latn")), 1);
311 311
312 // We don't track "en-XX" or "en-YY" as page codes. 312 // We don't track "en-XX" or "en-YY" as page codes.
313 translate::ReportLanguageDetectionConflict("en-XX", "es"); 313 translate::ReportLanguageDetectionConflict("en-XX", "es");
314 translate::ReportLanguageDetectionConflict("en-YY", "es"); 314 translate::ReportLanguageDetectionConflict("en-YY", "es");
315 recorder.CheckTotalCount(5); 315 recorder.CheckTotalCount(5);
316 EXPECT_EQ(recorder.GetCount(base::HashMetricName("other,es")), 2); 316 EXPECT_EQ(recorder.GetCount(base::HashMetricName("other,es")), 2);
317 } 317 }
318 318
319 } // namespace translate 319 } // namespace translate
OLDNEW
« no previous file with comments | « components/tracing/child/child_trace_message_filter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698