| 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 } | |
| 24 | 23 |
| 25 virtual void SetUp() OVERRIDE { | 24 virtual void SetUp() OVERRIDE { |
| 26 base::StatisticsRecorder::Initialize(); | 25 base::StatisticsRecorder::Initialize(); |
| 27 metrics_.reset(new SpellCheckHostMetrics); | 26 metrics_.reset(new SpellCheckHostMetrics); |
| 28 } | 27 } |
| 29 | 28 |
| 30 SpellCheckHostMetrics* metrics() { return metrics_.get(); } | 29 SpellCheckHostMetrics* metrics() { return metrics_.get(); } |
| 31 void RecordWordCountsForTesting() { metrics_->RecordWordCounts(); } | 30 void RecordWordCountsForTesting() { metrics_->RecordWordCounts(); } |
| 32 | 31 |
| 33 private: | 32 private: |
| 34 MessageLoop loop_; | 33 base::MessageLoop loop_; |
| 35 scoped_ptr<SpellCheckHostMetrics> metrics_; | 34 scoped_ptr<SpellCheckHostMetrics> metrics_; |
| 36 }; | 35 }; |
| 37 | 36 |
| 38 TEST_F(SpellcheckHostMetricsTest, RecordEnabledStats) { | 37 TEST_F(SpellcheckHostMetricsTest, RecordEnabledStats) { |
| 39 scoped_ptr<HistogramSamples> baseline; | 38 scoped_ptr<HistogramSamples> baseline; |
| 40 HistogramBase* histogram = | 39 HistogramBase* histogram = |
| 41 StatisticsRecorder::FindHistogram("SpellCheck.Enabled"); | 40 StatisticsRecorder::FindHistogram("SpellCheck.Enabled"); |
| 42 if (histogram) | 41 if (histogram) |
| 43 baseline = histogram->SnapshotSamples(); | 42 baseline = histogram->SnapshotSamples(); |
| 44 | 43 |
| 45 metrics()->RecordEnabledStats(false); | 44 metrics()->RecordEnabledStats(false); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 metrics()->RecordSpellingServiceStats(true); | 147 metrics()->RecordSpellingServiceStats(true); |
| 149 | 148 |
| 150 histogram = | 149 histogram = |
| 151 StatisticsRecorder::FindHistogram(kMetricName); | 150 StatisticsRecorder::FindHistogram(kMetricName); |
| 152 ASSERT_TRUE(histogram != NULL); | 151 ASSERT_TRUE(histogram != NULL); |
| 153 samples = histogram->SnapshotSamples(); | 152 samples = histogram->SnapshotSamples(); |
| 154 samples->Subtract(*baseline); | 153 samples->Subtract(*baseline); |
| 155 EXPECT_EQ(0, samples->GetCount(0)); | 154 EXPECT_EQ(0, samples->GetCount(0)); |
| 156 EXPECT_EQ(1, samples->GetCount(1)); | 155 EXPECT_EQ(1, samples->GetCount(1)); |
| 157 } | 156 } |
| OLD | NEW |