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 "chrome/grit/generated_resources.h"
7#include "content/public/browser/native_web_keyboard_event.h"  // For gmock.
8#include "ui/base/l10n/l10n_util.h"
9#include "ui/gfx/rect.h"  // Only needed because gmock needs complete types.
10
11namespace autofill {
12
13MockAutofillDialogViewDelegate::MockAutofillDialogViewDelegate() {
14  using testing::DefaultValue;
15  using testing::_;
16  using testing::Return;
17  using testing::ReturnRef;
18
19  // N.B. Setting DefaultValue in the ctor and deleting it in the dtor will
20  // only work if this Mock is not used together with other mock code that
21  // sets different defaults. If tests utilizing the MockController start
22  // breaking because of this, use ON_CALL instead.
23  DefaultValue<const DetailInputs&>::Set(default_inputs_);
24  DefaultValue<base::string16>::Set(base::string16());
25  DefaultValue<GURL>::Set(GURL());
26  DefaultValue<ValidityMessages>::Set(ValidityMessages());
27  DefaultValue<gfx::Image>::Set(gfx::Image());
28  DefaultValue<SuggestionState>::Set(SuggestionState(false,
29                                                     base::string16(),
30                                                     base::string16(),
31                                                     gfx::Image(),
32                                                     base::string16(),
33                                                     gfx::Image()));
34  DefaultValue<FieldIconMap>::Set(FieldIconMap());
35  DefaultValue<std::vector<DialogNotification> >::Set(
36      std::vector<DialogNotification>());
37
38  // SECTION_CC *must* have a CREDIT_CARD_VERIFICATION_CODE field.
39  const DetailInput kCreditCardInputs[] = {
40    { DetailInput::SHORT,
41      CREDIT_CARD_VERIFICATION_CODE,
42      l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC) }
43  };
44  cc_default_inputs_.push_back(kCreditCardInputs[0]);
45  ON_CALL(*this, RequestedFieldsForSection(SECTION_CC))
46      .WillByDefault(ReturnRef(cc_default_inputs_));
47  ON_CALL(*this, RequestedFieldsForSection(SECTION_CC_BILLING))
48      .WillByDefault(ReturnRef(cc_default_inputs_));
49
50  ON_CALL(*this, GetDialogButtons())
51      .WillByDefault(Return(ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL));
52  ON_CALL(*this, LegalDocumentLinks()).WillByDefault(ReturnRef(range_));
53
54  // Activate all sections but CC_BILLING - default for the real
55  // controller implementation, too.
56  ON_CALL(*this, SectionIsActive(_)).WillByDefault(Return(true));
57  ON_CALL(*this, SectionIsActive(SECTION_CC_BILLING))
58      .WillByDefault(Return(false));
59}
60
61void MockAutofillDialogViewDelegate::SetWebContents(
62    content::WebContents* contents) {
63  testing::DefaultValue<content::WebContents*>::Set(contents);
64}
65
66void MockAutofillDialogViewDelegate::SetProfile(Profile* profile) {
67  testing::DefaultValue<Profile*>::Set(profile);
68}
69
70MockAutofillDialogViewDelegate::~MockAutofillDialogViewDelegate() {
71  using testing::DefaultValue;
72
73  DefaultValue<SuggestionState>::Clear();
74  DefaultValue<gfx::Image>::Clear();
75  DefaultValue<ValidityMessages>::Clear();
76  DefaultValue<base::string16>::Clear();
77  DefaultValue<GURL>::Clear();
78  DefaultValue<const DetailInputs&>::Clear();
79  DefaultValue<FieldIconMap>::Clear();
80  DefaultValue<std::vector<DialogNotification> >::Clear();
81  DefaultValue<content::WebContents*>::Clear();
82  DefaultValue<Profile*>::Clear();
83}
84
85}  // namespace autofill
86