Chromium Code Reviews

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

Issue 11539003: Pop up requestAutocomplete UI when autofill server hints chrome client that it is in a multipage au… (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Refactor autofill_manager to expose GetWebContents(). Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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/autofill/autocheckout_infobar_delegate.h"
11 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" 12 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h"
12 #include "chrome/browser/autofill/autofill_common_test.h" 13 #include "chrome/browser/autofill/autofill_common_test.h"
13 #include "chrome/browser/autofill/autofill_manager.h" 14 #include "chrome/browser/autofill/autofill_manager.h"
14 #include "chrome/browser/autofill/autofill_manager_delegate.h" 15 #include "chrome/browser/autofill/autofill_manager_delegate.h"
15 #include "chrome/browser/autofill/autofill_metrics.h" 16 #include "chrome/browser/autofill/autofill_metrics.h"
16 #include "chrome/browser/autofill/personal_data_manager.h" 17 #include "chrome/browser/autofill/personal_data_manager.h"
17 #include "chrome/browser/autofill/personal_data_manager_factory.h" 18 #include "chrome/browser/autofill/personal_data_manager_factory.h"
18 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" 19 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h"
19 #include "chrome/browser/webdata/web_data_service.h" 20 #include "chrome/browser/webdata/web_data_service.h"
20 #include "chrome/common/form_data.h" 21 #include "chrome/common/form_data.h"
21 #include "chrome/common/form_field_data.h" 22 #include "chrome/common/form_field_data.h"
22 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 23 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
23 #include "chrome/test/base/testing_profile.h" 24 #include "chrome/test/base/testing_profile.h"
24 #include "content/public/test/test_browser_thread.h" 25 #include "content/public/test/test_browser_thread.h"
26 #include "googleurl/src/gurl.h"
25 #include "testing/gmock/include/gmock/gmock.h" 27 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
27 #include "ui/gfx/rect.h" 29 #include "ui/gfx/rect.h"
28 30
29 using content::BrowserThread; 31 using content::BrowserThread;
30 using ::testing::_; 32 using ::testing::_;
31 using ::testing::AnyNumber; 33 using ::testing::AnyNumber;
32 using ::testing::Mock; 34 using ::testing::Mock;
33 using base::TimeTicks; 35 using base::TimeTicks;
34 using base::TimeDelta; 36 using base::TimeDelta;
35 37
36 namespace { 38 namespace {
37 39
38 class MockAutofillMetrics : public AutofillMetrics { 40 class MockAutofillMetrics : public AutofillMetrics {
39 public: 41 public:
40 MockAutofillMetrics() {} 42 MockAutofillMetrics() {}
41 MOCK_CONST_METHOD1(LogCreditCardInfoBarMetric, void(InfoBarMetric metric)); 43 MOCK_CONST_METHOD1(LogCreditCardInfoBarMetric, void(InfoBarMetric metric));
44 MOCK_CONST_METHOD1(LogAutocheckoutInfoBarMetric, void(InfoBarMetric metric));
42 MOCK_CONST_METHOD1(LogDeveloperEngagementMetric, 45 MOCK_CONST_METHOD1(LogDeveloperEngagementMetric,
43 void(DeveloperEngagementMetric metric)); 46 void(DeveloperEngagementMetric metric));
44 MOCK_CONST_METHOD3(LogHeuristicTypePrediction, 47 MOCK_CONST_METHOD3(LogHeuristicTypePrediction,
45 void(FieldTypeQualityMetric metric, 48 void(FieldTypeQualityMetric metric,
46 AutofillFieldType field_type, 49 AutofillFieldType field_type,
47 const std::string& experiment_id)); 50 const std::string& experiment_id));
48 MOCK_CONST_METHOD3(LogOverallTypePrediction, 51 MOCK_CONST_METHOD3(LogOverallTypePrediction,
49 void(FieldTypeQualityMetric metric, 52 void(FieldTypeQualityMetric metric,
50 AutofillFieldType field_type, 53 AutofillFieldType field_type,
51 const std::string& experiment_id)); 54 const std::string& experiment_id));
(...skipping 198 matching lines...)
250 // AutofillManager is ref counted. 253 // AutofillManager is ref counted.
251 virtual ~TestAutofillManager() {} 254 virtual ~TestAutofillManager() {}
252 255
253 bool autofill_enabled_; 256 bool autofill_enabled_;
254 bool did_finish_async_form_submit_; 257 bool did_finish_async_form_submit_;
255 bool message_loop_is_running_; 258 bool message_loop_is_running_;
256 259
257 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); 260 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager);
258 }; 261 };
259 262
263 class TestAutocheckoutManager : public AutocheckoutManager {
264 public:
265 explicit TestAutocheckoutManager(AutofillManager* autofill_manager)
266 : AutocheckoutManager(autofill_manager) {
267 }
Ilya Sherman 2013/01/18 01:45:02 nit: It's best to explicitly include a (virtual) d
Raman Kakilate 2013/01/18 04:22:30 Done.
268
269 virtual void ShowAutocheckoutDialog(
270 const GURL& frame_url,
271 const content::SSLStatus& ssl_status) OVERRIDE {
272 // no-op. Just used as callback from autocheckout_infobar_delegate.
273 }
274
275 private:
276 DISALLOW_COPY_AND_ASSIGN(TestAutocheckoutManager);
277 };
278
260 } // namespace 279 } // namespace
261 280
262 class AutofillMetricsTest : public ChromeRenderViewHostTestHarness { 281 class AutofillMetricsTest : public ChromeRenderViewHostTestHarness {
263 public: 282 public:
264 AutofillMetricsTest(); 283 AutofillMetricsTest();
265 virtual ~AutofillMetricsTest(); 284 virtual ~AutofillMetricsTest();
266 285
267 virtual void SetUp() OVERRIDE; 286 virtual void SetUp() OVERRIDE;
268 virtual void TearDown() OVERRIDE; 287 virtual void TearDown() OVERRIDE;
269 288
270 protected: 289 protected:
271 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate( 290 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate(
272 MockAutofillMetrics* metric_logger, 291 MockAutofillMetrics* metric_logger,
273 CreditCard** created_card); 292 CreditCard** created_card);
274 293
294 scoped_ptr<ConfirmInfoBarDelegate> CreateAutocheckoutDelegate(
295 MockAutofillMetrics* metric_logger);
296
275 content::TestBrowserThread ui_thread_; 297 content::TestBrowserThread ui_thread_;
276 content::TestBrowserThread file_thread_; 298 content::TestBrowserThread file_thread_;
277 299
278 scoped_refptr<TestAutofillManager> autofill_manager_; 300 scoped_refptr<TestAutofillManager> autofill_manager_;
279 TestPersonalDataManager personal_data_; 301 TestPersonalDataManager personal_data_;
280 302
281 private: 303 private:
282 std::string default_gmock_verbosity_level_; 304 std::string default_gmock_verbosity_level_;
283 305
284 DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest); 306 DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest);
(...skipping 55 matching lines...)
340 EXPECT_CALL(*metric_logger, 362 EXPECT_CALL(*metric_logger,
341 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); 363 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN));
342 // The delegate created below will take ownership of this object. 364 // The delegate created below will take ownership of this object.
343 CreditCard* credit_card = new CreditCard(); 365 CreditCard* credit_card = new CreditCard();
344 if (created_card) 366 if (created_card)
345 *created_card = credit_card; 367 *created_card = credit_card;
346 return AutofillCCInfoBarDelegate::Create(credit_card, &personal_data_, 368 return AutofillCCInfoBarDelegate::Create(credit_card, &personal_data_,
347 metric_logger); 369 metric_logger);
348 } 370 }
349 371
372 scoped_ptr<ConfirmInfoBarDelegate>
373 AutofillMetricsTest::CreateAutocheckoutDelegate(
374 MockAutofillMetrics* metric_logger) {
375 EXPECT_CALL(*metric_logger,
376 LogAutocheckoutInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN));
377 GURL url("www.google.com");
378 content::SSLStatus ssl_status;
379 return AutocheckoutInfoBarDelegate::Create(
380 *metric_logger,
381 url,
382 ssl_status,
383 new TestAutocheckoutManager(NULL));
384 }
385
350 // Test that we log quality metrics appropriately. 386 // Test that we log quality metrics appropriately.
351 TEST_F(AutofillMetricsTest, QualityMetrics) { 387 TEST_F(AutofillMetricsTest, QualityMetrics) {
352 // Set up our form data. 388 // Set up our form data.
353 FormData form; 389 FormData form;
354 form.name = ASCIIToUTF16("TestForm"); 390 form.name = ASCIIToUTF16("TestForm");
355 form.method = ASCIIToUTF16("POST"); 391 form.method = ASCIIToUTF16("POST");
356 form.origin = GURL("http://example.com/form.html"); 392 form.origin = GURL("http://example.com/form.html");
357 form.action = GURL("http://example.com/submit.html"); 393 form.action = GURL("http://example.com/submit.html");
358 form.user_submitted = true; 394 form.user_submitted = true;
359 395
(...skipping 819 matching lines...)
1179 // Ignore the infobar. 1215 // Ignore the infobar.
1180 { 1216 {
1181 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger, 1217 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger,
1182 NULL)); 1218 NULL));
1183 ASSERT_TRUE(infobar); 1219 ASSERT_TRUE(infobar);
1184 EXPECT_CALL(metric_logger, 1220 EXPECT_CALL(metric_logger,
1185 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(1); 1221 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(1);
1186 } 1222 }
1187 } 1223 }
1188 1224
1225 // Test that autofill flow infobar metrics are logged correctly.
1226 TEST_F(AutofillMetricsTest, AutocheckoutInfoBar) {
1227 MockAutofillMetrics metric_logger;
1228 ::testing::InSequence dummy;
1229
1230 // Accept the infobar.
1231 {
1232 scoped_ptr<ConfirmInfoBarDelegate> infobar(
1233 CreateAutocheckoutDelegate(&metric_logger));
1234 ASSERT_TRUE(infobar);
1235 EXPECT_CALL(metric_logger,
1236 LogAutocheckoutInfoBarMetric(
1237 AutofillMetrics::INFOBAR_ACCEPTED)).Times(1);
1238 EXPECT_CALL(metric_logger,
1239 LogAutocheckoutInfoBarMetric(
1240 AutofillMetrics::INFOBAR_IGNORED)).Times(0);
1241 EXPECT_TRUE(infobar->Accept());
1242 }
1243
1244 // Cancel the infobar.
1245 {
1246 scoped_ptr<ConfirmInfoBarDelegate> infobar(
1247 CreateAutocheckoutDelegate(&metric_logger));
1248 ASSERT_TRUE(infobar);
1249 EXPECT_CALL(metric_logger,
1250 LogAutocheckoutInfoBarMetric(
1251 AutofillMetrics::INFOBAR_DENIED)).Times(1);
1252 EXPECT_CALL(metric_logger,
1253 LogAutocheckoutInfoBarMetric(
1254 AutofillMetrics::INFOBAR_IGNORED)).Times(0);
1255 EXPECT_TRUE(infobar->Cancel());
1256 }
1257
1258 // Dismiss the infobar.
1259 {
1260 scoped_ptr<ConfirmInfoBarDelegate> infobar(
1261 CreateAutocheckoutDelegate(&metric_logger));
1262 ASSERT_TRUE(infobar);
1263 EXPECT_CALL(metric_logger,
1264 LogAutocheckoutInfoBarMetric(
1265 AutofillMetrics::INFOBAR_DENIED)).Times(1);
1266 EXPECT_CALL(metric_logger,
1267 LogAutocheckoutInfoBarMetric(
1268 AutofillMetrics::INFOBAR_IGNORED)).Times(0);
1269 infobar->InfoBarDismissed();
1270 }
1271
1272 // Ignore the infobar.
1273 {
1274 scoped_ptr<ConfirmInfoBarDelegate> infobar(
1275 CreateAutocheckoutDelegate(&metric_logger));
1276 ASSERT_TRUE(infobar);
1277 EXPECT_CALL(metric_logger,
1278 LogAutocheckoutInfoBarMetric(
1279 AutofillMetrics::INFOBAR_IGNORED)).Times(1);
1280 }
1281 }
1282
1283
1189 // Test that server query response experiment id metrics are logged correctly. 1284 // Test that server query response experiment id metrics are logged correctly.
1190 TEST_F(AutofillMetricsTest, ServerQueryExperimentIdForQuery) { 1285 TEST_F(AutofillMetricsTest, ServerQueryExperimentIdForQuery) {
1191 MockAutofillMetrics metric_logger; 1286 MockAutofillMetrics metric_logger;
1192 ::testing::InSequence dummy; 1287 ::testing::InSequence dummy;
1193 1288
1194 // No experiment specified. 1289 // No experiment specified.
1195 EXPECT_CALL(metric_logger, 1290 EXPECT_CALL(metric_logger,
1196 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_RECEIVED)); 1291 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_RECEIVED));
1197 EXPECT_CALL(metric_logger, 1292 EXPECT_CALL(metric_logger,
1198 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_PARSED)); 1293 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_PARSED));
(...skipping 363 matching lines...)
1562 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); 1657 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
1563 autofill_manager_->OnDidFillAutofillFormData( 1658 autofill_manager_->OnDidFillAutofillFormData(
1564 TimeTicks::FromInternalValue(5)); 1659 TimeTicks::FromInternalValue(5));
1565 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 1660 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1566 TimeTicks::FromInternalValue(3)); 1661 TimeTicks::FromInternalValue(3));
1567 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); 1662 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17));
1568 autofill_manager_->Reset(); 1663 autofill_manager_->Reset();
1569 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); 1664 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1570 } 1665 }
1571 } 1666 }
OLDNEW

Powered by Google App Engine