summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorblundell@chromium.org <blundell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-05 08:25:33 +0000
committerblundell@chromium.org <blundell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-05 08:25:33 +0000
commit904cbcb712ebd4a81551711544ee4a84252aa149 (patch)
tree7437337453f99bab2e341b9f2f005a5ec394c4c3 /components
parent5c81f4b8ce46306fce09734e64e3df45fc7b39c7 (diff)
downloadchromium_src-904cbcb712ebd4a81551711544ee4a84252aa149.zip
chromium_src-904cbcb712ebd4a81551711544ee4a84252aa149.tar.gz
chromium_src-904cbcb712ebd4a81551711544ee4a84252aa149.tar.bz2
Abstract setting renderer form data action out of autofill core code.
This CL moves the concrete implementation of setting the renderer form data action into the implementations of AutofillDriver. BUG=247015 Review URL: https://chromiumcodereview.appspot.com/18272023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@210274 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components')
-rw-r--r--components/autofill/content/browser/autofill_driver_impl.cc20
-rw-r--r--components/autofill/content/browser/autofill_driver_impl.h2
-rw-r--r--components/autofill/content/browser/autofill_driver_impl_unittest.cc37
-rw-r--r--components/autofill/core/browser/autocomplete_history_manager_unittest.cc9
-rw-r--r--components/autofill/core/browser/autofill_driver.h13
-rw-r--r--components/autofill/core/browser/autofill_external_delegate.cc19
-rw-r--r--components/autofill/core/browser/autofill_external_delegate.h12
-rw-r--r--components/autofill/core/browser/autofill_external_delegate_unittest.cc34
-rw-r--r--components/autofill/core/browser/autofill_manager_unittest.cc9
-rw-r--r--components/autofill/core/browser/test_autofill_driver.cc4
-rw-r--r--components/autofill/core/browser/test_autofill_driver.h2
11 files changed, 136 insertions, 25 deletions
diff --git a/components/autofill/content/browser/autofill_driver_impl.cc b/components/autofill/content/browser/autofill_driver_impl.cc
index 64b3662..4a831e7 100644
--- a/components/autofill/content/browser/autofill_driver_impl.cc
+++ b/components/autofill/content/browser/autofill_driver_impl.cc
@@ -67,7 +67,8 @@ AutofillDriverImpl::AutofillDriverImpl(
autofill_manager_(new AutofillManager(
this, delegate, app_locale, enable_download_manager)) {
SetAutofillExternalDelegate(scoped_ptr<AutofillExternalDelegate>(
- new AutofillExternalDelegate(web_contents, autofill_manager_.get())));
+ new AutofillExternalDelegate(web_contents, autofill_manager_.get(),
+ this)));
registrar_.Add(this,
content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
@@ -89,6 +90,23 @@ bool AutofillDriverImpl::RendererIsAvailable() {
return (web_contents()->GetRenderViewHost() != NULL);
}
+void AutofillDriverImpl::SetRendererActionOnFormDataReception(
+ RendererFormDataAction action) {
+ if (!RendererIsAvailable())
+ return;
+
+ content::RenderViewHost* host = web_contents()->GetRenderViewHost();
+ switch(action) {
+ case FORM_DATA_ACTION_PREVIEW:
+ host->Send(new AutofillMsg_SetAutofillActionPreview(
+ host->GetRoutingID()));
+ return;
+ case FORM_DATA_ACTION_FILL:
+ host->Send(new AutofillMsg_SetAutofillActionFill(host->GetRoutingID()));
+ return;
+ }
+}
+
void AutofillDriverImpl::SendFormDataToRenderer(int query_id,
const FormData& data) {
if (!RendererIsAvailable())
diff --git a/components/autofill/content/browser/autofill_driver_impl.h b/components/autofill/content/browser/autofill_driver_impl.h
index 0296198..385dd30 100644
--- a/components/autofill/content/browser/autofill_driver_impl.h
+++ b/components/autofill/content/browser/autofill_driver_impl.h
@@ -47,6 +47,8 @@ class AutofillDriverImpl : public AutofillDriver,
// AutofillDriver:
virtual content::WebContents* GetWebContents() OVERRIDE;
virtual bool RendererIsAvailable() OVERRIDE;
+ virtual void SetRendererActionOnFormDataReception(
+ RendererFormDataAction action) OVERRIDE;
virtual void SendFormDataToRenderer(int query_id,
const FormData& data) OVERRIDE;
virtual void SendAutofillTypePredictionsToRenderer(
diff --git a/components/autofill/content/browser/autofill_driver_impl_unittest.cc b/components/autofill/content/browser/autofill_driver_impl_unittest.cc
index ae053fb..310a62a 100644
--- a/components/autofill/content/browser/autofill_driver_impl_unittest.cc
+++ b/components/autofill/content/browser/autofill_driver_impl_unittest.cc
@@ -124,6 +124,31 @@ class AutofillDriverImplTest : public ChromeRenderViewHostTestHarness {
return true;
}
+ // Searches for an |AutofillMsg_SetAutofillActionPreview| message in the
+ // queue of sent IPC messages. If none is present, returns false. Otherwise,
+ // clears the queue of sent messages and returns true.
+ bool GetSetAutofillActionPreviewMessage() {
+ const uint32 kMsgID = AutofillMsg_SetAutofillActionPreview::ID;
+ const IPC::Message* message =
+ process()->sink().GetFirstMessageMatching(kMsgID);
+ if (!message)
+ return false;
+ process()->sink().ClearMessages();
+ return true;
+ }
+
+ // Searches for an |AutofillMsg_SetAutofillActionFill| message in the
+ // queue of sent IPC messages. If none is present, returns false. Otherwise,
+ // clears the queue of sent messages and returns true.
+ bool GetSetAutofillActionFillMessage() {
+ const uint32 kMsgID = AutofillMsg_SetAutofillActionFill::ID;
+ const IPC::Message* message =
+ process()->sink().GetFirstMessageMatching(kMsgID);
+ if (!message)
+ return false;
+ process()->sink().ClearMessages();
+ return true;
+ }
scoped_ptr<TestAutofillManagerDelegate> test_manager_delegate_;
scoped_ptr<TestAutofillDriverImpl> driver_;
@@ -188,4 +213,16 @@ TEST_F(AutofillDriverImplTest, TypePredictionsSentToRendererWhenEnabled) {
EXPECT_EQ(expected_type_predictions, output_type_predictions);
}
+TEST_F(AutofillDriverImplTest, PreviewActionSentToRenderer) {
+ driver_->SetRendererActionOnFormDataReception(
+ AutofillDriver::FORM_DATA_ACTION_PREVIEW);
+ EXPECT_TRUE(GetSetAutofillActionPreviewMessage());
+}
+
+TEST_F(AutofillDriverImplTest, FillActionSentToRenderer) {
+ driver_->SetRendererActionOnFormDataReception(
+ AutofillDriver::FORM_DATA_ACTION_FILL);
+ EXPECT_TRUE(GetSetAutofillActionFillMessage());
+}
+
} // namespace autofill
diff --git a/components/autofill/core/browser/autocomplete_history_manager_unittest.cc b/components/autofill/core/browser/autocomplete_history_manager_unittest.cc
index 35e48f1..f3b7054 100644
--- a/components/autofill/core/browser/autocomplete_history_manager_unittest.cc
+++ b/components/autofill/core/browser/autocomplete_history_manager_unittest.cc
@@ -208,8 +208,10 @@ namespace {
class MockAutofillExternalDelegate : public AutofillExternalDelegate {
public:
MockAutofillExternalDelegate(content::WebContents* web_contents,
- AutofillManager* autofill_manager)
- : AutofillExternalDelegate(web_contents, autofill_manager) {}
+ AutofillManager* autofill_manager,
+ AutofillDriver* autofill_driver)
+ : AutofillExternalDelegate(web_contents, autofill_manager,
+ autofill_driver) {}
virtual ~MockAutofillExternalDelegate() {}
MOCK_METHOD5(OnSuggestionsReturned,
@@ -249,7 +251,8 @@ TEST_F(AutocompleteHistoryManagerTest, ExternalDelegate) {
AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER));
MockAutofillExternalDelegate external_delegate(web_contents(),
- autofill_manager.get());
+ autofill_manager.get(),
+ autofill_driver_.get());
autocomplete_history_manager.SetExternalDelegate(&external_delegate);
// Should trigger a call to OnSuggestionsReturned, verified by the mock.
diff --git a/components/autofill/core/browser/autofill_driver.h b/components/autofill/core/browser/autofill_driver.h
index 14620ed..2a7bc11 100644
--- a/components/autofill/core/browser/autofill_driver.h
+++ b/components/autofill/core/browser/autofill_driver.h
@@ -22,6 +22,14 @@ class FormStructure;
// implementation must be provided by the driver.
class AutofillDriver {
public:
+ // The possible actions that the renderer can take on receiving form data.
+ enum RendererFormDataAction {
+ // The renderer should fill the form data.
+ FORM_DATA_ACTION_FILL,
+ // The renderer should preview the form data.
+ FORM_DATA_ACTION_PREVIEW
+ };
+
virtual ~AutofillDriver() {}
// TODO(blundell): Remove this method once shared code no longer needs to
@@ -31,6 +39,11 @@ class AutofillDriver {
// Returns true iff the renderer is available for communication.
virtual bool RendererIsAvailable() = 0;
+ // Informs the renderer what action to take with the next form data that it
+ // receives. Must be called before each call to |SendFormDataToRenderer|.
+ virtual void SetRendererActionOnFormDataReception(
+ RendererFormDataAction action) = 0;
+
// Forwards |data| to the renderer. |query_id| is the id of the renderer's
// original request for the data. This method is a no-op if the renderer is
// not currently available.
diff --git a/components/autofill/core/browser/autofill_external_delegate.cc b/components/autofill/core/browser/autofill_external_delegate.cc
index b493726..d81307c 100644
--- a/components/autofill/core/browser/autofill_external_delegate.cc
+++ b/components/autofill/core/browser/autofill_external_delegate.cc
@@ -6,6 +6,7 @@
#include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/browser/autocomplete_history_manager.h"
+#include "components/autofill/core/browser/autofill_driver.h"
#include "components/autofill/core/browser/autofill_manager.h"
#include "components/autofill/core/common/autofill_messages.h"
#include "content/public/browser/render_view_host.h"
@@ -25,9 +26,11 @@ namespace autofill {
AutofillExternalDelegate::AutofillExternalDelegate(
content::WebContents* web_contents,
- AutofillManager* autofill_manager)
+ AutofillManager* autofill_manager,
+ AutofillDriver* autofill_driver)
: web_contents_(web_contents),
autofill_manager_(autofill_manager),
+ autofill_driver_(autofill_driver),
password_autofill_manager_(web_contents),
autofill_query_id_(0),
display_warning_if_disabled_(false),
@@ -257,16 +260,12 @@ void AutofillExternalDelegate::FillAutofillFormData(int unique_id,
if (unique_id == WebAutofillClient::MenuItemIDWarningMessage)
return;
- RenderViewHost* host = web_contents_->GetRenderViewHost();
-
- if (is_preview) {
- host->Send(new AutofillMsg_SetAutofillActionPreview(
- host->GetRoutingID()));
- } else {
- host->Send(new AutofillMsg_SetAutofillActionFill(
- host->GetRoutingID()));
- }
+ AutofillDriver::RendererFormDataAction renderer_action = is_preview ?
+ AutofillDriver::FORM_DATA_ACTION_PREVIEW :
+ AutofillDriver::FORM_DATA_ACTION_FILL;
+ DCHECK(autofill_driver_->RendererIsAvailable());
+ autofill_driver_->SetRendererActionOnFormDataReception(renderer_action);
// Fill the values for the whole form.
autofill_manager_->OnFillAutofillFormData(autofill_query_id_,
autofill_query_form_,
diff --git a/components/autofill/core/browser/autofill_external_delegate.h b/components/autofill/core/browser/autofill_external_delegate.h
index e6631ac..0974e34 100644
--- a/components/autofill/core/browser/autofill_external_delegate.h
+++ b/components/autofill/core/browser/autofill_external_delegate.h
@@ -28,6 +28,7 @@ class WebContents;
namespace autofill {
+class AutofillDriver;
class AutofillManager;
// TODO(csharp): A lot of the logic in this class is copied from autofillagent.
@@ -38,10 +39,11 @@ class AutofillManager;
class AutofillExternalDelegate
: public AutofillPopupDelegate {
public:
- // Creates an AutofillExternalDelegate for the specified contents; the second
- // argument is an AutofillManager managing Autofill for that WebContents.
+ // Creates an AutofillExternalDelegate for the specified contents,
+ // AutofillManager, and AutofillDriver.
AutofillExternalDelegate(content::WebContents* web_contents,
- AutofillManager* autofill_manager);
+ AutofillManager* autofill_manager,
+ AutofillDriver* autofill_driver);
virtual ~AutofillExternalDelegate();
// AutofillPopupDelegate implementation.
@@ -139,6 +141,10 @@ class AutofillExternalDelegate
content::WebContents* web_contents_; // weak; owns me.
AutofillManager* autofill_manager_; // weak.
+ // Provides driver-level context to the shared code of the component. Must
+ // outlive this object.
+ AutofillDriver* autofill_driver_; // weak
+
// Password Autofill manager, handles all password-related Autofilling.
PasswordAutofillManager password_autofill_manager_;
diff --git a/components/autofill/core/browser/autofill_external_delegate_unittest.cc b/components/autofill/core/browser/autofill_external_delegate_unittest.cc
index daa1f86..79a4800 100644
--- a/components/autofill/core/browser/autofill_external_delegate_unittest.cc
+++ b/components/autofill/core/browser/autofill_external_delegate_unittest.cc
@@ -34,11 +34,26 @@ const int kQueryId = 5;
// A constant value to use as an Autofill profile ID.
const int kAutofillProfileId = 1;
+class MockAutofillDriver : public TestAutofillDriver {
+ public:
+ explicit MockAutofillDriver(content::WebContents* web_contents)
+ : TestAutofillDriver(web_contents) {}
+
+ // Mock methods to enable testability.
+ MOCK_METHOD1(SetRendererActionOnFormDataReception,
+ void(RendererFormDataAction action));
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver);
+};
+
class MockAutofillExternalDelegate : public AutofillExternalDelegate {
public:
MockAutofillExternalDelegate(content::WebContents* web_contents,
- AutofillManager* autofill_manger)
- : AutofillExternalDelegate(web_contents, autofill_manger) {}
+ AutofillManager* autofill_manger,
+ AutofillDriver* autofill_driver)
+ : AutofillExternalDelegate(web_contents, autofill_manger,
+ autofill_driver) {}
~MockAutofillExternalDelegate() {}
@@ -95,14 +110,14 @@ class AutofillExternalDelegateUnitTest
protected:
virtual void SetUp() OVERRIDE {
ChromeRenderViewHostTestHarness::SetUp();
- autofill_driver_.reset(new TestAutofillDriver(web_contents()));
+ autofill_driver_.reset(new MockAutofillDriver(web_contents()));
autofill_manager_.reset(
new MockAutofillManager(autofill_driver_.get(),
&manager_delegate_));
external_delegate_.reset(
new testing::NiceMock<MockAutofillExternalDelegate>(
web_contents(),
- autofill_manager_.get()));
+ autofill_manager_.get(), autofill_driver_.get()));
}
virtual void TearDown() OVERRIDE {
@@ -128,7 +143,7 @@ class AutofillExternalDelegateUnitTest
}
MockAutofillManagerDelegate manager_delegate_;
- scoped_ptr<AutofillDriver> autofill_driver_;
+ scoped_ptr<MockAutofillDriver> autofill_driver_;
scoped_ptr<MockAutofillManager> autofill_manager_;
scoped_ptr<testing::NiceMock<MockAutofillExternalDelegate> >
external_delegate_;
@@ -163,6 +178,9 @@ TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) {
// Called by DidAutofillSuggestions, add expectation to remove warning.
EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _));
+ EXPECT_CALL(*autofill_driver_, SetRendererActionOnFormDataReception(
+ AutofillDriver::FORM_DATA_ACTION_FILL));
+
EXPECT_CALL(manager_delegate_, HideAutofillPopup());
// This should trigger a call to hide the popup since we've selected an
@@ -289,12 +307,16 @@ TEST_F(AutofillExternalDelegateUnitTest, NoAutofillWarningsWithoutSuggestions) {
TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) {
// Ensure it doesn't try to preview the negative id.
EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0);
+ EXPECT_CALL(*autofill_driver_,
+ SetRendererActionOnFormDataReception(_)).Times(0);
EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1);
external_delegate_->DidSelectSuggestion(-1);
// Ensure it doesn't try to fill the form in with the negative id.
EXPECT_CALL(manager_delegate_, HideAutofillPopup());
EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0);
+ EXPECT_CALL(*autofill_driver_,
+ SetRendererActionOnFormDataReception(_)).Times(0);
external_delegate_->DidAcceptSuggestion(base::string16(), -1);
}
@@ -311,6 +333,8 @@ TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) {
WebAutofillClient::MenuItemIDPasswordEntry);
EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1);
+ EXPECT_CALL(*autofill_driver_, SetRendererActionOnFormDataReception(
+ AutofillDriver::FORM_DATA_ACTION_PREVIEW));
external_delegate_->DidSelectSuggestion(1);
}
diff --git a/components/autofill/core/browser/autofill_manager_unittest.cc b/components/autofill/core/browser/autofill_manager_unittest.cc
index f983c33..bcefb01 100644
--- a/components/autofill/core/browser/autofill_manager_unittest.cc
+++ b/components/autofill/core/browser/autofill_manager_unittest.cc
@@ -3266,8 +3266,10 @@ class MockAutofillManagerDelegate : public TestAutofillManagerDelegate {
class MockAutofillExternalDelegate : public AutofillExternalDelegate {
public:
explicit MockAutofillExternalDelegate(content::WebContents* web_contents,
- AutofillManager* autofill_manager)
- : AutofillExternalDelegate(web_contents, autofill_manager) {}
+ AutofillManager* autofill_manager,
+ AutofillDriver* autofill_driver)
+ : AutofillExternalDelegate(web_contents, autofill_manager,
+ autofill_driver) {}
virtual ~MockAutofillExternalDelegate() {}
MOCK_METHOD5(OnQuery, void(int query_id,
@@ -3344,7 +3346,8 @@ TEST_F(AutofillManagerTest, TestAutocheckoutBubbleNotShown) {
// Test our external delegate is called at the right time.
TEST_F(AutofillManagerTest, TestExternalDelegate) {
MockAutofillExternalDelegate external_delegate(web_contents(),
- autofill_manager_.get());
+ autofill_manager_.get(),
+ autofill_driver_.get());
EXPECT_CALL(external_delegate, OnQuery(_, _, _, _, _));
autofill_manager_->SetExternalDelegate(&external_delegate);
diff --git a/components/autofill/core/browser/test_autofill_driver.cc b/components/autofill/core/browser/test_autofill_driver.cc
index e3a3d70..1991de1 100644
--- a/components/autofill/core/browser/test_autofill_driver.cc
+++ b/components/autofill/core/browser/test_autofill_driver.cc
@@ -19,6 +19,10 @@ bool TestAutofillDriver::RendererIsAvailable() {
return true;
}
+void TestAutofillDriver::SetRendererActionOnFormDataReception(
+ RendererFormDataAction action) {
+}
+
void TestAutofillDriver::SendFormDataToRenderer(int query_id,
const FormData& form_data) {
}
diff --git a/components/autofill/core/browser/test_autofill_driver.h b/components/autofill/core/browser/test_autofill_driver.h
index 3bf20e6..2475b76 100644
--- a/components/autofill/core/browser/test_autofill_driver.h
+++ b/components/autofill/core/browser/test_autofill_driver.h
@@ -25,6 +25,8 @@ class TestAutofillDriver : public AutofillDriver,
// AutofillDriver implementation.
virtual content::WebContents* GetWebContents() OVERRIDE;
virtual bool RendererIsAvailable() OVERRIDE;
+ virtual void SetRendererActionOnFormDataReception(
+ RendererFormDataAction action) OVERRIDE;
virtual void SendFormDataToRenderer(int query_id,
const FormData& data) OVERRIDE;
virtual void SendAutofillTypePredictionsToRenderer(