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

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

Issue 16286020: Abstract WebContentsObserver from Autofill shared code (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase to fix conflict Created 7 years, 6 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
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/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/time.h" 11 #include "base/time.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/autofill_common_test.h" 17 #include "components/autofill/browser/autofill_common_test.h"
18 #include "components/autofill/browser/autofill_manager.h" 18 #include "components/autofill/browser/autofill_manager.h"
19 #include "components/autofill/browser/autofill_manager_delegate.h" 19 #include "components/autofill/browser/autofill_manager_delegate.h"
20 #include "components/autofill/browser/autofill_metrics.h" 20 #include "components/autofill/browser/autofill_metrics.h"
21 #include "components/autofill/browser/personal_data_manager.h" 21 #include "components/autofill/browser/personal_data_manager.h"
22 #include "components/autofill/common/form_data.h" 22 #include "components/autofill/common/form_data.h"
23 #include "components/autofill/common/form_field_data.h" 23 #include "components/autofill/common/form_field_data.h"
24 #include "components/autofill/common/forms_seen_state.h" 24 #include "components/autofill/common/forms_seen_state.h"
25 #include "components/autofill/browser/test_autofill_driver.h"
25 #include "components/autofill/content/browser/autocheckout_page_meta_data.h" 26 #include "components/autofill/content/browser/autocheckout_page_meta_data.h"
26 #include "components/webdata/common/web_data_results.h" 27 #include "components/webdata/common/web_data_results.h"
27 #include "content/public/test/test_utils.h" 28 #include "content/public/test/test_utils.h"
28 #include "googleurl/src/gurl.h" 29 #include "googleurl/src/gurl.h"
29 #include "testing/gmock/include/gmock/gmock.h" 30 #include "testing/gmock/include/gmock/gmock.h"
30 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
31 #include "ui/gfx/rect.h" 32 #include "ui/gfx/rect.h"
32 33
33 using base::TimeDelta; 34 using base::TimeDelta;
34 using base::TimeTicks; 35 using base::TimeTicks;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 server_experiment_id_ = server_experiment_id; 178 server_experiment_id_ = server_experiment_id;
178 } 179 }
179 180
180 private: 181 private:
181 std::string server_experiment_id_; 182 std::string server_experiment_id_;
182 DISALLOW_COPY_AND_ASSIGN(TestFormStructure); 183 DISALLOW_COPY_AND_ASSIGN(TestFormStructure);
183 }; 184 };
184 185
185 class TestAutofillManager : public AutofillManager { 186 class TestAutofillManager : public AutofillManager {
186 public: 187 public:
187 TestAutofillManager(content::WebContents* web_contents, 188 TestAutofillManager(AutofillDriver* driver,
188 AutofillManagerDelegate* manager_delegate, 189 AutofillManagerDelegate* manager_delegate,
189 TestPersonalDataManager* personal_manager) 190 TestPersonalDataManager* personal_manager)
190 : AutofillManager(web_contents, manager_delegate, personal_manager), 191 : AutofillManager(driver, manager_delegate, personal_manager),
191 autofill_enabled_(true) { 192 autofill_enabled_(true) {
192 set_metric_logger(new testing::NiceMock<MockAutofillMetrics>); 193 set_metric_logger(new testing::NiceMock<MockAutofillMetrics>);
193 } 194 }
194 virtual ~TestAutofillManager() {} 195 virtual ~TestAutofillManager() {}
195 196
196 virtual std::string GetAutocheckoutURLPrefix() const OVERRIDE { 197 virtual std::string GetAutocheckoutURLPrefix() const OVERRIDE {
197 return std::string(); 198 return std::string();
198 } 199 }
199 200
200 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; } 201 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 public: 260 public:
260 virtual ~AutofillMetricsTest(); 261 virtual ~AutofillMetricsTest();
261 262
262 virtual void SetUp() OVERRIDE; 263 virtual void SetUp() OVERRIDE;
263 virtual void TearDown() OVERRIDE; 264 virtual void TearDown() OVERRIDE;
264 265
265 protected: 266 protected:
266 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate( 267 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate(
267 MockAutofillMetrics* metric_logger); 268 MockAutofillMetrics* metric_logger);
268 269
270 scoped_ptr<TestAutofillDriver> autofill_driver_;
269 scoped_ptr<TestAutofillManager> autofill_manager_; 271 scoped_ptr<TestAutofillManager> autofill_manager_;
270 scoped_ptr<TestPersonalDataManager> personal_data_; 272 scoped_ptr<TestPersonalDataManager> personal_data_;
271 }; 273 };
272 274
273 AutofillMetricsTest::~AutofillMetricsTest() { 275 AutofillMetricsTest::~AutofillMetricsTest() {
274 // Order of destruction is important as AutofillManager relies on 276 // Order of destruction is important as AutofillManager relies on
275 // PersonalDataManager to be around when it gets destroyed. 277 // PersonalDataManager to be around when it gets destroyed.
276 autofill_manager_.reset(); 278 autofill_manager_.reset();
277 } 279 }
278 280
279 void AutofillMetricsTest::SetUp() { 281 void AutofillMetricsTest::SetUp() {
280 TestingProfile* profile = new TestingProfile(); 282 TestingProfile* profile = new TestingProfile();
281 283
282 // Ensure Mac OS X does not pop up a modal dialog for the Address Book. 284 // Ensure Mac OS X does not pop up a modal dialog for the Address Book.
283 autofill::test::DisableSystemServices(profile); 285 autofill::test::DisableSystemServices(profile);
284 286
285 profile->CreateRequestContext(); 287 profile->CreateRequestContext();
286 browser_context_.reset(profile); 288 browser_context_.reset(profile);
287 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile, NULL); 289 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile, NULL);
288 290
289 ChromeRenderViewHostTestHarness::SetUp(); 291 ChromeRenderViewHostTestHarness::SetUp();
290 TabAutofillManagerDelegate::CreateForWebContents(web_contents()); 292 TabAutofillManagerDelegate::CreateForWebContents(web_contents());
291 293
292 personal_data_.reset(new TestPersonalDataManager()); 294 personal_data_.reset(new TestPersonalDataManager());
293 personal_data_->SetBrowserContext(profile); 295 personal_data_->SetBrowserContext(profile);
296 autofill_driver_.reset(new TestAutofillDriver(web_contents()));
294 autofill_manager_.reset(new TestAutofillManager( 297 autofill_manager_.reset(new TestAutofillManager(
295 web_contents(), 298 autofill_driver_.get(),
296 TabAutofillManagerDelegate::FromWebContents(web_contents()), 299 TabAutofillManagerDelegate::FromWebContents(web_contents()),
297 personal_data_.get())); 300 personal_data_.get()));
298 } 301 }
299 302
300 void AutofillMetricsTest::TearDown() { 303 void AutofillMetricsTest::TearDown() {
301 // Order of destruction is important as AutofillManager relies on 304 // Order of destruction is important as AutofillManager relies on
302 // PersonalDataManager to be around when it gets destroyed. Also, a real 305 // PersonalDataManager to be around when it gets destroyed. Also, a real
303 // AutofillManager is tied to the lifetime of the WebContents, so it must 306 // AutofillManager is tied to the lifetime of the WebContents, so it must
304 // be destroyed at the destruction of the WebContents. 307 // be destroyed at the destruction of the WebContents.
305 autofill_manager_.reset(); 308 autofill_manager_.reset();
309 autofill_driver_.reset();
306 personal_data_.reset(); 310 personal_data_.reset();
307 profile()->ResetRequestContext(); 311 profile()->ResetRequestContext();
308 ChromeRenderViewHostTestHarness::TearDown(); 312 ChromeRenderViewHostTestHarness::TearDown();
309 } 313 }
310 314
311 scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate( 315 scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate(
312 MockAutofillMetrics* metric_logger) { 316 MockAutofillMetrics* metric_logger) {
313 EXPECT_CALL(*metric_logger, 317 EXPECT_CALL(*metric_logger,
314 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); 318 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN));
315 319
(...skipping 1230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1546 TimeTicks::FromInternalValue(5)); 1550 TimeTicks::FromInternalValue(5));
1547 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 1551 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1548 TimeTicks::FromInternalValue(3)); 1552 TimeTicks::FromInternalValue(3));
1549 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); 1553 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17));
1550 autofill_manager_->Reset(); 1554 autofill_manager_->Reset();
1551 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); 1555 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1552 } 1556 }
1553 } 1557 }
1554 1558
1555 } // namespace autofill 1559 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/browser/autofill_manager_unittest.cc ('k') | components/autofill/browser/test_autofill_driver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698