mock_autofill_dialog_view_delegate.cc revision 8bcbed890bc3ce4d7a057a8f32cab53fa534672e
1// Copyright 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/browser/ui/autofill/mock_autofill_dialog_view_delegate.h" 6#include "content/public/browser/native_web_keyboard_event.h" // For gmock. 7#include "grit/generated_resources.h" 8#include "ui/gfx/rect.h" // Only needed because gmock needs complete types. 9 10namespace autofill { 11 12MockAutofillDialogViewDelegate::MockAutofillDialogViewDelegate() { 13 using testing::DefaultValue; 14 using testing::_; 15 using testing::Return; 16 using testing::ReturnRef; 17 18 // N.B. Setting DefaultValue in the ctor and deleting it in the dtor will 19 // only work if this Mock is not used together with other mock code that 20 // sets different defaults. If tests utilizing the MockController start 21 // breaking because of this, use ON_CALL instead. 22 DefaultValue<const DetailInputs&>::Set(default_inputs_); 23 DefaultValue<string16>::Set(string16()); 24 DefaultValue<ValidityMessages>::Set(ValidityMessages()); 25 DefaultValue<gfx::Image>::Set(gfx::Image()); 26 DefaultValue<SuggestionState>::Set(SuggestionState(false, 27 string16(), 28 string16(), 29 gfx::Image(), 30 string16(), 31 gfx::Image())); 32 DefaultValue<FieldIconMap>::Set(FieldIconMap()); 33 DefaultValue<std::vector<DialogNotification> >::Set( 34 std::vector<DialogNotification>()); 35 36 // SECTION_CC *must* have a CREDIT_CARD_VERIFICATION_CODE field. 37 const DetailInput kCreditCardInputs[] = { 38 { 2, CREDIT_CARD_VERIFICATION_CODE, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC } 39 }; 40 cc_default_inputs_.push_back(kCreditCardInputs[0]); 41 ON_CALL(*this, RequestedFieldsForSection(SECTION_CC)) 42 .WillByDefault(ReturnRef(cc_default_inputs_)); 43 44 ON_CALL(*this, GetDialogButtons()) 45 .WillByDefault(Return(ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL)); 46 ON_CALL(*this, LegalDocumentLinks()).WillByDefault(ReturnRef(range_)); 47 48 // Activate all sections but CC_BILLING - default for the real 49 // controller implementation, too. 50 ON_CALL(*this, SectionIsActive(_)).WillByDefault(Return(true)); 51 ON_CALL(*this, SectionIsActive(SECTION_CC_BILLING)) 52 .WillByDefault(Return(false)); 53} 54 55void MockAutofillDialogViewDelegate::SetWebContents( 56 content::WebContents* contents) { 57 testing::DefaultValue<content::WebContents*>::Set(contents); 58} 59 60MockAutofillDialogViewDelegate::~MockAutofillDialogViewDelegate() { 61 using testing::DefaultValue; 62 63 DefaultValue<SuggestionState>::Clear(); 64 DefaultValue<gfx::Image>::Clear(); 65 DefaultValue<ValidityMessages>::Clear(); 66 DefaultValue<string16>::Clear(); 67 DefaultValue<const DetailInputs&>::Clear(); 68 DefaultValue<FieldIconMap>::Clear(); 69 DefaultValue<std::vector<DialogNotification> >::Clear(); 70 DefaultValue<content::WebContents*>::Clear(); 71} 72 73} // namespace autofill 74