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

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

Issue 14197014: Add TestBrowserThreadBundle into RenderViewHostTestHarness. Kill some unnecessary real threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address jyasskin's comments\ Created 7 years, 7 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/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
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 profile->CreateRequestContext(); 281 profile->CreateRequestContext();
299 browser_context_.reset(profile); 282 browser_context_.reset(profile);
300 PersonalDataManagerFactory::GetInstance()->SetTestingFactory( profile, NULL); 283 PersonalDataManagerFactory::GetInstance()->SetTestingFactory( profile, NULL);
301 284
302 ChromeRenderViewHostTestHarness::SetUp(); 285 ChromeRenderViewHostTestHarness::SetUp();
303 io_thread_.StartIOThread();
304 TabAutofillManagerDelegate::CreateForWebContents(web_contents()); 286 TabAutofillManagerDelegate::CreateForWebContents(web_contents());
305 287
306 personal_data_.reset(new TestPersonalDataManager()); 288 personal_data_.reset(new TestPersonalDataManager());
307 personal_data_->SetBrowserContext(profile); 289 personal_data_->SetBrowserContext(profile);
308 autofill_manager_.reset(new TestAutofillManager( 290 autofill_manager_.reset(new TestAutofillManager(
309 web_contents(), 291 web_contents(),
310 TabAutofillManagerDelegate::FromWebContents(web_contents()), 292 TabAutofillManagerDelegate::FromWebContents(web_contents()),
311 personal_data_.get())); 293 personal_data_.get()));
312
313 file_thread_.Start();
314 } 294 }
315 295
316 void AutofillMetricsTest::TearDown() { 296 void AutofillMetricsTest::TearDown() {
317 // Order of destruction is important as AutofillManager relies on 297 // Order of destruction is important as AutofillManager relies on
318 // PersonalDataManager to be around when it gets destroyed. Also, a real 298 // PersonalDataManager to be around when it gets destroyed. Also, a real
319 // AutofillManager is tied to the lifetime of the WebContents, so it must 299 // AutofillManager is tied to the lifetime of the WebContents, so it must
320 // be destroyed at the destruction of the WebContents. 300 // be destroyed at the destruction of the WebContents.
321 autofill_manager_.reset(); 301 autofill_manager_.reset();
322 personal_data_.reset(); 302 personal_data_.reset();
323 profile()->ResetRequestContext(); 303 profile()->ResetRequestContext();
324 file_thread_.Stop();
325 ChromeRenderViewHostTestHarness::TearDown(); 304 ChromeRenderViewHostTestHarness::TearDown();
326 io_thread_.Stop();
327 } 305 }
328 306
329 scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate( 307 scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate(
330 MockAutofillMetrics* metric_logger) { 308 MockAutofillMetrics* metric_logger) {
331 EXPECT_CALL(*metric_logger, 309 EXPECT_CALL(*metric_logger,
332 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); 310 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN));
333 311
334 CreditCard credit_card; 312 CreditCard credit_card;
335 return AutofillCCInfoBarDelegate::CreateForTesting( 313 return AutofillCCInfoBarDelegate::CreateForTesting(
336 metric_logger, 314 metric_logger,
(...skipping 1227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 TimeTicks::FromInternalValue(5)); 1542 TimeTicks::FromInternalValue(5));
1565 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 1543 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1566 TimeTicks::FromInternalValue(3)); 1544 TimeTicks::FromInternalValue(3));
1567 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); 1545 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17));
1568 autofill_manager_->Reset(); 1546 autofill_manager_->Reset();
1569 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); 1547 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1570 } 1548 }
1571 } 1549 }
1572 1550
1573 } // namespace autofill 1551 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698