diff options
author | blundell@chromium.org <blundell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-09 14:29:04 +0000 |
---|---|---|
committer | blundell@chromium.org <blundell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-09 14:29:04 +0000 |
commit | 29fa265e48393bc063bc046964da351d61dcb9a9 (patch) | |
tree | c25951534e9252c846f03e92ef66b5d89c2cce7c /components | |
parent | 6e7fdeb137df46ee6459afd8473b09f2da84462f (diff) | |
download | chromium_src-29fa265e48393bc063bc046964da351d61dcb9a9.zip chromium_src-29fa265e48393bc063bc046964da351d61dcb9a9.tar.gz chromium_src-29fa265e48393bc063bc046964da351d61dcb9a9.tar.bz2 |
Move AutofillMsg_ClearForm IPC send to AutofillDriverImpl
Abstracts the implementation of communicating to the renderer that it should
fill the form into the AutofillDriver implementation.
BUG=247015
Review URL: https://chromiumcodereview.appspot.com/18238006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@210566 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components')
8 files changed, 46 insertions, 1 deletions
diff --git a/components/autofill/content/browser/autofill_driver_impl.cc b/components/autofill/content/browser/autofill_driver_impl.cc index 4a831e7..e56f947 100644 --- a/components/autofill/content/browser/autofill_driver_impl.cc +++ b/components/autofill/content/browser/autofill_driver_impl.cc @@ -133,6 +133,13 @@ void AutofillDriverImpl::SendAutofillTypePredictionsToRenderer( type_predictions)); } +void AutofillDriverImpl::RendererShouldClearForm() { + if (!RendererIsAvailable()) + return; + content::RenderViewHost* host = web_contents()->GetRenderViewHost(); + host->Send(new AutofillMsg_ClearForm(host->GetRoutingID())); +} + bool AutofillDriverImpl::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(AutofillDriverImpl, message) diff --git a/components/autofill/content/browser/autofill_driver_impl.h b/components/autofill/content/browser/autofill_driver_impl.h index 385dd30..9af0249 100644 --- a/components/autofill/content/browser/autofill_driver_impl.h +++ b/components/autofill/content/browser/autofill_driver_impl.h @@ -53,6 +53,7 @@ class AutofillDriverImpl : public AutofillDriver, const FormData& data) OVERRIDE; virtual void SendAutofillTypePredictionsToRenderer( const std::vector<FormStructure*>& forms) OVERRIDE; + virtual void RendererShouldClearForm() OVERRIDE; AutofillExternalDelegate* autofill_external_delegate() { return autofill_external_delegate_.get(); diff --git a/components/autofill/content/browser/autofill_driver_impl_unittest.cc b/components/autofill/content/browser/autofill_driver_impl_unittest.cc index 310a62a..b313211 100644 --- a/components/autofill/content/browser/autofill_driver_impl_unittest.cc +++ b/components/autofill/content/browser/autofill_driver_impl_unittest.cc @@ -150,6 +150,19 @@ class AutofillDriverImplTest : public ChromeRenderViewHostTestHarness { return true; } + // Searches for an |AutofillMsg_ClearForm| 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 GetClearFormMessage() { + const uint32 kMsgID = AutofillMsg_ClearForm::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_; }; @@ -225,4 +238,9 @@ TEST_F(AutofillDriverImplTest, FillActionSentToRenderer) { EXPECT_TRUE(GetSetAutofillActionFillMessage()); } +TEST_F(AutofillDriverImplTest, ClearFormSentToRenderer) { + driver_->RendererShouldClearForm(); + EXPECT_TRUE(GetClearFormMessage()); +} + } // namespace autofill diff --git a/components/autofill/core/browser/autofill_driver.h b/components/autofill/core/browser/autofill_driver.h index 2a7bc11..02ae8cf 100644 --- a/components/autofill/core/browser/autofill_driver.h +++ b/components/autofill/core/browser/autofill_driver.h @@ -54,6 +54,9 @@ class AutofillDriver { // command-line flag is not set. virtual void SendAutofillTypePredictionsToRenderer( const std::vector<FormStructure*>& forms) = 0; + + // Tells the renderer to clear the currently displayed Autofill results. + virtual void RendererShouldClearForm() = 0; }; } // namespace autofill diff --git a/components/autofill/core/browser/autofill_external_delegate.cc b/components/autofill/core/browser/autofill_external_delegate.cc index d81307c..b6a04eb 100644 --- a/components/autofill/core/browser/autofill_external_delegate.cc +++ b/components/autofill/core/browser/autofill_external_delegate.cc @@ -198,7 +198,7 @@ void AutofillExternalDelegate::DidAcceptSuggestion(const base::string16& value, autofill_manager_->OnShowAutofillDialog(); } else if (identifier == WebAutofillClient::MenuItemIDClearForm) { // User selected 'Clear form'. - host->Send(new AutofillMsg_ClearForm(host->GetRoutingID())); + autofill_driver_->RendererShouldClearForm(); } else if (identifier == WebAutofillClient::MenuItemIDPasswordEntry) { bool success = password_autofill_manager_.DidAcceptAutofillSuggestion( autofill_query_field_, value); diff --git a/components/autofill/core/browser/autofill_external_delegate_unittest.cc b/components/autofill/core/browser/autofill_external_delegate_unittest.cc index 79a4800..111dd8e 100644 --- a/components/autofill/core/browser/autofill_external_delegate_unittest.cc +++ b/components/autofill/core/browser/autofill_external_delegate_unittest.cc @@ -42,6 +42,7 @@ class MockAutofillDriver : public TestAutofillDriver { // Mock methods to enable testability. MOCK_METHOD1(SetRendererActionOnFormDataReception, void(RendererFormDataAction action)); + MOCK_METHOD0(RendererShouldClearForm, void()); private: DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver); @@ -392,6 +393,17 @@ TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegatePasswordSuggestions) { WebAutofillClient::MenuItemIDPasswordEntry); } +// Test that the driver is directed to clear the form after being notified that +// the user accepted the suggestion to clear the form. +TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearForm) { + EXPECT_CALL(manager_delegate_, HideAutofillPopup()); + EXPECT_CALL(*autofill_driver_, RendererShouldClearForm()); + + external_delegate_->DidAcceptSuggestion( + base::string16(), + WebAutofillClient::MenuItemIDClearForm); +} + TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateHideWarning) { // Set up a field that shouldn't get autocompleted or display warnings. const FormData form; diff --git a/components/autofill/core/browser/test_autofill_driver.cc b/components/autofill/core/browser/test_autofill_driver.cc index 1991de1..108c489 100644 --- a/components/autofill/core/browser/test_autofill_driver.cc +++ b/components/autofill/core/browser/test_autofill_driver.cc @@ -31,4 +31,7 @@ void TestAutofillDriver::SendAutofillTypePredictionsToRenderer( const std::vector<FormStructure*>& forms) { } +void TestAutofillDriver::RendererShouldClearForm() { +} + } // namespace autofill diff --git a/components/autofill/core/browser/test_autofill_driver.h b/components/autofill/core/browser/test_autofill_driver.h index 2475b76..d57e0d2 100644 --- a/components/autofill/core/browser/test_autofill_driver.h +++ b/components/autofill/core/browser/test_autofill_driver.h @@ -31,6 +31,7 @@ class TestAutofillDriver : public AutofillDriver, const FormData& data) OVERRIDE; virtual void SendAutofillTypePredictionsToRenderer( const std::vector<FormStructure*>& forms) OVERRIDE; + virtual void RendererShouldClearForm() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(TestAutofillDriver); |