OLD | NEW |
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/bind.h" |
7 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
8 #include "base/string16.h" | 9 #include "base/string16.h" |
9 #include "base/time.h" | 10 #include "base/time.h" |
10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/autofill/autocheckout_infobar_delegate.h" | 12 #include "chrome/browser/autofill/autocheckout_infobar_delegate.h" |
12 #include "chrome/browser/autofill/autocheckout_page_meta_data.h" | 13 #include "chrome/browser/autofill/autocheckout_page_meta_data.h" |
13 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" | 14 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" |
14 #include "chrome/browser/autofill/autofill_common_test.h" | 15 #include "chrome/browser/autofill/autofill_common_test.h" |
15 #include "chrome/browser/autofill/autofill_manager.h" | 16 #include "chrome/browser/autofill/autofill_manager.h" |
16 #include "chrome/browser/autofill/autofill_manager_delegate.h" | 17 #include "chrome/browser/autofill/autofill_manager_delegate.h" |
17 #include "chrome/browser/autofill/autofill_metrics.h" | 18 #include "chrome/browser/autofill/autofill_metrics.h" |
18 #include "chrome/browser/autofill/personal_data_manager.h" | 19 #include "chrome/browser/autofill/personal_data_manager.h" |
19 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 20 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 21 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
20 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" | 22 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" |
21 #include "chrome/browser/webdata/web_data_service.h" | 23 #include "chrome/browser/webdata/web_data_service.h" |
22 #include "chrome/common/form_data.h" | 24 #include "chrome/common/form_data.h" |
23 #include "chrome/common/form_field_data.h" | 25 #include "chrome/common/form_field_data.h" |
24 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 26 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
25 #include "chrome/test/base/testing_profile.h" | 27 #include "chrome/test/base/testing_profile.h" |
26 #include "content/public/test/test_browser_thread.h" | 28 #include "content/public/test/test_browser_thread.h" |
27 #include "googleurl/src/gurl.h" | 29 #include "googleurl/src/gurl.h" |
28 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
30 #include "ui/gfx/rect.h" | 32 #include "ui/gfx/rect.h" |
31 | 33 |
32 using content::BrowserThread; | 34 using content::BrowserThread; |
33 using ::testing::_; | 35 using ::testing::_; |
34 using ::testing::AnyNumber; | 36 using ::testing::AnyNumber; |
35 using ::testing::Mock; | 37 using ::testing::Mock; |
36 using base::TimeTicks; | 38 using base::TimeTicks; |
37 using base::TimeDelta; | 39 using base::TimeDelta; |
38 | 40 |
39 namespace { | 41 namespace { |
40 | 42 |
41 class MockAutofillMetrics : public AutofillMetrics { | 43 class MockAutofillMetrics : public AutofillMetrics { |
42 public: | 44 public: |
43 MockAutofillMetrics() {} | 45 MockAutofillMetrics() {} |
44 MOCK_CONST_METHOD1(LogCreditCardInfoBarMetric, void(InfoBarMetric metric)); | 46 MOCK_CONST_METHOD1(LogCreditCardInfoBarMetric, void(InfoBarMetric metric)); |
45 MOCK_CONST_METHOD1(LogAutocheckoutInfoBarMetric, void(InfoBarMetric metric)); | 47 MOCK_CONST_METHOD1(LogAutocheckoutInfoBarMetric, void(InfoBarMetric metric)); |
| 48 MOCK_CONST_METHOD3(LogRequestAutocompleteUiDuration, |
| 49 void(const TimeDelta& duration, |
| 50 autofill::DialogRequester requester, |
| 51 DialogDismissalAction dismissal_action)); |
46 MOCK_CONST_METHOD1(LogDeveloperEngagementMetric, | 52 MOCK_CONST_METHOD1(LogDeveloperEngagementMetric, |
47 void(DeveloperEngagementMetric metric)); | 53 void(DeveloperEngagementMetric metric)); |
48 MOCK_CONST_METHOD3(LogHeuristicTypePrediction, | 54 MOCK_CONST_METHOD3(LogHeuristicTypePrediction, |
49 void(FieldTypeQualityMetric metric, | 55 void(FieldTypeQualityMetric metric, |
50 AutofillFieldType field_type, | 56 AutofillFieldType field_type, |
51 const std::string& experiment_id)); | 57 const std::string& experiment_id)); |
52 MOCK_CONST_METHOD3(LogOverallTypePrediction, | 58 MOCK_CONST_METHOD3(LogOverallTypePrediction, |
53 void(FieldTypeQualityMetric metric, | 59 void(FieldTypeQualityMetric metric, |
54 AutofillFieldType field_type, | 60 AutofillFieldType field_type, |
55 const std::string& experiment_id)); | 61 const std::string& experiment_id)); |
(...skipping 26 matching lines...) Expand all Loading... |
82 DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics); | 88 DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics); |
83 }; | 89 }; |
84 | 90 |
85 class TestPersonalDataManager : public PersonalDataManager { | 91 class TestPersonalDataManager : public PersonalDataManager { |
86 public: | 92 public: |
87 TestPersonalDataManager() : autofill_enabled_(true) { | 93 TestPersonalDataManager() : autofill_enabled_(true) { |
88 set_metric_logger(new MockAutofillMetrics); | 94 set_metric_logger(new MockAutofillMetrics); |
89 CreateTestAutofillProfiles(&web_profiles_); | 95 CreateTestAutofillProfiles(&web_profiles_); |
90 } | 96 } |
91 | 97 |
| 98 static ProfileKeyedService* Build(Profile* profile) { |
| 99 return new TestPersonalDataManager(); |
| 100 } |
| 101 |
92 void SetBrowserContext(content::BrowserContext* context) { | 102 void SetBrowserContext(content::BrowserContext* context) { |
93 set_browser_context(context); | 103 set_browser_context(context); |
94 } | 104 } |
95 | 105 |
96 // Overridden to avoid a trip to the database. This should be a no-op except | 106 // Overridden to avoid a trip to the database. This should be a no-op except |
97 // for the side-effect of logging the profile count. | 107 // for the side-effect of logging the profile count. |
98 virtual void LoadProfiles() OVERRIDE { | 108 virtual void LoadProfiles() OVERRIDE { |
99 std::vector<AutofillProfile*> profiles; | 109 std::vector<AutofillProfile*> profiles; |
100 web_profiles_.release(&profiles); | 110 web_profiles_.release(&profiles); |
101 WDResult<std::vector<AutofillProfile*> > result(AUTOFILL_PROFILES_RESULT, | 111 WDResult<std::vector<AutofillProfile*> > result(AUTOFILL_PROFILES_RESULT, |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 // AutofillManager is ref counted. | 264 // AutofillManager is ref counted. |
255 virtual ~TestAutofillManager() {} | 265 virtual ~TestAutofillManager() {} |
256 | 266 |
257 bool autofill_enabled_; | 267 bool autofill_enabled_; |
258 bool did_finish_async_form_submit_; | 268 bool did_finish_async_form_submit_; |
259 bool message_loop_is_running_; | 269 bool message_loop_is_running_; |
260 | 270 |
261 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); | 271 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); |
262 }; | 272 }; |
263 | 273 |
264 class TestAutocheckoutManager : public AutocheckoutManager { | 274 class TestAutocheckoutManager : public autofill::AutocheckoutManager { |
265 public: | 275 public: |
266 explicit TestAutocheckoutManager(AutofillManager* autofill_manager) | 276 explicit TestAutocheckoutManager(AutofillManager* autofill_manager) |
267 : AutocheckoutManager(autofill_manager) { | 277 : AutocheckoutManager(autofill_manager) { |
268 } | 278 } |
269 | 279 |
270 virtual void ShowAutocheckoutDialog( | 280 virtual void ShowAutocheckoutDialog( |
271 const GURL& frame_url, | 281 const GURL& frame_url, |
272 const content::SSLStatus& ssl_status) OVERRIDE { | 282 const content::SSLStatus& ssl_status) OVERRIDE { |
273 // no-op. Just used as callback from autocheckout_infobar_delegate. | 283 // no-op. Just used as callback from autocheckout_infobar_delegate. |
274 } | 284 } |
275 | 285 |
276 virtual ~TestAutocheckoutManager() { | 286 virtual ~TestAutocheckoutManager() { |
277 } | 287 } |
278 | 288 |
279 private: | 289 private: |
280 DISALLOW_COPY_AND_ASSIGN(TestAutocheckoutManager); | 290 DISALLOW_COPY_AND_ASSIGN(TestAutocheckoutManager); |
281 }; | 291 }; |
282 | 292 |
| 293 void MockRequestAutocompleteDialogCallback(const FormStructure*) { |
| 294 } |
| 295 |
283 } // namespace | 296 } // namespace |
284 | 297 |
285 class AutofillMetricsTest : public ChromeRenderViewHostTestHarness { | 298 class AutofillMetricsTest : public ChromeRenderViewHostTestHarness { |
286 public: | 299 public: |
287 AutofillMetricsTest(); | 300 AutofillMetricsTest(); |
288 virtual ~AutofillMetricsTest(); | 301 virtual ~AutofillMetricsTest(); |
289 | 302 |
290 virtual void SetUp() OVERRIDE; | 303 virtual void SetUp() OVERRIDE; |
291 virtual void TearDown() OVERRIDE; | 304 virtual void TearDown() OVERRIDE; |
292 | 305 |
293 protected: | 306 protected: |
294 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate( | 307 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate( |
295 MockAutofillMetrics* metric_logger, | 308 MockAutofillMetrics* metric_logger, |
296 CreditCard** created_card); | 309 CreditCard** created_card); |
297 | 310 |
298 scoped_ptr<ConfirmInfoBarDelegate> CreateAutocheckoutDelegate( | 311 scoped_ptr<ConfirmInfoBarDelegate> CreateAutocheckoutDelegate( |
299 MockAutofillMetrics* metric_logger); | 312 MockAutofillMetrics* metric_logger); |
300 | 313 |
301 content::TestBrowserThread ui_thread_; | 314 content::TestBrowserThread ui_thread_; |
302 content::TestBrowserThread file_thread_; | 315 content::TestBrowserThread file_thread_; |
| 316 content::TestBrowserThread io_thread_; |
303 | 317 |
304 scoped_refptr<TestAutofillManager> autofill_manager_; | 318 scoped_refptr<TestAutofillManager> autofill_manager_; |
305 TestAutocheckoutManager autocheckout_manager_; | 319 TestAutocheckoutManager autocheckout_manager_; |
306 TestPersonalDataManager personal_data_; | 320 TestPersonalDataManager* personal_data_; |
307 | 321 |
308 private: | 322 private: |
309 std::string default_gmock_verbosity_level_; | 323 std::string default_gmock_verbosity_level_; |
310 | 324 |
311 DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest); | 325 DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest); |
312 }; | 326 }; |
313 | 327 |
314 AutofillMetricsTest::AutofillMetricsTest() | 328 AutofillMetricsTest::AutofillMetricsTest() |
315 : ChromeRenderViewHostTestHarness(), | 329 : ChromeRenderViewHostTestHarness(), |
316 ui_thread_(BrowserThread::UI, &message_loop_), | 330 ui_thread_(BrowserThread::UI, &message_loop_), |
317 file_thread_(BrowserThread::FILE), | 331 file_thread_(BrowserThread::FILE), |
| 332 io_thread_(BrowserThread::IO), |
318 autocheckout_manager_(NULL) { | 333 autocheckout_manager_(NULL) { |
319 } | 334 } |
320 | 335 |
321 AutofillMetricsTest::~AutofillMetricsTest() { | 336 AutofillMetricsTest::~AutofillMetricsTest() { |
322 // Order of destruction is important as AutofillManager relies on | 337 // Order of destruction is important as AutofillManager relies on |
323 // PersonalDataManager to be around when it gets destroyed. | 338 // PersonalDataManager to be around when it gets destroyed. |
324 autofill_manager_ = NULL; | 339 autofill_manager_ = NULL; |
325 } | 340 } |
326 | 341 |
327 void AutofillMetricsTest::SetUp() { | 342 void AutofillMetricsTest::SetUp() { |
328 Profile* profile = new TestingProfile(); | 343 TestingProfile* profile = new TestingProfile(); |
| 344 profile->CreateRequestContext(); |
329 browser_context_.reset(profile); | 345 browser_context_.reset(profile); |
330 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile, NULL); | 346 personal_data_ = |
| 347 static_cast<TestPersonalDataManager*>( |
| 348 PersonalDataManagerFactory::GetInstance()->SetTestingFactoryAndUse( |
| 349 profile, TestPersonalDataManager::Build)); |
331 | 350 |
332 ChromeRenderViewHostTestHarness::SetUp(); | 351 ChromeRenderViewHostTestHarness::SetUp(); |
333 TabAutofillManagerDelegate::CreateForWebContents(web_contents()); | 352 io_thread_.StartIOThread(); |
334 personal_data_.SetBrowserContext(profile); | 353 |
| 354 autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents()); |
| 355 personal_data_->SetBrowserContext(profile); |
335 autofill_manager_ = new TestAutofillManager( | 356 autofill_manager_ = new TestAutofillManager( |
336 web_contents(), | 357 web_contents(), |
337 TabAutofillManagerDelegate::FromWebContents(web_contents()), | 358 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents()), |
338 &personal_data_); | 359 personal_data_); |
339 | 360 |
340 file_thread_.Start(); | 361 file_thread_.Start(); |
341 | 362 |
342 // Ignore any metrics that we haven't explicitly set expectations for. | 363 // Ignore any metrics that we haven't explicitly set expectations for. |
343 // If we don't override the verbosity level, we'll get lots of log spew from | 364 // If we don't override the verbosity level, we'll get lots of log spew from |
344 // mocked functions that aren't relevant to a test but happen to be called | 365 // mocked functions that aren't relevant to a test but happen to be called |
345 // during the test's execution. | 366 // during the test's execution. |
346 // CAUTION: This is a global variable. So as to not affect other tests, this | 367 // CAUTION: This is a global variable. So as to not affect other tests, this |
347 // _must_ be restored to its original value at the end of the test. | 368 // _must_ be restored to its original value at the end of the test. |
348 default_gmock_verbosity_level_ = ::testing::FLAGS_gmock_verbose; | 369 default_gmock_verbosity_level_ = ::testing::FLAGS_gmock_verbose; |
349 ::testing::FLAGS_gmock_verbose = "error"; | 370 ::testing::FLAGS_gmock_verbose = "error"; |
350 } | 371 } |
351 | 372 |
352 void AutofillMetricsTest::TearDown() { | 373 void AutofillMetricsTest::TearDown() { |
353 // Restore the global Gmock verbosity level to its default value. | 374 // Restore the global Gmock verbosity level to its default value. |
354 ::testing::FLAGS_gmock_verbose = default_gmock_verbosity_level_; | 375 ::testing::FLAGS_gmock_verbose = default_gmock_verbosity_level_; |
355 | 376 |
356 // Order of destruction is important as AutofillManager relies on | 377 // Order of destruction is important as AutofillManager relies on |
357 // PersonalDataManager to be around when it gets destroyed. Also, a real | 378 // PersonalDataManager to be around when it gets destroyed. Also, a real |
358 // AutofillManager is tied to the lifetime of the WebContents, so it must | 379 // AutofillManager is tied to the lifetime of the WebContents, so it must |
359 // be destroyed at the destruction of the WebContents. | 380 // be destroyed at the destruction of the WebContents. |
360 autofill_manager_ = NULL; | 381 autofill_manager_ = NULL; |
361 file_thread_.Stop(); | 382 file_thread_.Stop(); |
| 383 |
| 384 profile()->ResetRequestContext(); |
362 ChromeRenderViewHostTestHarness::TearDown(); | 385 ChromeRenderViewHostTestHarness::TearDown(); |
| 386 io_thread_.Stop(); |
363 } | 387 } |
364 | 388 |
365 scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate( | 389 scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate( |
366 MockAutofillMetrics* metric_logger, | 390 MockAutofillMetrics* metric_logger, |
367 CreditCard** created_card) { | 391 CreditCard** created_card) { |
368 EXPECT_CALL(*metric_logger, | 392 EXPECT_CALL(*metric_logger, |
369 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); | 393 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); |
370 // The delegate created below will take ownership of this object. | 394 // The delegate created below will take ownership of this object. |
371 CreditCard* credit_card = new CreditCard(); | 395 CreditCard* credit_card = new CreditCard(); |
372 if (created_card) | 396 if (created_card) |
373 *created_card = credit_card; | 397 *created_card = credit_card; |
374 return AutofillCCInfoBarDelegate::Create(credit_card, &personal_data_, | 398 return AutofillCCInfoBarDelegate::Create(credit_card, personal_data_, |
375 metric_logger); | 399 metric_logger); |
376 } | 400 } |
377 | 401 |
378 scoped_ptr<ConfirmInfoBarDelegate> | 402 scoped_ptr<ConfirmInfoBarDelegate> |
379 AutofillMetricsTest::CreateAutocheckoutDelegate( | 403 AutofillMetricsTest::CreateAutocheckoutDelegate( |
380 MockAutofillMetrics* metric_logger) { | 404 MockAutofillMetrics* metric_logger) { |
381 EXPECT_CALL(*metric_logger, | 405 EXPECT_CALL(*metric_logger, |
382 LogAutocheckoutInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); | 406 LogAutocheckoutInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); |
383 GURL url("www.google.com"); | 407 GURL url("www.google.com"); |
384 content::SSLStatus ssl_status; | 408 content::SSLStatus ssl_status; |
385 return AutocheckoutInfoBarDelegate::Create( | 409 return autofill::AutocheckoutInfoBarDelegate::Create( |
386 *metric_logger, | 410 *metric_logger, |
387 url, | 411 url, |
388 ssl_status, | 412 ssl_status, |
389 &autocheckout_manager_); | 413 &autocheckout_manager_); |
390 } | 414 } |
391 | 415 |
392 // Test that we log quality metrics appropriately. | 416 // Test that we log quality metrics appropriately. |
393 TEST_F(AutofillMetricsTest, QualityMetrics) { | 417 TEST_F(AutofillMetricsTest, QualityMetrics) { |
394 // Set up our form data. | 418 // Set up our form data. |
395 FormData form; | 419 FormData form; |
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1053 ADDRESS_HOME_COUNTRY, experiment_id)); | 1077 ADDRESS_HOME_COUNTRY, experiment_id)); |
1054 | 1078 |
1055 // Simulate form submission. | 1079 // Simulate form submission. |
1056 EXPECT_NO_FATAL_FAILURE(autofill_manager_->FormSubmitted(form, | 1080 EXPECT_NO_FATAL_FAILURE(autofill_manager_->FormSubmitted(form, |
1057 TimeTicks::Now())); | 1081 TimeTicks::Now())); |
1058 } | 1082 } |
1059 | 1083 |
1060 // Test that the profile count is logged correctly. | 1084 // Test that the profile count is logged correctly. |
1061 TEST_F(AutofillMetricsTest, StoredProfileCount) { | 1085 TEST_F(AutofillMetricsTest, StoredProfileCount) { |
1062 // The metric should be logged when the profiles are first loaded. | 1086 // The metric should be logged when the profiles are first loaded. |
1063 EXPECT_CALL(*personal_data_.metric_logger(), | 1087 EXPECT_CALL(*personal_data_->metric_logger(), |
1064 LogStoredProfileCount(2)).Times(1); | 1088 LogStoredProfileCount(2)).Times(1); |
1065 personal_data_.LoadProfiles(); | 1089 personal_data_->LoadProfiles(); |
1066 | 1090 |
1067 // The metric should only be logged once. | 1091 // The metric should only be logged once. |
1068 EXPECT_CALL(*personal_data_.metric_logger(), | 1092 EXPECT_CALL(*personal_data_->metric_logger(), |
1069 LogStoredProfileCount(::testing::_)).Times(0); | 1093 LogStoredProfileCount(::testing::_)).Times(0); |
1070 personal_data_.LoadProfiles(); | 1094 personal_data_->LoadProfiles(); |
1071 } | 1095 } |
1072 | 1096 |
1073 // Test that we correctly log whether Autofill is enabled. | 1097 // Test that we correctly log whether Autofill is enabled. |
1074 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtStartup) { | 1098 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtStartup) { |
1075 personal_data_.set_autofill_enabled(true); | 1099 personal_data_->set_autofill_enabled(true); |
1076 EXPECT_CALL(*personal_data_.metric_logger(), | 1100 EXPECT_CALL(*personal_data_->metric_logger(), |
1077 LogIsAutofillEnabledAtStartup(true)).Times(1); | 1101 LogIsAutofillEnabledAtStartup(true)).Times(1); |
1078 personal_data_.Init(profile()); | 1102 personal_data_->Init(profile()); |
1079 personal_data_.Shutdown(); | 1103 personal_data_->Shutdown(); |
1080 | 1104 |
1081 personal_data_.set_autofill_enabled(false); | 1105 personal_data_->set_autofill_enabled(false); |
1082 EXPECT_CALL(*personal_data_.metric_logger(), | 1106 EXPECT_CALL(*personal_data_->metric_logger(), |
1083 LogIsAutofillEnabledAtStartup(false)).Times(1); | 1107 LogIsAutofillEnabledAtStartup(false)).Times(1); |
1084 personal_data_.Init(profile()); | 1108 personal_data_->Init(profile()); |
1085 } | 1109 } |
1086 | 1110 |
1087 // Test that we log the number of Autofill suggestions when filling a form. | 1111 // Test that we log the number of Autofill suggestions when filling a form. |
1088 TEST_F(AutofillMetricsTest, AddressSuggestionsCount) { | 1112 TEST_F(AutofillMetricsTest, AddressSuggestionsCount) { |
1089 // Set up our form data. | 1113 // Set up our form data. |
1090 FormData form; | 1114 FormData form; |
1091 form.name = ASCIIToUTF16("TestForm"); | 1115 form.name = ASCIIToUTF16("TestForm"); |
1092 form.method = ASCIIToUTF16("POST"); | 1116 form.method = ASCIIToUTF16("POST"); |
1093 form.origin = GURL("http://example.com/form.html"); | 1117 form.origin = GURL("http://example.com/form.html"); |
1094 form.action = GURL("http://example.com/submit.html"); | 1118 form.action = GURL("http://example.com/submit.html"); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1179 TEST_F(AutofillMetricsTest, CreditCardInfoBar) { | 1203 TEST_F(AutofillMetricsTest, CreditCardInfoBar) { |
1180 MockAutofillMetrics metric_logger; | 1204 MockAutofillMetrics metric_logger; |
1181 ::testing::InSequence dummy; | 1205 ::testing::InSequence dummy; |
1182 | 1206 |
1183 // Accept the infobar. | 1207 // Accept the infobar. |
1184 { | 1208 { |
1185 CreditCard* credit_card; | 1209 CreditCard* credit_card; |
1186 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger, | 1210 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger, |
1187 &credit_card)); | 1211 &credit_card)); |
1188 ASSERT_TRUE(infobar); | 1212 ASSERT_TRUE(infobar); |
1189 EXPECT_CALL(personal_data_, SaveImportedCreditCard(*credit_card)); | 1213 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(*credit_card)); |
1190 EXPECT_CALL(metric_logger, | 1214 EXPECT_CALL(metric_logger, |
1191 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED)).Times(1); | 1215 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED)).Times(1); |
1192 EXPECT_CALL(metric_logger, | 1216 EXPECT_CALL(metric_logger, |
1193 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0); | 1217 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0); |
1194 EXPECT_TRUE(infobar->Accept()); | 1218 EXPECT_TRUE(infobar->Accept()); |
1195 } | 1219 } |
1196 | 1220 |
1197 // Cancel the infobar. | 1221 // Cancel the infobar. |
1198 { | 1222 { |
1199 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger, | 1223 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1279 { | 1303 { |
1280 scoped_ptr<ConfirmInfoBarDelegate> infobar( | 1304 scoped_ptr<ConfirmInfoBarDelegate> infobar( |
1281 CreateAutocheckoutDelegate(&metric_logger)); | 1305 CreateAutocheckoutDelegate(&metric_logger)); |
1282 ASSERT_TRUE(infobar); | 1306 ASSERT_TRUE(infobar); |
1283 EXPECT_CALL(metric_logger, | 1307 EXPECT_CALL(metric_logger, |
1284 LogAutocheckoutInfoBarMetric( | 1308 LogAutocheckoutInfoBarMetric( |
1285 AutofillMetrics::INFOBAR_IGNORED)).Times(1); | 1309 AutofillMetrics::INFOBAR_IGNORED)).Times(1); |
1286 } | 1310 } |
1287 } | 1311 } |
1288 | 1312 |
| 1313 // TODO(isherman): Enable this test on other platforms once the UI is |
| 1314 // implemented on those platforms. |
| 1315 #if defined(TOOLKIT_VIEWS) |
| 1316 TEST_F(AutofillMetricsTest, RequestAutocompleteUiDuration) { |
| 1317 MockAutofillMetrics metric_logger; |
| 1318 ::testing::InSequence dummy; |
| 1319 |
| 1320 FormData form; |
| 1321 form.name = ASCIIToUTF16("TestForm"); |
| 1322 form.method = ASCIIToUTF16("POST"); |
| 1323 form.origin = GURL("http://example.com/form.html"); |
| 1324 form.action = GURL("http://example.com/submit.html"); |
| 1325 form.user_submitted = true; |
| 1326 |
| 1327 FormFieldData field; |
| 1328 field.autocomplete_attribute = "email"; |
| 1329 form.fields.push_back(field); |
| 1330 |
| 1331 // Submit the form data. |
| 1332 { |
| 1333 EXPECT_CALL(metric_logger, |
| 1334 LogRequestAutocompleteUiDuration( |
| 1335 _, |
| 1336 autofill::DIALOG_REQUESTER_REQUEST_AUTOCOMPLETE, |
| 1337 AutofillMetrics::DIALOG_ACCEPTED)).Times(1); |
| 1338 |
| 1339 autofill::AutofillDialogControllerImpl* dialog_controller = |
| 1340 new autofill::AutofillDialogControllerImpl( |
| 1341 web_contents(), form, GURL(), content::SSLStatus(), |
| 1342 metric_logger, |
| 1343 autofill::DIALOG_REQUESTER_REQUEST_AUTOCOMPLETE, |
| 1344 base::Bind(&MockRequestAutocompleteDialogCallback)); |
| 1345 dialog_controller->Show(); |
| 1346 dialog_controller->ViewClosed(autofill::ACTION_SUBMIT); |
| 1347 } |
| 1348 |
| 1349 // Cancel out of the dialog. |
| 1350 { |
| 1351 EXPECT_CALL(metric_logger, |
| 1352 LogRequestAutocompleteUiDuration( |
| 1353 _, autofill::DIALOG_REQUESTER_AUTOCHECKOUT, |
| 1354 AutofillMetrics::DIALOG_CANCELED)).Times(1); |
| 1355 |
| 1356 autofill::AutofillDialogControllerImpl* dialog_controller = |
| 1357 new autofill::AutofillDialogControllerImpl( |
| 1358 web_contents(), form, GURL(), content::SSLStatus(), |
| 1359 metric_logger, autofill::DIALOG_REQUESTER_AUTOCHECKOUT, |
| 1360 base::Bind(&MockRequestAutocompleteDialogCallback)); |
| 1361 dialog_controller->Show(); |
| 1362 dialog_controller->ViewClosed(autofill::ACTION_ABORT); |
| 1363 } |
| 1364 |
| 1365 // Take some other action that dismisses the dialog. |
| 1366 { |
| 1367 EXPECT_CALL(metric_logger, |
| 1368 LogRequestAutocompleteUiDuration( |
| 1369 _, |
| 1370 autofill::DIALOG_REQUESTER_AUTOCHECKOUT, |
| 1371 AutofillMetrics::DIALOG_CANCELED)).Times(1); |
| 1372 |
| 1373 autofill::AutofillDialogControllerImpl* dialog_controller = |
| 1374 new autofill::AutofillDialogControllerImpl( |
| 1375 web_contents(), form, GURL(), content::SSLStatus(), |
| 1376 metric_logger, autofill::DIALOG_REQUESTER_AUTOCHECKOUT, |
| 1377 base::Bind(&MockRequestAutocompleteDialogCallback)); |
| 1378 dialog_controller->Show(); |
| 1379 dialog_controller->Hide(); |
| 1380 } |
| 1381 } |
| 1382 #endif // defined(TOOLKIT_VIEWS) |
1289 | 1383 |
1290 // Test that server query response experiment id metrics are logged correctly. | 1384 // Test that server query response experiment id metrics are logged correctly. |
1291 TEST_F(AutofillMetricsTest, ServerQueryExperimentIdForQuery) { | 1385 TEST_F(AutofillMetricsTest, ServerQueryExperimentIdForQuery) { |
1292 MockAutofillMetrics metric_logger; | 1386 MockAutofillMetrics metric_logger; |
1293 ::testing::InSequence dummy; | 1387 ::testing::InSequence dummy; |
1294 | 1388 |
1295 // No experiment specified. | 1389 // No experiment specified. |
1296 EXPECT_CALL(metric_logger, | 1390 EXPECT_CALL(metric_logger, |
1297 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_RECEIVED)); | 1391 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_RECEIVED)); |
1298 EXPECT_CALL(metric_logger, | 1392 EXPECT_CALL(metric_logger, |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1668 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); | 1762 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); |
1669 autofill_manager_->OnDidFillAutofillFormData( | 1763 autofill_manager_->OnDidFillAutofillFormData( |
1670 TimeTicks::FromInternalValue(5)); | 1764 TimeTicks::FromInternalValue(5)); |
1671 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), | 1765 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), |
1672 TimeTicks::FromInternalValue(3)); | 1766 TimeTicks::FromInternalValue(3)); |
1673 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); | 1767 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); |
1674 autofill_manager_->Reset(); | 1768 autofill_manager_->Reset(); |
1675 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); | 1769 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); |
1676 } | 1770 } |
1677 } | 1771 } |
OLD | NEW |