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

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: Addressed Albert's comments 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
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/autofill_cc_infobar_delegate.h" 11 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h"
12 #include "chrome/browser/autofill/autofill_common_test.h" 12 #include "chrome/browser/autofill/autofill_common_test.h"
13 #include "chrome/browser/autofill/autofill_flow_infobar_delegate.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(LogAutofillFlowInfoBarMetric, 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 if (!did_finish_async_form_submit_) { 224 if (!did_finish_async_form_submit_) {
222 // TODO(isherman): It seems silly to need this variable. Is there some 225 // TODO(isherman): It seems silly to need this variable. Is there some
223 // way I can just query the message loop's state? 226 // way I can just query the message loop's state?
224 message_loop_is_running_ = true; 227 message_loop_is_running_ = true;
225 MessageLoop::current()->Run(); 228 MessageLoop::current()->Run();
226 } else { 229 } else {
227 did_finish_async_form_submit_ = false; 230 did_finish_async_form_submit_ = false;
228 } 231 }
229 } 232 }
230 233
234 void ShowAutofillFlowDialog(const FormData& form,
235 const GURL& frame_url,
236 const content::SSLStatus& ssl_status) {
Ilya Sherman 2013/01/15 06:31:52 nit: virtual and OVERRIDE
Raman Kakilate 2013/01/15 23:02:33 Done.
237 // no-op. Just used as callback into autofill_flow_infobar_delegate.
Ilya Sherman 2013/01/15 06:31:52 nit: "into" -> "from"
Raman Kakilate 2013/01/15 23:02:33 Done.
238 }
239
231 virtual void UploadFormDataAsyncCallback( 240 virtual void UploadFormDataAsyncCallback(
232 const FormStructure* submitted_form, 241 const FormStructure* submitted_form,
233 const base::TimeTicks& load_time, 242 const base::TimeTicks& load_time,
234 const base::TimeTicks& interaction_time, 243 const base::TimeTicks& interaction_time,
235 const base::TimeTicks& submission_time) OVERRIDE { 244 const base::TimeTicks& submission_time) OVERRIDE {
236 if (message_loop_is_running_) { 245 if (message_loop_is_running_) {
237 MessageLoop::current()->Quit(); 246 MessageLoop::current()->Quit();
238 message_loop_is_running_ = false; 247 message_loop_is_running_ = false;
239 } else { 248 } else {
240 did_finish_async_form_submit_ = true; 249 did_finish_async_form_submit_ = true;
(...skipping 24 matching lines...) Expand all
265 virtual ~AutofillMetricsTest(); 274 virtual ~AutofillMetricsTest();
266 275
267 virtual void SetUp() OVERRIDE; 276 virtual void SetUp() OVERRIDE;
268 virtual void TearDown() OVERRIDE; 277 virtual void TearDown() OVERRIDE;
269 278
270 protected: 279 protected:
271 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate( 280 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate(
272 MockAutofillMetrics* metric_logger, 281 MockAutofillMetrics* metric_logger,
273 CreditCard** created_card); 282 CreditCard** created_card);
274 283
284 scoped_ptr<ConfirmInfoBarDelegate> CreateAutofillFlowDelegate(
285 MockAutofillMetrics* metric_logger);
286
275 content::TestBrowserThread ui_thread_; 287 content::TestBrowserThread ui_thread_;
276 content::TestBrowserThread file_thread_; 288 content::TestBrowserThread file_thread_;
277 289
278 scoped_refptr<TestAutofillManager> autofill_manager_; 290 scoped_refptr<TestAutofillManager> autofill_manager_;
279 TestPersonalDataManager personal_data_; 291 TestPersonalDataManager personal_data_;
280 292
281 private: 293 private:
282 std::string default_gmock_verbosity_level_; 294 std::string default_gmock_verbosity_level_;
283 295
284 DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest); 296 DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 EXPECT_CALL(*metric_logger, 352 EXPECT_CALL(*metric_logger,
341 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); 353 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN));
342 // The delegate created below will take ownership of this object. 354 // The delegate created below will take ownership of this object.
343 CreditCard* credit_card = new CreditCard(); 355 CreditCard* credit_card = new CreditCard();
344 if (created_card) 356 if (created_card)
345 *created_card = credit_card; 357 *created_card = credit_card;
346 return AutofillCCInfoBarDelegate::Create(credit_card, &personal_data_, 358 return AutofillCCInfoBarDelegate::Create(credit_card, &personal_data_,
347 metric_logger); 359 metric_logger);
348 } 360 }
349 361
362 scoped_ptr<ConfirmInfoBarDelegate>
363 AutofillMetricsTest::CreateAutofillFlowDelegate(
364 MockAutofillMetrics* metric_logger) {
365 EXPECT_CALL(*metric_logger,
366 LogAutofillFlowInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN));
367 GURL url("www.google.com");
368 content::SSLStatus ssl_status;
369 return AutofillFlowInfoBarDelegate::Create(autofill_manager_.get(),
370 metric_logger,
371 url,
372 ssl_status);
373 }
374
350 // Test that we log quality metrics appropriately. 375 // Test that we log quality metrics appropriately.
351 TEST_F(AutofillMetricsTest, QualityMetrics) { 376 TEST_F(AutofillMetricsTest, QualityMetrics) {
352 // Set up our form data. 377 // Set up our form data.
353 FormData form; 378 FormData form;
354 form.name = ASCIIToUTF16("TestForm"); 379 form.name = ASCIIToUTF16("TestForm");
355 form.method = ASCIIToUTF16("POST"); 380 form.method = ASCIIToUTF16("POST");
356 form.origin = GURL("http://example.com/form.html"); 381 form.origin = GURL("http://example.com/form.html");
357 form.action = GURL("http://example.com/submit.html"); 382 form.action = GURL("http://example.com/submit.html");
358 form.user_submitted = true; 383 form.user_submitted = true;
359 384
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 // Ignore the infobar. 1204 // Ignore the infobar.
1180 { 1205 {
1181 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger, 1206 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger,
1182 NULL)); 1207 NULL));
1183 ASSERT_TRUE(infobar); 1208 ASSERT_TRUE(infobar);
1184 EXPECT_CALL(metric_logger, 1209 EXPECT_CALL(metric_logger,
1185 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(1); 1210 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(1);
1186 } 1211 }
1187 } 1212 }
1188 1213
1214 // Test that autofill flow infobar metrics are logged correctly.
1215 TEST_F(AutofillMetricsTest, AutofillFlowInfoBar) {
1216 MockAutofillMetrics metric_logger;
1217 ::testing::InSequence dummy;
1218
1219 // Accept the infobar.
1220 {
1221 scoped_ptr<ConfirmInfoBarDelegate> infobar(
1222 CreateAutofillFlowDelegate(&metric_logger));
1223 ASSERT_TRUE(infobar);
1224 EXPECT_CALL(metric_logger,
1225 LogAutofillFlowInfoBarMetric(
1226 AutofillMetrics::INFOBAR_ACCEPTED)).Times(1);
1227 EXPECT_CALL(metric_logger,
1228 LogAutofillFlowInfoBarMetric(
1229 AutofillMetrics::INFOBAR_IGNORED)).Times(0);
1230 EXPECT_TRUE(infobar->Accept());
1231 }
1232
1233 // Cancel the infobar.
1234 {
1235 scoped_ptr<ConfirmInfoBarDelegate> infobar(
1236 CreateAutofillFlowDelegate(&metric_logger));
1237 ASSERT_TRUE(infobar);
1238 EXPECT_CALL(metric_logger,
1239 LogAutofillFlowInfoBarMetric(
1240 AutofillMetrics::INFOBAR_DENIED)).Times(1);
1241 EXPECT_CALL(metric_logger,
1242 LogAutofillFlowInfoBarMetric(
1243 AutofillMetrics::INFOBAR_IGNORED)).Times(0);
1244 EXPECT_TRUE(infobar->Cancel());
1245 }
1246
1247 // Dismiss the infobar.
1248 {
1249 scoped_ptr<ConfirmInfoBarDelegate> infobar(
1250 CreateAutofillFlowDelegate(&metric_logger));
1251 ASSERT_TRUE(infobar);
1252 EXPECT_CALL(metric_logger,
1253 LogAutofillFlowInfoBarMetric(
1254 AutofillMetrics::INFOBAR_DENIED)).Times(1);
1255 EXPECT_CALL(metric_logger,
1256 LogAutofillFlowInfoBarMetric(
1257 AutofillMetrics::INFOBAR_IGNORED)).Times(0);
1258 infobar->InfoBarDismissed();
1259 }
1260
1261 // Ignore the infobar.
1262 {
1263 scoped_ptr<ConfirmInfoBarDelegate> infobar(
1264 CreateAutofillFlowDelegate(&metric_logger));
1265 ASSERT_TRUE(infobar);
1266 EXPECT_CALL(metric_logger,
1267 LogAutofillFlowInfoBarMetric(
1268 AutofillMetrics::INFOBAR_IGNORED)).Times(1);
1269 }
1270 }
1271
1272
1189 // Test that server query response experiment id metrics are logged correctly. 1273 // Test that server query response experiment id metrics are logged correctly.
1190 TEST_F(AutofillMetricsTest, ServerQueryExperimentIdForQuery) { 1274 TEST_F(AutofillMetricsTest, ServerQueryExperimentIdForQuery) {
1191 MockAutofillMetrics metric_logger; 1275 MockAutofillMetrics metric_logger;
1192 ::testing::InSequence dummy; 1276 ::testing::InSequence dummy;
1193 1277
1194 // No experiment specified. 1278 // No experiment specified.
1195 EXPECT_CALL(metric_logger, 1279 EXPECT_CALL(metric_logger,
1196 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_RECEIVED)); 1280 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_RECEIVED));
1197 EXPECT_CALL(metric_logger, 1281 EXPECT_CALL(metric_logger,
1198 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_PARSED)); 1282 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_PARSED));
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1562 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); 1646 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
1563 autofill_manager_->OnDidFillAutofillFormData( 1647 autofill_manager_->OnDidFillAutofillFormData(
1564 TimeTicks::FromInternalValue(5)); 1648 TimeTicks::FromInternalValue(5));
1565 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 1649 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1566 TimeTicks::FromInternalValue(3)); 1650 TimeTicks::FromInternalValue(3));
1567 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); 1651 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17));
1568 autofill_manager_->Reset(); 1652 autofill_manager_->Reset();
1569 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); 1653 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1570 } 1654 }
1571 } 1655 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698