Chromium Code Reviews| Index: components/autofill/browser/autocomplete_history_manager_unittest.cc |
| diff --git a/components/autofill/browser/autocomplete_history_manager_unittest.cc b/components/autofill/browser/autocomplete_history_manager_unittest.cc |
| index 0a3680d9ebde095537c09877d3f79b27a8c86520..84ad173a9d7519708d2576e9ad1985e6c4d28e6b 100644 |
| --- a/components/autofill/browser/autocomplete_history_manager_unittest.cc |
| +++ b/components/autofill/browser/autocomplete_history_manager_unittest.cc |
| @@ -17,6 +17,7 @@ |
| #include "components/autofill/browser/autocomplete_history_manager.h" |
| #include "components/autofill/browser/autofill_external_delegate.h" |
| #include "components/autofill/browser/autofill_manager.h" |
| +#include "components/autofill/browser/test_autofill_driver.h" |
| #include "components/autofill/browser/test_autofill_manager_delegate.h" |
| #include "components/autofill/browser/webdata/autofill_webdata_service.h" |
| #include "components/autofill/common/form_data.h" |
| @@ -99,7 +100,9 @@ class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness { |
| web_data_service_ = new MockWebDataService(); |
| WebDataServiceFactory::GetInstance()->SetTestingFactory( |
| profile(), MockWebDataServiceWrapperCurrent::Build); |
| - autocomplete_manager_.reset(new AutocompleteHistoryManager(web_contents())); |
| + autofill_driver_.reset(new TestAutofillDriver(web_contents())); |
| + autocomplete_manager_.reset( |
| + new AutocompleteHistoryManager(autofill_driver_.get())); |
| } |
| virtual void TearDown() OVERRIDE { |
| @@ -110,6 +113,7 @@ class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness { |
| scoped_refptr<MockWebDataService> web_data_service_; |
| scoped_ptr<AutocompleteHistoryManager> autocomplete_manager_; |
| + scoped_ptr<AutofillDriver> autofill_driver_; |
| MockAutofillManagerDelegate manager_delegate; |
| }; |
| @@ -202,9 +206,9 @@ namespace { |
| class MockAutofillExternalDelegate : public AutofillExternalDelegate { |
| public: |
| - explicit MockAutofillExternalDelegate(content::WebContents* web_contents) |
| - : AutofillExternalDelegate( |
| - web_contents, AutofillManager::FromWebContents(web_contents)) {} |
| + explicit MockAutofillExternalDelegate(content::WebContents* web_contents, |
| + AutofillManager* autofill_manager) |
| + : AutofillExternalDelegate(web_contents, autofill_manager) {} |
| virtual ~MockAutofillExternalDelegate() {} |
| MOCK_METHOD5(OnSuggestionsReturned, |
| @@ -218,38 +222,35 @@ class MockAutofillExternalDelegate : public AutofillExternalDelegate { |
| DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); |
| }; |
| -class AutocompleteHistoryManagerStubSend : public AutocompleteHistoryManager { |
| - public: |
| - explicit AutocompleteHistoryManagerStubSend(WebContents* web_contents) |
| - : AutocompleteHistoryManager(web_contents) {} |
| +class AutocompleteHistoryManagerNoIPC : public AutocompleteHistoryManager { |
| + public: |
| + explicit AutocompleteHistoryManagerNoIPC(AutofillDriver* driver) |
| + : AutocompleteHistoryManager(driver) { |
| + // Ensure that IPC is not sent during the test. |
| + send_ipc_ = false; |
| + } |
| // Increase visibility for testing. |
| void SendSuggestions(const std::vector<base::string16>* suggestions) { |
| AutocompleteHistoryManager::SendSuggestions(suggestions); |
| } |
|
Ilya Sherman
2013/06/14 02:44:37
nit: You can write this as "using AutocompleteHist
blundell
2013/06/14 09:54:08
This doesn't work as SendSuggestions() is a member
Ilya Sherman
2013/06/14 23:22:23
I'm pretty sure this should work. See https://cod
blundell
2013/06/15 12:52:32
Thanks for the pointer - nifty! I had misunderstoo
|
| - |
| - // Intentionally swallow the message. |
| - virtual bool Send(IPC::Message* message) OVERRIDE { |
| - delete message; |
| - return true; |
| - } |
| }; |
| } // namespace |
| // Make sure our external delegate is called at the right time. |
| TEST_F(AutocompleteHistoryManagerTest, ExternalDelegate) { |
| - // Local version with a stubbed out Send() |
| - AutocompleteHistoryManagerStubSend autocomplete_history_manager( |
| - web_contents()); |
| + AutocompleteHistoryManagerNoIPC autocomplete_history_manager( |
| + autofill_driver_.get()); |
| - AutofillManager::CreateForWebContentsAndDelegate( |
| - web_contents(), |
| + scoped_ptr<AutofillManager> autofill_manager(new AutofillManager( |
| + autofill_driver_.get(), |
| &manager_delegate, |
| "en-US", |
| - AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER); |
| + AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER)); |
| - MockAutofillExternalDelegate external_delegate(web_contents()); |
| + MockAutofillExternalDelegate external_delegate(web_contents(), |
| + autofill_manager.get()); |
| autocomplete_history_manager.SetExternalDelegate(&external_delegate); |
| // Should trigger a call to OnSuggestionsReturned, verified by the mock. |