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

Side by Side Diff: chrome/browser/autofill/autofill_metrics_unittest.cc

Issue 11644059: Change infobar creation to use a public static Create() method on the infobar delegate classes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <vector> 5 #include <vector>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/string16.h" 8 #include "base/string16.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/api/infobars/infobar_service.h"
12 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" 11 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h"
13 #include "chrome/browser/autofill/autofill_common_test.h" 12 #include "chrome/browser/autofill/autofill_common_test.h"
14 #include "chrome/browser/autofill/autofill_manager.h" 13 #include "chrome/browser/autofill/autofill_manager.h"
15 #include "chrome/browser/autofill/autofill_manager_delegate.h" 14 #include "chrome/browser/autofill/autofill_manager_delegate.h"
16 #include "chrome/browser/autofill/autofill_metrics.h" 15 #include "chrome/browser/autofill/autofill_metrics.h"
17 #include "chrome/browser/autofill/personal_data_manager.h" 16 #include "chrome/browser/autofill/personal_data_manager.h"
18 #include "chrome/browser/autofill/personal_data_manager_factory.h" 17 #include "chrome/browser/autofill/personal_data_manager_factory.h"
19 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" 18 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h"
20 #include "chrome/browser/webdata/web_data_service.h" 19 #include "chrome/browser/webdata/web_data_service.h"
21 #include "chrome/common/form_data.h" 20 #include "chrome/common/form_data.h"
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 261
263 class AutofillMetricsTest : public ChromeRenderViewHostTestHarness { 262 class AutofillMetricsTest : public ChromeRenderViewHostTestHarness {
264 public: 263 public:
265 AutofillMetricsTest(); 264 AutofillMetricsTest();
266 virtual ~AutofillMetricsTest(); 265 virtual ~AutofillMetricsTest();
267 266
268 virtual void SetUp() OVERRIDE; 267 virtual void SetUp() OVERRIDE;
269 virtual void TearDown() OVERRIDE; 268 virtual void TearDown() OVERRIDE;
270 269
271 protected: 270 protected:
272 AutofillCCInfoBarDelegate* CreateDelegate(MockAutofillMetrics* metric_logger, 271 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate(
273 CreditCard** created_card); 272 MockAutofillMetrics* metric_logger,
273 CreditCard** created_card);
274 274
275 content::TestBrowserThread ui_thread_; 275 content::TestBrowserThread ui_thread_;
276 content::TestBrowserThread file_thread_; 276 content::TestBrowserThread file_thread_;
277 277
278 scoped_refptr<TestAutofillManager> autofill_manager_; 278 scoped_refptr<TestAutofillManager> autofill_manager_;
279 TestPersonalDataManager personal_data_; 279 TestPersonalDataManager personal_data_;
280 280
281 private: 281 private:
282 std::string default_gmock_verbosity_level_; 282 std::string default_gmock_verbosity_level_;
283 283
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 327
328 // Order of destruction is important as AutofillManager relies on 328 // Order of destruction is important as AutofillManager relies on
329 // PersonalDataManager to be around when it gets destroyed. Also, a real 329 // PersonalDataManager to be around when it gets destroyed. Also, a real
330 // AutofillManager is tied to the lifetime of the WebContents, so it must 330 // AutofillManager is tied to the lifetime of the WebContents, so it must
331 // be destroyed at the destruction of the WebContents. 331 // be destroyed at the destruction of the WebContents.
332 autofill_manager_ = NULL; 332 autofill_manager_ = NULL;
333 file_thread_.Stop(); 333 file_thread_.Stop();
334 ChromeRenderViewHostTestHarness::TearDown(); 334 ChromeRenderViewHostTestHarness::TearDown();
335 } 335 }
336 336
337 AutofillCCInfoBarDelegate* AutofillMetricsTest::CreateDelegate( 337 scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate(
338 MockAutofillMetrics* metric_logger, 338 MockAutofillMetrics* metric_logger,
339 CreditCard** created_card) { 339 CreditCard** created_card) {
340 EXPECT_CALL(*metric_logger, 340 EXPECT_CALL(*metric_logger,
341 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); 341 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN));
342 // The delegate created below will take ownership of this object. 342 // The delegate created below will take ownership of this object.
343 CreditCard* credit_card = new CreditCard(); 343 CreditCard* credit_card = new CreditCard();
344 if (created_card) 344 if (created_card)
345 *created_card = credit_card; 345 *created_card = credit_card;
346 return new AutofillCCInfoBarDelegate( 346 return AutofillCCInfoBarDelegate::Create(credit_card, &personal_data_,
347 InfoBarService::FromWebContents(web_contents()), 347 metric_logger);
348 credit_card,
349 &personal_data_,
350 metric_logger);
351 } 348 }
352 349
353 // Test that we log quality metrics appropriately. 350 // Test that we log quality metrics appropriately.
354 TEST_F(AutofillMetricsTest, QualityMetrics) { 351 TEST_F(AutofillMetricsTest, QualityMetrics) {
355 // Set up our form data. 352 // Set up our form data.
356 FormData form; 353 FormData form;
357 form.name = ASCIIToUTF16("TestForm"); 354 form.name = ASCIIToUTF16("TestForm");
358 form.method = ASCIIToUTF16("POST"); 355 form.method = ASCIIToUTF16("POST");
359 form.origin = GURL("http://example.com/form.html"); 356 form.origin = GURL("http://example.com/form.html");
360 form.action = GURL("http://example.com/submit.html"); 357 form.action = GURL("http://example.com/submit.html");
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 // Establish our expectations. 1128 // Establish our expectations.
1132 EXPECT_CALL(*autofill_manager_->metric_logger(), 1129 EXPECT_CALL(*autofill_manager_->metric_logger(),
1133 LogIsAutofillEnabledAtPageLoad(false)).Times(1); 1130 LogIsAutofillEnabledAtPageLoad(false)).Times(1);
1134 1131
1135 autofill_manager_->set_autofill_enabled(false); 1132 autofill_manager_->set_autofill_enabled(false);
1136 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks()); 1133 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks());
1137 } 1134 }
1138 1135
1139 // Test that credit card infobar metrics are logged correctly. 1136 // Test that credit card infobar metrics are logged correctly.
1140 TEST_F(AutofillMetricsTest, CreditCardInfoBar) { 1137 TEST_F(AutofillMetricsTest, CreditCardInfoBar) {
1141 InfoBarService::CreateForWebContents(web_contents());
1142
1143 MockAutofillMetrics metric_logger; 1138 MockAutofillMetrics metric_logger;
1144 ::testing::InSequence dummy; 1139 ::testing::InSequence dummy;
1145 1140
1146 // Accept the infobar. 1141 // Accept the infobar.
1147 { 1142 {
1148 CreditCard* credit_card; 1143 CreditCard* credit_card;
1149 scoped_ptr<InfoBarDelegate> infobar(CreateDelegate(&metric_logger, 1144 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger,
1150 &credit_card)); 1145 &credit_card));
1146 ASSERT_TRUE(infobar);
1151 EXPECT_CALL(personal_data_, SaveImportedCreditCard(*credit_card)); 1147 EXPECT_CALL(personal_data_, SaveImportedCreditCard(*credit_card));
1152 EXPECT_CALL(metric_logger, 1148 EXPECT_CALL(metric_logger,
1153 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED)).Times(1); 1149 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED)).Times(1);
1154 EXPECT_CALL(metric_logger, 1150 EXPECT_CALL(metric_logger,
1155 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0); 1151 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0);
1156 EXPECT_TRUE(static_cast<ConfirmInfoBarDelegate*>(infobar.get())->Accept()); 1152 EXPECT_TRUE(infobar->Accept());
1157 } 1153 }
1158 1154
1159 // Cancel the infobar. 1155 // Cancel the infobar.
1160 { 1156 {
1161 scoped_ptr<InfoBarDelegate> infobar(CreateDelegate(&metric_logger, NULL)); 1157 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger,
1158 NULL));
1159 ASSERT_TRUE(infobar);
1162 EXPECT_CALL(metric_logger, 1160 EXPECT_CALL(metric_logger,
1163 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED)).Times(1); 1161 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED)).Times(1);
1164 EXPECT_CALL(metric_logger, 1162 EXPECT_CALL(metric_logger,
1165 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0); 1163 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0);
1166 EXPECT_TRUE(static_cast<ConfirmInfoBarDelegate*>(infobar.get())->Cancel()); 1164 EXPECT_TRUE(infobar->Cancel());
1167 } 1165 }
1168 1166
1169 // Dismiss the infobar. 1167 // Dismiss the infobar.
1170 { 1168 {
1171 scoped_ptr<InfoBarDelegate> infobar(CreateDelegate(&metric_logger, NULL)); 1169 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger,
1170 NULL));
1171 ASSERT_TRUE(infobar);
1172 EXPECT_CALL(metric_logger, 1172 EXPECT_CALL(metric_logger,
1173 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED)).Times(1); 1173 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED)).Times(1);
1174 EXPECT_CALL(metric_logger, 1174 EXPECT_CALL(metric_logger,
1175 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0); 1175 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0);
1176 infobar->InfoBarDismissed(); 1176 infobar->InfoBarDismissed();
1177 } 1177 }
1178 1178
1179 // Ignore the infobar. 1179 // Ignore the infobar.
1180 { 1180 {
1181 scoped_ptr<InfoBarDelegate> infobar(CreateDelegate(&metric_logger, NULL)); 1181 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger,
1182 NULL));
1183 ASSERT_TRUE(infobar);
1182 EXPECT_CALL(metric_logger, 1184 EXPECT_CALL(metric_logger,
1183 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(1); 1185 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(1);
1184 } 1186 }
1185 } 1187 }
1186 1188
1187 // Test that server query response experiment id metrics are logged correctly. 1189 // Test that server query response experiment id metrics are logged correctly.
1188 TEST_F(AutofillMetricsTest, ServerQueryExperimentIdForQuery) { 1190 TEST_F(AutofillMetricsTest, ServerQueryExperimentIdForQuery) {
1189 MockAutofillMetrics metric_logger; 1191 MockAutofillMetrics metric_logger;
1190 ::testing::InSequence dummy; 1192 ::testing::InSequence dummy;
1191 1193
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
1560 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); 1562 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
1561 autofill_manager_->OnDidFillAutofillFormData( 1563 autofill_manager_->OnDidFillAutofillFormData(
1562 TimeTicks::FromInternalValue(5)); 1564 TimeTicks::FromInternalValue(5));
1563 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 1565 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1564 TimeTicks::FromInternalValue(3)); 1566 TimeTicks::FromInternalValue(3));
1565 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); 1567 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17));
1566 autofill_manager_->Reset(); 1568 autofill_manager_->Reset();
1567 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); 1569 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1568 } 1570 }
1569 } 1571 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_manager.cc ('k') | chrome/browser/chrome_quota_permission_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698