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

Unified Diff: chrome/browser/ui/cocoa/browser/password_generation_bubble_controller_unittest.mm

Issue 18337014: Add a HistogramRecorder class and use cases. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Synced. Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/browser/password_generation_bubble_controller_unittest.mm
diff --git a/chrome/browser/ui/cocoa/browser/password_generation_bubble_controller_unittest.mm b/chrome/browser/ui/cocoa/browser/password_generation_bubble_controller_unittest.mm
index f5c3db84ab759e959ec4dd328939c560fb6afedf..79b5d08aaf580577596c0c72c0a903d714a77bfb 100644
--- a/chrome/browser/ui/cocoa/browser/password_generation_bubble_controller_unittest.mm
+++ b/chrome/browser/ui/cocoa/browser/password_generation_bubble_controller_unittest.mm
@@ -5,19 +5,14 @@
#import "chrome/browser/ui/cocoa/browser/password_generation_bubble_controller.h"
#include "base/logging.h"
-#include "base/metrics/histogram.h"
#include "base/metrics/histogram_samples.h"
-#include "base/metrics/statistics_recorder.h"
#include "base/strings/sys_string_conversions.h"
+#include "base/test/histogram_recorder.h"
#include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
#include "components/autofill/core/browser/password_generator.h"
#include "content/public/common/password_form.h"
#include "testing/gtest_mac.h"
-using base::HistogramBase;
-using base::HistogramSamples;
-using base::StatisticsRecorder;
-
const char kHistogramName[] = "PasswordGeneration.UserActions";
class PasswordGenerationBubbleControllerTest : public CocoaProfileTest {
@@ -25,19 +20,12 @@ class PasswordGenerationBubbleControllerTest : public CocoaProfileTest {
PasswordGenerationBubbleControllerTest()
: controller_(nil) {}
- static void SetUpTestCase() {
- StatisticsRecorder::Initialize();
- }
-
virtual void SetUp() {
CocoaProfileTest::SetUp();
generator_.reset(new autofill::PasswordGenerator(20));
- HistogramBase* histogram =
- StatisticsRecorder::FindHistogram(kHistogramName);
- if (histogram)
- original_ = histogram->SnapshotSamples();
+ histogram_recorder_.reset(new base::HistogramRecorder());
SetUpController();
}
@@ -65,26 +53,16 @@ class PasswordGenerationBubbleControllerTest : public CocoaProfileTest {
controller_ = nil;
}
- HistogramSamples* GetHistogramSamples() {
- HistogramBase* histogram =
- StatisticsRecorder::FindHistogram(kHistogramName);
- if (histogram) {
- current_ = histogram->SnapshotSamples();
- if (original_.get())
- current_->Subtract(*original_.get());
- }
- return current_.get();
+ scoped_ptr<base::HistogramSamples> GetHistogramSamples() {
+ return histogram_recorder_.get()->GetHistogramSamplesSinceCreation(
+ kHistogramName).Pass();
}
protected:
// Weak.
PasswordGenerationBubbleController* controller_;
- // Used to determine the histogram changes made just for this specific
- // test run.
- scoped_ptr<HistogramSamples> original_;
-
- scoped_ptr<HistogramSamples> current_;
+ scoped_ptr<base::HistogramRecorder> histogram_recorder_;
scoped_ptr<autofill::PasswordGenerator> generator_;
};
@@ -112,16 +90,17 @@ TEST_F(PasswordGenerationBubbleControllerTest, UMALogging) {
// Do nothing.
CloseController();
- HistogramSamples* samples = GetHistogramSamples();
+ scoped_ptr<base::HistogramSamples> samples(GetHistogramSamples());
EXPECT_EQ(
1,
- samples->GetCount(autofill::password_generation::IGNORE_FEATURE));
+ samples.get()->GetCount(autofill::password_generation::IGNORE_FEATURE));
EXPECT_EQ(
0,
- samples->GetCount(autofill::password_generation::ACCEPT_AFTER_EDITING));
+ samples.get()->GetCount(
+ autofill::password_generation::ACCEPT_AFTER_EDITING));
EXPECT_EQ(
0,
- samples->GetCount(
+ samples.get()->GetCount(
autofill::password_generation::ACCEPT_ORIGINAL_PASSWORD));
SetUpController();
@@ -134,13 +113,14 @@ TEST_F(PasswordGenerationBubbleControllerTest, UMALogging) {
samples = GetHistogramSamples();
EXPECT_EQ(
1,
- samples->GetCount(autofill::password_generation::IGNORE_FEATURE));
+ samples.get()->GetCount(autofill::password_generation::IGNORE_FEATURE));
EXPECT_EQ(
1,
- samples->GetCount(autofill::password_generation::ACCEPT_AFTER_EDITING));
+ samples.get()->GetCount(
+ autofill::password_generation::ACCEPT_AFTER_EDITING));
EXPECT_EQ(
0,
- samples->GetCount(
+ samples.get()->GetCount(
autofill::password_generation::ACCEPT_ORIGINAL_PASSWORD));
SetUpController();
@@ -152,13 +132,14 @@ TEST_F(PasswordGenerationBubbleControllerTest, UMALogging) {
samples = GetHistogramSamples();
EXPECT_EQ(
1,
- samples->GetCount(autofill::password_generation::IGNORE_FEATURE));
+ samples.get()->GetCount(autofill::password_generation::IGNORE_FEATURE));
EXPECT_EQ(
1,
- samples->GetCount(autofill::password_generation::ACCEPT_AFTER_EDITING));
+ samples.get()->GetCount(
+ autofill::password_generation::ACCEPT_AFTER_EDITING));
EXPECT_EQ(
1,
- samples->GetCount(
+ samples.get()->GetCount(
autofill::password_generation::ACCEPT_ORIGINAL_PASSWORD));
}

Powered by Google App Engine
This is Rietveld 408576698