diff options
author | csharp@chromium.org <csharp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-05 18:18:42 +0000 |
---|---|---|
committer | csharp@chromium.org <csharp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-05 18:18:42 +0000 |
commit | 61fd4dc472f8990d53b6773d98ef9c090dc33789 (patch) | |
tree | 25eb6a9cb4ee1832a59ebfc1eda5a26166699f80 /chrome/browser/autofill/autofill_external_delegate_unittest.cc | |
parent | c385b2015f0969f9885f1284123d23c578ed8d8b (diff) | |
download | chromium_src-61fd4dc472f8990d53b6773d98ef9c090dc33789.zip chromium_src-61fd4dc472f8990d53b6773d98ef9c090dc33789.tar.gz chromium_src-61fd4dc472f8990d53b6773d98ef9c090dc33789.tar.bz2 |
First pass for new GTK Autofill popup.
This first pass just displays the new Autofill popup and then hides it at the
correct times. The box is the correct size, but none of the text is drawn at the
moment. This is only enabled when the --external-autofill-popup flag is enabled.
BUG=51644
Review URL: http://codereview.chromium.org/8890035
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116512 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill/autofill_external_delegate_unittest.cc')
-rw-r--r-- | chrome/browser/autofill/autofill_external_delegate_unittest.cc | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/chrome/browser/autofill/autofill_external_delegate_unittest.cc b/chrome/browser/autofill/autofill_external_delegate_unittest.cc new file mode 100644 index 0000000..f9e6f6c --- /dev/null +++ b/chrome/browser/autofill/autofill_external_delegate_unittest.cc @@ -0,0 +1,106 @@ +// Copyright (c) 2012 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 <vector> + +#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/ui/tab_contents/test_tab_contents_wrapper.h" +#include "chrome/test/base/testing_profile.h" +#include "content/test/test_browser_thread.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "ui/gfx/rect.h" +#include "webkit/forms/form_data.h" +#include "webkit/forms/form_field.h" + +using content::BrowserThread; +using testing::_; +using webkit::forms::FormData; +using webkit::forms::FormField; + +namespace { + +class MockAutofillExternalDelegate : public AutofillExternalDelegate { + public: + explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper, + AutofillManager* autofill_manager) + : AutofillExternalDelegate(wrapper, autofill_manager) {} + virtual ~MockAutofillExternalDelegate() {} + + virtual void HideAutofillPopup() OVERRIDE {} + + MOCK_METHOD5(ApplyAutofillSuggestions, void( + 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, + int separator_index)); + + MOCK_METHOD4(OnQueryPlatformSpecific, + void(int query_id, + const webkit::forms::FormData& form, + const webkit::forms::FormField& field, + const gfx::Rect& bounds)); + + private: + DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); +}; + +} // namespace + +class AutofillExternalDelegateTest : public TabContentsWrapperTestHarness { + public: + AutofillExternalDelegateTest() + : ui_thread_(BrowserThread::UI, &message_loop_) {} + virtual ~AutofillExternalDelegateTest() {} + + virtual void SetUp() OVERRIDE { + TabContentsWrapperTestHarness::SetUp(); + autofill_manager_ = new AutofillManager(contents_wrapper()); + } + + protected: + scoped_refptr<AutofillManager> autofill_manager_; + + private: + content::TestBrowserThread ui_thread_; + + DISALLOW_COPY_AND_ASSIGN(AutofillExternalDelegateTest); +}; + +// Test that our external delegate called the virtual methods at the right time. +TEST_F(AutofillExternalDelegateTest, TestExternalDelegateVirtualCalls) { + MockAutofillExternalDelegate external_delegate(contents_wrapper(), + autofill_manager_); + const int kQueryId = 5; + const FormData form; + FormField field; + field.is_focusable = true; + field.should_autocomplete = true; + const gfx::Rect bounds; + + EXPECT_CALL(external_delegate, + OnQueryPlatformSpecific(kQueryId, form, field, bounds)); + + // This should call OnQueryPlatform specific. + external_delegate.OnQuery(kQueryId, form, field, bounds, false); + + + 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); +} |