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

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

Issue 11185011: Remove TabContents from autofill unittests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove some Created 8 years, 2 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"
11 #include "chrome/browser/api/infobars/infobar_service.h" 11 #include "chrome/browser/api/infobars/infobar_service.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/autofill_common_test.h" 13 #include "chrome/browser/autofill/autofill_common_test.h"
14 #include "chrome/browser/autofill/autofill_manager.h" 14 #include "chrome/browser/autofill/autofill_manager.h"
15 #include "chrome/browser/autofill/autofill_manager_delegate.h" 15 #include "chrome/browser/autofill/autofill_manager_delegate.h"
16 #include "chrome/browser/autofill/autofill_metrics.h" 16 #include "chrome/browser/autofill/autofill_metrics.h"
17 #include "chrome/browser/autofill/personal_data_manager.h" 17 #include "chrome/browser/autofill/personal_data_manager.h"
18 #include "chrome/browser/autofill/personal_data_manager_factory.h" 18 #include "chrome/browser/autofill/personal_data_manager_factory.h"
19 #include "chrome/browser/infobars/infobar_tab_helper.h"
19 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" 20 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h"
20 #include "chrome/browser/ui/tab_contents/tab_contents.h"
21 #include "chrome/browser/ui/tab_contents/test_tab_contents.h"
22 #include "chrome/browser/webdata/web_data_service.h" 21 #include "chrome/browser/webdata/web_data_service.h"
23 #include "chrome/common/form_data.h" 22 #include "chrome/common/form_data.h"
24 #include "chrome/common/form_field_data.h" 23 #include "chrome/common/form_field_data.h"
24 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
25 #include "chrome/test/base/testing_profile.h" 25 #include "chrome/test/base/testing_profile.h"
26 #include "content/public/test/test_browser_thread.h" 26 #include "content/public/test/test_browser_thread.h"
27 #include "testing/gmock/include/gmock/gmock.h" 27 #include "testing/gmock/include/gmock/gmock.h"
28 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
29 #include "ui/gfx/rect.h" 29 #include "ui/gfx/rect.h"
30 30
31 using content::BrowserThread; 31 using content::BrowserThread;
32 using ::testing::_; 32 using ::testing::_;
33 using ::testing::AnyNumber; 33 using ::testing::AnyNumber;
34 using ::testing::Mock; 34 using ::testing::Mock;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 248
249 bool autofill_enabled_; 249 bool autofill_enabled_;
250 bool did_finish_async_form_submit_; 250 bool did_finish_async_form_submit_;
251 bool message_loop_is_running_; 251 bool message_loop_is_running_;
252 252
253 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); 253 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager);
254 }; 254 };
255 255
256 } // namespace 256 } // namespace
257 257
258 class AutofillMetricsTest : public TabContentsTestHarness { 258 class AutofillMetricsTest : public ChromeRenderViewHostTestHarness {
259 public: 259 public:
260 AutofillMetricsTest(); 260 AutofillMetricsTest();
261 virtual ~AutofillMetricsTest(); 261 virtual ~AutofillMetricsTest();
262 262
263 virtual void SetUp() OVERRIDE; 263 virtual void SetUp() OVERRIDE;
264 virtual void TearDown() OVERRIDE; 264 virtual void TearDown() OVERRIDE;
265 265
266 protected: 266 protected:
267 AutofillCCInfoBarDelegate* CreateDelegate(MockAutofillMetrics* metric_logger, 267 AutofillCCInfoBarDelegate* CreateDelegate(MockAutofillMetrics* metric_logger,
268 CreditCard** created_card); 268 CreditCard** created_card);
269 269
270 content::TestBrowserThread ui_thread_; 270 content::TestBrowserThread ui_thread_;
271 content::TestBrowserThread file_thread_; 271 content::TestBrowserThread file_thread_;
272 272
273 scoped_refptr<TestAutofillManager> autofill_manager_; 273 scoped_refptr<TestAutofillManager> autofill_manager_;
274 TestPersonalDataManager personal_data_; 274 TestPersonalDataManager personal_data_;
275 275
276 private: 276 private:
277 DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest); 277 DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest);
278 }; 278 };
279 279
280 AutofillMetricsTest::AutofillMetricsTest() 280 AutofillMetricsTest::AutofillMetricsTest()
281 : TabContentsTestHarness(), 281 : ChromeRenderViewHostTestHarness(),
282 ui_thread_(BrowserThread::UI, &message_loop_), 282 ui_thread_(BrowserThread::UI, &message_loop_),
283 file_thread_(BrowserThread::FILE) { 283 file_thread_(BrowserThread::FILE) {
284 } 284 }
285 285
286 AutofillMetricsTest::~AutofillMetricsTest() { 286 AutofillMetricsTest::~AutofillMetricsTest() {
287 // Order of destruction is important as AutofillManager relies on 287 // Order of destruction is important as AutofillManager relies on
288 // PersonalDataManager to be around when it gets destroyed. 288 // PersonalDataManager to be around when it gets destroyed.
289 autofill_manager_ = NULL; 289 autofill_manager_ = NULL;
290 } 290 }
291 291
292 void AutofillMetricsTest::SetUp() { 292 void AutofillMetricsTest::SetUp() {
293 Profile* profile = new TestingProfile(); 293 Profile* profile = new TestingProfile();
294 browser_context_.reset(profile); 294 browser_context_.reset(profile);
295 PersonalDataManagerFactory::GetInstance()->SetTestingFactory( 295 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile, NULL);
296 profile, NULL);
297 296
298 TabContentsTestHarness::SetUp(); 297 ChromeRenderViewHostTestHarness::SetUp();
299 TabAutofillManagerDelegate::CreateForWebContents(web_contents()); 298 TabAutofillManagerDelegate::CreateForWebContents(web_contents());
300 autofill_manager_ = new TestAutofillManager( 299 autofill_manager_ = new TestAutofillManager(
301 web_contents(), 300 web_contents(),
302 TabAutofillManagerDelegate::FromWebContents(web_contents()), 301 TabAutofillManagerDelegate::FromWebContents(web_contents()),
303 &personal_data_); 302 &personal_data_);
304 303
305 file_thread_.Start(); 304 file_thread_.Start();
306 } 305 }
307 306
308 void AutofillMetricsTest::TearDown() { 307 void AutofillMetricsTest::TearDown() {
309 file_thread_.Stop(); 308 file_thread_.Stop();
310 TabContentsTestHarness::TearDown(); 309 ChromeRenderViewHostTestHarness::TearDown();
311 } 310 }
312 311
313 AutofillCCInfoBarDelegate* AutofillMetricsTest::CreateDelegate( 312 AutofillCCInfoBarDelegate* AutofillMetricsTest::CreateDelegate(
314 MockAutofillMetrics* metric_logger, 313 MockAutofillMetrics* metric_logger,
315 CreditCard** created_card) { 314 CreditCard** created_card) {
316 EXPECT_CALL(*metric_logger, 315 EXPECT_CALL(*metric_logger,
317 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); 316 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN));
318 // The delegate created below will take ownership of this object. 317 // The delegate created below will take ownership of this object.
319 CreditCard* credit_card = new CreditCard(); 318 CreditCard* credit_card = new CreditCard();
320 if (created_card) 319 if (created_card)
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 // Establish our expectations. 1031 // Establish our expectations.
1033 EXPECT_CALL(*autofill_manager_->metric_logger(), 1032 EXPECT_CALL(*autofill_manager_->metric_logger(),
1034 LogIsAutofillEnabledAtPageLoad(false)).Times(1); 1033 LogIsAutofillEnabledAtPageLoad(false)).Times(1);
1035 1034
1036 autofill_manager_->set_autofill_enabled(false); 1035 autofill_manager_->set_autofill_enabled(false);
1037 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks()); 1036 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks());
1038 } 1037 }
1039 1038
1040 // Test that credit card infobar metrics are logged correctly. 1039 // Test that credit card infobar metrics are logged correctly.
1041 TEST_F(AutofillMetricsTest, CreditCardInfoBar) { 1040 TEST_F(AutofillMetricsTest, CreditCardInfoBar) {
1041 InfoBarTabHelper::CreateForWebContents(web_contents());
1042
1042 MockAutofillMetrics metric_logger; 1043 MockAutofillMetrics metric_logger;
1043 ::testing::InSequence dummy; 1044 ::testing::InSequence dummy;
1044 1045
1045 // Accept the infobar. 1046 // Accept the infobar.
1046 { 1047 {
1047 CreditCard* credit_card; 1048 CreditCard* credit_card;
1048 scoped_ptr<InfoBarDelegate> infobar(CreateDelegate(&metric_logger, 1049 scoped_ptr<InfoBarDelegate> infobar(CreateDelegate(&metric_logger,
1049 &credit_card)); 1050 &credit_card));
1050 EXPECT_CALL(personal_data_, SaveImportedCreditCard(*credit_card)); 1051 EXPECT_CALL(personal_data_, SaveImportedCreditCard(*credit_card));
1051 EXPECT_CALL(metric_logger, 1052 EXPECT_CALL(metric_logger,
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 1467 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1467 TimeTicks::FromInternalValue(3)); 1468 TimeTicks::FromInternalValue(3));
1468 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); 1469 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17));
1469 autofill_manager_->Reset(); 1470 autofill_manager_->Reset();
1470 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); 1471 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1471 } 1472 }
1472 1473
1473 // Restore the global Gmock verbosity level to its default value. 1474 // Restore the global Gmock verbosity level to its default value.
1474 ::testing::FLAGS_gmock_verbose = "warning"; 1475 ::testing::FLAGS_gmock_verbose = "warning";
1475 } 1476 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698