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

Side by Side Diff: chrome/browser/search/most_visited_iframe_source_unittest.cc

Issue 111423005: [Most Visited] Log suggestion provider to UMA (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase? Created 7 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/metrics/histogram.h" 6 #include "base/metrics/histogram.h"
7 #include "base/metrics/statistics_recorder.h" 7 #include "base/metrics/statistics_recorder.h"
8 #include "base/strings/stringprintf.h"
8 #include "chrome/browser/search/most_visited_iframe_source.h" 9 #include "chrome/browser/search/most_visited_iframe_source.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 11
11 class MostVisitedIframeSourceTest : public testing::Test { 12 class MostVisitedIframeSourceTest : public testing::Test {
12 public: 13 public:
13 void ExpectNullData(base::RefCountedMemory* data) { 14 void ExpectNullData(base::RefCountedMemory* data) {
14 EXPECT_EQ(NULL, data); 15 EXPECT_EQ(NULL, data);
15 } 16 }
16 17
17 protected: 18 protected:
18 MostVisitedIframeSource* source() { return source_.get(); } 19 MostVisitedIframeSource* source() { return source_.get(); }
19 20
20 private: 21 private:
21 virtual void SetUp() { source_.reset(new MostVisitedIframeSource()); } 22 virtual void SetUp() { source_.reset(new MostVisitedIframeSource()); }
22 23
23 scoped_ptr<MostVisitedIframeSource> source_; 24 scoped_ptr<MostVisitedIframeSource> source_;
24 }; 25 };
25 26
26 TEST_F(MostVisitedIframeSourceTest, LogEndpointIsValid) { 27 TEST_F(MostVisitedIframeSourceTest, LogEndpointIsValidNoProvider) {
27 content::URLDataSource::GotDataCallback callback = base::Bind( 28 content::URLDataSource::GotDataCallback callback = base::Bind(
28 &MostVisitedIframeSourceTest::ExpectNullData, base::Unretained(this)); 29 &MostVisitedIframeSourceTest::ExpectNullData, base::Unretained(this));
29 30
30 base::StatisticsRecorder::Initialize(); 31 base::StatisticsRecorder::Initialize();
31 // Making sure the histogram is created. 32 // Making sure the histogram is created.
32 UMA_HISTOGRAM_ENUMERATION(MostVisitedIframeSource::kMostVisitedHistogramName, 33 UMA_HISTOGRAM_ENUMERATION(MostVisitedIframeSource::kMostVisitedHistogramName,
33 0, MostVisitedIframeSource::kNumMostVisited); 34 0, MostVisitedIframeSource::kNumMostVisited);
34 35
35 base::HistogramBase* histogram = base::StatisticsRecorder::FindHistogram( 36 base::HistogramBase* histogram = base::StatisticsRecorder::FindHistogram(
36 MostVisitedIframeSource::kMostVisitedHistogramName); 37 MostVisitedIframeSource::kMostVisitedHistogramName);
(...skipping 19 matching lines...) Expand all
56 EXPECT_EQ(1, samples3->GetCount(5)); 57 EXPECT_EQ(1, samples3->GetCount(5));
57 EXPECT_EQ(2, samples3->GetCount(1)); 58 EXPECT_EQ(2, samples3->GetCount(1));
58 59
59 // If 'pos' is unspecified or invalid, callback still gets called but values 60 // If 'pos' is unspecified or invalid, callback still gets called but values
60 // are not incremented. 61 // are not incremented.
61 source()->StartDataRequest("log.html?pos=", 0, 0, callback); 62 source()->StartDataRequest("log.html?pos=", 0, 0, callback);
62 source()->StartDataRequest("log.html", 0, 0, callback); 63 source()->StartDataRequest("log.html", 0, 0, callback);
63 // Total count hasn't changed. 64 // Total count hasn't changed.
64 EXPECT_EQ(samples2->TotalCount() + 2, samples3->TotalCount()); 65 EXPECT_EQ(samples2->TotalCount() + 2, samples3->TotalCount());
65 } 66 }
67
68 TEST_F(MostVisitedIframeSourceTest, LogEndpointIsValidWithProvider) {
69 content::URLDataSource::GotDataCallback callback = base::Bind(
70 &MostVisitedIframeSourceTest::ExpectNullData, base::Unretained(this));
71
72 base::StatisticsRecorder::Initialize();
73 // Making sure a test histogram with provider is created by logging a dummy
74 // value.
75 const std::string histogram_name =
76 MostVisitedIframeSource::GetHistogramNameForProvider("foobar");
77 UMA_HISTOGRAM_ENUMERATION(histogram_name, 0,
78 MostVisitedIframeSource::kNumMostVisited);
79
80 base::HistogramBase* histogram = base::StatisticsRecorder::FindHistogram(
81 histogram_name);
82 scoped_ptr<base::HistogramSamples> samples1(histogram->SnapshotSamples());
83 // The dummy value got logged.
84 EXPECT_EQ(1, samples1->TotalCount());
85 EXPECT_EQ(1, samples1->GetCount(0));
86
87 // Test the method.
88 source()->StartDataRequest("log.html?pos=1&pr=foobar", 0, 0, callback);
89
90 scoped_ptr<base::HistogramSamples> samples2(histogram->SnapshotSamples());
91 EXPECT_EQ(samples1->TotalCount() + 1, samples2->TotalCount());
92 EXPECT_EQ(1, samples2->GetCount(1));
93
94 // Counts accumulate and behave as expected.
95 source()->StartDataRequest("log.html?pos=5&pr=foobar", 0, 0, callback);
96 source()->StartDataRequest("log.html?pos=1&pr=foobar", 0, 0, callback);
97 // This should have no effect for the "foobar" histogram.
98 source()->StartDataRequest("log.html?pos=1&pr=nofoo", 0, 0, callback);
99
100 scoped_ptr<base::HistogramSamples> samples3(histogram->SnapshotSamples());
101 EXPECT_EQ(samples2->TotalCount() + 2, samples3->TotalCount());
102 EXPECT_EQ(1, samples3->GetCount(5));
103 EXPECT_EQ(2, samples3->GetCount(1));
104 }
OLDNEW
« no previous file with comments | « chrome/browser/search/most_visited_iframe_source.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698