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