summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkaiwang@chromium.org <kaiwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-27 05:18:08 +0000
committerkaiwang@chromium.org <kaiwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-27 05:18:08 +0000
commit8ac8bfdd62df5edd56b7cd298e816e6de8d7b47d (patch)
treed5ee4acd5ee996c0c50bb99b622afbef17eff247
parent48164f956d68e19019f76e97688a21e4fcd9b564 (diff)
downloadchromium_src-8ac8bfdd62df5edd56b7cd298e816e6de8d7b47d.zip
chromium_src-8ac8bfdd62df5edd56b7cd298e816e6de8d7b47d.tar.gz
chromium_src-8ac8bfdd62df5edd56b7cd298e816e6de8d7b47d.tar.bz2
Move the UI related code from AutofillExternalDelegate to AutofillManagerDelegate
Move the UI related code (autofill popup controlling) to AutofillManagerDelegate (implementated by TabAutofillManagerDelegate), which is a better place for UI dependencies, and many other UI dependencies are already there. Note: work in progress. Will modify tests BUG=140037 Review URL: https://chromiumcodereview.appspot.com/12340065 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@184881 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autofill/DEPS1
-rw-r--r--chrome/browser/autofill/autocheckout_manager_unittest.cc48
-rw-r--r--chrome/browser/autofill/autocomplete_history_manager_unittest.cc46
-rw-r--r--chrome/browser/autofill/autofill_browsertest.cc9
-rw-r--r--chrome/browser/autofill/autofill_external_delegate.cc69
-rw-r--r--chrome/browser/autofill/autofill_external_delegate.h22
-rw-r--r--chrome/browser/autofill/autofill_external_delegate_browsertest.cc106
-rw-r--r--chrome/browser/autofill/autofill_external_delegate_unittest.cc125
-rw-r--r--chrome/browser/autofill/autofill_manager.cc6
-rw-r--r--chrome/browser/autofill/autofill_manager.h4
-rw-r--r--chrome/browser/autofill/autofill_manager_delegate.h20
-rw-r--r--chrome/browser/autofill/autofill_manager_unittest.cc5
-rw-r--r--chrome/browser/autofill/test_autofill_external_delegate.cc22
-rw-r--r--chrome/browser/autofill/test_autofill_external_delegate.h23
-rw-r--r--chrome/browser/autofill/test_autofill_manager_delegate.cc70
-rw-r--r--chrome/browser/autofill/test_autofill_manager_delegate.h60
-rw-r--r--chrome/browser/password_manager/password_manager_delegate_impl.cc3
-rw-r--r--chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc40
-rw-r--r--chrome/browser/ui/autofill/tab_autofill_manager_delegate.cc57
-rw-r--r--chrome/browser/ui/autofill/tab_autofill_manager_delegate.h15
-rw-r--r--chrome/chrome_tests_unit.gypi6
21 files changed, 385 insertions, 372 deletions
diff --git a/chrome/browser/autofill/DEPS b/chrome/browser/autofill/DEPS
index 4245a2a..8abc235 100644
--- a/chrome/browser/autofill/DEPS
+++ b/chrome/browser/autofill/DEPS
@@ -38,7 +38,6 @@ specific_include_rules = {
"!chrome/browser/webdata/autofill_web_data_service_impl.h",
"!chrome/browser/webdata/web_data_service.h",
"!chrome/browser/webdata/web_data_service_factory.h",
- "!chrome/browser/ui/autofill/tab_autofill_manager_delegate.h",
"!chrome/browser/ui/browser.h",
"!chrome/browser/ui/browser_tabstrip.h",
"!chrome/browser/ui/browser_window.h",
diff --git a/chrome/browser/autofill/autocheckout_manager_unittest.cc b/chrome/browser/autofill/autocheckout_manager_unittest.cc
index 8c22bce..2e7b974 100644
--- a/chrome/browser/autofill/autocheckout_manager_unittest.cc
+++ b/chrome/browser/autofill/autocheckout_manager_unittest.cc
@@ -7,8 +7,8 @@
#include "chrome/browser/autofill/autocheckout_manager.h"
#include "chrome/browser/autofill/autofill_common_test.h"
#include "chrome/browser/autofill/autofill_manager.h"
-#include "chrome/browser/autofill/autofill_manager_delegate.h"
#include "chrome/browser/autofill/form_structure.h"
+#include "chrome/browser/autofill/test_autofill_manager_delegate.h"
#include "chrome/common/autofill_messages.h"
#include "chrome/common/form_data.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
@@ -198,51 +198,20 @@ scoped_ptr<FormStructure> FakeUserSubmittedFormStructure() {
return form_structure.Pass();
}
-class TestAutofillManagerDelegate : public AutofillManagerDelegate {
+class MockAutofillManagerDelegate : public TestAutofillManagerDelegate {
public:
- TestAutofillManagerDelegate()
+ MockAutofillManagerDelegate()
: request_autocomplete_dialog_open_(false),
- autocheckout_bubble_shown_(false) {
- }
-
- virtual ~TestAutofillManagerDelegate() {
- }
-
- virtual InfoBarService* GetInfoBarService() OVERRIDE {
- return NULL;
- }
-
- virtual PersonalDataManager* GetPersonalDataManager() OVERRIDE {
- return NULL;
- }
-
- virtual PrefService* GetPrefs() OVERRIDE {
- return NULL;
- }
+ autocheckout_bubble_shown_(false) {}
- virtual ProfileSyncServiceBase* GetProfileSyncService() OVERRIDE {
- return NULL;
- }
+ virtual ~MockAutofillManagerDelegate() {}
virtual void HideRequestAutocompleteDialog() OVERRIDE {
request_autocomplete_dialog_open_ = false;
}
- virtual bool IsSavingPasswordsEnabled() const OVERRIDE {
- return false;
- }
-
MOCK_METHOD0(OnAutocheckoutError, void());
- virtual void ShowAutofillSettings() OVERRIDE {
- }
-
- virtual void ShowPasswordGenerationBubble(
- const gfx::Rect& bounds,
- const content::PasswordForm& form,
- PasswordGenerator* generator) OVERRIDE {
- }
-
virtual void ShowAutocheckoutBubble(
const gfx::RectF& bounds,
const gfx::NativeView& native_view,
@@ -262,9 +231,6 @@ class TestAutofillManagerDelegate : public AutofillManagerDelegate {
callback.Run(user_supplied_data_.get());
}
- virtual void RequestAutocompleteDialogClosed() OVERRIDE {
- }
-
MOCK_METHOD1(UpdateProgressBar, void(double value));
void SetUserSuppliedData(scoped_ptr<FormStructure> user_supplied_data) {
@@ -374,12 +340,12 @@ class AutocheckoutManagerTest : public ChromeRenderViewHostTestHarness {
content::TestBrowserThread ui_thread_;
scoped_ptr<TestAutofillManager> autofill_manager_;
scoped_ptr<TestAutocheckoutManager> autocheckout_manager_;
- scoped_ptr<TestAutofillManagerDelegate> autofill_manager_delegate_;
+ scoped_ptr<MockAutofillManagerDelegate> autofill_manager_delegate_;
private:
virtual void SetUp() OVERRIDE {
ChromeRenderViewHostTestHarness::SetUp();
- autofill_manager_delegate_.reset(new TestAutofillManagerDelegate());
+ autofill_manager_delegate_.reset(new MockAutofillManagerDelegate());
autofill_manager_.reset(new TestAutofillManager(
web_contents(),
autofill_manager_delegate_.get()));
diff --git a/chrome/browser/autofill/autocomplete_history_manager_unittest.cc b/chrome/browser/autofill/autocomplete_history_manager_unittest.cc
index a09eb10..471fbfd 100644
--- a/chrome/browser/autofill/autocomplete_history_manager_unittest.cc
+++ b/chrome/browser/autofill/autocomplete_history_manager_unittest.cc
@@ -9,9 +9,9 @@
#include "base/string16.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/autofill/autocomplete_history_manager.h"
+#include "chrome/browser/autofill/autofill_external_delegate.h"
#include "chrome/browser/autofill/autofill_manager.h"
-#include "chrome/browser/autofill/autofill_manager_delegate.h"
-#include "chrome/browser/autofill/test_autofill_external_delegate.h"
+#include "chrome/browser/autofill/test_autofill_manager_delegate.h"
#include "chrome/browser/webdata/autofill_web_data_service_impl.h"
#include "chrome/browser/webdata/web_data_service.h"
#include "chrome/browser/webdata/web_data_service_factory.h"
@@ -55,39 +55,12 @@ class MockWebDataService : public WebDataService {
MockWebDataService* MockWebDataService::current_mock_web_data_service_ = NULL;
-class MockAutofillManagerDelegate : public autofill::AutofillManagerDelegate {
+class MockAutofillManagerDelegate
+ : public autofill::TestAutofillManagerDelegate {
public:
MockAutofillManagerDelegate() {}
virtual ~MockAutofillManagerDelegate() {}
-
- // AutofillManagerDelegate:
- virtual PersonalDataManager* GetPersonalDataManager() OVERRIDE {
- return NULL;
- }
- virtual InfoBarService* GetInfoBarService() { return NULL; }
virtual PrefService* GetPrefs() { return &prefs_; }
- virtual ProfileSyncServiceBase* GetProfileSyncService() { return NULL; }
- virtual void HideRequestAutocompleteDialog() OVERRIDE {}
- virtual bool IsSavingPasswordsEnabled() const { return false; }
- virtual void OnAutocheckoutError() OVERRIDE {}
- virtual void ShowAutofillSettings() {}
- virtual void ShowPasswordGenerationBubble(
- const gfx::Rect& bounds,
- const content::PasswordForm& form,
- autofill::PasswordGenerator* generator) {}
- virtual void ShowAutocheckoutBubble(
- const gfx::RectF& bounding_box,
- const gfx::NativeView& native_view,
- const base::Closure& callback) {}
- virtual void ShowRequestAutocompleteDialog(
- const FormData& form,
- const GURL& source_url,
- const content::SSLStatus& ssl_status,
- const AutofillMetrics& metric_logger,
- autofill::DialogType dialog_type,
- const base::Callback<void(const FormStructure*)>& callback) {}
- virtual void RequestAutocompleteDialogClosed() {}
- virtual void UpdateProgressBar(double value) {}
private:
TestingPrefServiceSimple prefs_;
@@ -210,20 +183,13 @@ TEST_F(AutocompleteHistoryManagerTest, SearchField) {
namespace {
-class MockAutofillExternalDelegate :
- public autofill::TestAutofillExternalDelegate {
+class MockAutofillExternalDelegate : public AutofillExternalDelegate {
public:
explicit MockAutofillExternalDelegate(content::WebContents* web_contents)
- : TestAutofillExternalDelegate(
+ : AutofillExternalDelegate(
web_contents, AutofillManager::FromWebContents(web_contents)) {}
virtual ~MockAutofillExternalDelegate() {}
- virtual void ApplyAutofillSuggestions(
- const std::vector<string16>& autofill_values,
- const std::vector<string16>& autofill_labels,
- const std::vector<string16>& autofill_icons,
- const std::vector<int>& autofill_unique_ids) OVERRIDE {};
-
MOCK_METHOD5(OnSuggestionsReturned,
void(int query_id,
const std::vector<string16>& autofill_values,
diff --git a/chrome/browser/autofill/autofill_browsertest.cc b/chrome/browser/autofill/autofill_browsertest.cc
index 4c56770..522c35e 100644
--- a/chrome/browser/autofill/autofill_browsertest.cc
+++ b/chrome/browser/autofill/autofill_browsertest.cc
@@ -203,15 +203,6 @@ class AutofillTest : public InProcessBrowserTest {
autofill_manager->SetExternalDelegate(external_delegate_.get());
}
- virtual void CleanUpOnMainThread() OVERRIDE {
- // Tear down the test external delegate while the UI is still up, as it
- // might try to close the active popup if there still is one.
- content::WebContents* web_contents =
- browser()->tab_strip_model()->GetActiveWebContents();
- AutofillManager::FromWebContents(web_contents)->SetExternalDelegate(NULL);
- external_delegate_.reset();
- }
-
PersonalDataManager* personal_data_manager() {
return PersonalDataManagerFactory::GetForProfile(browser()->profile());
}
diff --git a/chrome/browser/autofill/autofill_external_delegate.cc b/chrome/browser/autofill/autofill_external_delegate.cc
index 6d60412..4940737 100644
--- a/chrome/browser/autofill/autofill_external_delegate.cc
+++ b/chrome/browser/autofill/autofill_external_delegate.cc
@@ -6,7 +6,6 @@
#include "chrome/browser/autofill/autocomplete_history_manager.h"
#include "chrome/browser/autofill/autofill_external_delegate.h"
#include "chrome/browser/autofill/autofill_manager.h"
-#include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
#include "chrome/common/autofill_messages.h"
#include "chrome/common/chrome_constants.h"
#include "content/public/browser/navigation_controller.h"
@@ -15,7 +14,6 @@
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
-#include "content/public/browser/web_contents_view.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h"
@@ -64,10 +62,7 @@ AutofillExternalDelegate::AutofillExternalDelegate(
&(web_contents->GetController())));
}
-AutofillExternalDelegate::~AutofillExternalDelegate() {
- if (controller_)
- controller_->Hide();
-}
+AutofillExternalDelegate::~AutofillExternalDelegate() {}
void AutofillExternalDelegate::OnQuery(int query_id,
const FormData& form,
@@ -78,8 +73,7 @@ void AutofillExternalDelegate::OnQuery(int query_id,
autofill_query_field_ = field;
display_warning_if_disabled_ = display_warning_if_disabled;
autofill_query_id_ = query_id;
-
- EnsurePopupForElement(element_bounds);
+ element_bounds_ = element_bounds;
}
void AutofillExternalDelegate::OnSuggestionsReturned(
@@ -88,7 +82,7 @@ void AutofillExternalDelegate::OnSuggestionsReturned(
const std::vector<string16>& autofill_labels,
const std::vector<string16>& autofill_icons,
const std::vector<int>& autofill_unique_ids) {
- if (query_id != autofill_query_id_ || !controller_)
+ if (query_id != autofill_query_id_)
return;
std::vector<string16> values(autofill_values);
@@ -129,13 +123,15 @@ void AutofillExternalDelegate::OnSuggestionsReturned(
if (values.empty()) {
// No suggestions, any popup currently showing is obsolete.
- HideAutofillPopup();
+ autofill_manager_->delegate()->HideAutofillPopup();
return;
}
// Send to display.
- if (autofill_query_field_.is_focusable)
- ApplyAutofillSuggestions(values, labels, icons, ids);
+ if (autofill_query_field_.is_focusable) {
+ autofill_manager_->delegate()->ShowAutofillPopup(
+ element_bounds_, values, labels, icons, ids, this);
+ }
}
void AutofillExternalDelegate::OnShowPasswordSuggestions(
@@ -143,44 +139,18 @@ void AutofillExternalDelegate::OnShowPasswordSuggestions(
const FormFieldData& field,
const gfx::RectF& element_bounds) {
autofill_query_field_ = field;
- EnsurePopupForElement(element_bounds);
+ element_bounds_ = element_bounds;
if (suggestions.empty()) {
- HideAutofillPopup();
+ autofill_manager_->delegate()->HideAutofillPopup();
return;
}
std::vector<string16> empty(suggestions.size());
std::vector<int> password_ids(suggestions.size(),
WebAutofillClient::MenuItemIDPasswordEntry);
- ApplyAutofillSuggestions(suggestions, empty, empty, password_ids);
-}
-
-void AutofillExternalDelegate::EnsurePopupForElement(
- const gfx::RectF& element_bounds) {
- // Convert element_bounds to be in screen space.
- gfx::Rect client_area;
- web_contents_->GetView()->GetContainerBounds(&client_area);
- gfx::RectF element_bounds_in_screen_space =
- element_bounds + client_area.OffsetFromOrigin();
-
- // |controller_| owns itself.
- controller_ = AutofillPopupControllerImpl::GetOrCreate(
- controller_,
- this,
- web_contents()->GetView()->GetContentNativeView(),
- element_bounds_in_screen_space);
-}
-
-void AutofillExternalDelegate::ApplyAutofillSuggestions(
- const std::vector<string16>& autofill_values,
- const std::vector<string16>& autofill_labels,
- const std::vector<string16>& autofill_icons,
- const std::vector<int>& autofill_unique_ids) {
- controller_->Show(autofill_values,
- autofill_labels,
- autofill_icons,
- autofill_unique_ids);
+ autofill_manager_->delegate()->ShowAutofillPopup(
+ element_bounds_, suggestions, empty, empty, password_ids, this);
}
void AutofillExternalDelegate::SetCurrentDataListValues(
@@ -247,7 +217,7 @@ void AutofillExternalDelegate::DidAcceptSuggestion(const string16& value,
FillAutofillFormData(identifier, false);
}
- HideAutofillPopup();
+ autofill_manager_->delegate()->HideAutofillPopup();
}
void AutofillExternalDelegate::RemoveSuggestion(const string16& value,
@@ -261,7 +231,7 @@ void AutofillExternalDelegate::RemoveSuggestion(const string16& value,
}
void AutofillExternalDelegate::DidEndTextFieldEditing() {
- HideAutofillPopup();
+ autofill_manager_->delegate()->HideAutofillPopup();
has_shown_autofill_popup_for_current_edit_ = false;
}
@@ -272,13 +242,8 @@ void AutofillExternalDelegate::ClearPreviewedForm() {
host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID()));
}
-void AutofillExternalDelegate::HideAutofillPopup() {
- if (controller_)
- controller_->Hide();
-}
-
void AutofillExternalDelegate::Reset() {
- HideAutofillPopup();
+ autofill_manager_->delegate()->HideAutofillPopup();
password_autofill_manager_.Reset();
}
@@ -409,9 +374,9 @@ void AutofillExternalDelegate::Observe(
const content::NotificationDetails& details) {
if (type == content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED) {
if (!*content::Details<bool>(details).ptr())
- HideAutofillPopup();
+ autofill_manager_->delegate()->HideAutofillPopup();
} else if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) {
- HideAutofillPopup();
+ autofill_manager_->delegate()->HideAutofillPopup();
} else {
NOTREACHED();
}
diff --git a/chrome/browser/autofill/autofill_external_delegate.h b/chrome/browser/autofill/autofill_external_delegate.h
index d370bb0..9fc33dd 100644
--- a/chrome/browser/autofill/autofill_external_delegate.h
+++ b/chrome/browser/autofill/autofill_external_delegate.h
@@ -21,7 +21,6 @@
#include "ui/gfx/rect.h"
class AutofillManager;
-class AutofillPopupControllerImpl;
namespace gfx {
class Rect;
@@ -102,31 +101,14 @@ class AutofillExternalDelegate
const FormFieldData& form,
const PasswordFormFillData& fill_data);
- virtual void HideAutofillPopup();
-
protected:
friend class content::WebContentsUserData<AutofillExternalDelegate>;
AutofillExternalDelegate(content::WebContents* web_contents,
AutofillManager* autofill_manager);
virtual ~AutofillExternalDelegate();
- // Displays the Autofill results to the user with an external Autofill popup
- // that lives completely in the browser. The suggestions have been correctly
- // formatted by this point.
- virtual void ApplyAutofillSuggestions(
- const std::vector<string16>& autofill_values,
- const std::vector<string16>& autofill_labels,
- const std::vector<string16>& autofill_icons,
- const std::vector<int>& autofill_unique_ids);
-
- // Create the popup if it doesn't already exist. |element_bounds| is the
- // bounding rect for the element it is popping up for.
- virtual void EnsurePopupForElement(const gfx::RectF& element_bounds);
-
content::WebContents* web_contents() { return web_contents_; }
- AutofillPopupControllerImpl* controller() { return controller_; }
-
private:
// Fills the form with the Autofill data corresponding to |unique_id|.
// If |is_preview| is true then this is just a preview to show the user what
@@ -163,7 +145,6 @@ class AutofillExternalDelegate
// The web_contents associated with this delegate.
content::WebContents* web_contents_; // weak; owns me.
AutofillManager* autofill_manager_; // weak.
- base::WeakPtr<AutofillPopupControllerImpl> controller_;
// Password Autofill manager, handles all password-related Autofilling.
PasswordAutofillManager password_autofill_manager_;
@@ -179,6 +160,9 @@ class AutofillExternalDelegate
FormData autofill_query_form_;
FormFieldData autofill_query_field_;
+ // The bounds of the form field that user is interacting with.
+ gfx::RectF element_bounds_;
+
// Should we display a warning if Autofill is disabled?
bool display_warning_if_disabled_;
diff --git a/chrome/browser/autofill/autofill_external_delegate_browsertest.cc b/chrome/browser/autofill/autofill_external_delegate_browsertest.cc
index 0c2863a..c7ed801 100644
--- a/chrome/browser/autofill/autofill_external_delegate_browsertest.cc
+++ b/chrome/browser/autofill/autofill_external_delegate_browsertest.cc
@@ -5,13 +5,13 @@
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/autofill/autofill_manager.h"
#include "chrome/browser/autofill/test_autofill_external_delegate.h"
-#include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
-#include "chrome/browser/ui/autofill/autofill_popup_view.h"
+#include "chrome/browser/autofill/test_autofill_manager_delegate.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/testing_pref_service_syncable.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
@@ -19,51 +19,53 @@
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/test_utils.h"
+#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/rect.h"
namespace {
-class MockAutofillExternalDelegate : public AutofillExternalDelegate {
+class MockAutofillManagerDelegate
+ : public autofill::TestAutofillManagerDelegate {
public:
- explicit MockAutofillExternalDelegate(content::WebContents* web_contents)
- : AutofillExternalDelegate(
- web_contents,
- AutofillManager::FromWebContents(web_contents)),
- popup_hidden_(true) {}
- ~MockAutofillExternalDelegate() {}
+ virtual PrefService* GetPrefs() { return &prefs_; }
- virtual void DidSelectSuggestion(int unique_id) OVERRIDE {}
-
- virtual void ClearPreviewedForm() OVERRIDE {}
-
- AutofillPopupControllerImpl* GetController() {
- return controller();
+ PrefRegistrySyncable* GetPrefRegistry() {
+ return prefs_.registry();
}
- virtual void ApplyAutofillSuggestions(
- const std::vector<string16>& autofill_values,
- const std::vector<string16>& autofill_labels,
- const std::vector<string16>& autofill_icons,
- const std::vector<int>& autofill_unique_ids) OVERRIDE {
- popup_hidden_ = false;
-
- AutofillExternalDelegate::ApplyAutofillSuggestions(autofill_values,
- autofill_labels,
- autofill_icons,
- autofill_unique_ids);
- }
+ MOCK_METHOD6(ShowAutofillPopup,
+ void(const gfx::RectF& element_bounds,
+ const std::vector<string16>& values,
+ const std::vector<string16>& labels,
+ const std::vector<string16>& icons,
+ const std::vector<int>& identifiers,
+ AutofillPopupDelegate* delegate));
- virtual void HideAutofillPopup() OVERRIDE {
- popup_hidden_ = true;
+ MOCK_METHOD0(HideAutofillPopup, void());
- AutofillExternalDelegate::HideAutofillPopup();
- }
+ private:
+ TestingPrefServiceSyncable prefs_;
+};
- bool popup_hidden() const { return popup_hidden_; }
+// Subclass AutofillManager so we can create AutofillManager instance.
+class TestAutofillManager : public AutofillManager {
+ public:
+ TestAutofillManager(content::WebContents* web_contents,
+ autofill::AutofillManagerDelegate* delegate)
+ : AutofillManager(web_contents, delegate) {}
+ virtual ~TestAutofillManager() {}
private:
- bool popup_hidden_;
+ DISALLOW_COPY_AND_ASSIGN(TestAutofillManager);
+};
+
+class TestAutofillExternalDelegate : public AutofillExternalDelegate {
+ public:
+ TestAutofillExternalDelegate(content::WebContents* web_contents,
+ AutofillManager* autofill_manager)
+ : AutofillExternalDelegate(web_contents, autofill_manager) {}
+ ~TestAutofillExternalDelegate() {}
};
} // namespace
@@ -80,8 +82,13 @@ class AutofillExternalDelegateBrowserTest
ASSERT_TRUE(web_contents_ != NULL);
Observe(web_contents_);
+ AutofillManager::RegisterUserPrefs(manager_delegate_.GetPrefRegistry());
+
+ autofill_manager_.reset(
+ new TestAutofillManager(web_contents_, &manager_delegate_));
autofill_external_delegate_.reset(
- new MockAutofillExternalDelegate(web_contents_));
+ new TestAutofillExternalDelegate(web_contents_,
+ autofill_manager_.get()));
}
// Normally the WebContents will automatically delete the delegate, but here
@@ -90,32 +97,42 @@ class AutofillExternalDelegateBrowserTest
OVERRIDE {
DCHECK_EQ(web_contents_, web_contents);
autofill_external_delegate_.reset();
+ autofill_manager_.reset();
}
protected:
content::WebContents* web_contents_;
- scoped_ptr<MockAutofillExternalDelegate> autofill_external_delegate_;
+
+ testing::NiceMock<MockAutofillManagerDelegate> manager_delegate_;
+ scoped_ptr<TestAutofillManager> autofill_manager_;
+ scoped_ptr<TestAutofillExternalDelegate> autofill_external_delegate_;
};
IN_PROC_BROWSER_TEST_F(AutofillExternalDelegateBrowserTest,
SwitchTabAndHideAutofillPopup) {
autofill::GenerateTestAutofillPopup(autofill_external_delegate_.get());
+ // Notification is different on platforms. On linux this will be called twice,
+ // while on windows only once.
+ EXPECT_CALL(manager_delegate_, HideAutofillPopup())
+ .Times(testing::AtLeast(1));
+
content::WindowedNotificationObserver observer(
content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
content::Source<content::WebContents>(web_contents_));
chrome::AddSelectedTabWithURL(browser(), GURL(chrome::kAboutBlankURL),
content::PAGE_TRANSITION_AUTO_TOPLEVEL);
observer.Wait();
-
- EXPECT_TRUE(autofill_external_delegate_->popup_hidden());
}
IN_PROC_BROWSER_TEST_F(AutofillExternalDelegateBrowserTest,
TestPageNavigationHidingAutofillPopup) {
autofill::GenerateTestAutofillPopup(autofill_external_delegate_.get());
- EXPECT_FALSE(autofill_external_delegate_->popup_hidden());
+ // Notification is different on platforms. On linux this will be called twice,
+ // while on windows only once.
+ EXPECT_CALL(manager_delegate_, HideAutofillPopup())
+ .Times(testing::AtLeast(1));
content::WindowedNotificationObserver observer(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
@@ -128,17 +145,4 @@ IN_PROC_BROWSER_TEST_F(AutofillExternalDelegateBrowserTest,
GURL(chrome::kChromeUIAboutURL), content::Referrer(),
CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false));
observer.Wait();
-
- EXPECT_TRUE(autofill_external_delegate_->popup_hidden());
-}
-
-// Tests that closing the widget does not leak any resources. This test is
-// only really meaningful when run on the memory bots.
-IN_PROC_BROWSER_TEST_F(AutofillExternalDelegateBrowserTest,
- CloseWidgetAndNoLeaking) {
- autofill::GenerateTestAutofillPopup(autofill_external_delegate_.get());
-
- // Delete the view from under the delegate to ensure that the
- // delegate and the controller can handle the popup getting deleted elsewhere.
- autofill_external_delegate_->GetController()->view()->Hide();
}
diff --git a/chrome/browser/autofill/autofill_external_delegate_unittest.cc b/chrome/browser/autofill/autofill_external_delegate_unittest.cc
index cb5df56..6f7a0c6 100644
--- a/chrome/browser/autofill/autofill_external_delegate_unittest.cc
+++ b/chrome/browser/autofill/autofill_external_delegate_unittest.cc
@@ -8,7 +8,7 @@
#include "base/string16.h"
#include "chrome/browser/autofill/autofill_manager.h"
#include "chrome/browser/autofill/test_autofill_external_delegate.h"
-#include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h"
+#include "chrome/browser/autofill/test_autofill_manager_delegate.h"
#include "chrome/common/form_data.h"
#include "chrome/common/form_field_data.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
@@ -31,31 +31,43 @@ const int kQueryId = 5;
// A constant value to use as an Autofill profile ID.
const int kAutofillProfileId = 1;
-class MockAutofillExternalDelegate :
- public autofill::TestAutofillExternalDelegate {
+class MockAutofillExternalDelegate : public AutofillExternalDelegate {
public:
MockAutofillExternalDelegate(content::WebContents* web_contents,
AutofillManager* autofill_manger)
- : TestAutofillExternalDelegate(web_contents, autofill_manger) {}
- ~MockAutofillExternalDelegate() {}
+ : AutofillExternalDelegate(web_contents, autofill_manger) {}
- MOCK_METHOD4(ApplyAutofillSuggestions, void(
- const std::vector<string16>& labels,
- const std::vector<string16>& sub_labels,
- const std::vector<string16>& icons,
- const std::vector<int>& identifiers));
+ ~MockAutofillExternalDelegate() {}
MOCK_METHOD0(ClearPreviewedForm, void());
- MOCK_METHOD1(EnsurePopupForElement, void(const gfx::RectF& element_bounds));
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate);
+};
+
+class MockAutofillManagerDelegate
+ : public autofill::TestAutofillManagerDelegate {
+ public:
+ MockAutofillManagerDelegate() {}
+
+ MOCK_METHOD6(ShowAutofillPopup,
+ void(const gfx::RectF& element_bounds,
+ const std::vector<string16>& values,
+ const std::vector<string16>& labels,
+ const std::vector<string16>& icons,
+ const std::vector<int>& identifiers,
+ AutofillPopupDelegate* delegate));
MOCK_METHOD0(HideAutofillPopup, void());
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate);
};
class MockAutofillManager : public AutofillManager {
public:
- explicit MockAutofillManager(content::WebContents* web_contents,
- autofill::AutofillManagerDelegate* delegate)
+ MockAutofillManager(content::WebContents* web_contents,
+ MockAutofillManagerDelegate* delegate)
// Force to use the constructor designated for unit test, but we don't
// really need personal_data in this test so we pass a NULL pointer.
: AutofillManager(web_contents, delegate, NULL) {
@@ -67,6 +79,9 @@ class MockAutofillManager : public AutofillManager {
const FormData& form,
const FormFieldData& field,
int unique_id));
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockAutofillManager);
};
} // namespace
@@ -79,8 +94,7 @@ class AutofillExternalDelegateUnitTest
virtual ~AutofillExternalDelegateUnitTest() {}
protected:
- // Set up the expectation for a platform specific OnQuery call and then
- // execute it with the given QueryId.
+ // Issue an OnQuery call with the given |query_id|.
void IssueOnQuery(int query_id) {
const FormData form;
FormFieldData field;
@@ -88,10 +102,10 @@ class AutofillExternalDelegateUnitTest
field.should_autocomplete = true;
const gfx::RectF element_bounds;
- EXPECT_CALL(*external_delegate_, EnsurePopupForElement(element_bounds));
external_delegate_->OnQuery(query_id, form, field, element_bounds, false);
}
+ MockAutofillManagerDelegate manager_delegate_;
scoped_ptr<MockAutofillManager> autofill_manager_;
scoped_ptr<testing::NiceMock<MockAutofillExternalDelegate> >
external_delegate_;
@@ -99,10 +113,8 @@ class AutofillExternalDelegateUnitTest
private:
virtual void SetUp() OVERRIDE {
ChromeRenderViewHostTestHarness::SetUp();
- autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents());
- autofill_manager_.reset(new MockAutofillManager(
- web_contents(),
- autofill::TabAutofillManagerDelegate::FromWebContents(web_contents())));
+ autofill_manager_.reset(
+ new MockAutofillManager(web_contents(), &manager_delegate_));
external_delegate_.reset(
new testing::NiceMock<MockAutofillExternalDelegate>(
web_contents(),
@@ -129,14 +141,17 @@ TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) {
IssueOnQuery(kQueryId);
// The enums must be cast to ints to prevent compile errors on linux_rel.
- EXPECT_CALL(*external_delegate_,
- ApplyAutofillSuggestions(_, _, _, testing::ElementsAre(
- kAutofillProfileId,
- static_cast<int>(WebAutofillClient::MenuItemIDSeparator),
- static_cast<int>(
- WebAutofillClient::MenuItemIDAutofillOptions))));
-
- // This should call ApplyAutofillSuggestions.
+ EXPECT_CALL(manager_delegate_,
+ ShowAutofillPopup(
+ _, _, _, _,
+ testing::ElementsAre(
+ kAutofillProfileId,
+ static_cast<int>(WebAutofillClient::MenuItemIDSeparator),
+ static_cast<int>(
+ WebAutofillClient::MenuItemIDAutofillOptions)),
+ external_delegate_.get()));
+
+ // This should call ShowAutofillPopup.
std::vector<string16> autofill_item;
autofill_item.push_back(string16());
std::vector<int> autofill_ids;
@@ -150,10 +165,10 @@ TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) {
// Called by DidAutofillSuggestions, add expectation to remove warning.
EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _));
- EXPECT_CALL(*external_delegate_, HideAutofillPopup());
+ EXPECT_CALL(manager_delegate_, HideAutofillPopup());
- // This should trigger a call to hide the popup since
- // we've selected an option.
+ // This should trigger a call to hide the popup since we've selected an
+ // option.
external_delegate_->DidAcceptSuggestion(autofill_item[0], autofill_ids[0]);
}
@@ -172,18 +187,20 @@ TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) {
data_list_ids);
// The enums must be cast to ints to prevent compile errors on linux_rel.
- EXPECT_CALL(*external_delegate_,
- ApplyAutofillSuggestions(
- _, _, _, testing::ElementsAre(
+ EXPECT_CALL(manager_delegate_,
+ ShowAutofillPopup(
+ _, _, _, _,
+ testing::ElementsAre(
static_cast<int>(
WebAutofillClient::MenuItemIDDataListEntry),
static_cast<int>(WebAutofillClient::MenuItemIDSeparator),
kAutofillProfileId,
static_cast<int>(WebAutofillClient::MenuItemIDSeparator),
static_cast<int>(
- WebAutofillClient::MenuItemIDAutofillOptions))));
+ WebAutofillClient::MenuItemIDAutofillOptions)),
+ external_delegate_.get()));
- // This should call ApplyAutofillSuggestions.
+ // This should call ShowAutofillPopup.
std::vector<string16> autofill_item;
autofill_item.push_back(string16());
std::vector<int> autofill_ids;
@@ -197,11 +214,13 @@ TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) {
// Try calling OnSuggestionsReturned with no Autofill values and ensure
// the datalist items are still shown.
// The enum must be cast to an int to prevent compile errors on linux_rel.
- EXPECT_CALL(*external_delegate_,
- ApplyAutofillSuggestions(
- _, _, _, testing::ElementsAre(
+ EXPECT_CALL(manager_delegate_,
+ ShowAutofillPopup(
+ _, _, _, _,
+ testing::ElementsAre(
static_cast<int>(
- WebAutofillClient::MenuItemIDDataListEntry))));
+ WebAutofillClient::MenuItemIDDataListEntry)),
+ external_delegate_.get()));
autofill_item = std::vector<string16>();
autofill_ids = std::vector<int>();
@@ -221,6 +240,7 @@ TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) {
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);
external_delegate_->DidAcceptSuggestion(string16(), -1);
}
@@ -228,8 +248,7 @@ TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) {
// Test that the ClearPreview IPC is only sent the form was being previewed
// (i.e. it isn't autofilling a password).
TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) {
- // Called by DidSelectSuggestion, add expectation to remove
- // warning.
+ // Called by DidSelectSuggestion, add expectation to remove warning.
EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _));
// Ensure selecting a new password entries or Autofill entries will
@@ -245,13 +264,10 @@ TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) {
// Test that the popup is hidden once we are done editing the autofill field.
TEST_F(AutofillExternalDelegateUnitTest,
ExternalDelegateHidePopupAfterEditing) {
- EXPECT_CALL(*external_delegate_, EnsurePopupForElement(_));
- EXPECT_CALL(*external_delegate_, ApplyAutofillSuggestions(_, _, _, _));
-
+ EXPECT_CALL(manager_delegate_, ShowAutofillPopup(_, _, _, _, _, _));
autofill::GenerateTestAutofillPopup(external_delegate_.get());
- EXPECT_CALL(*external_delegate_, HideAutofillPopup());
-
+ EXPECT_CALL(manager_delegate_, HideAutofillPopup());
external_delegate_->DidEndTextFieldEditing();
}
@@ -266,13 +282,14 @@ TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegatePasswordSuggestions) {
field.should_autocomplete = true;
const gfx::RectF element_bounds;
- EXPECT_CALL(*external_delegate_, EnsurePopupForElement(element_bounds));
-
// The enums must be cast to ints to prevent compile errors on linux_rel.
- EXPECT_CALL(*external_delegate_,
- ApplyAutofillSuggestions(_, _, _, testing::ElementsAre(
- static_cast<int>(
- WebAutofillClient::MenuItemIDPasswordEntry))));
+ EXPECT_CALL(manager_delegate_,
+ ShowAutofillPopup(
+ _, _, _, _,
+ testing::ElementsAre(
+ static_cast<int>(
+ WebAutofillClient::MenuItemIDPasswordEntry)),
+ external_delegate_.get()));
external_delegate_->OnShowPasswordSuggestions(suggestions,
field,
@@ -281,7 +298,7 @@ TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegatePasswordSuggestions) {
// Called by DidAutofillSuggestions, add expectation to remove warning.
EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _));
- EXPECT_CALL(*external_delegate_, HideAutofillPopup());
+ EXPECT_CALL(manager_delegate_, HideAutofillPopup());
// This should trigger a call to hide the popup since
// we've selected an option.
diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc
index ae55f14..eedeb9c 100644
--- a/chrome/browser/autofill/autofill_manager.cc
+++ b/chrome/browser/autofill/autofill_manager.cc
@@ -323,7 +323,7 @@ void AutofillManager::SetExternalDelegate(AutofillExternalDelegate* delegate) {
autocomplete_history_manager_.SetExternalDelegate(delegate);
}
-bool AutofillManager::HasExternalDelegate() {
+bool AutofillManager::IsNativeUiEnabled() {
return external_delegate_ != NULL;
}
@@ -729,8 +729,8 @@ void AutofillManager::OnDidShowAutofillSuggestions(bool is_new_popup) {
}
void AutofillManager::OnHideAutofillPopup() {
- if (external_delegate_)
- external_delegate_->HideAutofillPopup();
+ if (IsNativeUiEnabled())
+ manager_delegate_->HideAutofillPopup();
}
void AutofillManager::OnShowPasswordGenerationPopup(
diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h
index ca52e4a..b071265 100644
--- a/chrome/browser/autofill/autofill_manager.h
+++ b/chrome/browser/autofill/autofill_manager.h
@@ -89,8 +89,8 @@ class AutofillManager : public content::WebContentsObserver,
// Set an external delegate.
void SetExternalDelegate(AutofillExternalDelegate* delegate);
- // Used to say if this class has an external delegate that it is using.
- bool HasExternalDelegate();
+ // Whether browser process will create and own the Autofill popup UI.
+ bool IsNativeUiEnabled();
// Called from our external delegate so they cannot be private.
virtual void OnFillAutofillFormData(int query_id,
diff --git a/chrome/browser/autofill/autofill_manager_delegate.h b/chrome/browser/autofill/autofill_manager_delegate.h
index 721dd8a..f908352 100644
--- a/chrome/browser/autofill/autofill_manager_delegate.h
+++ b/chrome/browser/autofill/autofill_manager_delegate.h
@@ -5,7 +5,10 @@
#ifndef CHROME_BROWSER_AUTOFILL_AUTOFILL_MANAGER_DELEGATE_H_
#define CHROME_BROWSER_AUTOFILL_AUTOFILL_MANAGER_DELEGATE_H_
+#include <vector>
+
#include "base/callback_forward.h"
+#include "base/string16.h"
#include "ui/gfx/native_widget_types.h"
namespace autofill {
@@ -23,6 +26,7 @@ class RectF;
}
class AutofillMetrics;
+class AutofillPopupDelegate;
class FormStructure;
class GURL;
class InfoBarService;
@@ -104,9 +108,23 @@ class AutofillManagerDelegate {
DialogType dialog_type,
const base::Callback<void(const FormStructure*)>& callback) = 0;
- // Called when the dialog for request autocomplete closes.
+ // Called when the dialog for request autocomplete closes. (So UI code will
+ // free memory, etc.)
virtual void RequestAutocompleteDialogClosed() = 0;
+ // Shows an Autofill popup with the given |values|, |labels|, |icons|, and
+ // |identifiers| for the element at |element_bounds|. |delegate| will be
+ // notified of popup events.
+ virtual void ShowAutofillPopup(const gfx::RectF& element_bounds,
+ const std::vector<string16>& values,
+ const std::vector<string16>& labels,
+ const std::vector<string16>& icons,
+ const std::vector<int>& identifiers,
+ AutofillPopupDelegate* delegate) = 0;
+
+ // Hide the Autofill popup if one is currently showing.
+ virtual void HideAutofillPopup() = 0;
+
// Updates the Autocheckout progress bar. |value| must be in [0.0, 1.0].
virtual void UpdateProgressBar(double value) = 0;
};
diff --git a/chrome/browser/autofill/autofill_manager_unittest.cc b/chrome/browser/autofill/autofill_manager_unittest.cc
index 7d494b9..b730e49 100644
--- a/chrome/browser/autofill/autofill_manager_unittest.cc
+++ b/chrome/browser/autofill/autofill_manager_unittest.cc
@@ -3191,12 +3191,11 @@ TEST_F(AutofillManagerTest, DisabledAutofillDispatchesError) {
namespace {
-class MockAutofillExternalDelegate :
- public autofill::TestAutofillExternalDelegate {
+class MockAutofillExternalDelegate : public AutofillExternalDelegate {
public:
explicit MockAutofillExternalDelegate(content::WebContents* web_contents,
AutofillManager* autofill_manager)
- : TestAutofillExternalDelegate(web_contents, autofill_manager) {}
+ : AutofillExternalDelegate(web_contents, autofill_manager) {}
virtual ~MockAutofillExternalDelegate() {}
MOCK_METHOD5(OnQuery, void(int query_id,
diff --git a/chrome/browser/autofill/test_autofill_external_delegate.cc b/chrome/browser/autofill/test_autofill_external_delegate.cc
index 7bbdc23..ef56594 100644
--- a/chrome/browser/autofill/test_autofill_external_delegate.cc
+++ b/chrome/browser/autofill/test_autofill_external_delegate.cc
@@ -26,26 +26,4 @@ void GenerateTestAutofillPopup(
query_id, autofill_item, autofill_item, autofill_item, autofill_id);
}
-TestAutofillExternalDelegate::TestAutofillExternalDelegate(
- content::WebContents* web_contents,
- AutofillManager* autofill_manager)
- : AutofillExternalDelegate(web_contents, autofill_manager) {
- // Initialize Controller.
- const gfx::RectF element_bounds;
- AutofillExternalDelegate::EnsurePopupForElement(element_bounds);
-}
-
-TestAutofillExternalDelegate::~TestAutofillExternalDelegate() {}
-
-void TestAutofillExternalDelegate::ApplyAutofillSuggestions(
- const std::vector<string16>& autofill_values,
- const std::vector<string16>& autofill_labels,
- const std::vector<string16>& autofill_icons,
- const std::vector<int>& autofill_unique_ids) {}
-
-void TestAutofillExternalDelegate::HideAutofillPopup() {}
-
-void TestAutofillExternalDelegate::EnsurePopupForElement(
- const gfx::RectF& element_bounds) {}
-
} // namespace autofill
diff --git a/chrome/browser/autofill/test_autofill_external_delegate.h b/chrome/browser/autofill/test_autofill_external_delegate.h
index 10a845f..19e1473 100644
--- a/chrome/browser/autofill/test_autofill_external_delegate.h
+++ b/chrome/browser/autofill/test_autofill_external_delegate.h
@@ -16,29 +16,6 @@ namespace autofill {
void GenerateTestAutofillPopup(
AutofillExternalDelegate* autofill_external_delegate);
-// This test class is meant to give tests a base AutofillExternalDelegate
-// class that requires no additional work to compile with (i.e. all the
-// pure virtual functions have been giving empty methods).
-class TestAutofillExternalDelegate : public AutofillExternalDelegate {
- public:
- TestAutofillExternalDelegate(content::WebContents* web_contents,
- AutofillManager* autofill_manager);
- virtual ~TestAutofillExternalDelegate();
-
- virtual void ApplyAutofillSuggestions(
- const std::vector<string16>& autofill_values,
- const std::vector<string16>& autofill_labels,
- const std::vector<string16>& autofill_icons,
- const std::vector<int>& autofill_unique_ids) OVERRIDE;
-
- virtual void HideAutofillPopup() OVERRIDE;
-
- virtual void EnsurePopupForElement(const gfx::RectF& element_bounds) OVERRIDE;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(TestAutofillExternalDelegate);
-};
-
} // namespace autofill
#endif // CHROME_BROWSER_AUTOFILL_TEST_AUTOFILL_EXTERNAL_DELEGATE_H_
diff --git a/chrome/browser/autofill/test_autofill_manager_delegate.cc b/chrome/browser/autofill/test_autofill_manager_delegate.cc
new file mode 100644
index 0000000..169db1f
--- /dev/null
+++ b/chrome/browser/autofill/test_autofill_manager_delegate.cc
@@ -0,0 +1,70 @@
+// Copyright (c) 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 "chrome/browser/autofill/test_autofill_manager_delegate.h"
+
+namespace autofill {
+
+TestAutofillManagerDelegate::TestAutofillManagerDelegate() {}
+TestAutofillManagerDelegate::~TestAutofillManagerDelegate() {}
+
+InfoBarService* TestAutofillManagerDelegate::GetInfoBarService() {
+ return NULL;
+}
+
+PersonalDataManager* TestAutofillManagerDelegate::GetPersonalDataManager() {
+ return NULL;
+}
+
+PrefService* TestAutofillManagerDelegate::GetPrefs() {
+ return NULL;
+}
+
+ProfileSyncServiceBase* TestAutofillManagerDelegate::GetProfileSyncService() {
+ return NULL;
+}
+
+void TestAutofillManagerDelegate::HideRequestAutocompleteDialog() {}
+
+bool TestAutofillManagerDelegate::IsSavingPasswordsEnabled() const {
+ return false;
+}
+
+void TestAutofillManagerDelegate::OnAutocheckoutError() {}
+
+void TestAutofillManagerDelegate::ShowAutofillSettings() {}
+
+void TestAutofillManagerDelegate::ShowPasswordGenerationBubble(
+ const gfx::Rect& bounds,
+ const content::PasswordForm& form,
+ autofill::PasswordGenerator* generator) {}
+
+void TestAutofillManagerDelegate::ShowAutocheckoutBubble(
+ const gfx::RectF& bounding_box,
+ const gfx::NativeView& native_view,
+ const base::Closure& callback) {}
+
+void TestAutofillManagerDelegate::ShowRequestAutocompleteDialog(
+ const FormData& form,
+ const GURL& source_url,
+ const content::SSLStatus& ssl_status,
+ const AutofillMetrics& metric_logger,
+ DialogType dialog_type,
+ const base::Callback<void(const FormStructure*)>& callback) {}
+
+void TestAutofillManagerDelegate::RequestAutocompleteDialogClosed() {}
+
+void TestAutofillManagerDelegate::ShowAutofillPopup(
+ const gfx::RectF& element_bounds,
+ const std::vector<string16>& values,
+ const std::vector<string16>& labels,
+ const std::vector<string16>& icons,
+ const std::vector<int>& identifiers,
+ AutofillPopupDelegate* delegate) {}
+
+void TestAutofillManagerDelegate::HideAutofillPopup() {}
+
+void TestAutofillManagerDelegate::UpdateProgressBar(double value) {}
+
+} // namespace autofill
diff --git a/chrome/browser/autofill/test_autofill_manager_delegate.h b/chrome/browser/autofill/test_autofill_manager_delegate.h
new file mode 100644
index 0000000..86ab904
--- /dev/null
+++ b/chrome/browser/autofill/test_autofill_manager_delegate.h
@@ -0,0 +1,60 @@
+// Copyright (c) 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.
+
+#ifndef CHROME_BROWSER_AUTOFILL_TEST_AUTOFILL_MANAGER_DELEGATE_H_
+#define CHROME_BROWSER_AUTOFILL_TEST_AUTOFILL_MANAGER_DELEGATE_H_
+
+#include "base/compiler_specific.h"
+#include "chrome/browser/autofill/autofill_manager_delegate.h"
+
+namespace autofill {
+
+// This class is only for easier writing of testings. All pure virtual functions
+// have been giving empty methods.
+class TestAutofillManagerDelegate : public AutofillManagerDelegate {
+ public:
+ TestAutofillManagerDelegate();
+ virtual ~TestAutofillManagerDelegate();
+
+ // AutofillManagerDelegate implementation.
+ virtual InfoBarService* GetInfoBarService() OVERRIDE;
+ virtual PersonalDataManager* GetPersonalDataManager() OVERRIDE;
+ virtual PrefService* GetPrefs() OVERRIDE;
+ virtual ProfileSyncServiceBase* GetProfileSyncService() OVERRIDE;
+ virtual void HideRequestAutocompleteDialog() OVERRIDE;
+ virtual bool IsSavingPasswordsEnabled() const OVERRIDE;
+ virtual void OnAutocheckoutError() OVERRIDE;
+ virtual void ShowAutofillSettings() OVERRIDE;
+ virtual void ShowPasswordGenerationBubble(
+ const gfx::Rect& bounds,
+ const content::PasswordForm& form,
+ autofill::PasswordGenerator* generator) OVERRIDE;
+ virtual void ShowAutocheckoutBubble(
+ const gfx::RectF& bounding_box,
+ const gfx::NativeView& native_view,
+ const base::Closure& callback) OVERRIDE;
+ virtual void ShowRequestAutocompleteDialog(
+ const FormData& form,
+ const GURL& source_url,
+ const content::SSLStatus& ssl_status,
+ const AutofillMetrics& metric_logger,
+ DialogType dialog_type,
+ const base::Callback<void(const FormStructure*)>& callback) OVERRIDE;
+ virtual void RequestAutocompleteDialogClosed() OVERRIDE;
+ virtual void ShowAutofillPopup(const gfx::RectF& element_bounds,
+ const std::vector<string16>& values,
+ const std::vector<string16>& labels,
+ const std::vector<string16>& icons,
+ const std::vector<int>& identifiers,
+ AutofillPopupDelegate* delegate) OVERRIDE;
+ virtual void HideAutofillPopup() OVERRIDE;
+ virtual void UpdateProgressBar(double value) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestAutofillManagerDelegate);
+};
+
+} // namespace autofill
+
+#endif // CHROME_BROWSER_AUTOFILL_TEST_AUTOFILL_MANAGER_DELEGATE_H_
diff --git a/chrome/browser/password_manager/password_manager_delegate_impl.cc b/chrome/browser/password_manager/password_manager_delegate_impl.cc
index fc9c55e..52b0819 100644
--- a/chrome/browser/password_manager/password_manager_delegate_impl.cc
+++ b/chrome/browser/password_manager/password_manager_delegate_impl.cc
@@ -166,7 +166,8 @@ void PasswordManagerDelegateImpl::FillPasswordForm(
const PasswordFormFillData& form_data) {
AutofillManager* autofill_manager =
AutofillManager::FromWebContents(web_contents_);
- bool disable_popup = autofill_manager->HasExternalDelegate();
+ // Browser process will own popup UI, so renderer should not show the popup.
+ bool disable_popup = autofill_manager->IsNativeUiEnabled();
web_contents_->GetRenderViewHost()->Send(
new AutofillMsg_FillPasswordForm(
diff --git a/chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc b/chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc
index 92406d96..4bd1f01 100644
--- a/chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc
+++ b/chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc
@@ -6,9 +6,10 @@
#include "base/memory/weak_ptr.h"
#include "base/prefs/testing_pref_service.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/autofill/autofill_external_delegate.h"
#include "chrome/browser/autofill/autofill_manager.h"
-#include "chrome/browser/autofill/autofill_manager_delegate.h"
#include "chrome/browser/autofill/test_autofill_external_delegate.h"
+#include "chrome/browser/autofill/test_autofill_manager_delegate.h"
#include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
@@ -26,55 +27,26 @@ using WebKit::WebAutofillClient;
namespace {
-class MockAutofillExternalDelegate :
- public autofill::TestAutofillExternalDelegate {
+class MockAutofillExternalDelegate : public AutofillExternalDelegate {
public:
MockAutofillExternalDelegate(content::WebContents* web_contents,
AutofillManager* autofill_manager)
- : TestAutofillExternalDelegate(web_contents, autofill_manager) {}
+ : AutofillExternalDelegate(web_contents, autofill_manager) {}
virtual ~MockAutofillExternalDelegate() {}
virtual void DidSelectSuggestion(int identifier) OVERRIDE {}
virtual void RemoveSuggestion(const string16& value, int identifier) OVERRIDE
{}
virtual void ClearPreviewedForm() OVERRIDE {}
-
- MOCK_METHOD0(ControllerDestroyed, void());
};
-class MockAutofillManagerDelegate : public autofill::AutofillManagerDelegate {
+class MockAutofillManagerDelegate
+ : public autofill::TestAutofillManagerDelegate {
public:
MockAutofillManagerDelegate() {}
virtual ~MockAutofillManagerDelegate() {}
- // AutofillManagerDelegate:
- virtual PersonalDataManager* GetPersonalDataManager() OVERRIDE {
- return NULL;
- }
- virtual InfoBarService* GetInfoBarService() { return NULL; }
virtual PrefService* GetPrefs() { return &prefs_; }
- virtual ProfileSyncServiceBase* GetProfileSyncService() { return NULL; }
- virtual void HideRequestAutocompleteDialog() OVERRIDE {}
- virtual bool IsSavingPasswordsEnabled() const { return false; }
- virtual void OnAutocheckoutError() OVERRIDE {}
- virtual void ShowAutofillSettings() {}
- virtual void ShowPasswordGenerationBubble(
- const gfx::Rect& bounds,
- const content::PasswordForm& form,
- autofill::PasswordGenerator* generator) {}
- virtual void ShowAutocheckoutBubble(
- const gfx::RectF& bounding_box,
- const gfx::NativeView& native_view,
- const base::Closure& callback) {}
- virtual void ShowRequestAutocompleteDialog(
- const FormData& form,
- const GURL& source_url,
- const content::SSLStatus& ssl_status,
- const AutofillMetrics& metric_logger,
- autofill::DialogType dialog_type,
- const base::Callback<void(const FormStructure*)>& callback) {}
- virtual void RequestAutocompleteDialogClosed() {}
- virtual void UpdateProgressBar(double value) {}
private:
TestingPrefServiceSimple prefs_;
diff --git a/chrome/browser/ui/autofill/tab_autofill_manager_delegate.cc b/chrome/browser/ui/autofill/tab_autofill_manager_delegate.cc
index b5457d8..22d1ed9 100644
--- a/chrome/browser/ui/autofill/tab_autofill_manager_delegate.cc
+++ b/chrome/browser/ui/autofill/tab_autofill_manager_delegate.cc
@@ -20,6 +20,7 @@
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/common/url_constants.h"
+#include "content/public/browser/web_contents_view.h"
#include "content/public/common/password_form.h"
#include "ui/gfx/rect.h"
@@ -31,10 +32,14 @@ TabAutofillManagerDelegate::TabAutofillManagerDelegate(
content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
web_contents_(web_contents),
- autofill_dialog_controller_(NULL) {
+ dialog_controller_(NULL) {
DCHECK(web_contents);
}
+TabAutofillManagerDelegate::~TabAutofillManagerDelegate() {
+ HideAutofillPopup();
+}
+
InfoBarService* TabAutofillManagerDelegate::GetInfoBarService() {
return InfoBarService::FromWebContents(web_contents_);
}
@@ -61,8 +66,8 @@ bool TabAutofillManagerDelegate::IsSavingPasswordsEnabled() const {
}
void TabAutofillManagerDelegate::OnAutocheckoutError() {
- // TODO(ahutter): Notify |autofill_dialog_controller_| of the error once it
- // stays open for Autocheckout.
+ // TODO(ahutter): Notify |dialog_controller_| of the error once it stays open
+ // for Autocheckout.
}
void TabAutofillManagerDelegate::ShowAutofillSettings() {
@@ -103,7 +108,7 @@ void TabAutofillManagerDelegate::ShowRequestAutocompleteDialog(
const base::Callback<void(const FormStructure*)>& callback) {
HideRequestAutocompleteDialog();
- autofill_dialog_controller_ =
+ dialog_controller_ =
new autofill::AutofillDialogControllerImpl(web_contents_,
form,
source_url,
@@ -111,21 +116,49 @@ void TabAutofillManagerDelegate::ShowRequestAutocompleteDialog(
metric_logger,
dialog_type,
callback);
- autofill_dialog_controller_->Show();
+ dialog_controller_->Show();
}
void TabAutofillManagerDelegate::RequestAutocompleteDialogClosed() {
- autofill_dialog_controller_ = NULL;
+ dialog_controller_ = NULL;
+}
+
+void TabAutofillManagerDelegate::ShowAutofillPopup(
+ const gfx::RectF& element_bounds,
+ const std::vector<string16>& values,
+ const std::vector<string16>& labels,
+ const std::vector<string16>& icons,
+ const std::vector<int>& identifiers,
+ AutofillPopupDelegate* delegate) {
+ // Convert element_bounds to be in screen space.
+ gfx::Rect client_area;
+ web_contents_->GetView()->GetContainerBounds(&client_area);
+ gfx::RectF element_bounds_in_screen_space =
+ element_bounds + client_area.OffsetFromOrigin();
+
+ // Will delete or reuse the old |popup_controller_|.
+ popup_controller_ = AutofillPopupControllerImpl::GetOrCreate(
+ popup_controller_,
+ delegate,
+ web_contents()->GetView()->GetContentNativeView(),
+ element_bounds_in_screen_space);
+
+ popup_controller_->Show(values, labels, icons, identifiers);
+}
+
+void TabAutofillManagerDelegate::HideAutofillPopup() {
+ if (popup_controller_)
+ popup_controller_->Hide();
}
void TabAutofillManagerDelegate::UpdateProgressBar(double value) {
- // TODO(ahutter): Notify |autofill_dialog_controller_| of the change once it
- // stays open for Autocheckout.
+ // TODO(ahutter): Notify |dialog_controller_| of the change once it stays open
+ // for Autocheckout.
}
void TabAutofillManagerDelegate::HideRequestAutocompleteDialog() {
- if (autofill_dialog_controller_) {
- autofill_dialog_controller_->Hide();
+ if (dialog_controller_) {
+ dialog_controller_->Hide();
RequestAutocompleteDialogClosed();
}
}
@@ -133,8 +166,8 @@ void TabAutofillManagerDelegate::HideRequestAutocompleteDialog() {
void TabAutofillManagerDelegate::DidNavigateMainFrame(
const content::LoadCommittedDetails& details,
const content::FrameNavigateParams& params) {
- if (autofill_dialog_controller_ &&
- autofill_dialog_controller_->dialog_type() ==
+ if (dialog_controller_ &&
+ dialog_controller_->dialog_type() ==
autofill::DIALOG_TYPE_REQUEST_AUTOCOMPLETE) {
HideRequestAutocompleteDialog();
}
diff --git a/chrome/browser/ui/autofill/tab_autofill_manager_delegate.h b/chrome/browser/ui/autofill/tab_autofill_manager_delegate.h
index 141c975..ed53ff0 100644
--- a/chrome/browser/ui/autofill/tab_autofill_manager_delegate.h
+++ b/chrome/browser/ui/autofill/tab_autofill_manager_delegate.h
@@ -6,11 +6,14 @@
#define CHROME_BROWSER_UI_AUTOFILL_TAB_AUTOFILL_MANAGER_DELEGATE_H_
#include "base/compiler_specific.h"
+#include "base/memory/weak_ptr.h"
#include "chrome/browser/autofill/autofill_manager_delegate.h"
#include "chrome/browser/ui/autofill/autofill_dialog_types.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
+class AutofillPopupControllerImpl;
+
namespace content {
struct FrameNavigateParams;
struct LoadCommittedDetails;
@@ -27,7 +30,7 @@ class TabAutofillManagerDelegate
public content::WebContentsUserData<TabAutofillManagerDelegate>,
public content::WebContentsObserver {
public:
- virtual ~TabAutofillManagerDelegate() {}
+ virtual ~TabAutofillManagerDelegate();
// AutofillManagerDelegate implementation.
virtual InfoBarService* GetInfoBarService() OVERRIDE;
@@ -54,6 +57,13 @@ class TabAutofillManagerDelegate
DialogType dialog_type,
const base::Callback<void(const FormStructure*)>& callback) OVERRIDE;
virtual void RequestAutocompleteDialogClosed() OVERRIDE;
+ virtual void ShowAutofillPopup(const gfx::RectF& element_bounds,
+ const std::vector<string16>& values,
+ const std::vector<string16>& labels,
+ const std::vector<string16>& icons,
+ const std::vector<int>& identifiers,
+ AutofillPopupDelegate* delegate) OVERRIDE;
+ virtual void HideAutofillPopup() OVERRIDE;
virtual void UpdateProgressBar(double value) OVERRIDE;
// content::WebContentsObserver implementation.
@@ -66,7 +76,8 @@ class TabAutofillManagerDelegate
friend class content::WebContentsUserData<TabAutofillManagerDelegate>;
content::WebContents* const web_contents_;
- AutofillDialogControllerImpl* autofill_dialog_controller_; // weak.
+ AutofillDialogControllerImpl* dialog_controller_; // weak.
+ base::WeakPtr<AutofillPopupControllerImpl> popup_controller_;
DISALLOW_COPY_AND_ASSIGN(TabAutofillManagerDelegate);
};
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index 7c5a540..9f09db0 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -50,6 +50,8 @@
'browser/autofill/data_driven_test.h',
'browser/autofill/test_autofill_external_delegate.cc',
'browser/autofill/test_autofill_external_delegate.h',
+ 'browser/autofill/test_autofill_manager_delegate.cc',
+ 'browser/autofill/test_autofill_manager_delegate.h',
'browser/automation/mock_tab_event_observer.cc',
'browser/automation/mock_tab_event_observer.h',
'browser/browsing_data/mock_browsing_data_appcache_helper.cc',
@@ -1622,8 +1624,8 @@
'service/cloud_print/cloud_print_token_store_unittest.cc',
'service/cloud_print/cloud_print_url_fetcher_unittest.cc',
'service/cloud_print/connector_settings_unittest.cc',
- 'service/cloud_print/printer_job_handler_unittest.cc',
- 'service/cloud_print/printer_job_queue_handler_unittest.cc',
+ 'service/cloud_print/printer_job_handler_unittest.cc',
+ 'service/cloud_print/printer_job_queue_handler_unittest.cc',
'service/service_process_prefs_unittest.cc',
'service/service_process_unittest.cc',
'test/base/browser_with_test_window_test.cc',