mock_autofill_dialog_view_delegate.cc revision 1e9bf3e0803691d0a228da41fc608347b6db4340
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<GURL>::Set(GURL()); 25 DefaultValue<ValidityMessages>::Set(ValidityMessages()); 26 DefaultValue<gfx::Image>::Set(gfx::Image()); 27 DefaultValue<SuggestionState>::Set(SuggestionState(false, 28 string16(), 29 string16(), 30 gfx::Image(), 31 string16(), 32 gfx::Image())); 33 DefaultValue<FieldIconMap>::Set(FieldIconMap()); 34 DefaultValue<std::vector<DialogNotification> >::Set( 35 std::vector<DialogNotification>()); 36 37 // SECTION_CC *must* have a CREDIT_CARD_VERIFICATION_CODE field. 38 const DetailInput kCreditCardInputs[] = { 39 { 2, CREDIT_CARD_VERIFICATION_CODE, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC } 40 }; 41 cc_default_inputs_.push_back(kCreditCardInputs[0]); 42 ON_CALL(*this, RequestedFieldsForSection(SECTION_CC)) 43 .WillByDefault(ReturnRef(cc_default_inputs_)); 44 45 ON_CALL(*this, GetDialogButtons()) 46 .WillByDefault(Return(ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL)); 47 ON_CALL(*this, LegalDocumentLinks()).WillByDefault(ReturnRef(range_)); 48 49 // Activate all sections but CC_BILLING - default for the real 50 // controller implementation, too. 51 ON_CALL(*this, SectionIsActive(_)).WillByDefault(Return(true)); 52 ON_CALL(*this, SectionIsActive(SECTION_CC_BILLING)) 53 .WillByDefault(Return(false)); 54} 55 56void MockAutofillDialogViewDelegate::SetWebContents( 57 content::WebContents* contents) { 58 testing::DefaultValue<content::WebContents*>::Set(contents); 59} 60 61void MockAutofillDialogViewDelegate::SetProfile(Profile* profile) { 62 testing::DefaultValue<Profile*>::Set(profile); 63} 64 65MockAutofillDialogViewDelegate::~MockAutofillDialogViewDelegate() { 66 using testing::DefaultValue; 67 68 DefaultValue<SuggestionState>::Clear(); 69 DefaultValue<gfx::Image>::Clear(); 70 DefaultValue<ValidityMessages>::Clear(); 71 DefaultValue<string16>::Clear(); 72 DefaultValue<GURL>::Clear(); 73 DefaultValue<const DetailInputs&>::Clear(); 74 DefaultValue<FieldIconMap>::Clear(); 75 DefaultValue<std::vector<DialogNotification> >::Clear(); 76 DefaultValue<content::WebContents*>::Clear(); 77 DefaultValue<Profile*>::Clear(); 78} 79 80} // namespace autofill 81