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

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

Powered by Google App Engine
This is Rietveld 408576698