1 // Copyright 2014 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.
5 #include "chrome/browser/ui/views/autofill/autofill_dialog_view_tester_views.h"
7 #include "base/logging.h"
8 #include "chrome/browser/ui/views/autofill/autofill_dialog_views.h"
9 #include "chrome/browser/ui/views/autofill/expanding_textfield.h"
10 #include "ui/base/models/combobox_model.h"
11 #include "ui/views/controls/combobox/combobox.h"
12 #include "ui/views/controls/textfield/textfield.h"
13 #include "ui/views/controls/webview/webview.h"
14 #include "ui/views/widget/widget.h"
15 #include "ui/views/window/dialog_client_view.h"
19 scoped_ptr
<AutofillDialogViewTester
> AutofillDialogViewTester::For(
20 AutofillDialogView
* view
) {
21 return scoped_ptr
<AutofillDialogViewTester
>(new
22 AutofillDialogViewTesterViews(static_cast<AutofillDialogViews
*>(view
)));
25 AutofillDialogViewTesterViews::AutofillDialogViewTesterViews(
26 AutofillDialogViews
* view
)
29 AutofillDialogViewTesterViews::~AutofillDialogViewTesterViews() {}
31 void AutofillDialogViewTesterViews::SubmitForTesting() {
35 void AutofillDialogViewTesterViews::CancelForTesting() {
36 view_
->GetDialogClientView()->CancelWindow();
39 base::string16
AutofillDialogViewTesterViews::GetTextContentsOfInput(
40 ServerFieldType type
) {
41 ExpandingTextfield
* textfield
= view_
->TextfieldForType(type
);
43 return textfield
->GetText();
45 views::Combobox
* combobox
= view_
->ComboboxForType(type
);
47 return combobox
->model()->GetItemAt(combobox
->selected_index());
50 return base::string16();
53 void AutofillDialogViewTesterViews::SetTextContentsOfInput(
55 const base::string16
& contents
) {
56 ExpandingTextfield
* textfield
= view_
->TextfieldForType(type
);
58 textfield
->SetText(contents
);
62 views::Combobox
* combobox
= view_
->ComboboxForType(type
);
64 if (!combobox
->SelectValue(contents
))
65 combobox
->SetSelectedIndex(combobox
->model()->GetDefaultIndex());
72 void AutofillDialogViewTesterViews::SetTextContentsOfSuggestionInput(
73 DialogSection section
,
74 const base::string16
& text
) {
75 view_
->GroupForSection(section
)->suggested_info
->textfield()->SetText(text
);
78 void AutofillDialogViewTesterViews::ActivateInput(ServerFieldType type
) {
79 view_
->InputEditedOrActivated(type
, gfx::Rect(), false);
82 gfx::Size
AutofillDialogViewTesterViews::GetSize() const {
83 return view_
->GetWidget() ? view_
->GetWidget()->GetRootView()->size() :
87 bool AutofillDialogViewTesterViews::IsShowingSection(DialogSection section
)
89 return view_
->GroupForSection(section
)->container
->visible();
92 } // namespace autofill