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 "chrome/browser/spellchecker/spellcheck_host_metrics.h" | 5 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/metrics/histogram_samples.h" | 11 #include "base/metrics/histogram_samples.h" |
12 #include "base/metrics/statistics_recorder.h" | 12 #include "base/metrics/statistics_recorder.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 using base::HistogramBase; | 16 using base::HistogramBase; |
17 using base::HistogramSamples; | 17 using base::HistogramSamples; |
18 using base::StatisticsRecorder; | 18 using base::StatisticsRecorder; |
19 | 19 |
20 class SpellcheckHostMetricsTest : public testing::Test { | 20 class SpellcheckHostMetricsTest : public testing::Test { |
21 public: | 21 public: |
22 SpellcheckHostMetricsTest() : loop_(MessageLoop::TYPE_DEFAULT) { | 22 SpellcheckHostMetricsTest() : loop_(base::MessageLoop::TYPE_DEFAULT) { |
23 } | 23 } |
24 | 24 |
25 virtual void SetUp() OVERRIDE { | 25 virtual void SetUp() OVERRIDE { |
26 base::StatisticsRecorder::Initialize(); | 26 base::StatisticsRecorder::Initialize(); |
27 metrics_.reset(new SpellCheckHostMetrics); | 27 metrics_.reset(new SpellCheckHostMetrics); |
28 } | 28 } |
29 | 29 |
30 SpellCheckHostMetrics* metrics() { return metrics_.get(); } | 30 SpellCheckHostMetrics* metrics() { return metrics_.get(); } |
31 void RecordWordCountsForTesting() { metrics_->RecordWordCounts(); } | 31 void RecordWordCountsForTesting() { metrics_->RecordWordCounts(); } |
32 | 32 |
33 private: | 33 private: |
34 MessageLoop loop_; | 34 base::MessageLoop loop_; |
35 scoped_ptr<SpellCheckHostMetrics> metrics_; | 35 scoped_ptr<SpellCheckHostMetrics> metrics_; |
36 }; | 36 }; |
37 | 37 |
38 TEST_F(SpellcheckHostMetricsTest, RecordEnabledStats) { | 38 TEST_F(SpellcheckHostMetricsTest, RecordEnabledStats) { |
39 scoped_ptr<HistogramSamples> baseline; | 39 scoped_ptr<HistogramSamples> baseline; |
40 HistogramBase* histogram = | 40 HistogramBase* histogram = |
41 StatisticsRecorder::FindHistogram("SpellCheck.Enabled"); | 41 StatisticsRecorder::FindHistogram("SpellCheck.Enabled"); |
42 if (histogram) | 42 if (histogram) |
43 baseline = histogram->SnapshotSamples(); | 43 baseline = histogram->SnapshotSamples(); |
44 | 44 |
45 metrics()->RecordEnabledStats(false); | 45 metrics()->RecordEnabledStats(false); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 metrics()->RecordSpellingServiceStats(true); | 148 metrics()->RecordSpellingServiceStats(true); |
149 | 149 |
150 histogram = | 150 histogram = |
151 StatisticsRecorder::FindHistogram(kMetricName); | 151 StatisticsRecorder::FindHistogram(kMetricName); |
152 ASSERT_TRUE(histogram != NULL); | 152 ASSERT_TRUE(histogram != NULL); |
153 samples = histogram->SnapshotSamples(); | 153 samples = histogram->SnapshotSamples(); |
154 samples->Subtract(*baseline); | 154 samples->Subtract(*baseline); |
155 EXPECT_EQ(0, samples->GetCount(0)); | 155 EXPECT_EQ(0, samples->GetCount(0)); |
156 EXPECT_EQ(1, samples->GetCount(1)); | 156 EXPECT_EQ(1, samples->GetCount(1)); |
157 } | 157 } |
OLD | NEW |