summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgroby@chromium.org <groby@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-20 01:05:58 +0000
committergroby@chromium.org <groby@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-20 01:05:58 +0000
commit243f55f68ef7a32d3d1c7f11ff26dfcf5cdda112 (patch)
tree61c4a7bb61d5815cc017d5eb76c08b24749c7170
parent30c4e38db36476b71b2cda57635aa7fd45102d55 (diff)
downloadchromium_src-243f55f68ef7a32d3d1c7f11ff26dfcf5cdda112.zip
chromium_src-243f55f68ef7a32d3d1c7f11ff26dfcf5cdda112.tar.gz
chromium_src-243f55f68ef7a32d3d1c7f11ff26dfcf5cdda112.tar.bz2
[rAC] Complete mock object.
Make all functions of MockAutofillDialogController mockable via gtest. R=isherman@chromium.org BUG=none Review URL: https://chromiumcodereview.appspot.com/19278007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@212710 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc199
-rw-r--r--chrome/browser/ui/autofill/mock_autofill_dialog_controller.h105
2 files changed, 83 insertions, 221 deletions
diff --git a/chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc b/chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc
index 6ca8614..3718086 100644
--- a/chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc
+++ b/chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc
@@ -3,15 +3,32 @@
// found in the LICENSE file.
#include "chrome/browser/ui/autofill/mock_autofill_dialog_controller.h"
+#include "content/public/browser/native_web_keyboard_event.h" // For gmock.
#include "grit/generated_resources.h"
-#include "testing/gmock/include/gmock/gmock.h"
+#include "ui/gfx/rect.h" // Only needed because gmock needs complete types.
namespace autofill {
MockAutofillDialogController::MockAutofillDialogController() {
- testing::DefaultValue<const DetailInputs&>::Set(default_inputs_);
- testing::DefaultValue<ui::ComboboxModel*>::Set(NULL);
- testing::DefaultValue<ValidityData>::Set(ValidityData());
+ using testing::DefaultValue;
+ using testing::_;
+ using testing::Return;
+ using testing::ReturnRef;
+
+ // N.B. Setting DefaultValue in the ctor and deleting it in the dtor will
+ // only work if this Mock is not used together with other mock code that
+ // sets different defaults. If tests utilizing the MockController start
+ // breaking because of this, use ON_CALL instead.
+ DefaultValue<const DetailInputs&>::Set(default_inputs_);
+ DefaultValue<string16>::Set(string16());
+ DefaultValue<ValidityData>::Set(ValidityData());
+ DefaultValue<DialogSignedInState>::Set(REQUIRES_RESPONSE);
+ DefaultValue<gfx::Image>::Set(gfx::Image());
+ DefaultValue<SuggestionState>::Set(SuggestionState(string16(),
+ gfx::Font::NORMAL,
+ gfx::Image(),
+ string16(),
+ gfx::Image()));
// SECTION_CC *must* have a CREDIT_CARD_VERIFICATION_CODE field.
const DetailInput kCreditCardInputs[] = {
@@ -19,172 +36,28 @@ MockAutofillDialogController::MockAutofillDialogController() {
};
cc_default_inputs_.push_back(kCreditCardInputs[0]);
ON_CALL(*this, RequestedFieldsForSection(SECTION_CC))
- .WillByDefault(testing::ReturnRef(cc_default_inputs_));
+ .WillByDefault(ReturnRef(cc_default_inputs_));
+
+ ON_CALL(*this, GetDialogButtons())
+ .WillByDefault(Return(ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL));
+ ON_CALL(*this, LegalDocumentLinks()).WillByDefault(ReturnRef(range_));
// Activate all sections but CC_BILLING - default for the real
// controller implementation, too.
- ON_CALL(*this, SectionIsActive(testing::_))
- .WillByDefault(testing::Return(true));
+ ON_CALL(*this, SectionIsActive(_)).WillByDefault(Return(true));
ON_CALL(*this, SectionIsActive(SECTION_CC_BILLING))
- .WillByDefault(testing::Return(false));
+ .WillByDefault(Return(false));
}
MockAutofillDialogController::~MockAutofillDialogController() {
- testing::DefaultValue<ValidityData>::Clear();
- testing::DefaultValue<ui::ComboboxModel*>::Clear();
- testing::DefaultValue<const DetailInputs&>::Clear();
-}
-
-string16 MockAutofillDialogController::DialogTitle() const {
- return string16();
-}
-
-string16 MockAutofillDialogController::AccountChooserText() const {
- return string16();
-}
-
-string16 MockAutofillDialogController::SignInLinkText() const {
- return string16();
-}
-
-string16 MockAutofillDialogController::EditSuggestionText() const {
- return string16();
-}
-
-string16 MockAutofillDialogController::CancelButtonText() const {
- return string16();
-}
-
-string16 MockAutofillDialogController::ConfirmButtonText() const {
- return string16();
-}
-
-string16 MockAutofillDialogController::SaveLocallyText() const {
- return string16();
-}
-
-string16 MockAutofillDialogController::LegalDocumentsText() {
- return string16();
-}
-
-DialogSignedInState MockAutofillDialogController::SignedInState() const {
- return REQUIRES_RESPONSE;
-}
-
-bool MockAutofillDialogController::ShouldShowSpinner() const {
- return false;
-}
-
-gfx::Image MockAutofillDialogController::AccountChooserImage() {
- return gfx::Image();
-}
-
-bool MockAutofillDialogController::ShouldShowDetailArea() const {
- return false;
-}
-
-bool MockAutofillDialogController::ShouldShowProgressBar() const {
- return false;
-}
-
-int MockAutofillDialogController::GetDialogButtons() const {
- return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL;
-}
-
-bool MockAutofillDialogController::IsDialogButtonEnabled(
- ui::DialogButton button) const {
- return false;
-}
-
-DialogOverlayState MockAutofillDialogController::GetDialogOverlay() const {
- return DialogOverlayState();
-}
-
-const std::vector<ui::Range>&
- MockAutofillDialogController::LegalDocumentLinks() {
- return range_;
-}
-
-string16 MockAutofillDialogController::LabelForSection(
- DialogSection section) const {
- return string16();
-}
-
-SuggestionState MockAutofillDialogController::SuggestionStateForSection(
- DialogSection section) {
- return SuggestionState(string16(),
- gfx::Font::NORMAL,
- gfx::Image(),
- string16(),
- gfx::Image());
-}
-
-void MockAutofillDialogController::EditClickedForSection(
- DialogSection section) {}
-
-void MockAutofillDialogController::EditCancelledForSection(
- DialogSection section) {}
-
-gfx::Image MockAutofillDialogController::IconForField(
- AutofillFieldType type, const string16& user_input) const {
- return gfx::Image();
-}
-
-string16 MockAutofillDialogController::InputValidityMessage(
- DialogSection section,
- AutofillFieldType type,
- const string16& value) {
- return string16();
-}
-
-void MockAutofillDialogController::UserEditedOrActivatedInput(
- DialogSection section,
- const DetailInput* input,
- gfx::NativeView parent_view,
- const gfx::Rect& content_bounds,
- const string16& field_contents,
- bool was_edit) {}
-
-bool MockAutofillDialogController::HandleKeyPressEventInInput(
- const content::NativeWebKeyboardEvent& event) {
- return false;
-}
-
-void MockAutofillDialogController::FocusMoved() {}
-
-gfx::Image MockAutofillDialogController::SplashPageImage() const {
- return gfx::Image();
-}
-
-void MockAutofillDialogController::ViewClosed() {}
-
-std::vector<DialogNotification> MockAutofillDialogController::
- CurrentNotifications() {
- return std::vector<DialogNotification>();
-}
-
-std::vector<DialogAutocheckoutStep> MockAutofillDialogController::
- CurrentAutocheckoutSteps() const {
- return std::vector<DialogAutocheckoutStep>();
-}
-
-void MockAutofillDialogController::SignInLinkClicked() {}
-
-void MockAutofillDialogController::NotificationCheckboxStateChanged(
- DialogNotification::Type type,
- bool checked) {}
-
-void MockAutofillDialogController::LegalDocumentLinkClicked(
- const ui::Range& range) {}
-
-void MockAutofillDialogController::OverlayButtonPressed() {}
-
-void MockAutofillDialogController::OnCancel() {}
-
-void MockAutofillDialogController::OnAccept() {}
-
-content::WebContents* MockAutofillDialogController::web_contents() {
- return NULL;
+ using testing::DefaultValue;
+
+ DefaultValue<SuggestionState>::Clear();
+ DefaultValue<gfx::Image>::Clear();
+ DefaultValue<DialogSignedInState>::Clear();
+ DefaultValue<ValidityData>::Clear();
+ DefaultValue<string16>::Clear();
+ DefaultValue<const DetailInputs&>::Clear();
}
} // namespace autofill
diff --git a/chrome/browser/ui/autofill/mock_autofill_dialog_controller.h b/chrome/browser/ui/autofill/mock_autofill_dialog_controller.h
index 61a25d3..8e90d5f 100644
--- a/chrome/browser/ui/autofill/mock_autofill_dialog_controller.h
+++ b/chrome/browser/ui/autofill/mock_autofill_dialog_controller.h
@@ -15,76 +15,65 @@ class MockAutofillDialogController : public AutofillDialogController {
MockAutofillDialogController();
virtual ~MockAutofillDialogController();
- virtual string16 DialogTitle() const OVERRIDE;
- virtual string16 AccountChooserText() const OVERRIDE;
- virtual string16 SignInLinkText() const OVERRIDE;
- virtual string16 EditSuggestionText() const OVERRIDE;
- virtual string16 CancelButtonText() const OVERRIDE;
- virtual string16 ConfirmButtonText() const OVERRIDE;
- virtual string16 SaveLocallyText() const OVERRIDE;
- virtual string16 LegalDocumentsText() OVERRIDE;
- virtual DialogSignedInState SignedInState() const OVERRIDE;
- virtual bool ShouldShowSpinner() const OVERRIDE;
+ MOCK_CONST_METHOD0(DialogTitle, string16());
+ MOCK_CONST_METHOD0(AccountChooserText, string16());
+ MOCK_CONST_METHOD0(SignInLinkText, string16());
+ MOCK_CONST_METHOD0(EditSuggestionText, string16());
+ MOCK_CONST_METHOD0(CancelButtonText, string16());
+ MOCK_CONST_METHOD0(ConfirmButtonText, string16());
+ MOCK_CONST_METHOD0(SaveLocallyText, string16());
+ MOCK_METHOD0(LegalDocumentsText, string16());
+ MOCK_CONST_METHOD0(SignedInState, DialogSignedInState());
+ MOCK_CONST_METHOD0(ShouldShowSpinner, bool());
MOCK_CONST_METHOD0(ShouldOfferToSaveInChrome, bool());
MOCK_METHOD0(MenuModelForAccountChooser, ui::MenuModel*());
- virtual gfx::Image AccountChooserImage() OVERRIDE;
- virtual bool ShouldShowProgressBar() const OVERRIDE;
- virtual int GetDialogButtons() const OVERRIDE;
- virtual bool ShouldShowDetailArea() const OVERRIDE;
- virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE;
- virtual DialogOverlayState GetDialogOverlay() const OVERRIDE;
- virtual const std::vector<ui::Range>& LegalDocumentLinks() OVERRIDE;
+ MOCK_METHOD0(AccountChooserImage, gfx::Image());
+ MOCK_CONST_METHOD0(ShouldShowProgressBar, bool());
+ MOCK_CONST_METHOD0(GetDialogButtons, int());
+ MOCK_CONST_METHOD0(ShouldShowDetailArea, bool());
+ MOCK_CONST_METHOD1(IsDialogButtonEnabled, bool(ui::DialogButton button));
+ MOCK_CONST_METHOD0(GetDialogOverlay, DialogOverlayState());
+ MOCK_METHOD0(LegalDocumentLinks, const std::vector<ui::Range>&());
MOCK_CONST_METHOD1(SectionIsActive, bool(DialogSection));
MOCK_CONST_METHOD1(RequestedFieldsForSection,
const DetailInputs&(DialogSection));
MOCK_METHOD1(ComboboxModelForAutofillType,
ui::ComboboxModel*(AutofillFieldType));
MOCK_METHOD1(MenuModelForSection, ui::MenuModel*(DialogSection));
- virtual string16 LabelForSection(DialogSection section) const OVERRIDE;
- virtual SuggestionState SuggestionStateForSection(
- DialogSection section) OVERRIDE;
- virtual void EditClickedForSection(DialogSection section) OVERRIDE;
- virtual void EditCancelledForSection(DialogSection section) OVERRIDE;
- virtual gfx::Image IconForField(AutofillFieldType type,
- const string16& user_input) const OVERRIDE;
- virtual string16 InputValidityMessage(
- DialogSection section,
- AutofillFieldType type,
- const string16& value) OVERRIDE;
+ MOCK_CONST_METHOD1(LabelForSection, string16(DialogSection section));
+ MOCK_METHOD1(SuggestionStateForSection, SuggestionState(DialogSection));
+ MOCK_METHOD1(EditClickedForSection, void(DialogSection section));
+ MOCK_METHOD1(EditCancelledForSection, void(DialogSection section));
+ MOCK_CONST_METHOD2(IconForField,
+ gfx::Image(AutofillFieldType, const string16&));
+ MOCK_METHOD3(InputValidityMessage,
+ string16(DialogSection, AutofillFieldType, const string16&));
MOCK_METHOD3(InputsAreValid, ValidityData(DialogSection,
const DetailOutputMap&,
ValidationType));
- virtual void UserEditedOrActivatedInput(DialogSection section,
- const DetailInput* input,
- gfx::NativeView parent_view,
- const gfx::Rect& content_bounds,
- const string16& field_contents,
- bool was_edit) OVERRIDE;
- virtual bool HandleKeyPressEventInInput(
- const content::NativeWebKeyboardEvent& event) OVERRIDE;
-
- virtual void FocusMoved() OVERRIDE;
-
- virtual gfx::Image SplashPageImage() const OVERRIDE;
-
- virtual void ViewClosed() OVERRIDE;
-
- virtual std::vector<DialogNotification> CurrentNotifications() OVERRIDE;
-
- virtual std::vector<DialogAutocheckoutStep> CurrentAutocheckoutSteps()
- const OVERRIDE;
-
- virtual void SignInLinkClicked() OVERRIDE;
- virtual void NotificationCheckboxStateChanged(DialogNotification::Type type,
- bool checked) OVERRIDE;
-
- virtual void LegalDocumentLinkClicked(const ui::Range& range) OVERRIDE;
- virtual void OverlayButtonPressed() OVERRIDE;
- virtual void OnCancel() OVERRIDE;
- virtual void OnAccept() OVERRIDE;
-
+ MOCK_METHOD6(UserEditedOrActivatedInput,void(DialogSection,
+ const DetailInput*,
+ gfx::NativeView,
+ const gfx::Rect&,
+ const string16&,
+ bool was_edit));
+ MOCK_METHOD1(HandleKeyPressEventInInput,
+ bool(const content::NativeWebKeyboardEvent& event));
+ MOCK_METHOD0(FocusMoved, void());
+ MOCK_CONST_METHOD0(SplashPageImage, gfx::Image());
+ MOCK_METHOD0(ViewClosed, void());
+ MOCK_METHOD0(CurrentNotifications,std::vector<DialogNotification>());
+ MOCK_CONST_METHOD0(CurrentAutocheckoutSteps,
+ std::vector<DialogAutocheckoutStep>());
+ MOCK_METHOD0(SignInLinkClicked, void());
+ MOCK_METHOD2(NotificationCheckboxStateChanged,
+ void(DialogNotification::Type, bool));
+ MOCK_METHOD1(LegalDocumentLinkClicked, void(const ui::Range&));
+ MOCK_METHOD0(OverlayButtonPressed, void());
+ MOCK_METHOD0(OnCancel, void());
+ MOCK_METHOD0(OnAccept, void());
MOCK_METHOD0(profile, Profile*());
- virtual content::WebContents* web_contents() OVERRIDE;
+ MOCK_METHOD0(web_contents, content::WebContents*());
private:
DetailInputs default_inputs_;
DetailInputs cc_default_inputs_; // Default inputs for SECTION_CC.