Index: trunk/src/chrome/browser/ui/cocoa/browser/password_generation_bubble_controller_unittest.mm |
=================================================================== |
--- trunk/src/chrome/browser/ui/cocoa/browser/password_generation_bubble_controller_unittest.mm (revision 242174) |
+++ trunk/src/chrome/browser/ui/cocoa/browser/password_generation_bubble_controller_unittest.mm (working copy) |
@@ -5,14 +5,19 @@ |
#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 "components/autofill/core/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 { |
@@ -21,7 +26,7 @@ |
: controller_(nil) {} |
static void SetUpTestCase() { |
- base::HistogramRecorder::Initialize(); |
+ StatisticsRecorder::Initialize(); |
} |
virtual void SetUp() { |
@@ -29,7 +34,10 @@ |
generator_.reset(new autofill::PasswordGenerator(20)); |
- histogram_recorder_.reset(new base::HistogramRecorder()); |
+ HistogramBase* histogram = |
+ StatisticsRecorder::FindHistogram(kHistogramName); |
+ if (histogram) |
+ original_ = histogram->SnapshotSamples(); |
SetUpController(); |
} |
@@ -57,17 +65,27 @@ |
controller_ = nil; |
} |
- scoped_ptr<base::HistogramSamples> GetHistogramSamples() { |
- return histogram_recorder_->GetHistogramSamplesSinceCreation( |
- kHistogramName).Pass(); |
+ HistogramSamples* GetHistogramSamples() { |
+ HistogramBase* histogram = |
+ StatisticsRecorder::FindHistogram(kHistogramName); |
+ if (histogram) { |
+ current_ = histogram->SnapshotSamples(); |
+ if (original_.get()) |
+ current_->Subtract(*original_.get()); |
+ } |
+ return current_.get(); |
} |
protected: |
// Weak. |
PasswordGenerationBubbleController* controller_; |
- scoped_ptr<base::HistogramRecorder> histogram_recorder_; |
+ // Used to determine the histogram changes made just for this specific |
+ // test run. |
+ scoped_ptr<HistogramSamples> original_; |
+ scoped_ptr<HistogramSamples> current_; |
+ |
scoped_ptr<autofill::PasswordGenerator> generator_; |
}; |
@@ -94,7 +112,7 @@ |
// Do nothing. |
CloseController(); |
- scoped_ptr<base::HistogramSamples> samples(GetHistogramSamples()); |
+ HistogramSamples* samples = GetHistogramSamples(); |
EXPECT_EQ( |
1, |
samples->GetCount(autofill::password_generation::IGNORE_FEATURE)); |
@@ -142,4 +160,5 @@ |
1, |
samples->GetCount( |
autofill::password_generation::ACCEPT_ORIGINAL_PASSWORD)); |
+ |
} |