summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorblundell@chromium.org <blundell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-22 14:32:02 +0000
committerblundell@chromium.org <blundell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-22 14:32:02 +0000
commit992559a386c5dcbcb36e4e10c9a80281b2948a3c (patch)
tree040f67b47b38f69696f5bc1cfd4b676203be5cd2 /components
parentc87ae2fa721f9fcbe0f2e8a2f7cd0057835c4cf4 (diff)
downloadchromium_src-992559a386c5dcbcb36e4e10c9a80281b2948a3c.zip
chromium_src-992559a386c5dcbcb36e4e10c9a80281b2948a3c.tar.gz
chromium_src-992559a386c5dcbcb36e4e10c9a80281b2948a3c.tar.bz2
Create AutofillDriverImpl unit test.
The unit test is currently skeletal; future CLs will flesh it out. BUG=247015 Review URL: https://chromiumcodereview.appspot.com/17450010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@208039 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components')
-rw-r--r--components/autofill/content/browser/DEPS3
-rw-r--r--components/autofill/content/browser/autofill_driver_impl.cc55
-rw-r--r--components/autofill/content/browser/autofill_driver_impl.h11
-rw-r--r--components/autofill/content/browser/autofill_driver_impl_unittest.cc100
-rw-r--r--components/autofill/core/browser/autofill_manager.h4
5 files changed, 145 insertions, 28 deletions
diff --git a/components/autofill/content/browser/DEPS b/components/autofill/content/browser/DEPS
index 9da9e19..2924d7c 100644
--- a/components/autofill/content/browser/DEPS
+++ b/components/autofill/content/browser/DEPS
@@ -33,4 +33,7 @@ specific_include_rules = {
"!chrome/test/base/chrome_render_view_host_test_harness.h",
"!chrome/test/base/testing_profile.h",
],
+ 'autofill_driver_impl_unittest.cc': [
+ "!chrome/test/base/chrome_render_view_host_test_harness.h",
+ ],
}
diff --git a/components/autofill/content/browser/autofill_driver_impl.cc b/components/autofill/content/browser/autofill_driver_impl.cc
index d0bae53..095822c 100644
--- a/components/autofill/content/browser/autofill_driver_impl.cc
+++ b/components/autofill/content/browser/autofill_driver_impl.cc
@@ -56,9 +56,10 @@ AutofillDriverImpl::AutofillDriverImpl(
const std::string& app_locale,
AutofillManager::AutofillDownloadManagerState enable_download_manager)
: content::WebContentsObserver(web_contents),
- autofill_manager_(this, delegate, app_locale, enable_download_manager) {
+ autofill_manager_(new AutofillManager(
+ this, delegate, app_locale, enable_download_manager)) {
SetAutofillExternalDelegate(scoped_ptr<AutofillExternalDelegate>(
- new AutofillExternalDelegate(web_contents, &autofill_manager_)));
+ new AutofillExternalDelegate(web_contents, autofill_manager_.get())));
}
AutofillDriverImpl::~AutofillDriverImpl() {}
@@ -70,52 +71,54 @@ content::WebContents* AutofillDriverImpl::GetWebContents() {
bool AutofillDriverImpl::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(AutofillDriverImpl, message)
- IPC_MESSAGE_FORWARD(AutofillHostMsg_FormsSeen, &autofill_manager_,
+ IPC_MESSAGE_FORWARD(AutofillHostMsg_FormsSeen, autofill_manager_.get(),
AutofillManager::OnFormsSeen)
- IPC_MESSAGE_FORWARD(AutofillHostMsg_FormSubmitted, &autofill_manager_,
+ IPC_MESSAGE_FORWARD(AutofillHostMsg_FormSubmitted, autofill_manager_.get(),
AutofillManager::OnFormSubmitted)
- IPC_MESSAGE_FORWARD(AutofillHostMsg_TextFieldDidChange, &autofill_manager_,
+ IPC_MESSAGE_FORWARD(AutofillHostMsg_TextFieldDidChange,
+ autofill_manager_.get(),
AutofillManager::OnTextFieldDidChange)
IPC_MESSAGE_FORWARD(AutofillHostMsg_QueryFormFieldAutofill,
- &autofill_manager_,
+ autofill_manager_.get(),
AutofillManager::OnQueryFormFieldAutofill)
- IPC_MESSAGE_FORWARD(AutofillHostMsg_ShowAutofillDialog, &autofill_manager_,
+ IPC_MESSAGE_FORWARD(AutofillHostMsg_ShowAutofillDialog,
+ autofill_manager_.get(),
AutofillManager::OnShowAutofillDialog)
IPC_MESSAGE_FORWARD(AutofillHostMsg_FillAutofillFormData,
- &autofill_manager_,
+ autofill_manager_.get(),
AutofillManager::OnFillAutofillFormData)
IPC_MESSAGE_FORWARD(AutofillHostMsg_DidPreviewAutofillFormData,
- &autofill_manager_,
+ autofill_manager_.get(),
AutofillManager::OnDidPreviewAutofillFormData)
IPC_MESSAGE_FORWARD(AutofillHostMsg_DidFillAutofillFormData,
- &autofill_manager_,
+ autofill_manager_.get(),
AutofillManager::OnDidFillAutofillFormData)
IPC_MESSAGE_FORWARD(AutofillHostMsg_DidShowAutofillSuggestions,
- &autofill_manager_,
+ autofill_manager_.get(),
AutofillManager::OnDidShowAutofillSuggestions)
IPC_MESSAGE_FORWARD(AutofillHostMsg_DidEndTextFieldEditing,
- &autofill_manager_,
+ autofill_manager_.get(),
AutofillManager::OnDidEndTextFieldEditing)
- IPC_MESSAGE_FORWARD(AutofillHostMsg_HideAutofillUi, &autofill_manager_,
+ IPC_MESSAGE_FORWARD(AutofillHostMsg_HideAutofillUi, autofill_manager_.get(),
AutofillManager::OnHideAutofillUi)
IPC_MESSAGE_FORWARD(AutofillHostMsg_AddPasswordFormMapping,
- &autofill_manager_,
+ autofill_manager_.get(),
AutofillManager::OnAddPasswordFormMapping)
IPC_MESSAGE_FORWARD(AutofillHostMsg_ShowPasswordSuggestions,
- &autofill_manager_,
+ autofill_manager_.get(),
AutofillManager::OnShowPasswordSuggestions)
- IPC_MESSAGE_FORWARD(AutofillHostMsg_SetDataList, &autofill_manager_,
+ IPC_MESSAGE_FORWARD(AutofillHostMsg_SetDataList, autofill_manager_.get(),
AutofillManager::OnSetDataList)
IPC_MESSAGE_FORWARD(AutofillHostMsg_RequestAutocomplete,
- &autofill_manager_,
+ autofill_manager_.get(),
AutofillManager::OnRequestAutocomplete)
- IPC_MESSAGE_FORWARD(AutofillHostMsg_ClickFailed, &autofill_manager_,
+ IPC_MESSAGE_FORWARD(AutofillHostMsg_ClickFailed, autofill_manager_.get(),
AutofillManager::OnClickFailed)
IPC_MESSAGE_FORWARD(AutofillHostMsg_MaybeShowAutocheckoutBubble,
- &autofill_manager_,
+ autofill_manager_.get(),
AutofillManager::OnMaybeShowAutocheckoutBubble)
IPC_MESSAGE_FORWARD(AutofillHostMsg_RemoveAutocompleteEntry,
- &autofill_manager_,
+ autofill_manager_.get(),
AutofillManager::RemoveAutocompleteEntry)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
@@ -126,13 +129,19 @@ void AutofillDriverImpl::DidNavigateMainFrame(
const content::LoadCommittedDetails& details,
const content::FrameNavigateParams& params) {
if (details.is_navigation_to_different_page())
- autofill_manager_.Reset();
+ autofill_manager_->Reset();
}
void AutofillDriverImpl::SetAutofillExternalDelegate(
scoped_ptr<AutofillExternalDelegate> delegate) {
- autofill_external_delegate_.reset(delegate.release());
- autofill_manager_.SetExternalDelegate(autofill_external_delegate_.get());
+ autofill_external_delegate_ = delegate.Pass();
+ autofill_manager_->SetExternalDelegate(autofill_external_delegate_.get());
+}
+
+void AutofillDriverImpl::SetAutofillManager(
+ scoped_ptr<AutofillManager> manager) {
+ autofill_manager_ = manager.Pass();
+ autofill_manager_->SetExternalDelegate(autofill_external_delegate_.get());
}
} // namespace autofill
diff --git a/components/autofill/content/browser/autofill_driver_impl.h b/components/autofill/content/browser/autofill_driver_impl.h
index 6181b80..c8c852b 100644
--- a/components/autofill/content/browser/autofill_driver_impl.h
+++ b/components/autofill/content/browser/autofill_driver_impl.h
@@ -53,9 +53,9 @@ class AutofillDriverImpl : public AutofillDriver,
void SetAutofillExternalDelegate(
scoped_ptr<AutofillExternalDelegate> delegate);
- AutofillManager* autofill_manager() { return &autofill_manager_; }
+ AutofillManager* autofill_manager() { return autofill_manager_.get(); }
- private:
+ protected:
AutofillDriverImpl(
content::WebContents* web_contents,
autofill::AutofillManagerDelegate* delegate,
@@ -69,13 +69,18 @@ class AutofillDriverImpl : public AutofillDriver,
const content::FrameNavigateParams& params) OVERRIDE;
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
+ // Sets the manager to |manager| and sets |manager|'s external delegate
+ // to |autofill_external_delegate_|. Takes ownership of |manager|.
+ void SetAutofillManager(scoped_ptr<AutofillManager> manager);
+
+ private:
// AutofillExternalDelegate instance that this object instantiates in the
// case where the autofill native UI is enabled.
scoped_ptr<AutofillExternalDelegate> autofill_external_delegate_;
// AutofillManager instance via which this object drives the shared Autofill
// code.
- AutofillManager autofill_manager_;
+ scoped_ptr<AutofillManager> autofill_manager_;
};
} // namespace autofill
diff --git a/components/autofill/content/browser/autofill_driver_impl_unittest.cc b/components/autofill/content/browser/autofill_driver_impl_unittest.cc
new file mode 100644
index 0000000..9b0e5d4
--- /dev/null
+++ b/components/autofill/content/browser/autofill_driver_impl_unittest.cc
@@ -0,0 +1,100 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <algorithm>
+#include <vector>
+
+#include "base/memory/scoped_ptr.h"
+#include "chrome/test/base/chrome_render_view_host_test_harness.h"
+#include "components/autofill/content/browser/autofill_driver_impl.h"
+#include "components/autofill/core/browser/autofill_external_delegate.h"
+#include "components/autofill/core/browser/autofill_manager.h"
+#include "components/autofill/core/browser/test_autofill_manager_delegate.h"
+#include "content/public/browser/navigation_details.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/common/frame_navigate_params.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace autofill {
+
+namespace {
+
+const std::string kAppLocale = "en-US";
+const AutofillManager::AutofillDownloadManagerState kDownloadState =
+ AutofillManager::DISABLE_AUTOFILL_DOWNLOAD_MANAGER;
+
+} // namespace
+
+class MockAutofillManager : public AutofillManager {
+ public:
+ MockAutofillManager(AutofillDriver* driver,
+ AutofillManagerDelegate* delegate)
+ : AutofillManager(driver, delegate, kAppLocale, kDownloadState) {
+ }
+ virtual ~MockAutofillManager() {}
+
+ MOCK_METHOD0(Reset, void());
+};
+
+class TestAutofillDriverImpl : public AutofillDriverImpl {
+ public:
+ TestAutofillDriverImpl(content::WebContents* contents,
+ AutofillManagerDelegate* delegate)
+ : AutofillDriverImpl(contents, delegate, kAppLocale, kDownloadState) {
+ scoped_ptr<AutofillManager> autofill_manager(
+ new MockAutofillManager(this, delegate));
+ SetAutofillManager(autofill_manager.Pass());
+ }
+ virtual ~TestAutofillDriverImpl() {}
+
+ virtual MockAutofillManager* mock_autofill_manager() {
+ return static_cast<MockAutofillManager*>(autofill_manager());
+ }
+
+ using AutofillDriverImpl::DidNavigateMainFrame;
+};
+
+class AutofillDriverImplTest : public ChromeRenderViewHostTestHarness {
+ public:
+ virtual void SetUp() OVERRIDE {
+ ChromeRenderViewHostTestHarness::SetUp();
+
+ test_manager_delegate_.reset(new TestAutofillManagerDelegate());
+ driver_.reset(new TestAutofillDriverImpl(web_contents(),
+ test_manager_delegate_.get()));
+ }
+
+ virtual void TearDown() OVERRIDE {
+ // Reset the driver now to cause all pref observers to be removed and avoid
+ // crashes that otherwise occur in the destructor.
+ driver_.reset();
+ ChromeRenderViewHostTestHarness::TearDown();
+ }
+
+ protected:
+ scoped_ptr<TestAutofillManagerDelegate> test_manager_delegate_;
+ scoped_ptr<TestAutofillDriverImpl> driver_;
+};
+
+TEST_F(AutofillDriverImplTest, NavigatedToDifferentPage) {
+ EXPECT_CALL(*driver_->mock_autofill_manager(), Reset());
+ content::LoadCommittedDetails details = content::LoadCommittedDetails();
+ details.is_main_frame = true;
+ details.is_in_page = false;
+ ASSERT_TRUE(details.is_navigation_to_different_page());
+ content::FrameNavigateParams params = content::FrameNavigateParams();
+ driver_->DidNavigateMainFrame(details, params);
+}
+
+TEST_F(AutofillDriverImplTest, NavigatedWithinSamePage) {
+ EXPECT_CALL(*driver_->mock_autofill_manager(), Reset()).Times(0);
+ content::LoadCommittedDetails details = content::LoadCommittedDetails();
+ details.is_main_frame = false;
+ ASSERT_TRUE(!details.is_navigation_to_different_page());
+ content::FrameNavigateParams params = content::FrameNavigateParams();
+ driver_->DidNavigateMainFrame(details, params);
+}
+
+} // namespace autofill
diff --git a/components/autofill/core/browser/autofill_manager.h b/components/autofill/core/browser/autofill_manager.h
index c8192a14..eabc19a 100644
--- a/components/autofill/core/browser/autofill_manager.h
+++ b/components/autofill/core/browser/autofill_manager.h
@@ -84,7 +84,7 @@ class AutofillManager : public AutofillDownloadManager::Observer {
AutofillDownloadManagerState enable_download_manager);
virtual ~AutofillManager();
- // Set an external delegate.
+ // Sets an external delegate.
void SetExternalDelegate(AutofillExternalDelegate* delegate);
// Whether browser process will create and own the Autofill popup UI.
@@ -185,7 +185,7 @@ class AutofillManager : public AutofillDownloadManager::Observer {
const gfx::RectF& bounding_box);
// Resets cache.
- void Reset();
+ virtual void Reset();
protected:
// Test code should prefer to use this constructor.