Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6374)

Unified Diff: chrome/browser/autofill/autofill_external_delegate_unittest.cc

Issue 9235072: Adding Mouse Support for new GTK Autofill (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixing problem with autofillAgent browser tests Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autofill/autofill_external_delegate_unittest.cc
diff --git a/chrome/browser/autofill/autofill_external_delegate_unittest.cc b/chrome/browser/autofill/autofill_external_delegate_unittest.cc
index f9e6f6c0a65f19df99879fde185e8d60d7bbee1e..e0ba283f60935c83805430e9f0f8f6899e3a7b9e 100644
--- a/chrome/browser/autofill/autofill_external_delegate_unittest.cc
+++ b/chrome/browser/autofill/autofill_external_delegate_unittest.cc
@@ -7,8 +7,8 @@
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/string16.h"
-#include "chrome/browser/autofill/autofill_external_delegate.h"
#include "chrome/browser/autofill/autofill_manager.h"
+#include "chrome/browser/autofill/test_autofill_external_delegate.h"
#include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h"
#include "chrome/test/base/testing_profile.h"
#include "content/test/test_browser_thread.h"
@@ -25,14 +25,12 @@ using webkit::forms::FormField;
namespace {
-class MockAutofillExternalDelegate : public AutofillExternalDelegate {
+class MockAutofillExternalDelegate : public TestAutofillExternalDelegate {
public:
- explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper,
- AutofillManager* autofill_manager)
- : AutofillExternalDelegate(wrapper, autofill_manager) {}
- virtual ~MockAutofillExternalDelegate() {}
-
- virtual void HideAutofillPopup() OVERRIDE {}
+ MockAutofillExternalDelegate(TabContentsWrapper* wrapper,
+ AutofillManager* autofill_manger)
+ : TestAutofillExternalDelegate(wrapper, autofill_manger) {}
+ ~MockAutofillExternalDelegate() {}
MOCK_METHOD5(ApplyAutofillSuggestions, void(
const std::vector<string16>& autofill_values,
@@ -47,36 +45,53 @@ class MockAutofillExternalDelegate : public AutofillExternalDelegate {
const webkit::forms::FormField& field,
const gfx::Rect& bounds));
+ MOCK_METHOD0(HideAutofillPopup, void());
+
private:
- DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate);
+ virtual void HideAutofillPopupInternal() {};
+};
+
+class MockAutofillManager : public AutofillManager {
+ public:
+ explicit MockAutofillManager(TabContentsWrapper* tab_contents)
+ : AutofillManager(tab_contents) {}
+ ~MockAutofillManager() {}
+
+ MOCK_METHOD4(OnFillAutofillFormData,
+ void(int query_id,
+ const webkit::forms::FormData& form,
+ const webkit::forms::FormField& field,
+ int unique_id));
};
} // namespace
-class AutofillExternalDelegateTest : public TabContentsWrapperTestHarness {
+class AutofillExternalDelegateUnitTest : public TabContentsWrapperTestHarness {
public:
- AutofillExternalDelegateTest()
+ AutofillExternalDelegateUnitTest()
: ui_thread_(BrowserThread::UI, &message_loop_) {}
- virtual ~AutofillExternalDelegateTest() {}
+ virtual ~AutofillExternalDelegateUnitTest() {}
virtual void SetUp() OVERRIDE {
TabContentsWrapperTestHarness::SetUp();
- autofill_manager_ = new AutofillManager(contents_wrapper());
+ autofill_manager_ = new MockAutofillManager(contents_wrapper());
+ external_delegate_.reset(new MockAutofillExternalDelegate(
+ contents_wrapper(),
+ autofill_manager_));
}
protected:
- scoped_refptr<AutofillManager> autofill_manager_;
+ scoped_refptr<MockAutofillManager> autofill_manager_;
+ scoped_ptr<MockAutofillExternalDelegate> external_delegate_;
private:
content::TestBrowserThread ui_thread_;
- DISALLOW_COPY_AND_ASSIGN(AutofillExternalDelegateTest);
+ DISALLOW_COPY_AND_ASSIGN(AutofillExternalDelegateUnitTest);
};
// Test that our external delegate called the virtual methods at the right time.
-TEST_F(AutofillExternalDelegateTest, TestExternalDelegateVirtualCalls) {
- MockAutofillExternalDelegate external_delegate(contents_wrapper(),
- autofill_manager_);
+TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) {
const int kQueryId = 5;
const FormData form;
FormField field;
@@ -84,23 +99,42 @@ TEST_F(AutofillExternalDelegateTest, TestExternalDelegateVirtualCalls) {
field.should_autocomplete = true;
const gfx::Rect bounds;
- EXPECT_CALL(external_delegate,
+ EXPECT_CALL(*external_delegate_,
OnQueryPlatformSpecific(kQueryId, form, field, bounds));
// This should call OnQueryPlatform specific.
- external_delegate.OnQuery(kQueryId, form, field, bounds, false);
-
+ external_delegate_->OnQuery(kQueryId, form, field, bounds, false);
- EXPECT_CALL(external_delegate, ApplyAutofillSuggestions(_, _, _, _, _));
+ EXPECT_CALL(*external_delegate_, ApplyAutofillSuggestions(_, _, _, _, _));
// This should call ApplyAutofillSuggestions.
std::vector<string16> autofill_item;
autofill_item.push_back(string16());
std::vector<int> autofill_ids;
autofill_ids.push_back(1);
- external_delegate.OnSuggestionsReturned(kQueryId,
- autofill_item,
- autofill_item,
- autofill_item,
- autofill_ids);
+ external_delegate_->OnSuggestionsReturned(kQueryId,
+ autofill_item,
+ autofill_item,
+ autofill_item,
+ autofill_ids);
+
+
+ EXPECT_CALL(*external_delegate_, HideAutofillPopup());
+
+ // This should trigger a call to hide the popup since
+ // we've selected an option.
+ external_delegate_->DidAcceptAutofillSuggestions(autofill_item[0],
+ autofill_ids[0], 0);
+}
+
+// Test that the Autofill delegate doesn't try and fill a form with a
+// negative unique id.
+TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) {
+ // Ensure it doesn't try to preview the negative id.
+ EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0);
+ external_delegate_->SelectAutofillSuggestionAtIndex(-1, 0);
+
+ // Ensure it doesn't try to fill the form in with the negative id.
+ EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0);
+ external_delegate_->DidAcceptAutofillSuggestions(string16(), -1, 0);
}
« no previous file with comments | « chrome/browser/autofill/autofill_external_delegate_gtk.cc ('k') | chrome/browser/autofill/autofill_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698