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/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/string16.h" | 9 #include "base/string16.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" | 12 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" |
13 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 13 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
14 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" | 14 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" |
15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
17 #include "components/autofill/browser/autocheckout_page_meta_data.h" | 17 #include "components/autofill/browser/autocheckout_page_meta_data.h" |
18 #include "components/autofill/browser/autofill_common_test.h" | 18 #include "components/autofill/browser/autofill_common_test.h" |
19 #include "components/autofill/browser/autofill_manager.h" | 19 #include "components/autofill/browser/autofill_manager.h" |
20 #include "components/autofill/browser/autofill_manager_delegate.h" | 20 #include "components/autofill/browser/autofill_manager_delegate.h" |
21 #include "components/autofill/browser/autofill_metrics.h" | 21 #include "components/autofill/browser/autofill_metrics.h" |
22 #include "components/autofill/browser/personal_data_manager.h" | 22 #include "components/autofill/browser/personal_data_manager.h" |
23 #include "components/autofill/common/form_data.h" | 23 #include "components/autofill/common/form_data.h" |
24 #include "components/autofill/common/form_field_data.h" | 24 #include "components/autofill/common/form_field_data.h" |
25 #include "components/autofill/common/forms_seen_state.h" | 25 #include "components/autofill/common/forms_seen_state.h" |
26 #include "components/webdata/common/web_data_results.h" | 26 #include "components/webdata/common/web_data_results.h" |
27 #include "content/public/test/test_browser_thread.h" | |
28 #include "content/public/test/test_utils.h" | 27 #include "content/public/test/test_utils.h" |
29 #include "googleurl/src/gurl.h" | 28 #include "googleurl/src/gurl.h" |
30 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
32 #include "ui/gfx/rect.h" | 31 #include "ui/gfx/rect.h" |
33 | 32 |
34 using content::BrowserThread; | 33 using base::TimeDelta; |
35 using ::testing::_; | |
36 using ::testing::AnyNumber; | |
37 using ::testing::Mock; | |
38 using base::TimeTicks; | 34 using base::TimeTicks; |
39 using base::TimeDelta; | 35 using testing::_; |
| 36 using testing::AnyNumber; |
| 37 using testing::Mock; |
40 | 38 |
41 namespace autofill { | 39 namespace autofill { |
42 | 40 |
43 namespace { | 41 namespace { |
44 | 42 |
45 class MockAutofillMetrics : public AutofillMetrics { | 43 class MockAutofillMetrics : public AutofillMetrics { |
46 public: | 44 public: |
47 MockAutofillMetrics() {} | 45 MockAutofillMetrics() {} |
48 MOCK_CONST_METHOD1(LogCreditCardInfoBarMetric, void(InfoBarMetric metric)); | 46 MOCK_CONST_METHOD1(LogCreditCardInfoBarMetric, void(InfoBarMetric metric)); |
49 MOCK_CONST_METHOD1(LogDeveloperEngagementMetric, | 47 MOCK_CONST_METHOD1(LogDeveloperEngagementMetric, |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 bool autofill_enabled_; | 250 bool autofill_enabled_; |
253 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 251 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
254 | 252 |
255 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); | 253 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); |
256 }; | 254 }; |
257 | 255 |
258 } // namespace | 256 } // namespace |
259 | 257 |
260 class AutofillMetricsTest : public ChromeRenderViewHostTestHarness { | 258 class AutofillMetricsTest : public ChromeRenderViewHostTestHarness { |
261 public: | 259 public: |
262 AutofillMetricsTest(); | |
263 virtual ~AutofillMetricsTest(); | 260 virtual ~AutofillMetricsTest(); |
264 | 261 |
265 virtual void SetUp() OVERRIDE; | 262 virtual void SetUp() OVERRIDE; |
266 virtual void TearDown() OVERRIDE; | 263 virtual void TearDown() OVERRIDE; |
267 | 264 |
268 protected: | 265 protected: |
269 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate( | 266 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate( |
270 MockAutofillMetrics* metric_logger); | 267 MockAutofillMetrics* metric_logger); |
271 | 268 |
272 content::TestBrowserThread ui_thread_; | |
273 content::TestBrowserThread file_thread_; | |
274 content::TestBrowserThread io_thread_; | |
275 | |
276 scoped_ptr<TestAutofillManager> autofill_manager_; | 269 scoped_ptr<TestAutofillManager> autofill_manager_; |
277 scoped_ptr<TestPersonalDataManager> personal_data_; | 270 scoped_ptr<TestPersonalDataManager> personal_data_; |
278 | |
279 private: | |
280 DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest); | |
281 }; | 271 }; |
282 | 272 |
283 AutofillMetricsTest::AutofillMetricsTest() | |
284 : ChromeRenderViewHostTestHarness(), | |
285 ui_thread_(BrowserThread::UI, &message_loop_), | |
286 file_thread_(BrowserThread::FILE), | |
287 io_thread_(BrowserThread::IO) { | |
288 } | |
289 | |
290 AutofillMetricsTest::~AutofillMetricsTest() { | 273 AutofillMetricsTest::~AutofillMetricsTest() { |
291 // Order of destruction is important as AutofillManager relies on | 274 // Order of destruction is important as AutofillManager relies on |
292 // PersonalDataManager to be around when it gets destroyed. | 275 // PersonalDataManager to be around when it gets destroyed. |
293 autofill_manager_.reset(); | 276 autofill_manager_.reset(); |
294 } | 277 } |
295 | 278 |
296 void AutofillMetricsTest::SetUp() { | 279 void AutofillMetricsTest::SetUp() { |
297 TestingProfile* profile = new TestingProfile(); | 280 TestingProfile* profile = new TestingProfile(); |
298 | 281 |
299 // Ensure Mac OS X does not pop up a modal dialog for the Address Book. | 282 // Ensure Mac OS X does not pop up a modal dialog for the Address Book. |
300 autofill::test::DisableSystemServices(profile); | 283 autofill::test::DisableSystemServices(profile); |
301 | 284 |
302 profile->CreateRequestContext(); | 285 profile->CreateRequestContext(); |
303 browser_context_.reset(profile); | 286 browser_context_.reset(profile); |
304 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile, NULL); | 287 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile, NULL); |
305 | 288 |
306 ChromeRenderViewHostTestHarness::SetUp(); | 289 ChromeRenderViewHostTestHarness::SetUp(); |
307 io_thread_.StartIOThread(); | |
308 TabAutofillManagerDelegate::CreateForWebContents(web_contents()); | 290 TabAutofillManagerDelegate::CreateForWebContents(web_contents()); |
309 | 291 |
310 personal_data_.reset(new TestPersonalDataManager()); | 292 personal_data_.reset(new TestPersonalDataManager()); |
311 personal_data_->SetBrowserContext(profile); | 293 personal_data_->SetBrowserContext(profile); |
312 autofill_manager_.reset(new TestAutofillManager( | 294 autofill_manager_.reset(new TestAutofillManager( |
313 web_contents(), | 295 web_contents(), |
314 TabAutofillManagerDelegate::FromWebContents(web_contents()), | 296 TabAutofillManagerDelegate::FromWebContents(web_contents()), |
315 personal_data_.get())); | 297 personal_data_.get())); |
316 | |
317 file_thread_.Start(); | |
318 } | 298 } |
319 | 299 |
320 void AutofillMetricsTest::TearDown() { | 300 void AutofillMetricsTest::TearDown() { |
321 // Order of destruction is important as AutofillManager relies on | 301 // Order of destruction is important as AutofillManager relies on |
322 // PersonalDataManager to be around when it gets destroyed. Also, a real | 302 // PersonalDataManager to be around when it gets destroyed. Also, a real |
323 // AutofillManager is tied to the lifetime of the WebContents, so it must | 303 // AutofillManager is tied to the lifetime of the WebContents, so it must |
324 // be destroyed at the destruction of the WebContents. | 304 // be destroyed at the destruction of the WebContents. |
325 autofill_manager_.reset(); | 305 autofill_manager_.reset(); |
326 personal_data_.reset(); | 306 personal_data_.reset(); |
327 profile()->ResetRequestContext(); | 307 profile()->ResetRequestContext(); |
328 file_thread_.Stop(); | |
329 ChromeRenderViewHostTestHarness::TearDown(); | 308 ChromeRenderViewHostTestHarness::TearDown(); |
330 io_thread_.Stop(); | |
331 } | 309 } |
332 | 310 |
333 scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate( | 311 scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate( |
334 MockAutofillMetrics* metric_logger) { | 312 MockAutofillMetrics* metric_logger) { |
335 EXPECT_CALL(*metric_logger, | 313 EXPECT_CALL(*metric_logger, |
336 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); | 314 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); |
337 | 315 |
338 CreditCard credit_card; | 316 CreditCard credit_card; |
339 return AutofillCCInfoBarDelegate::CreateForTesting( | 317 return AutofillCCInfoBarDelegate::CreateForTesting( |
340 metric_logger, | 318 metric_logger, |
(...skipping 1227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1568 TimeTicks::FromInternalValue(5)); | 1546 TimeTicks::FromInternalValue(5)); |
1569 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), | 1547 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), |
1570 TimeTicks::FromInternalValue(3)); | 1548 TimeTicks::FromInternalValue(3)); |
1571 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); | 1549 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); |
1572 autofill_manager_->Reset(); | 1550 autofill_manager_->Reset(); |
1573 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); | 1551 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); |
1574 } | 1552 } |
1575 } | 1553 } |
1576 | 1554 |
1577 } // namespace autofill | 1555 } // namespace autofill |
OLD | NEW |