|
|
Created:
7 years, 5 months ago by groby-ooo-7-16 Modified:
7 years, 5 months ago Reviewers:
Ilya Sherman CC:
chromium-reviews, Raman Kakilate, benquan, ahutter, Dane Wallinga, dyu1, estade+watch_chromium.org, Albert Bodenhamer, Ilya Sherman, rouslan+autofillwatch_chromium.org Base URL:
svn://svn.chromium.org/chrome/trunk/src Visibility:
Public. |
Description[rAC] Complete mock object.
Make all functions of MockAutofillDialogController mockable via gtest.
R=isherman@chromium.org
BUG=none
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=212710
Patch Set 1 #
Total comments: 8
Patch Set 2 : Review fixes. More default values. #Patch Set 3 : Merge to HEAD. #
Messages
Total messages: 7 (0 generated)
Instead of fixing the functions piecemeal, updated all of MockAutofillDialogController to be gmockable.
LGTM w/nits. https://codereview.chromium.org/19278007/diff/1/chrome/browser/ui/autofill/mo... File chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc (right): https://codereview.chromium.org/19278007/diff/1/chrome/browser/ui/autofill/mo... chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc:6: #include "content/public/browser/native_web_keyboard_event.h" // For gtest. I'm confused... you're not using gtest in this file. Do you mean gmock? https://codereview.chromium.org/19278007/diff/1/chrome/browser/ui/autofill/mo... chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc:8: #include "testing/gmock/include/gmock/gmock.h" nit: Already included in the header. https://codereview.chromium.org/19278007/diff/1/chrome/browser/ui/autofill/mo... chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc:9: #include "ui/gfx/rect.h" // Only needed because gtest needs complete types. Ditto https://codereview.chromium.org/19278007/diff/1/chrome/browser/ui/autofill/mo... chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc:13: using namespace testing; nit: "using namespace" is disallowed by the style guide.
Addressed review comments. Also, added more default values so tests don't crash any more. (gmock can't actually just create defaults even if a default ctor exists. Not enough template magic has been applied :) https://codereview.chromium.org/19278007/diff/1/chrome/browser/ui/autofill/mo... File chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc (right): https://codereview.chromium.org/19278007/diff/1/chrome/browser/ui/autofill/mo... chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc:6: #include "content/public/browser/native_web_keyboard_event.h" // For gtest. On 2013/07/16 21:21:56, Ilya Sherman wrote: > I'm confused... you're not using gtest in this file. Do you mean gmock? Done. https://codereview.chromium.org/19278007/diff/1/chrome/browser/ui/autofill/mo... chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc:8: #include "testing/gmock/include/gmock/gmock.h" On 2013/07/16 21:21:56, Ilya Sherman wrote: > nit: Already included in the header. Done. https://codereview.chromium.org/19278007/diff/1/chrome/browser/ui/autofill/mo... chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc:9: #include "ui/gfx/rect.h" // Only needed because gtest needs complete types. On 2013/07/16 21:21:56, Ilya Sherman wrote: > Ditto Done. https://codereview.chromium.org/19278007/diff/1/chrome/browser/ui/autofill/mo... chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc:13: using namespace testing; On 2013/07/16 21:21:56, Ilya Sherman wrote: > nit: "using namespace" is disallowed by the style guide. Done. TMYK.
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/groby@chromium.org/19278007/10001
Failed to apply patch for chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc: While running patch -p1 --forward --force --no-backup-if-mismatch; patching file chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc Hunk #2 FAILED at 36. 1 out of 2 hunks FAILED -- saving rejects to file chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc.rej Patch: chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc Index: chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc diff --git a/chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc b/chrome/browser/ui/autofill/mock_autofill_dialog_controller.cc index f1295673d8998b8f2271070cd959a9406e584fcb..371808695f49aa46f95918544d2d93f1bbb9d5e5 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,176 +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; -} - -bool MockAutofillDialogController::ShouldOfferToSaveInChrome() 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
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/groby@chromium.org/19278007/21001
Message was sent while issue was closed.
Change committed as 212710 |