summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill/autofill_metrics_unittest.cc
diff options
context:
space:
mode:
authorisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-01 03:56:01 +0000
committerisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-01 03:56:01 +0000
commite2c66c328e40b7d84b104c12074e5d84c15e308d (patch)
tree3527ba18749322a8f4eb481bc5a94745c00198fe /chrome/browser/autofill/autofill_metrics_unittest.cc
parentcaf167dc928373bc9e7316088a383ddea9ecded1 (diff)
downloadchromium_src-e2c66c328e40b7d84b104c12074e5d84c15e308d.zip
chromium_src-e2c66c328e40b7d84b104c12074e5d84c15e308d.tar.gz
chromium_src-e2c66c328e40b7d84b104c12074e5d84c15e308d.tar.bz2
Add UMA metric for number of autofill profiles
BUG=73933 TEST=unit_tests --gtest_filter=AutoFillMetricsTest.ProfileCount Review URL: http://codereview.chromium.org/6574022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76352 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill/autofill_metrics_unittest.cc')
-rw-r--r--chrome/browser/autofill/autofill_metrics_unittest.cc65
1 files changed, 54 insertions, 11 deletions
diff --git a/chrome/browser/autofill/autofill_metrics_unittest.cc b/chrome/browser/autofill/autofill_metrics_unittest.cc
index ca51a20..f3d9d99 100644
--- a/chrome/browser/autofill/autofill_metrics_unittest.cc
+++ b/chrome/browser/autofill/autofill_metrics_unittest.cc
@@ -12,6 +12,7 @@
#include "chrome/browser/autofill/autofill_manager.h"
#include "chrome/browser/autofill/autofill_metrics.h"
#include "chrome/browser/autofill/personal_data_manager.h"
+#include "chrome/browser/webdata/web_data_service.h"
#include "content/browser/renderer_host/test_render_view_host.h"
#include "content/browser/tab_contents/test_tab_contents.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -24,10 +25,23 @@ using webkit_glue::FormField;
namespace {
+class MockAutofillMetrics : public AutofillMetrics {
+ public:
+ MockAutofillMetrics() {}
+ MOCK_CONST_METHOD1(Log, void(ServerQueryMetric metric));
+ MOCK_CONST_METHOD2(Log, void(QualityMetric metric,
+ const std::string& experiment_id));
+ MOCK_CONST_METHOD1(LogProfileCount, void(size_t num_profiles));
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics);
+};
+
// TODO(isherman): Move this into autofill_common_test.h?
class TestPersonalDataManager : public PersonalDataManager {
public:
TestPersonalDataManager() {
+ set_metric_logger(new MockAutofillMetrics);
CreateTestAutoFillProfiles(&web_profiles_);
CreateTestCreditCards(&credit_cards_);
}
@@ -36,6 +50,31 @@ class TestPersonalDataManager : public PersonalDataManager {
virtual void SaveImportedFormData() {}
virtual bool IsDataLoaded() const { return true; }
+ // Overridden to avoid a trip to the database. This should be a no-op except
+ // for the side-effect of logging the profile count.
+ virtual void LoadProfiles() {
+ std::vector<AutoFillProfile*> profiles;
+ web_profiles_.release(&profiles);
+ WDResult<std::vector<AutoFillProfile*> > result(AUTOFILL_PROFILES_RESULT,
+ profiles);
+ ReceiveLoadedProfiles(0, &result);
+ }
+
+ // Adds |profile| to |web_profiles_| and takes ownership of the profile's
+ // memory.
+ virtual void AddProfile(AutoFillProfile* profile) {
+ web_profiles_.push_back(profile);
+ }
+
+ const MockAutofillMetrics* metric_logger() const {
+ return static_cast<const MockAutofillMetrics*>(
+ PersonalDataManager::metric_logger());
+ }
+
+ static void ResetHasLoggedProfileCount() {
+ PersonalDataManager::set_has_logged_profile_count(false);
+ }
+
private:
void CreateTestAutoFillProfiles(ScopedVector<AutoFillProfile>* profiles) {
AutoFillProfile* profile = new AutoFillProfile;
@@ -83,17 +122,6 @@ class TestPersonalDataManager : public PersonalDataManager {
DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager);
};
-class MockAutofillMetrics : public AutofillMetrics {
- public:
- MockAutofillMetrics() {}
- MOCK_CONST_METHOD1(Log, void(ServerQueryMetric metric));
- MOCK_CONST_METHOD2(Log, void(QualityMetric metric,
- const std::string& experiment_id));
-
- private:
- DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics);
-};
-
class TestAutofillManager : public AutoFillManager {
public:
TestAutofillManager(TabContents* tab_contents,
@@ -538,3 +566,18 @@ TEST_F(AutofillMetricsTest, QualityMetricsWithExperimentId) {
// Simulate form submission.
EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form));
}
+
+// Test that the profile count is logged correctly.
+TEST_F(AutofillMetricsTest, ProfileCount) {
+ TestPersonalDataManager::ResetHasLoggedProfileCount();
+
+ // The metric should be logged when the profiles are first loaded.
+ EXPECT_CALL(*test_personal_data_->metric_logger(),
+ LogProfileCount(3)).Times(1);
+ test_personal_data_->LoadProfiles();
+
+ // The metric should only be logged once.
+ EXPECT_CALL(*test_personal_data_->metric_logger(),
+ LogProfileCount(::testing::_)).Times(0);
+ test_personal_data_->LoadProfiles();
+}