diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-23 05:26:40 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-23 05:26:40 +0000 |
commit | ce2f39e2f3206f375584d717999c743da6670bbf (patch) | |
tree | 320c1722c95d9027771ed1d8a442dd3379e7b6dc | |
parent | 19a02a38120fd47eec89b0ed5a3ba1d32fa24f07 (diff) | |
download | chromium_src-ce2f39e2f3206f375584d717999c743da6670bbf.zip chromium_src-ce2f39e2f3206f375584d717999c743da6670bbf.tar.gz chromium_src-ce2f39e2f3206f375584d717999c743da6670bbf.tar.bz2 |
improved testing for AutofillDialogView.
- add new interface for assisting in testing of AutofillDialogView
- refactor AutofillDialogController browser tests.
- write test which should pass after the linked bug is fixed, but which currently fails.
BUG=231988
TBR=sail@chromium.org
Review URL: https://chromiumcodereview.appspot.com/14096012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195722 0039d316-1c4b-4281-b951-d872f2087c98
16 files changed, 287 insertions, 153 deletions
diff --git a/chrome/browser/ui/android/autofill/autofill_dialog_view_android.cc b/chrome/browser/ui/android/autofill/autofill_dialog_view_android.cc index 6a95754..1d68229 100644 --- a/chrome/browser/ui/android/autofill/autofill_dialog_view_android.cc +++ b/chrome/browser/ui/android/autofill/autofill_dialog_view_android.cc @@ -261,14 +261,6 @@ void AutofillDialogViewAndroid::ModelChanged() { UpdateSection(SECTION_SHIPPING, CLEAR_USER_INPUT); } -void AutofillDialogViewAndroid::SubmitForTesting() { - controller_->OnAccept(); -} - -void AutofillDialogViewAndroid::CancelForTesting() { - controller_->OnCancel(); -} - // TODO(aruslan): bind to the list of accounts population. std::vector<std::string> AutofillDialogViewAndroid::GetAvailableUserAccounts() { std::vector<std::string> account_names; diff --git a/chrome/browser/ui/android/autofill/autofill_dialog_view_android.h b/chrome/browser/ui/android/autofill/autofill_dialog_view_android.h index b46196a..b1fd07d 100644 --- a/chrome/browser/ui/android/autofill/autofill_dialog_view_android.h +++ b/chrome/browser/ui/android/autofill/autofill_dialog_view_android.h @@ -37,8 +37,6 @@ class AutofillDialogViewAndroid : public AutofillDialogView { virtual void HideSignIn() OVERRIDE; virtual void UpdateProgressBar(double value) OVERRIDE; virtual void ModelChanged() OVERRIDE; - virtual void SubmitForTesting() OVERRIDE; - virtual void CancelForTesting() OVERRIDE; // Java to C++ calls void ItemSelected(JNIEnv* env, jobject obj, jint section, jint index); diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc index 0db3e48..2a1e3bb 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc @@ -9,10 +9,13 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" #include "chrome/browser/ui/autofill/autofill_dialog_view.h" +#include "chrome/browser/ui/autofill/testable_autofill_dialog_view.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/test/base/in_process_browser_test.h" +#include "components/autofill/browser/autofill_common_test.h" #include "components/autofill/browser/autofill_metrics.h" +#include "components/autofill/browser/test_personal_data_manager.h" #include "components/autofill/common/form_data.h" #include "components/autofill/common/form_field_data.h" #include "content/public/test/test_utils.h" @@ -107,6 +110,18 @@ class TestAutofillDialogController : public AutofillDialogControllerImpl { // Increase visibility for testing. AutofillDialogView* view() { return AutofillDialogControllerImpl::view(); } + const DetailInput* input_showing_popup() const { + return AutofillDialogControllerImpl::input_showing_popup(); + } + + TestPersonalDataManager* GetTestingManager() { + return &test_manager_; + } + + protected: + virtual PersonalDataManager* GetManager() OVERRIDE { + return &test_manager_; + } private: // To specify our own metric logger. @@ -115,6 +130,7 @@ class TestAutofillDialogController : public AutofillDialogControllerImpl { } const AutofillMetrics& metric_logger_; + TestPersonalDataManager test_manager_; scoped_refptr<content::MessageLoopRunner> message_loop_runner_; DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); @@ -127,136 +143,139 @@ class AutofillDialogControllerTest : public InProcessBrowserTest { AutofillDialogControllerTest() {} virtual ~AutofillDialogControllerTest() {} - content::WebContents* GetActiveWebContents() { - return browser()->tab_strip_model()->GetActiveWebContents(); - } + void InitializeControllerOfType(DialogType dialog_type) { + FormData form; + form.name = ASCIIToUTF16("TestForm"); + form.method = ASCIIToUTF16("POST"); + form.origin = GURL("http://example.com/form.html"); + form.action = GURL("http://example.com/submit.html"); + form.user_submitted = true; + + FormFieldData field; + field.autocomplete_attribute = "email"; + form.fields.push_back(field); - TestAutofillDialogController* CreateController( - const FormData& form, - const AutofillMetrics& metric_logger, - const DialogType dialog_type) { message_loop_runner_ = new content::MessageLoopRunner; - return new TestAutofillDialogController( - GetActiveWebContents(), form, metric_logger, message_loop_runner_, + controller_ = new TestAutofillDialogController( + GetActiveWebContents(), + form, + metric_logger_, + message_loop_runner_, dialog_type); + controller_->Show(); } + content::WebContents* GetActiveWebContents() { + return browser()->tab_strip_model()->GetActiveWebContents(); + } + + const MockAutofillMetrics& metric_logger() { return metric_logger_; } + TestAutofillDialogController* controller() { return controller_; } + void RunMessageLoop() { message_loop_runner_->Run(); } private: + MockAutofillMetrics metric_logger_; + TestAutofillDialogController* controller_; // Weak reference. scoped_refptr<content::MessageLoopRunner> message_loop_runner_; DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest); }; -// TODO(isherman): Enable this test on other platforms once the UI is +// TODO(isherman): Enable these tests on other platforms once the UI is // implemented on those platforms. #if defined(TOOLKIT_VIEWS) -#define MAYBE_RequestAutocompleteUiDurationMetrics \ - RequestAutocompleteUiDurationMetrics -#else -#define MAYBE_RequestAutocompleteUiDurationMetrics \ - DISABLED_RequestAutocompleteUiDurationMetrics -#endif // defined(TOOLKIT_VIEWS) -IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, - MAYBE_RequestAutocompleteUiDurationMetrics) { - FormData form; - form.name = ASCIIToUTF16("TestForm"); - form.method = ASCIIToUTF16("POST"); - form.origin = GURL("http://example.com/form.html"); - form.action = GURL("http://example.com/submit.html"); - form.user_submitted = true; - - FormFieldData field; - field.autocomplete_attribute = "email"; - form.fields.push_back(field); - - // Submit the form data. - { - MockAutofillMetrics metric_logger; - TestAutofillDialogController* dialog_controller = CreateController( - form, metric_logger, DIALOG_TYPE_REQUEST_AUTOCOMPLETE); - dialog_controller->Show(); - dialog_controller->view()->SubmitForTesting(); - - RunMessageLoop(); - - EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, - metric_logger.dialog_dismissal_action()); - EXPECT_EQ(DIALOG_TYPE_REQUEST_AUTOCOMPLETE, metric_logger.dialog_type()); - } +// Submit the form data. +IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, Submit) { + InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); + controller()->view()->GetTestableView()->SubmitForTesting(); - // Cancel out of the dialog. - { - MockAutofillMetrics metric_logger; - TestAutofillDialogController* dialog_controller = CreateController( - form, metric_logger, DIALOG_TYPE_AUTOCHECKOUT); - dialog_controller->Show(); - dialog_controller->view()->CancelForTesting(); + RunMessageLoop(); - RunMessageLoop(); + EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, + metric_logger().dialog_dismissal_action()); + EXPECT_EQ(DIALOG_TYPE_REQUEST_AUTOCOMPLETE, metric_logger().dialog_type()); +} - EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, - metric_logger.dialog_dismissal_action()); - EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger.dialog_type()); - } +// Cancel out of the dialog. +IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, Cancel) { + InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); + controller()->view()->GetTestableView()->CancelForTesting(); - // Take some other action that dismisses the dialog. - { - MockAutofillMetrics metric_logger; - TestAutofillDialogController* dialog_controller = CreateController( - form, metric_logger, DIALOG_TYPE_AUTOCHECKOUT); - dialog_controller->Show(); - dialog_controller->Hide(); + RunMessageLoop(); - RunMessageLoop(); + EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, + metric_logger().dialog_dismissal_action()); + EXPECT_EQ(DIALOG_TYPE_REQUEST_AUTOCOMPLETE, metric_logger().dialog_type()); +} - EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, - metric_logger.dialog_dismissal_action()); - EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger.dialog_type()); - } +// Take some other action that dismisses the dialog. +IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, Hide) { + InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); + controller()->Hide(); + RunMessageLoop(); - // Test Autocheckout success metrics. - { - MockAutofillMetrics metric_logger; - TestAutofillDialogController* dialog_controller = CreateController( - form, metric_logger, DIALOG_TYPE_AUTOCHECKOUT); - dialog_controller->Show(); - dialog_controller->view()->SubmitForTesting(); + EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, + metric_logger().dialog_dismissal_action()); + EXPECT_EQ(DIALOG_TYPE_REQUEST_AUTOCOMPLETE, metric_logger().dialog_type()); +} - EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, - metric_logger.dialog_dismissal_action()); - EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger.dialog_type()); +// Test Autocheckout success metrics. +IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AutocheckoutSuccess) { + InitializeControllerOfType(DIALOG_TYPE_AUTOCHECKOUT); + controller()->view()->GetTestableView()->SubmitForTesting(); - dialog_controller->Hide(); + EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, + metric_logger().dialog_dismissal_action()); + EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type()); - RunMessageLoop(); + controller()->Hide(); + RunMessageLoop(); - EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_SUCCEEDED, - metric_logger.autocheckout_status()); - } + EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_SUCCEEDED, + metric_logger().autocheckout_status()); +} - // Test Autocheckout failure metric. - { - MockAutofillMetrics metric_logger; - TestAutofillDialogController* dialog_controller = CreateController( - form, metric_logger, DIALOG_TYPE_AUTOCHECKOUT); - dialog_controller->Show(); - dialog_controller->view()->SubmitForTesting(); +// Test Autocheckout failure metric. +IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AutocheckoutError) { + InitializeControllerOfType(DIALOG_TYPE_AUTOCHECKOUT); + controller()->view()->GetTestableView()->SubmitForTesting(); - EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, - metric_logger.dialog_dismissal_action()); - EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger.dialog_type()); + EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, + metric_logger().dialog_dismissal_action()); + EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type()); - dialog_controller->OnAutocheckoutError(); - dialog_controller->view()->CancelForTesting(); + controller()->OnAutocheckoutError(); + controller()->view()->GetTestableView()->CancelForTesting(); - RunMessageLoop(); + RunMessageLoop(); - EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_FAILED, - metric_logger.autocheckout_status()); - } + EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_FAILED, + metric_logger().autocheckout_status()); } +// TODO(estade): fix the code so this test passes. http://crbug.com/231988 +IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, + DISABLED_FillInputFromAutofill) { + InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); + + AutofillProfile full_profile(test::GetFullProfile()); + controller()->GetTestingManager()->AddTestingProfile(&full_profile); + + const DetailInputs& inputs = + controller()->RequestedFieldsForSection(SECTION_SHIPPING); + const DetailInput& input = inputs[0]; + string16 value = full_profile.GetRawInfo(input.type); + TestableAutofillDialogView* view = controller()->view()->GetTestableView(); + view->SetTextContentsOfInput(input, value.substr(0, value.size() / 2)); + view->ActivateInput(input); + + ASSERT_EQ(&input, controller()->input_showing_popup()); + + controller()->DidAcceptSuggestion(string16(), 0); + EXPECT_EQ(value, view->GetTextContentsOfInput(input)); +} +#endif // defined(TOOLKIT_VIEWS) + } // namespace autofill diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.h b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.h index fa89a8f..c0feb8c 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.h +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.h @@ -232,6 +232,9 @@ class AutofillDialogControllerImpl : public AutofillDialogController, // Exposed for testing. AutofillDialogView* view() { return view_.get(); } virtual AutofillDialogView* CreateView(); + const DetailInput* input_showing_popup() const { + return input_showing_popup_; + } // Returns the PersonalDataManager for |profile_|. virtual PersonalDataManager* GetManager(); diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc index 4434099..10b76afb 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc @@ -13,6 +13,7 @@ #include "chrome/test/base/testing_profile.h" #include "components/autofill/browser/autofill_common_test.h" #include "components/autofill/browser/autofill_metrics.h" +#include "components/autofill/browser/test_personal_data_manager.h" #include "components/autofill/browser/wallet/full_wallet.h" #include "components/autofill/browser/wallet/instrument.h" #include "components/autofill/browser/wallet/wallet_address.h" @@ -63,8 +64,6 @@ class TestAutofillDialogView : public AutofillDialogView { } virtual void HideSignIn() OVERRIDE {} virtual void UpdateProgressBar(double value) OVERRIDE {} - virtual void SubmitForTesting() OVERRIDE {} - virtual void CancelForTesting() OVERRIDE {} MOCK_METHOD0(ModelChanged, void()); @@ -78,33 +77,6 @@ class TestAutofillDialogView : public AutofillDialogView { DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogView); }; -class TestPersonalDataManager : public PersonalDataManager { - public: - TestPersonalDataManager() : PersonalDataManager("en-US") {} - virtual ~TestPersonalDataManager() {} - - void AddTestingProfile(AutofillProfile* profile) { - profiles_.push_back(profile); - FOR_EACH_OBSERVER(PersonalDataManagerObserver, observers_, - OnPersonalDataChanged()); - } - - virtual const std::vector<AutofillProfile*>& GetProfiles() OVERRIDE { - return profiles_; - } - - virtual void SaveImportedProfile(const AutofillProfile& imported_profile) - OVERRIDE { - imported_profile_ = imported_profile; - } - - const AutofillProfile& imported_profile() { return imported_profile_; } - - private: - std::vector<AutofillProfile*> profiles_; - AutofillProfile imported_profile_; -}; - class TestWalletClient : public wallet::WalletClient { public: TestWalletClient(net::URLRequestContextGetter* context, diff --git a/chrome/browser/ui/autofill/autofill_dialog_view.cc b/chrome/browser/ui/autofill/autofill_dialog_view.cc index dc5914a..a4442e4 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_view.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_view.cc @@ -6,6 +6,8 @@ #include "chrome/browser/ui/autofill/autofill_dialog_view.h" +#include "chrome/browser/ui/autofill/testable_autofill_dialog_view.h" + namespace autofill { AutofillDialogView::~AutofillDialogView() {} @@ -18,4 +20,10 @@ AutofillDialogView* AutofillDialogView::Create( } #endif +TestableAutofillDialogView* AutofillDialogView::GetTestableView() { + return NULL; +} + +TestableAutofillDialogView::~TestableAutofillDialogView() {} + } // namespace autofill diff --git a/chrome/browser/ui/autofill/autofill_dialog_view.h b/chrome/browser/ui/autofill/autofill_dialog_view.h index 6a38637..f4b377b 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_view.h +++ b/chrome/browser/ui/autofill/autofill_dialog_view.h @@ -13,6 +13,8 @@ class NavigationController; namespace autofill { +class TestableAutofillDialogView; + // An interface for the dialog that appears when a site initiates an Autofill // action via the imperative autocomplete API. class AutofillDialogView { @@ -64,11 +66,10 @@ class AutofillDialogView { // Called when the active suggestions data model changed. virtual void ModelChanged() = 0; - // Simulates the user pressing 'Submit' to accept the dialog. - virtual void SubmitForTesting() = 0; - - // Simulates the user pressing 'Cancel' to abort the dialog. - virtual void CancelForTesting() = 0; + // Returns an object that can be used to test that the view is behaving as + // expected. This should be implemented on all platforms, but for now returns + // NULL on everything but Views. + virtual TestableAutofillDialogView* GetTestableView(); // Factory function to create the dialog (implemented once per view // implementation). |controller| will own the created dialog. diff --git a/chrome/browser/ui/autofill/testable_autofill_dialog_view.h b/chrome/browser/ui/autofill/testable_autofill_dialog_view.h new file mode 100644 index 0000000..87e48db --- /dev/null +++ b/chrome/browser/ui/autofill/testable_autofill_dialog_view.h @@ -0,0 +1,35 @@ +// 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. + +#ifndef CHROME_BROWSER_UI_AUTOFILL_TESTABLE_AUTOFILL_DIALOG_VIEW_H_ +#define CHROME_BROWSER_UI_AUTOFILL_TESTABLE_AUTOFILL_DIALOG_VIEW_H_ + +namespace autofill { + +// Functions that an AutofillDialogView implementation should implement in order +// to assist in unit testing. +class TestableAutofillDialogView { + public: + virtual ~TestableAutofillDialogView(); + + // Simulates the user pressing 'Submit' to accept the dialog. + virtual void SubmitForTesting() = 0; + + // Simulates the user pressing 'Cancel' to abort the dialog. + virtual void CancelForTesting() = 0; + + // Returns the actual contents of the input which is modelled by |input|. + virtual string16 GetTextContentsOfInput(const DetailInput& input) = 0; + + // Sets the actual contents of the input which is modelled by |input|. + virtual void SetTextContentsOfInput(const DetailInput& input, + const string16& contents) = 0; + + // Simulates a user activatino of the input which is modelled by |input|. + virtual void ActivateInput(const DetailInput& input) = 0; +}; + +} // namespace autofill + +#endif // CHROME_BROWSER_UI_AUTOFILL_TESTABLE_AUTOFILL_DIALOG_VIEW_H_ diff --git a/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h b/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h index d7471c0..30a3595 100644 --- a/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h +++ b/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h @@ -46,8 +46,6 @@ class AutofillDialogCocoa : public AutofillDialogView, virtual void HideSignIn() OVERRIDE; virtual void UpdateProgressBar(double value) OVERRIDE; virtual void ModelChanged() OVERRIDE; - virtual void SubmitForTesting() OVERRIDE; - virtual void CancelForTesting() OVERRIDE; // ConstrainedWindowMacDelegate implementation. virtual void OnConstrainedWindowClosed( diff --git a/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.mm b/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.mm index 7c12e96..32fe9c0 100644 --- a/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.mm +++ b/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.mm @@ -84,12 +84,6 @@ void AutofillDialogCocoa::UpdateProgressBar(double value) {} void AutofillDialogCocoa::ModelChanged() {} -void AutofillDialogCocoa::SubmitForTesting() {} - -void AutofillDialogCocoa::CancelForTesting() { - PerformClose(); -} - void AutofillDialogCocoa::OnConstrainedWindowClosed( ConstrainedWindowMac* window) { constrained_window_.reset(); diff --git a/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa_browsertest.mm b/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa_browsertest.mm index f04fb01..a52299a 100644 --- a/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa_browsertest.mm +++ b/chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa_browsertest.mm @@ -53,8 +53,10 @@ class TestAutofillDialogController : public AutofillDialogControllerImpl { runner_->Run(); } - // Increase visibility for testing. - AutofillDialogView* view() { return AutofillDialogControllerImpl::view(); } + AutofillDialogCocoa* GetView() { + return static_cast<AutofillDialogCocoa*>( + AutofillDialogControllerImpl::view()); + } private: // To specify our own metric logger. @@ -111,7 +113,7 @@ class AutofillDialogCocoaBrowserTest : public InProcessBrowserTest { #endif IN_PROC_BROWSER_TEST_F(AutofillDialogCocoaBrowserTest, MAYBE_DisplayUI) { controller()->Show(); - controller()->view()->CancelForTesting(); + controller()->GetView()->PerformClose(); controller()->RunMessageLoop(); } diff --git a/chrome/browser/ui/views/autofill/autofill_dialog_views.cc b/chrome/browser/ui/views/autofill/autofill_dialog_views.cc index 6a0ce17..b89b07f 100644 --- a/chrome/browser/ui/views/autofill/autofill_dialog_views.cc +++ b/chrome/browser/ui/views/autofill/autofill_dialog_views.cc @@ -753,6 +753,10 @@ void AutofillDialogViews::ModelChanged() { } } +TestableAutofillDialogView* AutofillDialogViews::GetTestableView() { + return this; +} + void AutofillDialogViews::SubmitForTesting() { Accept(); } @@ -762,6 +766,19 @@ void AutofillDialogViews::CancelForTesting() { Hide(); } +string16 AutofillDialogViews::GetTextContentsOfInput(const DetailInput& input) { + return TextfieldForInput(input)->text(); +} + +void AutofillDialogViews::SetTextContentsOfInput(const DetailInput& input, + const string16& contents) { + TextfieldForInput(input)->SetText(contents); +} + +void AutofillDialogViews::ActivateInput(const DetailInput& input) { + TextfieldEditedOrActivated(TextfieldForInput(input), false); +} + string16 AutofillDialogViews::GetWindowTitle() const { return controller_->DialogTitle(); } @@ -1363,6 +1380,19 @@ AutofillDialogViews::DetailsGroup* AutofillDialogViews::GroupForView( return NULL; } +views::Textfield* AutofillDialogViews::TextfieldForInput( + const DetailInput& input) { + for (DetailGroupMap::iterator iter = detail_groups_.begin(); + iter != detail_groups_.end(); ++iter) { + TextfieldMap::iterator text_mapping = iter->second.textfields.find(&input); + if (text_mapping != iter->second.textfields.end()) + return text_mapping->second->textfield(); + } + + NOTREACHED(); + return NULL; +} + AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) : section(section), container(NULL), diff --git a/chrome/browser/ui/views/autofill/autofill_dialog_views.h b/chrome/browser/ui/views/autofill/autofill_dialog_views.h index 374697e..b5086d1 100644 --- a/chrome/browser/ui/views/autofill/autofill_dialog_views.h +++ b/chrome/browser/ui/views/autofill/autofill_dialog_views.h @@ -10,6 +10,7 @@ #include "base/memory/weak_ptr.h" #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" #include "chrome/browser/ui/autofill/autofill_dialog_view.h" +#include "chrome/browser/ui/autofill/testable_autofill_dialog_view.h" #include "ui/views/controls/button/button.h" #include "ui/views/controls/button/menu_button_listener.h" #include "ui/views/controls/combobox/combobox_listener.h" @@ -56,6 +57,7 @@ struct DetailInput; // Views toolkit implementation of the Autofill dialog that handles the // imperative autocomplete API call. class AutofillDialogViews : public AutofillDialogView, + public TestableAutofillDialogView, public views::DialogDelegate, public views::ButtonListener, public views::TextfieldController, @@ -83,8 +85,15 @@ class AutofillDialogViews : public AutofillDialogView, virtual void HideSignIn() OVERRIDE; virtual void UpdateProgressBar(double value) OVERRIDE; virtual void ModelChanged() OVERRIDE; + virtual TestableAutofillDialogView* GetTestableView() OVERRIDE; + + // TestableAutofillDialogView implementation: virtual void SubmitForTesting() OVERRIDE; virtual void CancelForTesting() OVERRIDE; + virtual string16 GetTextContentsOfInput(const DetailInput& input) OVERRIDE; + virtual void SetTextContentsOfInput(const DetailInput& input, + const string16& contents) OVERRIDE; + virtual void ActivateInput(const DetailInput& input) OVERRIDE; // views::DialogDelegate implementation: virtual string16 GetWindowTitle() const OVERRIDE; @@ -424,6 +433,9 @@ class AutofillDialogViews : public AutofillDialogView, // Call this when the size of anything in |contents_| might've changed. void ContentsPreferredSizeChanged(); + // Gets the textfield view that is shown for the given DetailInput model. + views::Textfield* TextfieldForInput(const DetailInput& input); + // The controller that drives this view. Weak pointer, always non-NULL. AutofillDialogController* const controller_; diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index 4f0f736..d2998c8 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -280,6 +280,8 @@ '../components/autofill/browser/test_autofill_external_delegate.h', '../components/autofill/browser/test_autofill_manager_delegate.cc', '../components/autofill/browser/test_autofill_manager_delegate.h', + '../components/autofill/browser/test_personal_data_manager.cc', + '../components/autofill/browser/test_personal_data_manager.h', '../ui/gfx/image/image_unittest_util.h', '../ui/gfx/image/image_unittest_util.cc', diff --git a/components/autofill/browser/test_personal_data_manager.cc b/components/autofill/browser/test_personal_data_manager.cc new file mode 100644 index 0000000..98e1973 --- /dev/null +++ b/components/autofill/browser/test_personal_data_manager.cc @@ -0,0 +1,31 @@ +// Copyright 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 "components/autofill/browser/test_personal_data_manager.h" + +#include "components/autofill/browser/personal_data_manager_observer.h" + +namespace autofill { + +TestPersonalDataManager::TestPersonalDataManager() + : PersonalDataManager("en-US") {} + +TestPersonalDataManager::~TestPersonalDataManager() {} + +void TestPersonalDataManager::AddTestingProfile(AutofillProfile* profile) { + profiles_.push_back(profile); + FOR_EACH_OBSERVER(PersonalDataManagerObserver, observers_, + OnPersonalDataChanged()); +} + +const std::vector<AutofillProfile*>& TestPersonalDataManager::GetProfiles() { + return profiles_; +} + +void TestPersonalDataManager::SaveImportedProfile( + const AutofillProfile& imported_profile) { + imported_profile_ = imported_profile; +} + +} // namespace autofill diff --git a/components/autofill/browser/test_personal_data_manager.h b/components/autofill/browser/test_personal_data_manager.h new file mode 100644 index 0000000..e0b8c21 --- /dev/null +++ b/components/autofill/browser/test_personal_data_manager.h @@ -0,0 +1,37 @@ +// Copyright 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 COMPONENTS_BROWSER_AUTOFILL_TEST_PERSONAL_DATA_MANAGER_H_ +#define COMPONENTS_BROWSER_AUTOFILL_TEST_PERSONAL_DATA_MANAGER_H_ + +#include <vector> + +#include "components/autofill/browser/autofill_profile.h" +#include "components/autofill/browser/personal_data_manager.h" + +namespace autofill { + +// A simplistic PersonalDataManager used for testing. +class TestPersonalDataManager : public PersonalDataManager { + public: + TestPersonalDataManager(); + virtual ~TestPersonalDataManager(); + + // Adds |profile| to |profiles_|. This does not take ownership of |profile|. + void AddTestingProfile(AutofillProfile* profile); + + virtual const std::vector<AutofillProfile*>& GetProfiles() OVERRIDE; + virtual void SaveImportedProfile(const AutofillProfile& imported_profile) + OVERRIDE; + + const AutofillProfile& imported_profile() { return imported_profile_; } + + private: + std::vector<AutofillProfile*> profiles_; + AutofillProfile imported_profile_; +}; + +} // namespace autofill + +#endif // COMPONENTS_BROWSER_AUTOFILL_TEST_PERSONAL_DATA_MANAGER_H_ |