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

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

Issue 11867025: Download autocheckout whitelist and enable autocheckout for whitelisted sites only. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix memory leak in AutofillMetricsTest. Created 7 years, 10 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"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 profiles->push_back(profile); 140 profiles->push_back(profile);
141 } 141 }
142 142
143 bool autofill_enabled_; 143 bool autofill_enabled_;
144 144
145 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); 145 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager);
146 }; 146 };
147 147
148 class TestFormStructure : public FormStructure { 148 class TestFormStructure : public FormStructure {
149 public: 149 public:
150 explicit TestFormStructure(const FormData& form) : FormStructure(form) {} 150 explicit TestFormStructure(const FormData& form)
151 : FormStructure(form, false) {}
151 virtual ~TestFormStructure() {} 152 virtual ~TestFormStructure() {}
152 153
153 void SetFieldTypes(const std::vector<AutofillFieldType>& heuristic_types, 154 void SetFieldTypes(const std::vector<AutofillFieldType>& heuristic_types,
154 const std::vector<AutofillFieldType>& server_types) { 155 const std::vector<AutofillFieldType>& server_types) {
155 ASSERT_EQ(field_count(), heuristic_types.size()); 156 ASSERT_EQ(field_count(), heuristic_types.size());
156 ASSERT_EQ(field_count(), server_types.size()); 157 ASSERT_EQ(field_count(), server_types.size());
157 158
158 for (size_t i = 0; i < field_count(); ++i) { 159 for (size_t i = 0; i < field_count(); ++i) {
159 AutofillField* form_field = field(i); 160 AutofillField* form_field = field(i);
160 ASSERT_TRUE(form_field); 161 ASSERT_TRUE(form_field);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 protected: 293 protected:
293 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate( 294 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate(
294 MockAutofillMetrics* metric_logger, 295 MockAutofillMetrics* metric_logger,
295 CreditCard** created_card); 296 CreditCard** created_card);
296 297
297 scoped_ptr<ConfirmInfoBarDelegate> CreateAutocheckoutDelegate( 298 scoped_ptr<ConfirmInfoBarDelegate> CreateAutocheckoutDelegate(
298 MockAutofillMetrics* metric_logger); 299 MockAutofillMetrics* metric_logger);
299 300
300 content::TestBrowserThread ui_thread_; 301 content::TestBrowserThread ui_thread_;
301 content::TestBrowserThread file_thread_; 302 content::TestBrowserThread file_thread_;
303 content::TestBrowserThread io_thread_;
302 304
303 scoped_refptr<TestAutofillManager> autofill_manager_; 305 scoped_refptr<TestAutofillManager> autofill_manager_;
304 TestAutocheckoutManager autocheckout_manager_; 306 TestAutocheckoutManager autocheckout_manager_;
305 TestPersonalDataManager personal_data_; 307 TestPersonalDataManager personal_data_;
306 308
307 private: 309 private:
308 std::string default_gmock_verbosity_level_; 310 std::string default_gmock_verbosity_level_;
309 311
310 DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest); 312 DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest);
311 }; 313 };
312 314
313 AutofillMetricsTest::AutofillMetricsTest() 315 AutofillMetricsTest::AutofillMetricsTest()
314 : ChromeRenderViewHostTestHarness(), 316 : ChromeRenderViewHostTestHarness(),
315 ui_thread_(BrowserThread::UI, &message_loop_), 317 ui_thread_(BrowserThread::UI, &message_loop_),
316 file_thread_(BrowserThread::FILE), 318 file_thread_(BrowserThread::FILE),
319 io_thread_(BrowserThread::IO),
317 autocheckout_manager_(NULL) { 320 autocheckout_manager_(NULL) {
318 } 321 }
319 322
320 AutofillMetricsTest::~AutofillMetricsTest() { 323 AutofillMetricsTest::~AutofillMetricsTest() {
321 // Order of destruction is important as AutofillManager relies on 324 // Order of destruction is important as AutofillManager relies on
322 // PersonalDataManager to be around when it gets destroyed. 325 // PersonalDataManager to be around when it gets destroyed.
323 autofill_manager_ = NULL; 326 autofill_manager_ = NULL;
324 } 327 }
325 328
326 void AutofillMetricsTest::SetUp() { 329 void AutofillMetricsTest::SetUp() {
327 Profile* profile = new TestingProfile(); 330 TestingProfile* profile = new TestingProfile();
331 profile->CreateRequestContext();
328 browser_context_.reset(profile); 332 browser_context_.reset(profile);
329 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile, NULL); 333 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile, NULL);
330 334
331 ChromeRenderViewHostTestHarness::SetUp(); 335 ChromeRenderViewHostTestHarness::SetUp();
336 io_thread_.StartIOThread();
332 TabAutofillManagerDelegate::CreateForWebContents(web_contents()); 337 TabAutofillManagerDelegate::CreateForWebContents(web_contents());
333 personal_data_.SetBrowserContext(profile); 338 personal_data_.SetBrowserContext(profile);
334 autofill_manager_ = new TestAutofillManager( 339 autofill_manager_ = new TestAutofillManager(
335 web_contents(), 340 web_contents(),
336 TabAutofillManagerDelegate::FromWebContents(web_contents()), 341 TabAutofillManagerDelegate::FromWebContents(web_contents()),
337 &personal_data_); 342 &personal_data_);
338 343
339 file_thread_.Start(); 344 file_thread_.Start();
340 345
341 // Ignore any metrics that we haven't explicitly set expectations for. 346 // Ignore any metrics that we haven't explicitly set expectations for.
342 // If we don't override the verbosity level, we'll get lots of log spew from 347 // If we don't override the verbosity level, we'll get lots of log spew from
343 // mocked functions that aren't relevant to a test but happen to be called 348 // mocked functions that aren't relevant to a test but happen to be called
344 // during the test's execution. 349 // during the test's execution.
345 // CAUTION: This is a global variable. So as to not affect other tests, this 350 // CAUTION: This is a global variable. So as to not affect other tests, this
346 // _must_ be restored to its original value at the end of the test. 351 // _must_ be restored to its original value at the end of the test.
347 default_gmock_verbosity_level_ = ::testing::FLAGS_gmock_verbose; 352 default_gmock_verbosity_level_ = ::testing::FLAGS_gmock_verbose;
348 ::testing::FLAGS_gmock_verbose = "error"; 353 ::testing::FLAGS_gmock_verbose = "error";
349 } 354 }
350 355
351 void AutofillMetricsTest::TearDown() { 356 void AutofillMetricsTest::TearDown() {
352 // Restore the global Gmock verbosity level to its default value. 357 // Restore the global Gmock verbosity level to its default value.
353 ::testing::FLAGS_gmock_verbose = default_gmock_verbosity_level_; 358 ::testing::FLAGS_gmock_verbose = default_gmock_verbosity_level_;
354 359
355 // Order of destruction is important as AutofillManager relies on 360 // Order of destruction is important as AutofillManager relies on
356 // PersonalDataManager to be around when it gets destroyed. Also, a real 361 // PersonalDataManager to be around when it gets destroyed. Also, a real
357 // AutofillManager is tied to the lifetime of the WebContents, so it must 362 // AutofillManager is tied to the lifetime of the WebContents, so it must
358 // be destroyed at the destruction of the WebContents. 363 // be destroyed at the destruction of the WebContents.
359 autofill_manager_ = NULL; 364 autofill_manager_ = NULL;
365 profile()->ResetRequestContext();
360 file_thread_.Stop(); 366 file_thread_.Stop();
361 ChromeRenderViewHostTestHarness::TearDown(); 367 ChromeRenderViewHostTestHarness::TearDown();
368 io_thread_.Stop();
362 } 369 }
363 370
364 scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate( 371 scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate(
365 MockAutofillMetrics* metric_logger, 372 MockAutofillMetrics* metric_logger,
366 CreditCard** created_card) { 373 CreditCard** created_card) {
367 EXPECT_CALL(*metric_logger, 374 EXPECT_CALL(*metric_logger,
368 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); 375 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN));
369 // The delegate created below will take ownership of this object. 376 // The delegate created below will take ownership of this object.
370 CreditCard* credit_card = new CreditCard(); 377 CreditCard* credit_card = new CreditCard();
371 if (created_card) 378 if (created_card)
(...skipping 1290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1662 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); 1669 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
1663 autofill_manager_->OnDidFillAutofillFormData( 1670 autofill_manager_->OnDidFillAutofillFormData(
1664 TimeTicks::FromInternalValue(5)); 1671 TimeTicks::FromInternalValue(5));
1665 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 1672 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1666 TimeTicks::FromInternalValue(3)); 1673 TimeTicks::FromInternalValue(3));
1667 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); 1674 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17));
1668 autofill_manager_->Reset(); 1675 autofill_manager_->Reset();
1669 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); 1676 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1670 } 1677 }
1671 } 1678 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698