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

Side by Side Diff: components/autofill/content/browser/autofill_driver_impl_unittest.cc

Issue 17450010: Create AutofillDriverImpl unit test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase after 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <algorithm>
6 #include <vector>
7
8 #include "base/memory/scoped_ptr.h"
9 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
10 #include "components/autofill/content/browser/autofill_driver_impl.h"
11 #include "components/autofill/core/browser/autofill_external_delegate.h"
12 #include "components/autofill/core/browser/autofill_manager.h"
13 #include "components/autofill/core/browser/test_autofill_manager_delegate.h"
14 #include "content/public/browser/navigation_details.h"
15 #include "content/public/browser/web_contents.h"
16 #include "content/public/common/frame_navigate_params.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20 namespace autofill {
21
22 namespace {
23
24 const std::string kAppLocale = "en-US";
25 const AutofillManager::AutofillDownloadManagerState kDownloadState =
26 AutofillManager::DISABLE_AUTOFILL_DOWNLOAD_MANAGER;
27
28 } // namespace
29
30 class MockAutofillManager : public AutofillManager {
31 public:
32 MockAutofillManager(AutofillDriver* driver,
33 AutofillManagerDelegate* delegate)
34 : AutofillManager(driver, delegate, kAppLocale, kDownloadState) {
35 }
36 virtual ~MockAutofillManager() {}
37
38 MOCK_METHOD0(Reset, void());
39 };
40
41 class TestAutofillDriverImpl : public AutofillDriverImpl {
42 public:
43 TestAutofillDriverImpl(content::WebContents* contents,
44 AutofillManagerDelegate* delegate)
45 : AutofillDriverImpl(contents, delegate, kAppLocale, kDownloadState) {
46 scoped_ptr<AutofillManager> autofill_manager(
47 new MockAutofillManager(this, delegate));
48 SetAutofillManager(autofill_manager.Pass());
49 }
50 virtual ~TestAutofillDriverImpl() {}
51
52 virtual MockAutofillManager* mock_autofill_manager() {
53 return static_cast<MockAutofillManager*>(autofill_manager());
54 }
55
56 using AutofillDriverImpl::DidNavigateMainFrame;
57 };
58
59 class AutofillDriverImplTest : public ChromeRenderViewHostTestHarness {
60 public:
61 virtual void SetUp() OVERRIDE {
62 ChromeRenderViewHostTestHarness::SetUp();
63
64 test_manager_delegate_.reset(new TestAutofillManagerDelegate());
65 driver_.reset(new TestAutofillDriverImpl(web_contents(),
66 test_manager_delegate_.get()));
67 }
68
69 virtual void TearDown() OVERRIDE {
70 // Reset the driver now to cause all pref observers to be removed and avoid
71 // crashes that otherwise occur in the destructor.
72 driver_.reset();
73 ChromeRenderViewHostTestHarness::TearDown();
74 }
75
76 protected:
77 scoped_ptr<TestAutofillManagerDelegate> test_manager_delegate_;
78 scoped_ptr<TestAutofillDriverImpl> driver_;
79 };
80
81 TEST_F(AutofillDriverImplTest, NavigatedToDifferentPage) {
82 EXPECT_CALL(*driver_->mock_autofill_manager(), Reset());
83 content::LoadCommittedDetails details = content::LoadCommittedDetails();
84 details.is_main_frame = true;
85 details.is_in_page = false;
86 ASSERT_TRUE(details.is_navigation_to_different_page());
87 content::FrameNavigateParams params = content::FrameNavigateParams();
88 driver_->DidNavigateMainFrame(details, params);
89 }
90
91 TEST_F(AutofillDriverImplTest, NavigatedWithinSamePage) {
92 EXPECT_CALL(*driver_->mock_autofill_manager(), Reset()).Times(0);
93 content::LoadCommittedDetails details = content::LoadCommittedDetails();
94 details.is_main_frame = false;
95 ASSERT_TRUE(!details.is_navigation_to_different_page());
96 content::FrameNavigateParams params = content::FrameNavigateParams();
97 driver_->DidNavigateMainFrame(details, params);
98 }
99
100 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/content/browser/autofill_driver_impl.cc ('k') | components/autofill/core/browser/autofill_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698