This source file includes following definitions.
- SetUpTestCase
- SetUp
- metrics
- RecordWordCountsForTesting
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "chrome/browser/spellchecker/spellcheck_host_metrics.h"
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/metrics/histogram_samples.h"
#include "base/metrics/statistics_recorder.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/statistics_delta_reader.h"
#include "testing/gtest/include/gtest/gtest.h"
#if defined(OS_WIN)
#include "base/win/windows_version.h"
#endif
class SpellcheckHostMetricsTest : public testing::Test {
public:
SpellcheckHostMetricsTest() {
}
static void SetUpTestCase() {
base::StatisticsRecorder::Initialize();
}
virtual void SetUp() OVERRIDE {
metrics_.reset(new SpellCheckHostMetrics);
}
SpellCheckHostMetrics* metrics() { return metrics_.get(); }
void RecordWordCountsForTesting() { metrics_->RecordWordCounts(); }
private:
base::MessageLoop loop_;
scoped_ptr<SpellCheckHostMetrics> metrics_;
};
TEST_F(SpellcheckHostMetricsTest, RecordEnabledStats) {
const char kMetricName[] = "SpellCheck.Enabled";
base::StatisticsDeltaReader statistics_delta_reader1;
metrics()->RecordEnabledStats(false);
scoped_ptr<base::HistogramSamples> samples(
statistics_delta_reader1.GetHistogramSamplesSinceCreation(kMetricName));
EXPECT_EQ(1, samples->GetCount(0));
EXPECT_EQ(0, samples->GetCount(1));
base::StatisticsDeltaReader statistics_delta_reader2;
metrics()->RecordEnabledStats(true);
samples =
statistics_delta_reader2.GetHistogramSamplesSinceCreation(kMetricName);
EXPECT_EQ(0, samples->GetCount(0));
EXPECT_EQ(1, samples->GetCount(1));
}
TEST_F(SpellcheckHostMetricsTest, CustomWordStats) {
#if defined(OS_WIN)
if (base::win::GetVersion() >= base::win::VERSION_VISTA)
return;
#endif
SpellCheckHostMetrics::RecordCustomWordCountStats(123);
EXPECT_TRUE(base::StatisticsRecorder::IsActive());
base::StatisticsDeltaReader statistics_delta_reader;
SpellCheckHostMetrics::RecordCustomWordCountStats(23);
scoped_ptr<base::HistogramSamples> samples(
statistics_delta_reader.GetHistogramSamplesSinceCreation(
"SpellCheck.CustomWords"));
EXPECT_EQ(23, samples->sum());
}
TEST_F(SpellcheckHostMetricsTest, RecordWordCountsDiscardsDuplicates) {
const char* histogramName[] = {
"SpellCheck.CheckedWords",
"SpellCheck.MisspelledWords",
"SpellCheck.ReplacedWords",
"SpellCheck.UniqueWords",
"SpellCheck.ShownSuggestions"
};
metrics()->RecordCheckedWordStats(base::ASCIIToUTF16("test"), false);
RecordWordCountsForTesting();
base::StatisticsDeltaReader statistics_delta_reader;
RecordWordCountsForTesting();
scoped_ptr<base::HistogramSamples> samples;
for (size_t i = 0; i < arraysize(histogramName); ++i) {
samples = statistics_delta_reader.GetHistogramSamplesSinceCreation(
histogramName[i]);
EXPECT_EQ(0, samples->TotalCount());
}
}
TEST_F(SpellcheckHostMetricsTest, RecordSpellingServiceStats) {
const char kMetricName[] = "SpellCheck.SpellingService.Enabled";
base::StatisticsDeltaReader statistics_delta_reader1;
metrics()->RecordSpellingServiceStats(false);
scoped_ptr<base::HistogramSamples> samples(
statistics_delta_reader1.GetHistogramSamplesSinceCreation(kMetricName));
EXPECT_EQ(1, samples->GetCount(0));
EXPECT_EQ(0, samples->GetCount(1));
base::StatisticsDeltaReader statistics_delta_reader2;
metrics()->RecordSpellingServiceStats(true);
samples =
statistics_delta_reader2.GetHistogramSamplesSinceCreation(kMetricName);
EXPECT_EQ(0, samples->GetCount(0));
EXPECT_EQ(1, samples->GetCount(1));
}